Skip to content

Commit

Permalink
Merge pull request #118 from Sydiepus/idle_notify_v1
Browse files Browse the repository at this point in the history
add idle_notify_v1 protocol.
  • Loading branch information
flacjacket authored Apr 8, 2023
2 parents c3fab40 + 0d88f68 commit e3140ce
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tiny/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from wlroots.util.log import logger
from wlroots.wlr_types import (
Cursor,
idle_notify_v1,
Keyboard,
Output,
OutputLayout,
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2774,6 +2787,7 @@ def has_xwayland() -> bool:
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_layer_shell_v1.h>
Expand Down
33 changes: 33 additions & 0 deletions wlroots/wlr_types/idle_notify_v1.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e3140ce

Please sign in to comment.