Skip to content

Commit

Permalink
Merge pull request #123 from Sydiepus/wlr_keyboard_notify_modifiers
Browse files Browse the repository at this point in the history
Expose `wlr_keyboard_notify_modifiers` function.
  • Loading branch information
flacjacket authored Sep 11, 2023
2 parents 0d51adc + 9b71206 commit 4ef8ce3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@ def has_xwayland() -> bool:
struct wlr_input_device *input_device);
"""

# wlr/interfaces/wlr_keyboard.h
CDEF += """
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
uint32_t group);
"""

# types/wlr_linux_dmabuf_v1.h
CDEF += """
struct wlr_linux_dmabuf_v1 *wlr_linux_dmabuf_v1_create(struct wl_display *display,
Expand Down
26 changes: 26 additions & 0 deletions wlroots/wlr_types/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ class KeyboardModifier(enum.IntFlag):
MOD5 = lib.WLR_MODIFIER_MOD5


class ModifiersMask:
def __init__(self, keyboard: Keyboard) -> None:
"""The modifiers mask"""
self._mask = ffi.new("xkb_mod_mask_t *", 0)
self._one = ffi.new("uint32_t *", 1)
self._keyboard = keyboard

def add(self, modifier: str) -> None:
"""Add a modifier to the mask
Numlock is Mod2 and Capslock is Lock
"""
idx = ffi.new("xkb_mod_index_t *")
idx[0] = lib.xkb_keymap_mod_get_index(
self._keyboard._ptr.keymap,
ffi.new("const char []", modifier.encode("ascii")),
)
self._mask[0] |= self._one[0] << idx[0]


class KeyboardKeyEvent(Ptr):
def __init__(self, ptr) -> None:
"""Event that a key has been pressed or release
Expand Down Expand Up @@ -108,6 +127,13 @@ def set_repeat_info(self, rate, delay) -> None:
"""
lib.wlr_keyboard_set_repeat_info(self._ptr, rate, delay)

def notify_modifiers(self, mask: ModifiersMask) -> None:
"""Notify the keyboard that modifiers have been updated"""
zero = ffi.new("uint32_t *", 0)
lib.wlr_keyboard_notify_modifiers(
self._ptr, zero[0], zero[0], mask._mask[0], zero[0]
)

@property
def keycodes(self):
"""Keycodes associated with the keyboard"""
Expand Down

0 comments on commit 4ef8ce3

Please sign in to comment.