diff --git a/tiny/server.py b/tiny/server.py index 1defa63f..0253e995 100644 --- a/tiny/server.py +++ b/tiny/server.py @@ -17,6 +17,7 @@ from wlroots.util.log import logger from wlroots.wlr_types import ( Cursor, + idle_notify_v1, Keyboard, Output, OutputLayout, @@ -99,6 +100,9 @@ def __init__( self._cursor = cursor self._cursor_manager = cursor_manager + # idle_notify_v1 support + self.idle_notify = idle_notify_v1.IdleNotifierV1(self._display) + # the seat manages the keyboard focus information self._seat = seat self.keyboards: list[KeyboardHandler] = [] @@ -195,6 +199,7 @@ def _process_cursor_resize(self) -> None: self.grabbed_view.xdg_surface.set_size(new_width, new_height) def process_cursor_motion(self, time) -> None: + self.idle_notify.notify_activity(self._seat) if self.cursor_mode == CursorMode.MOVE: self._process_cursor_move() return @@ -226,6 +231,7 @@ def send_modifiers( self._seat.keyboard_notify_modifiers(modifiers) def send_key(self, key_event: KeyboardKeyEvent, input_device: InputDevice) -> None: + self.idle_notify.notify_activity(self._seat) keyboard = Keyboard.from_input_device(input_device) keyboard_modifier = keyboard.modifier diff --git a/wlroots/ffi_build.py b/wlroots/ffi_build.py index ff26334a..72fa8b88 100644 --- a/wlroots/ffi_build.py +++ b/wlroots/ffi_build.py @@ -854,6 +854,19 @@ def has_xwayland() -> bool: struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display); """ +# types/wlr_idle_notify_v1.h +CDEF += """ +struct wlr_idle_notifier_v1; + +struct wlr_idle_notifier_v1 *wlr_idle_notifier_v1_create(struct wl_display *display); + +void wlr_idle_notifier_v1_set_inhibited(struct wlr_idle_notifier_v1 *notifier, + bool inhibited); + +void wlr_idle_notifier_v1_notify_activity(struct wlr_idle_notifier_v1 *notifier, + struct wlr_seat *seat); +""" + # types/wlr_input_device.h CDEF += """ enum wlr_button_state { @@ -2774,6 +2787,7 @@ def has_xwayland() -> bool: #include #include #include +#include #include #include #include diff --git a/wlroots/wlr_types/idle_notify_v1.py b/wlroots/wlr_types/idle_notify_v1.py new file mode 100644 index 00000000..d6a520c6 --- /dev/null +++ b/wlroots/wlr_types/idle_notify_v1.py @@ -0,0 +1,33 @@ +# Copyright (c) Charbel Assaad 2023 +from pywayland.server import Display + +from wlroots import lib, Ptr + +from .seat import Seat + + +class IdleNotifierV1(Ptr): + def __init__(self, display: Display) -> None: + self._ptr = lib.wlr_idle_notifier_v1_create(display._ptr) + + @property + def inhibited(self) -> bool: + return bool(self._ptr.inhibited) + + def set_inhibited(self, inhibited: bool) -> None: + """ + Inhibit idle. + + Compositors should call this function when the idle state is disabled, e.g. + because a visible client is using the idle-inhibit protocol. + """ + lib.wlr_idle_notifier_v1_set_inhibited(self._ptr, inhibited) + + def notify_activity(self, seat: Seat) -> None: + """ + Notify for user activity on a seat. + + Compositors should call this function whenever an input event is triggered + on a seat. + """ + lib.wlr_idle_notifier_v1_notify_activity(self._ptr, seat._ptr)