Skip to content

Commit

Permalink
stronger type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 11, 2024
1 parent 742e105 commit e1a4126
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions xpra/platform/win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,18 @@ def add_window_hooks(window) -> None:
apply_maxsize_hints(window, window.geometry_hints)

if LANGCHANGE:
def inputlangchange(_hwnd, _event, wParam, lParam):
def inputlangchange(_hwnd: int, _event: int, wParam: int, lParam: int) -> int:
keylog("WM_INPUTLANGCHANGE: character set: %i, input locale identifier: %i", wParam, lParam)
window.keyboard_layout_changed("WM_INPUTLANGCHANGE", wParam, lParam)
return 0

win32hooks.add_window_event_handler(win32con.WM_INPUTLANGCHANGE, inputlangchange)

if WHEEL:
VERTICAL = "vertical"
HORIZONTAL = "horizontal"

def handle_wheel(orientation, wParam, lParam):
def handle_wheel(orientation: str, wParam: int, lParam: int):
distance = wParam >> 16
if distance > 2 ** 15:
# ie: 0xFF88 -> 0x78 (120)
Expand All @@ -630,11 +631,11 @@ def handle_wheel(orientation, wParam, lParam):
device_id = -1
client.wheel_event(device_id, wid, deltax, deltay, pointer)

def mousewheel(_hwnd, _event, wParam, lParam):
def mousewheel(_hwnd: int, _event: int, wParam: int, lParam: int) -> int:
handle_wheel(VERTICAL, wParam, lParam)
return 0

def mousehwheel(_hwnd, _event, wParam, lParam):
def mousehwheel(_hwnd: int, _event: int, wParam: int, lParam: int) -> int:
handle_wheel(HORIZONTAL, wParam, lParam)
return 0

Expand Down
4 changes: 2 additions & 2 deletions xpra/platform/win32/window_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, hwnd: int):
log("Win32Hooks: window frame size is %sx%s", self.frame_width, self.frame_height)
log("Win32Hooks: message_map=%s", self._message_map)

def add_window_event_handler(self, event: int, handler: Callable) -> None:
def add_window_event_handler(self, event: int, handler: Callable[[int, int, int, int], int]) -> None:
self._message_map[event] = handler

def setup(self) -> None:
Expand All @@ -78,7 +78,7 @@ def setup(self) -> None:
except Exception:
log.error(f"Error setting up window hook for {self._hwnd}", exc_info=True)

def on_getminmaxinfo(self, hwnd: int, msg, wparam: int, lparam: int):
def on_getminmaxinfo(self, hwnd: int, msg, wparam: int, lparam: int) -> int:
if (self.min_size or self.max_size) and lparam:
info = cast(lparam, POINTER(MINMAXINFO)).contents
style = GetWindowLongW(hwnd, win32con.GWL_STYLE)
Expand Down

0 comments on commit e1a4126

Please sign in to comment.