Skip to content

Commit

Permalink
Merge pull request #151 from heuer/issue_141
Browse files Browse the repository at this point in the history
Added Cursor.detach_input_device. Fixes #141
  • Loading branch information
flacjacket authored Mar 18, 2024
2 parents 82c8036 + 0daf4ca commit 4f66c06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def has_xwayland() -> bool:
int32_t hotspot_x, int32_t hotspot_y);
void wlr_cursor_attach_input_device(struct wlr_cursor *cur,
struct wlr_input_device *dev);
void wlr_cursor_detach_input_device(struct wlr_cursor *cur,
struct wlr_input_device *dev);
void wlr_cursor_attach_output_layout(struct wlr_cursor *cur,
struct wlr_output_layout *l);
void wlr_cursor_map_to_output(struct wlr_cursor *cur,
Expand Down
38 changes: 28 additions & 10 deletions wlroots/wlr_types/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class WarpMode(enum.Enum):
AbsoluteClosest = enum.auto()


def _ensure_attachable(input_device: InputDevice) -> None:
"""Helper for cursor.attach_input_device and detach_input_device.
:raises ValueError: If the input device is not allowed.
"""
allowed_device_types = (
InputDeviceType.POINTER,
InputDeviceType.TOUCH,
InputDeviceType.TABLET_TOOL,
)
if input_device.type not in allowed_device_types:
raise ValueError(
f"Input device must be one of pointer, touch, or tablet tool, got: {input_device.type}"
)


class Cursor(PtrHasData):
def __init__(self, output_layout: OutputLayout) -> None:
"""Manage a cursor attached to the given output layout
Expand Down Expand Up @@ -148,18 +164,20 @@ def attach_input_device(self, input_device: InputDevice) -> None:
:param input_device:
The input device to attach to the cursor
"""
allowed_device_types = (
InputDeviceType.POINTER,
InputDeviceType.TOUCH,
InputDeviceType.TABLET_TOOL,
)
if input_device.type not in allowed_device_types:
raise ValueError(
f"Input device must be one of pointer, touch, or tablet tool, got: {input_device.type}"
)

_ensure_attachable(input_device)
lib.wlr_cursor_attach_input_device(self._ptr, input_device._ptr)

def detach_input_device(self, input_device: InputDevice) -> None:
"""Detaches the provided input device from this cursor
See attach_input_device() for allowed types of input devices.
:param input_device:
The input device to detach from the cursor.
"""
_ensure_attachable(input_device)
lib.wlr_cursor_detach_input_device(self._ptr, input_device._ptr)

def move(
self,
delta_x: float,
Expand Down

0 comments on commit 4f66c06

Please sign in to comment.