Skip to content

Commit

Permalink
Merge pull request #163 from heuer/better_errormsg
Browse files Browse the repository at this point in the history
Better error message: Use human readable name rather than a numeric constant.
  • Loading branch information
flacjacket authored Apr 16, 2024
2 parents c149904 + fe6ead6 commit 5a5c270
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions wlroots/wlr_types/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pywayland.server import Signal

from wlroots import PtrHasData, ffi, lib
from wlroots import PtrHasData, ffi, lib, ptr_or_null

from .input_device import InputDevice, InputDeviceType
from .output import Output
Expand Down Expand Up @@ -51,7 +51,7 @@ def _ensure_attachable(input_device: InputDevice) -> None:
)
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}"
f"Input device must be one of pointer, touch, or tablet tool, got: {input_device.type.name}"
)


Expand Down Expand Up @@ -192,11 +192,7 @@ def move(
The `input_device` may be passed to respect device mapping constraints.
If `input_device` is None, device mapping constraints will be ignored.
"""
if input_device is None:
input_device_ptr = ffi.NULL
else:
input_device_ptr = input_device._ptr

input_device_ptr = ptr_or_null(input_device)
lib.wlr_cursor_move(self._ptr, input_device_ptr, delta_x, delta_y)

def warp(
Expand Down Expand Up @@ -228,10 +224,7 @@ def warp(
if y is None:
y = float("NaN")

if input_device is None:
input_device_ptr = ffi.NULL
else:
input_device_ptr = input_device._ptr
input_device_ptr = ptr_or_null(input_device)

if warp_mode == WarpMode.Layout:
return lib.wlr_cursor_warp(self._ptr, input_device_ptr, x, y)
Expand All @@ -253,10 +246,7 @@ def absolute_to_layout_coords(
If `input_device` is `None`, device mapping constraints will be
ignored.
"""
if input_device is None:
input_device_ptr = ffi.NULL
else:
input_device_ptr = input_device._ptr
input_device_ptr = ptr_or_null(input_device)

xy_ptr = ffi.new("double[2]")
lib.wlr_cursor_absolute_to_layout_coords(
Expand All @@ -272,11 +262,7 @@ def set_surface(self, surface: Surface | None, hotspot: tuple[int, int]) -> None
position is subtracted from the hotspot. A None surface commit hides
the cursor.
"""
if surface is None:
surface_ptr = ffi.NULL
else:
surface_ptr = surface._ptr

surface_ptr = ptr_or_null(surface)
lib.wlr_cursor_set_surface(self._ptr, surface_ptr, hotspot[0], hotspot[1])

def __enter__(self) -> Cursor:
Expand All @@ -293,11 +279,7 @@ def map_to_output(self, output: Output | None) -> None:
current output_layout for this cursor. This call is invalid for a cursor without
an associated output layout.
"""
if output is None:
output_ptr = ffi.NULL
else:
output_ptr = output._ptr

output_ptr = ptr_or_null(output)
lib.wlr_cursor_map_to_output(self._ptr, output_ptr)

def map_input_to_output(
Expand All @@ -308,9 +290,5 @@ def map_input_to_output(
must be attached to this cursor and the output must be among the outputs in the
attached output layout.
"""
if output is None:
output_ptr = ffi.NULL
else:
output_ptr = output._ptr

output_ptr = ptr_or_null(output)
lib.wlr_cursor_map_input_to_output(self._ptr, input_device._ptr, output_ptr)

0 comments on commit 5a5c270

Please sign in to comment.