Simplify focus a lot by using transient windows
This commit is contained in:
parent
9034dc8f3b
commit
122c0dad16
@ -15,48 +15,11 @@ class WindowManager:
|
||||
ABSOLUTE = 0
|
||||
SCREEN_RELATIVE = 1
|
||||
|
||||
VISIBLE = 0
|
||||
SLIDED_IN = 1
|
||||
HIDDEN = 2
|
||||
|
||||
def __init__(self, window):
|
||||
self._window = window
|
||||
self._visibility = WindowManager.HIDDEN
|
||||
|
||||
WindowManager.__managers_list.append(self)
|
||||
|
||||
window.connect("key-press-event", self.__key_press_event_cb)
|
||||
window.connect("focus-in-event", self.__focus_in_event_cb)
|
||||
window.connect_after("focus-out-event", self.__focus_out_event_cb)
|
||||
|
||||
def has_focus(self):
|
||||
return self._window.has_toplevel_focus()
|
||||
|
||||
def _update_visibility(self):
|
||||
visible = False
|
||||
|
||||
if self._visibility is WindowManager.VISIBLE:
|
||||
visible = True
|
||||
elif self._visibility is WindowManager.HIDDEN:
|
||||
visible = False
|
||||
elif self._visibility is WindowManager.SLIDED_IN:
|
||||
for manager in WindowManager.__managers_list:
|
||||
if manager.has_focus():
|
||||
visible = True
|
||||
|
||||
if self._window.get_property('visible') != visible:
|
||||
self._window.set_property('visible', visible)
|
||||
|
||||
def __focus_change_idle(self):
|
||||
for manager in WindowManager.__managers_list:
|
||||
manager._update_visibility()
|
||||
return False
|
||||
|
||||
def __focus_in_event_cb(self, window, event):
|
||||
gobject.idle_add(self.__focus_change_idle)
|
||||
|
||||
def __focus_out_event_cb(self, window, event):
|
||||
gobject.idle_add(self.__focus_change_idle)
|
||||
WindowManager.__managers_list.append(self)
|
||||
|
||||
def __key_press_event_cb(self, window, event):
|
||||
manager = None
|
||||
@ -117,16 +80,13 @@ class WindowManager:
|
||||
self._window.resize(width, height)
|
||||
|
||||
def slide_window_in(self):
|
||||
self._visibility = WindowManager.SLIDED_IN
|
||||
self._update_visibility()
|
||||
self._window.show()
|
||||
|
||||
def slide_window_out(self):
|
||||
self._visibility = WindowManager.HIDDEN
|
||||
self._update_visibility()
|
||||
self._window.hide()
|
||||
|
||||
def show(self):
|
||||
self._visibility = WindowManager.VISIBLE
|
||||
self._window.show()
|
||||
|
||||
def manage(self):
|
||||
self._update_size_and_position()
|
||||
self._update_visibility()
|
||||
|
@ -215,7 +215,6 @@ class ActivityHost(dbus.service.Object):
|
||||
class ActivityContainer(dbus.service.Object):
|
||||
|
||||
def __init__(self, service, bus):
|
||||
|
||||
self.activities = []
|
||||
|
||||
self.bus = bus
|
||||
@ -225,7 +224,11 @@ class ActivityContainer(dbus.service.Object):
|
||||
bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
|
||||
|
||||
self.window = gtk.Window()
|
||||
self.window.connect("key-press-event", self.__key_press_event_cb)
|
||||
self.window.set_title("OLPC Sugar")
|
||||
|
||||
self._fullscreen = False
|
||||
|
||||
self.notebook = gtk.Notebook()
|
||||
|
||||
tab_label = gtk.Label("Everyone")
|
||||
@ -308,6 +311,15 @@ class ActivityContainer(dbus.service.Object):
|
||||
for owner, activity in self.activities:
|
||||
print " %d: owner=%s activity_object_name=%s" % (i, owner, activity.dbus_object_name)
|
||||
i += 1
|
||||
|
||||
def __key_press_event_cb(self, window, event):
|
||||
if event.keyval == gtk.keysyms.F11:
|
||||
if self._fullscreen:
|
||||
window.unfullscreen()
|
||||
self._fullscreen = False
|
||||
else:
|
||||
window.fullscreen()
|
||||
self._fullscreen = True
|
||||
|
||||
class ConsoleLogger(dbus.service.Object):
|
||||
def __init__(self):
|
||||
@ -383,6 +395,7 @@ def main():
|
||||
wm.manage()
|
||||
|
||||
presence_window = PresenceWindow(activity_container)
|
||||
presence_window.set_transient_for(activity_container.window)
|
||||
|
||||
wm = WindowManager(presence_window)
|
||||
|
||||
@ -392,6 +405,7 @@ def main():
|
||||
wm.manage()
|
||||
|
||||
group_chat = GroupChat()
|
||||
group_chat.set_transient_for(activity_container.window)
|
||||
group_chat.set_decorated(False)
|
||||
group_chat.set_skip_taskbar_hint(True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user