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

keymap: add xkb_keymap_keyname_get_keycode() #29

Closed
wants to merge 1 commit into from

Conversation

zmike
Copy link
Contributor

@zmike zmike commented Jan 20, 2016

this function allows finding a keycode from a given keyname and
is useful for generating keyboard events to use in regression tests
during CI

Signed-off-by: Mike Blumenkrantz [email protected]

@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

Would it be possible to do a release after merging this?

@bluetech
Copy link
Member

This is indeed a lacuna in the API, so makes sense to add. Some comments:

  1. I do not particularly like hiding the loop in the function; it suggests we actually want to export the inverse, i.e. keycode -> name. However, due to the aliases, the function is not invertible, so we do need the name -> keycode function. But please do add the inverse, to be consistent with the similar functions we have for mods, layouts, leds. It should return the canonical name (please add a comment to this effect!).
  2. Please call the functions xkb_keymap_key_get_name, xkb_keymap_key_by_name - more consistent with existing names.
  3. Please add a simple test just to exercise the code. I can do it after merging if you prefer.

Thanks.

return key->keycode;
}

name = XkbResolveKeyAlias(keymap, name);
Copy link
Member

Choose a reason for hiding this comment

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

Would be better to canonicalize the name first, then do just one loop. An alias cannot conflict with a canonical name, so the result is the same.

@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

I tried adding a simple test (https://gist.github.com/zmike/88daf2a29a7b6d5d4987), but the first call fails and XKB_KEYCODE_INVALID is returned. Seems unexpected; did I do something wrong in the implementation?

@bluetech
Copy link
Member

The problem with the test is that there is no key with the name "9". You can check /usr/share/X11/xkb/keycodes/evdev to see the usual names (surrounded by <..>).

And two more comments :)

  1. Please squash to one commit.
  2. I don't think test/state.c is appropriate for this, as that file is meant for xkb_state tests. I don't see an existing appropriate file, so please add a new one test/keymap.c or so.

Thanks!

@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

Okay, I've added a separate test using a keyname from the evdev keycodes file, but it's still failing.

@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

Ah, and I'll squash after everything is resolved.

@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

Nevermind, user error. Squashing...

xkb_keymap_key_by_name() allows finding a keycode from a given keyname and
is useful for generating keyboard events to use in regression tests
during CI

xkb_keymap_key_get_name() is the inverse of xkb_keymap_key_by_name()

Signed-off-by: Mike Blumenkrantz <[email protected]>
@zmike
Copy link
Contributor Author

zmike commented Jan 20, 2016

Should be all done now.

@bluetech
Copy link
Member

I made some tiny tweaks and pushed, thanks.

A release is definitely overdue, I'll prepare one. @fooishbar what do you about making this one 1.0.0? I think it's about time :)

@bluetech bluetech closed this Jan 20, 2016
@fooishbar
Copy link
Member

@bluetech sadly I think we need to resolve #17 first. :( It's on my TODO ...

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

3 participants