From d0814db5edafb5dc6adbf8a85ea529f1333f2a20 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 26 Jun 2018 07:43:00 +0000 Subject: [PATCH] #1707: keep track of when we modify the tray icon, so we don't overwrite it with the startup reset code git-svn-id: https://xpra.org/svn/Xpra/trunk@19719 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/client/gtk_base/statusicon_tray.py | 3 ++- src/xpra/client/mixins/tray.py | 12 +++++++++--- src/xpra/client/tray_base.py | 3 +++ src/xpra/platform/darwin/osx_tray.py | 3 +++ src/xpra/platform/win32/win32_tray.py | 3 +++ src/xpra/platform/xposix/appindicator_tray.py | 3 ++- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/xpra/client/gtk_base/statusicon_tray.py b/src/xpra/client/gtk_base/statusicon_tray.py index bc3a5bdc88..19c29c06c6 100644 --- a/src/xpra/client/gtk_base/statusicon_tray.py +++ b/src/xpra/client/gtk_base/statusicon_tray.py @@ -7,7 +7,7 @@ # A tray implemented using gtk.StatusIcon import os -from xpra.os_util import WIN32, OSX, POSIX, PYTHON3 +from xpra.os_util import WIN32, OSX, POSIX, PYTHON3, monotonic_time from xpra.util import envbool from xpra.gtk_common.gobject_compat import import_gtk, import_gdk gtk = import_gtk() @@ -177,6 +177,7 @@ def set_icon_from_pixbuf(self, tray_icon): else: tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER) self.tray_widget.set_from_pixbuf(tray_icon) + self.icon_timestamp = monotonic_time() def main(): diff --git a/src/xpra/client/mixins/tray.py b/src/xpra/client/mixins/tray.py index 4a21844473..951b5872e7 100644 --- a/src/xpra/client/mixins/tray.py +++ b/src/xpra/client/mixins/tray.py @@ -45,9 +45,15 @@ def setup_xpra_tray(*args): self.tray = self.setup_xpra_tray(self.tray_icon or "xpra") if self.tray: self.tray.show() - #re-set the icon after a short delay, - #seems to help with buggy tray geometries: - self.timeout_add(1000, self.tray.set_icon) + icon_timestamp = self.tray.icon_timestamp + def reset_icon(): + #re-set the icon after a short delay, + #seems to help with buggy tray geometries, + #but don't do it if we have already changed the icon + #(ie: the dynamic window icon code may have set a new one) + if icon_timestamp==self.tray.icon_timestamp: + self.tray.set_icon() + self.timeout_add(1000, reset_icon) if self.delay_tray: self.connect("first-ui-received", setup_xpra_tray) else: diff --git a/src/xpra/client/tray_base.py b/src/xpra/client/tray_base.py index 1ca2fcda08..c3f051dd35 100644 --- a/src/xpra/client/tray_base.py +++ b/src/xpra/client/tray_base.py @@ -6,6 +6,7 @@ from xpra.platform.paths import get_icon_filename from xpra.log import Logger +from xpra.os_util import monotonic_time from collections import deque log = Logger("tray") @@ -31,6 +32,7 @@ def __init__(self, _client, app_id, menu, tooltip, icon_filename, size_changed_c self.geometry_guess = None self.tray_event_locations = deque(maxlen=512) self.default_icon_extension = "png" + self.icon_timestamp = 0 def __repr__(self): return "Tray(%i:%s)" % (self.app_id, self.tooltip) @@ -91,6 +93,7 @@ def set_icon_from_file(self, filename): if not self.tray_widget: return self.do_set_icon_from_file(filename) + self.icon_timestamp = monotonic_time() def do_set_icon_from_file(self, filename): raise Exception("override me!") diff --git a/src/xpra/platform/darwin/osx_tray.py b/src/xpra/platform/darwin/osx_tray.py index 9659fadf2f..9895bacb89 100644 --- a/src/xpra/platform/darwin/osx_tray.py +++ b/src/xpra/platform/darwin/osx_tray.py @@ -10,6 +10,7 @@ from xpra.log import Logger log = Logger("tray", "osx") +from xpra.os_util import monotonic_time from xpra.client.tray_base import TrayBase from xpra.gtk_common.gtk_util import pixbuf_new_from_data, pixbuf_new_from_file, COLORSPACE_RGB from xpra.platform.darwin.osx_menu import getOSXMenuHelper @@ -68,12 +69,14 @@ def set_blinking(self, on): def set_icon_from_data(self, pixels, has_alpha, w, h, rowstride, options={}): tray_icon = pixbuf_new_from_data(pixels, COLORSPACE_RGB, has_alpha, 8, w, h, rowstride) self.macapp.set_dock_icon_pixbuf(tray_icon) + self.icon_timestamp = monotonic_time() def do_set_icon_from_file(self, filename): if not self.macapp: return pixbuf = pixbuf_new_from_file(filename) self.macapp.set_dock_icon_pixbuf(pixbuf) + self.icon_timestamp = monotonic_time() def set_global_menu(self): diff --git a/src/xpra/platform/win32/win32_tray.py b/src/xpra/platform/win32/win32_tray.py index 3599b5c2f1..7eb1227fb1 100755 --- a/src/xpra/platform/win32/win32_tray.py +++ b/src/xpra/platform/win32/win32_tray.py @@ -12,6 +12,7 @@ from xpra.log import Logger log = Logger("tray", "win32") +from xpra.os_util import monotonic_time from xpra.platform.win32 import constants as win32con from xpra.platform.win32.gui import EnumDisplayMonitors, GetMonitorInfo from xpra.platform.win32.win32_NotifyIcon import win32NotifyIcon @@ -86,10 +87,12 @@ def set_tooltip(self, name): def set_icon_from_data(self, pixels, has_alpha, w, h, rowstride, options={}): if self.tray_widget: self.tray_widget.set_icon_from_data(pixels, has_alpha, w, h, rowstride, options) + self.icon_timestamp = monotonic_time() def do_set_icon_from_file(self, filename): if self.tray_widget: self.tray_widget.set_icon(filename) + self.icon_timestamp = monotonic_time() def set_blinking(self, on): if self.tray_widget: diff --git a/src/xpra/platform/xposix/appindicator_tray.py b/src/xpra/platform/xposix/appindicator_tray.py index 6fa54aaa66..3fb89db0dc 100644 --- a/src/xpra/platform/xposix/appindicator_tray.py +++ b/src/xpra/platform/xposix/appindicator_tray.py @@ -12,7 +12,7 @@ log = Logger("tray", "posix") from xpra.util import envbool -from xpra.os_util import is_unity +from xpra.os_util import is_unity, monotonic_time from xpra.client.tray_base import TrayBase from xpra.platform.paths import get_icon_dir, get_icon_filename @@ -109,6 +109,7 @@ def do_set_icon_from_file(self, filename): log("do_set_icon_from_file(%s) setting icon=%s", filename, noext) self.tray_widget.set_icon(noext) self._has_icon = True + self.icon_timestamp = monotonic_time() def main():