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

Support Keymap.key_get_mods_for_level() #20

Merged
merged 2 commits into from
Apr 10, 2024
Merged

Conversation

sde1000
Copy link
Owner

@sde1000 sde1000 commented Apr 9, 2024

xkb_keymap_key_get_mods_for_level() was introduced in libxkbcommon-1.0

@sde1000
Copy link
Owner Author

sde1000 commented Apr 9, 2024

Would it be helpful to add helper functions for dealing with xkb_mod_mask_t? Eg. to decompose it into a set of xkb_mod_index_t or a set of modifier names?

Arguably Keymap.key_get_mods_for_level() should return a suitable IntFlag type, but we would have to generate a new type for each Keymap instance because the mapping between xkb_mod_index_t and modifier name can change.

Ubuntu 20.04 only has libxkbcommon-0.8, and we are preparing to require
libxkbcommon-1.0

Python 3.6 and Python 3.7 are no longer supported.

Add Python 3.12 to CI

Update action scripts to avoid deprecation warnings
xkb_keymap_key_get_mods_for_level() was introduced in libxkbcommon-1.0
@ldrahnik
Copy link

ldrahnik commented Apr 9, 2024

I think return mask is ok then I can implement in Python something similar to:

num_mods = xkb_keymap_num_mods(keymap);

...

               for (xkb_mod_index_t mod = 0; mod < num_mods; mod++) {
                   if ((mask & (1 << mod)) == 0) {
                       continue;
                   }
                   printf("%s ", xkb_keymap_mod_get_name(keymap, mod));
               }

I tested the Python code below for masks returned by key_get_consumed_mods and it works:

        consumed_mods = keyboard_state.key_get_consumed_mods(keycode)
        if consumed_mods > 0:
            print("char: `" + char + "`, consumed mods mask: " + str(consumed_mods))
            for mod_index in range(0, keymap.num_mods()):

                if (consumed_mods & (1 << mod_index) == 0):
                    continue

                mod_name = keymap.mod_get_name(mod_index)
                print(mod_name)

Sounds better to me use cycle outside and not put cycle into this lib.

@sde1000 sde1000 merged commit 9cefa14 into master Apr 10, 2024
5 checks passed
@sde1000 sde1000 deleted the key_get_mods_for_level branch June 26, 2024 15:42
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.

None yet

2 participants