Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose wlr_keyboard_notify_modifiers function. #123

Merged
merged 4 commits into from
Sep 11, 2023

Conversation

Sydiepus
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Contributor Author

Sydiepus commented Aug 6, 2023

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
Copy link
Contributor Author

Sydiepus commented Aug 6, 2023

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

@otaj
Copy link

otaj commented Aug 11, 2023

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)

Copy link
Owner

@flacjacket flacjacket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@flacjacket flacjacket merged commit 4ef8ce3 into flacjacket:main Sep 11, 2023
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants