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

API equivalent for 'xmodmap -pm' #91

Open
VanLaser opened this issue Feb 25, 2019 · 6 comments
Open

API equivalent for 'xmodmap -pm' #91

VanLaser opened this issue Feb 25, 2019 · 6 comments
Labels
enhancement Indicates new feature requests help wanted Indicates that a maintainer wants help on an issue or pull request X11 legacy: missing feature Indicates a need to implement legacy X11 features

Comments

@VanLaser
Copy link

Hello,

I'm writing a 'touchscreen' keyboard (dockable, sticky etc.) for X11 (for a Linux-based tablet); the key sending method is based on /dev/uinput, so that the X keyboard settings will be taken into account as if the events come from a "real" keyboard device. I'm trying to find out what keys, when pressed, affect the modifiers of the keyboard, so that I can make those keys 1) remain depressed and 2) release automatically after another (non-modifier) key is pressed. Basically, I think, to find out the same info xmodmap -pm offers from the CLI. I may be daft, but I don't see a way to find out this information with xkbcommon API. Any idea? Thanks!

@bluetech
Copy link
Member

There is no API which exposes such a thing directly.

What you can do is use an imperative approach. Create a scratch xkb_state, simulate a key press (xkb_state_update_key()), and see if it affected the depressed and/or locked modifiers (enum xkb_state_components in the return value). Note layouts can also be depressed and/or be locked by keys.

If you need more pointers, or if it doesn't work for the use case, let us know.

@yshui
Copy link

yshui commented Jun 30, 2019

@bluetech That is a really roundabout way to get information that should be available directly.

It would be really nice if there is a function for this.

@yshui
Copy link

yshui commented Jul 1, 2019

And, some of the keycodes, e.g. Meta_L (0xcd), Mode_switch (0xcb), cannot be discovered this way.

@bluetech
Copy link
Member

I guess it would be easier to consider if someone who needs this proposes an API that would have been useful for them (implementation not needed, just an API proposal).

@sdilts
Copy link

sdilts commented Sep 5, 2022

Since xkb_keymap_mod_get_index, xkb_keymap_mod_get_name, and xkb_keymap_num_mods already exist, I guess it would make sense to introduce something similar to this:

/**
 * Get the keycodes associated with a modifier by index.
 * @param[in] keymap The keymap
 * @param[in] idx The index of the modifier
 * @param[out] codes_out A buffer in which the codes should be stored
 * @param[out] codes_size The size of the codes_out buffer
 * 
 * @returns the number of key codes in the keysyms_out array.  
 */
size_t xkb_keymap_mod_get_codes(struct xkb_keymap *keymap,
                                xkb_mod_index_t idx,
                                xkb_keycode_t *codes_out,
                                size_t codes_size);

Although it might be nice (if a bit dangerous) to allow code_size < return_value if the buffer isn't big enough.

@wismill wismill added enhancement Indicates new feature requests help wanted Indicates that a maintainer wants help on an issue or pull request X11 legacy: missing feature Indicates a need to implement legacy X11 features labels May 15, 2023
@wismill
Copy link
Member

wismill commented Sep 22, 2023

I added a feature similar to xmodmap -pm in #352. Note that it is only available as a debug tool, because it exposes internal mapping of modifiers.

About your use case: do you need to know in advance the keys affecting the modifiers, or could it be simplier to just watch the keyboard state and update the key accordingly when you detect a modifier change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests help wanted Indicates that a maintainer wants help on an issue or pull request X11 legacy: missing feature Indicates a need to implement legacy X11 features
Projects
None yet
Development

No branches or pull requests

5 participants