Skip to content

Commit

Permalink
Regenerate icon on resolution change
Browse files Browse the repository at this point in the history
  • Loading branch information
moses-palmer committed Nov 29, 2022
1 parent d477177 commit 484b2f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pystray/_util/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


WM_CREATE = 0x0001
WM_DISPLAYCHANGE = 0x007E
WM_NCCREATE = 0x0081
WM_LBUTTONUP = 0x0202
WM_RBUTTONUP = 0x0205
Expand Down
11 changes: 11 additions & 0 deletions lib/pystray/_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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``.
Expand Down

0 comments on commit 484b2f7

Please sign in to comment.