From 0887138d984c897571f44896bf80732be8d528e6 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 4 Mar 2014 09:28:17 +0000 Subject: [PATCH] fix win32 system tray forwarding: * add move_callbacks to win32NotifyIcon instead of using get_win32_event_listener (which stopped working?!) * move_cb can then call recalculate_geometry Also add some debug logging. git-svn-id: https://xpra.org/svn/Xpra/trunk@5700 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/client/client_tray.py | 2 ++ src/xpra/client/tray_base.py | 3 ++- src/xpra/platform/win32/win32_NotifyIcon.py | 12 ++++++++--- src/xpra/platform/win32/win32_tray.py | 23 ++++++--------------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/xpra/client/client_tray.py b/src/xpra/client/client_tray.py index 20ae9f33f1..af213b6035 100644 --- a/src/xpra/client/client_tray.py +++ b/src/xpra/client/client_tray.py @@ -54,6 +54,7 @@ def get_tray_size(self): def reconfigure(self, force_send_configure=False): geometry = self.tray_widget.get_geometry() + log("%s.reconfigure(%s) geometry=%s", self, force_send_configure, geometry) if geometry is None: if self._geometry: geometry = self._geometry @@ -76,6 +77,7 @@ def reconfigure(self, force_send_configure=False): screen = self.tray_widget.get_screen() if screen>=0: client_properties["screen"] = screen + log("%s.reconfigure(%s) sending configure: %s", self, force_send_configure, (x, y, w, h, client_properties)) self._client.send("configure-window", self._id, x, y, w, h, client_properties) if self._size!=(w, h): self.new_backing(w, h) diff --git a/src/xpra/client/tray_base.py b/src/xpra/client/tray_base.py index 02effa3fd0..f8764cf1a6 100644 --- a/src/xpra/client/tray_base.py +++ b/src/xpra/client/tray_base.py @@ -107,6 +107,7 @@ def do_set_icon_from_file(self, filename): raise Exception("override me!") def recalculate_geometry(self, x, y, width, height): + log("recalculate_geometry%s tray event locations: %s", (x, y, width, height), len(self.tray_event_locations)) if len(self.tray_event_locations)>0 and self.tray_event_locations[-1]==(x,y): #unchanged return @@ -139,6 +140,6 @@ def recalculate_geometry(self, x, y, width, height): miny -= pady/2 oldgeom = self.geometry_guess self.geometry_guess = minx, miny, width, height - log("recalculate_geometry() %s", self.geometry_guess) + log("recalculate_geometry() geometry guess=%s", self.geometry_guess) if self.size_changed_cb and self.geometry_guess!=oldgeom: self.size_changed_cb() diff --git a/src/xpra/platform/win32/win32_NotifyIcon.py b/src/xpra/platform/win32/win32_NotifyIcon.py index 80f0376830..2a2e6bb9a4 100755 --- a/src/xpra/platform/win32/win32_NotifyIcon.py +++ b/src/xpra/platform/win32/win32_NotifyIcon.py @@ -43,11 +43,12 @@ class win32NotifyIcon(object): click_callbacks = {} + move_callbacks = {} exit_callbacks = {} command_callbacks = {} live_hwnds = set() - def __init__(self, title, click_callback, exit_callback, command_callback=None, iconPathName=None): + def __init__(self, title, move_callbacks, click_callback, exit_callback, command_callback=None, iconPathName=None): self.title = title[:127] self.current_icon = None # Register the Window class. @@ -62,6 +63,7 @@ def __init__(self, title, click_callback, exit_callback, command_callback=None, win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP)) #register callbacks: win32NotifyIcon.live_hwnds.add(self.hwnd) + win32NotifyIcon.move_callbacks[self.hwnd] = move_callbacks win32NotifyIcon.click_callbacks[self.hwnd] = click_callback win32NotifyIcon.exit_callbacks[self.hwnd] = exit_callback win32NotifyIcon.command_callbacks[self.hwnd] = command_callback @@ -212,8 +214,12 @@ def OnDestroy(cls, hwnd, msg, wparam, lparam): @classmethod def OnTaskbarNotify(cls, hwnd, msg, wparam, lparam): - bm = BUTTON_MAP.get(lparam) - cc = cls.click_callbacks.get(hwnd) + if lparam==win32con.WM_MOUSEMOVE: + cc = cls.move_callbacks.get(hwnd) + bm = [(hwnd, msg, wparam, lparam)] + else: + cc = cls.click_callbacks.get(hwnd) + bm = BUTTON_MAP.get(lparam) log("OnTaskbarNotify(%s,%s,%s,%s) button(s) lookup: %s, callback=%s", hwnd, msg, wparam, lparam, bm, cc) if bm is not None and cc: for button_event in bm: diff --git a/src/xpra/platform/win32/win32_tray.py b/src/xpra/platform/win32/win32_tray.py index 47a0651ed0..69e6c4376e 100755 --- a/src/xpra/platform/win32/win32_tray.py +++ b/src/xpra/platform/win32/win32_tray.py @@ -12,8 +12,7 @@ from xpra.log import Logger log = Logger("tray", "win32") -from xpra.platform.win32.win32_events import get_win32_event_listener, BALLOON_EVENTS -from xpra.platform.win32.win32_NotifyIcon import win32NotifyIcon, WM_TRAY_EVENT, BUTTON_MAP +from xpra.platform.win32.win32_NotifyIcon import win32NotifyIcon from xpra.client.tray_base import TrayBase @@ -24,10 +23,7 @@ def __init__(self, *args): self.default_icon_extension = "ico" self.default_icon_name = "xpra.ico" icon_filename = self.get_tray_icon_filename(self.default_icon_filename) - self.tray_widget = win32NotifyIcon(self.tooltip, self.click_cb, self.exit_cb, None, icon_filename) - #now let's try to hook the session notification - el = get_win32_event_listener() - el.add_event_callback(WM_TRAY_EVENT, self.tray_event) + self.tray_widget = win32NotifyIcon(self.tooltip, self.move_cb, self.click_cb, self.exit_cb, None, icon_filename) def ready(self): pass @@ -72,17 +68,10 @@ def get_geometry(self): return self.geometry_guess - def tray_event(self, wParam, lParam): + def move_cb(self, *args): x, y = win32api.GetCursorPos() size = win32api.GetSystemMetrics(win32con.SM_CXSMICON) + log("move_cb%s x=%s, y=%s, size=%s", args, x, y, size) self.recalculate_geometry(x, y, size, size) - if lParam in BALLOON_EVENTS: - log("WM_TRAY_EVENT: %s", BALLOON_EVENTS.get(lParam)) - elif lParam==win32con.WM_MOUSEMOVE: - log("WM_TRAY_EVENT: WM_MOUSEMOVE") - if self.mouseover_cb: - self.mouseover_cb(x, y) - elif lParam in BUTTON_MAP: - log("WM_TRAY_EVENT: click %s", BUTTON_MAP.get(lParam)) - else: - log.warn("WM_TRAY_EVENT: unknown event: %s / %s", wParam, lParam) + if self.mouseover_cb: + self.mouseover_cb(x, y)