feat(overlay): handle WM_DISPLAYCHANGE and WM_SETTINGCHANGE for dynamic display updates
This commit is contained in:
@@ -76,6 +76,8 @@ WM_LBUTTONDOWN = 0x0201
|
|||||||
WM_LBUTTONUP = 0x0202
|
WM_LBUTTONUP = 0x0202
|
||||||
WM_MOUSEMOVE = 0x0200
|
WM_MOUSEMOVE = 0x0200
|
||||||
WM_NCHITTEST = 0x0084
|
WM_NCHITTEST = 0x0084
|
||||||
|
WM_DISPLAYCHANGE = 0x007E
|
||||||
|
WM_SETTINGCHANGE = 0x001A
|
||||||
|
|
||||||
# Cursors
|
# Cursors
|
||||||
IDC_ARROW = 32512
|
IDC_ARROW = 32512
|
||||||
@@ -187,6 +189,7 @@ class OverlayWindow:
|
|||||||
on_mouse_down: Optional[Callable[[int, int], None]] = None,
|
on_mouse_down: Optional[Callable[[int, int], None]] = None,
|
||||||
on_mouse_move: Optional[Callable[[int, int], None]] = None,
|
on_mouse_move: Optional[Callable[[int, int], None]] = None,
|
||||||
on_mouse_up: Optional[Callable[[int, int], None]] = None,
|
on_mouse_up: Optional[Callable[[int, int], None]] = None,
|
||||||
|
on_display_change: Optional[Callable[[], None]] = None,
|
||||||
):
|
):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
@@ -196,6 +199,7 @@ class OverlayWindow:
|
|||||||
self.on_mouse_down = on_mouse_down
|
self.on_mouse_down = on_mouse_down
|
||||||
self.on_mouse_move = on_mouse_move
|
self.on_mouse_move = on_mouse_move
|
||||||
self.on_mouse_up = on_mouse_up
|
self.on_mouse_up = on_mouse_up
|
||||||
|
self.on_display_change = on_display_change
|
||||||
|
|
||||||
self.hwnd: Optional[int] = None
|
self.hwnd: Optional[int] = None
|
||||||
self._wndproc_ref = None # Prevent garbage collection of callback
|
self._wndproc_ref = None # Prevent garbage collection of callback
|
||||||
@@ -352,6 +356,14 @@ class OverlayWindow:
|
|||||||
self.on_mouse_up(pos.x, pos.y)
|
self.on_mouse_up(pos.x, pos.y)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
elif msg in (WM_DISPLAYCHANGE, WM_SETTINGCHANGE):
|
||||||
|
if self.on_display_change:
|
||||||
|
try:
|
||||||
|
self.on_display_change()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in on_display_change callback: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
elif msg == WM_DESTROY:
|
elif msg == WM_DESTROY:
|
||||||
user32.PostQuitMessage(0)
|
user32.PostQuitMessage(0)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user