From 484b2f75f254fd6831ae4547a5bd3e9238d6da8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Tue, 29 Nov 2022 18:49:47 +0100 Subject: [PATCH] Regenerate icon on resolution change --- lib/pystray/_util/win32.py | 1 + lib/pystray/_win32.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/pystray/_util/win32.py b/lib/pystray/_util/win32.py index c053e9d..df65f5b 100644 --- a/lib/pystray/_util/win32.py +++ b/lib/pystray/_util/win32.py @@ -23,6 +23,7 @@ WM_CREATE = 0x0001 +WM_DISPLAYCHANGE = 0x007E WM_NCCREATE = 0x0081 WM_LBUTTONUP = 0x0202 WM_RBUTTONUP = 0x0205 diff --git a/lib/pystray/_win32.py b/lib/pystray/_win32.py index 0768daf..ea4c832 100644 --- a/lib/pystray/_win32.py +++ b/lib/pystray/_win32.py @@ -40,6 +40,7 @@ def __init__(self, *args, **kwargs): # This is a mapping from win32 event codes to handlers used by the # mainloop self._message_handlers = { + win32.WM_DISPLAYCHANGE: self._on_display_change, win32.WM_STOP: self._on_stop, win32.WM_NOTIFY: self._on_notify, win32.WM_TASKBARCREATED: self._on_taskbarcreated} @@ -171,6 +172,16 @@ def _mainloop(self): win32.DestroyMenu(hmenu) self._unregister_class(self._atom) + def _on_display_change(self, wparam, lparam): + """Handles ``WM_DISPLAYCHANGE``. + + This method updates the icon to prevent blurring when changing + resolutions. + """ + if self.visible: + self._hide() + self._show() + def _on_stop(self, wparam, lparam): """Handles ``WM_STOP``.