Skip to content

Commit

Permalink
Merge pull request #140 from heuer/main
Browse files Browse the repository at this point in the history
Replaced classmethod decorator with staticmethod if the class variable is not used
  • Loading branch information
flacjacket authored Mar 6, 2024
2 parents b38b6ce + e5443f6 commit 6061887
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
6 changes: 3 additions & 3 deletions tiny/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def send_modifiers(
self, modifiers: KeyboardModifiers, input_device: InputDevice
) -> None:
keyboard = Keyboard.from_input_device(input_device)
self._seat.set_keyboard(keyboard)
self._seat.keyboard = keyboard
self._seat.keyboard_notify_modifiers(modifiers)

def send_key(self, key_event: KeyboardKeyEvent, input_device: InputDevice) -> None:
Expand All @@ -254,7 +254,7 @@ def send_key(self, key_event: KeyboardKeyEvent, input_device: InputDevice) -> No

# Otherwise, we pass it along to the client
if not handled:
self._seat.set_keyboard(keyboard)
self._seat.keyboard = keyboard
self._seat.keyboard_notify_key(key_event)

def handle_keybinding(self, keysym: int) -> bool:
Expand Down Expand Up @@ -396,7 +396,7 @@ def _server_new_keyboard(self, input_device: InputDevice) -> None:
keyboard_handler = KeyboardHandler(keyboard, input_device, self)
self.keyboards.append(keyboard_handler)

self._seat.set_keyboard(keyboard)
self._seat.keyboard = keyboard

# #############################################################
# cursor motion callbacks
Expand Down
4 changes: 2 additions & 2 deletions wlroots/allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def __init__(self, ptr) -> None:
"""
self._ptr = ptr

@classmethod
def autocreate(cls, backend: Backend, renderer: Renderer) -> Allocator:
@staticmethod
def autocreate(backend: Backend, renderer: Renderer) -> Allocator:
"""Creates the adequate allocator given a backend and a renderer."""
ret = lib.wlr_allocator_autocreate(backend._ptr, renderer._ptr)
if not ret:
Expand Down
4 changes: 2 additions & 2 deletions wlroots/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, ptr) -> None:
"""
self._ptr = ptr

@classmethod
def autocreate(cls, backend: Backend) -> Renderer:
@staticmethod
def autocreate(backend: Backend) -> Renderer:
"""Creates a suitable renderer for a backend."""
ret = lib.wlr_renderer_autocreate(backend._ptr)
if not ret:
Expand Down
4 changes: 2 additions & 2 deletions wlroots/wlr_types/layer_shell_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def configure(self, width: int, height: int) -> None:
def destroy(self) -> None:
lib.wlr_layer_surface_v1_destroy(self._ptr)

@classmethod
def from_wlr_surface(cls, surface: Surface):
@staticmethod
def from_wlr_surface(surface: Surface):
surface_ptr = lib.wlr_layer_surface_v1_from_wlr_surface(surface._ptr)
_weakkeydict[surface_ptr] = surface._ptr
return LayerSurfaceV1(surface_ptr)
Expand Down
4 changes: 2 additions & 2 deletions wlroots/wlr_types/output_management_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def __init__(self, ptr) -> None:
"""An instance of wlr_output_configuration_head_v1"""
self._ptr = ptr

@classmethod
@staticmethod
def create(
cls, config: OutputConfigurationV1, output: Output
config: OutputConfigurationV1, output: Output
) -> OutputConfigurationHeadV1:
"""Create a new wlr_output_configuration_head_v1"""
ptr = lib.wlr_output_configuration_head_v1_create(config._ptr, output._ptr)
Expand Down
4 changes: 2 additions & 2 deletions wlroots/wlr_types/pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Pointer(Ptr):
def __init__(self, ptr) -> None:
self._ptr = ptr

@classmethod
def from_input_device(cls, input_device: InputDevice) -> Pointer:
@staticmethod
def from_input_device(input_device: InputDevice) -> Pointer:
return Pointer(lib.wlr_pointer_from_input_device(input_device._ptr))

@property
Expand Down
21 changes: 19 additions & 2 deletions wlroots/wlr_types/seat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import warnings
from weakref import WeakKeyDictionary

from pywayland.protocol.wayland import WlSeat
Expand Down Expand Up @@ -123,6 +124,15 @@ def keyboard(self) -> Keyboard | None:
return None
return Keyboard(keyboard_ptr)

@keyboard.setter
def keyboard(self, keyboard: Keyboard | None) -> None:
"""Set this keyboard as the active keyboard for the seat
"""
if keyboard is None:
lib.wlr_seat_set_keyboard(self._ptr, ffi.NULL)
else:
lib.wlr_seat_set_keyboard(self._ptr, keyboard._ptr)

def destroy(self) -> None:
"""Clean up the seat"""
if self._ptr is not None:
Expand Down Expand Up @@ -229,13 +239,20 @@ def pointer_has_grab(self):
"""Whether or not the pointer has a grab other than the default grab"""
lib.wlr_seat_pointer_has_grab(self._ptr)

def set_keyboard(self, keyboard: Keyboard) -> None:
def set_keyboard(self, keyboard: Keyboard | None) -> None:
"""Set this keyboard as the active keyboard for the seat
Deprecated: Use the keyboard property.
:param keyboard:
The keyboard to set as active.
"""
lib.wlr_seat_set_keyboard(self._ptr, keyboard._ptr)
warnings.warn(
"Use the keyboard property of the seat, this method will be removed in the future.",
DeprecationWarning,
stacklevel=1,
)
self.keyboard = keyboard

def grab(self) -> KeyboardGrab:
"""Start a grab of the keyboard of this seat"""
Expand Down
6 changes: 2 additions & 4 deletions wlroots/wlr_types/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class Texture(Ptr):
def __init__(self, ptr) -> None:
self._ptr = ptr

@classmethod
@staticmethod
def from_pixels(
cls,
renderer: Renderer,
fmt: int,
stride: int,
Expand All @@ -40,9 +39,8 @@ def from_pixels(
ptr = ffi.gc(ptr, lib.wlr_texture_destroy)
return Texture(ptr)

@classmethod
@staticmethod
def from_buffer(
cls,
renderer: Renderer,
buffer: Buffer,
) -> Texture:
Expand Down
4 changes: 2 additions & 2 deletions wlroots/wlr_types/xdg_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, ptr) -> None:
data_wrapper=XdgSurfaceConfigure,
)

@classmethod
def from_surface(cls, surface: Surface) -> XdgSurface:
@staticmethod
def from_surface(surface: Surface) -> XdgSurface:
"""Get the xdg surface associated with the given surface"""
if not surface.is_xdg_surface:
raise RuntimeError("Surface is not XDG surface")
Expand Down

0 comments on commit 6061887

Please sign in to comment.