# HG changeset patch # User Jon Nordby # Date 1256230524 -7200 # Node ID f08e364e96e6c7850237bf2ac3c65b645fc72548 # Parent e363de9ac54978d2c307955184e33b68cc4f92ce systray: Keep running in tray. Toggle manager on click. Handle the rare case where the user has no top level window and disables the systray by showing the manager window. diff -r e363de9ac549 -r f08e364e96e6 src/virtManager/engine.py --- a/src/virtManager/engine.py Wed Oct 21 12:01:53 2009 -0400 +++ b/src/virtManager/engine.py Thu Oct 22 18:55:24 2009 +0200 @@ -78,13 +78,15 @@ logging.debug("Libvirt doesn't support threading, skipping.") # Counter keeping track of how many manager and details windows - # are open. When it is decremented to 0, close the app + # are open. When it is decremented to 0, close the app or + # keep running in system tray if enabled self.windows = 0 self.netdevHelper = vmmNetDevHelper(self.config) self.init_systray() self.config.on_stats_update_interval_changed(self.reschedule_timer) + self.config.on_view_system_tray_changed(self.system_tray_changed) self.schedule_timer() self.load_stored_uris() @@ -95,7 +97,7 @@ return self.systray = vmmSystray(self.config, self) - self.systray.connect("action-view-manager", self._do_show_manager) + self.systray.connect("action-toggle-manager", self._do_toggle_manager) self.systray.connect("action-suspend-domain", self._do_suspend_domain) self.systray.connect("action-resume-domain", self._do_resume_domain) self.systray.connect("action-run-domain", self._do_run_domain) @@ -106,6 +108,12 @@ self.systray.connect("action-show-details", self._do_show_details) self.systray.connect("action-exit-app", self._do_exit_app) + def system_tray_changed(self, *ignore): + systray_enabled = self.config.get_view_system_tray() + if self.windows == 0 and not systray_enabled: + # Show the manager so that the user can control the application + self.show_manager() + def load_stored_uris(self): uris = self.config.get_connections() if uris != None: @@ -235,6 +243,8 @@ self.show_help(index) def _do_show_console(self, src, uri, uuid): self.show_console(uri, uuid) + def _do_toggle_manager(self, src): + self.toggle_manager() def _do_show_manager(self, src): self.show_manager() def _do_refresh_console(self, src, uri, uuid): @@ -366,6 +376,11 @@ self.windowManager.connect("action-exit-app", self._do_exit_app) return self.windowManager + def toggle_manager(self): + manager = self.get_manager() + if not manager.close(): + manager.show() + def show_manager(self): self.get_manager().show() @@ -376,7 +391,8 @@ def decrement_window_counter(self): self.windows -= 1 logging.debug("window counter decremented to %s" % self.windows) - if self.windows <= 0: + # Don't exit if system tray is enabled + if self.windows <= 0 and not self.config.get_view_system_tray() : self.exit_app() def exit_app(self): diff -r e363de9ac549 -r f08e364e96e6 src/virtManager/systray.py --- a/src/virtManager/systray.py Wed Oct 21 12:01:53 2009 -0400 +++ b/src/virtManager/systray.py Thu Oct 22 18:55:24 2009 +0200 @@ -24,6 +24,8 @@ class vmmSystray(gobject.GObject): __gsignals__ = { + "action-toggle-manager": (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, []), "action-view-manager": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, []), "action-suspend-domain": (gobject.SIGNAL_RUN_FIRST, @@ -208,7 +210,7 @@ # Listeners def systray_activate(self, widget): - self.emit("action-view-manager") + self.emit("action-toggle-manager") def systray_popup(self, widget, button, event_time): if button != 3: