Skip to content

Commit

Permalink
fix win32 system tray forwarding:
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
totaam committed Mar 4, 2014
1 parent 2eefd57 commit 0887138
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/xpra/client/client_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/client/tray_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
12 changes: 9 additions & 3 deletions src/xpra/platform/win32/win32_NotifyIcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 6 additions & 17 deletions src/xpra/platform/win32/win32_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 0887138

Please sign in to comment.