flacjacket / pywlroots

Python binding to the wlroots library using cffi
University of Illinois/NCSA Open Source License
51 stars 12 forks source link

Expose `wlr_keyboard_notify_modifiers` function. #123

Closed Sydiepus closed 1 year ago

Sydiepus commented 1 year ago

Sway uses this function to configure the initial state of numlock/capslock.

Tested with Qtile.

Compositors would implement something similar to sway, like this to enable Numlock:

mask = ffi.new("xkb_mod_mask_t *", 0)
one = ffi.new("uint32_t *", 1)
idx = ffi.new("xkb_mod_index_t *")
idx[0] = lib.xkb_keymap_mod_get_index(self.keyboard._ptr.keymap, ffi.new("const char []", "Mod2".encode("ascii")))
mask[0] |= one[0] << idx[0]
zero = ffi.new("uint32_t *", 0)           
lib.wlr_keyboard_notify_modifiers(self.keyboard._ptr, zero[0], zero[0], mask[0], zero[0])

the Capslock is named Lock. My implementation is definitely not the best but it works.

I'm not sure if there's a way to do the same thing using pywlroots instead of copying sway's implementation.

flacjacket commented 1 year ago

This change seems fine to me. Is there any way that we can wrap this in some Python API for qtile to be able to use it? That would definitely be preferred to just exposing it directly in the ffi object.

Sydiepus commented 1 year ago

Like adding a method to the Keyboard class ? notify_modifiers(mask) and get_index. I think the mask can be created with python and casted to the correct type later. Or configure(mod_name) method that does all the work.

Sydiepus commented 1 year ago

Compositors now have to do something like this :

from wlroots.wlr_types.keyboard import ModifiersMask

mask = ModifiersMask(self.keyboard)
if numlock:
    mask.add("Mod2")
if capslock:
    mask.add("Lock")
self.keyboard.notify_modifiers(mask)
Sydiepus commented 1 year ago

Maybe pass the keyboard to ModifiersMask instead of the add method ?

otaj commented 1 year ago

I was just about to start working on exposing this functionality to pywlroots in order to make it happen in qtile, this is awesome! Thank you, @Sydiepus.

(btw, I'm just random passerby, no affiliation with qtile or pywlroots)