From 483a8de6c1b6079215bdd40b5e7e8dd5ba3c953c Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 17 Mar 2018 11:46:38 -0400 Subject: [PATCH] systray: Change window tracking a bit We should only prevent app closing if the systray is actually embedded --- virtManager/engine.py | 14 +++++++++++--- virtManager/systray.py | 6 ++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/virtManager/engine.py b/virtManager/engine.py index d3303c9b..739b2f78 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -32,6 +32,7 @@ from .baseclass import vmmGObject from .connect import vmmConnect from .connmanager import vmmConnectionManager from .inspection import vmmInspection +from .systray import vmmSystray DETAILS_PERF = 1 DETAILS_CONFIG = 2 @@ -96,7 +97,6 @@ class vmmEngine(vmmGObject): """ Actual startup routines if we are running a new instance of the app """ - from .systray import vmmSystray vmmSystray.get_instance() vmmInspection.get_instance() @@ -313,7 +313,6 @@ class vmmEngine(vmmGObject): return 1 def _handle_tick_error(self, msg, details): - from .systray import vmmSystray if (self._window_count == 1 and vmmSystray.get_instance().is_visible()): # This means the systray icon is running. Don't raise an error @@ -359,8 +358,17 @@ class vmmEngine(vmmGObject): self._exit_app_if_no_windows() + def _systray_is_embedded(self): + """ + We don't use window tracking here: systray isn't a window and even + when 'show' has been requested it may not be embedded in a visible + tray area, so we have to check it separately. + """ + return vmmSystray.get_instance().is_embedded() + def _can_exit(self): - return self._window_count <= 0 + return (self._window_count <= 0 and not + self._systray_is_embedded()) def _exit_app_if_no_windows(self): if self._can_exit(): diff --git a/virtManager/systray.py b/virtManager/systray.py index ebe9982b..f2d3dc55 100644 --- a/virtManager/systray.py +++ b/virtManager/systray.py @@ -25,7 +25,6 @@ from gi.repository import Gtk from . import vmmenu from .baseclass import vmmGObject from .connmanager import vmmConnectionManager -from .engine import vmmEngine class vmmSystray(vmmGObject): @@ -60,7 +59,7 @@ class vmmSystray(vmmGObject): for conn in connmanager.conns.values(): self._conn_added(connmanager, conn) - def is_visible(self): + def is_embedded(self): return (self.systray_icon and self.systray_icon.is_embedded()) @@ -97,14 +96,12 @@ class vmmSystray(vmmGObject): self.systray_icon.connect("activate", self.systray_activate) self.systray_icon.connect("popup-menu", self.systray_popup) self.systray_icon.set_tooltip_text(_("Virtual Machine Manager")) - vmmEngine.get_instance().increment_window_counter() def _hide(self): if not self.systray_icon: return self.systray_icon.set_visible(False) self.systray_icon = None - vmmEngine.get_instance().decrement_window_counter() def _show_systray_changed_cb(self): do_show = self.config.get_view_system_tray() @@ -295,4 +292,5 @@ class vmmSystray(vmmGObject): menu.update_widget_states(vm) def exit_app(self, _src): + from .engine import vmmEngine vmmEngine.get_instance().exit_app()