-
Notifications
You must be signed in to change notification settings - Fork 124
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
"Control" modifier incorrectly consumed on keypad #17
Comments
The file
The type
So the type indeed does not explicitly assign a level for just Now, you might think this is unintuitive (= not what user expects), and that in cases where the is no explicit assignment the modifiers of the type should not be consumed. And in fact this is what we did initially in libxkbcommon. But this caused problems in other cases and is not what Xlib does. So it was changed to the current behavior here: 1054962 This behavior is debatable but I think we should keep it as-is. If you want to explain the actual problem this caused you (I'm assuming having to do with shortcuts, which are actually very tricky to get right) there might be a solution... Or you can argue for xkeyboard-config to add a |
This commit looks like it's of cosmetic nature. Got the wrong one?
This is about handling key shortcuts in a wayland application. I want to distinguish between |
I'll reply a little later, but yes, I meant this one: 5417440 |
As I said, shortcuts are tricky. Every time you fix one edge case another pops up. So I'd recommend using a toolkit if possible instead of rolling your own (even they still have issues though). But let's try... Here are some definitions first so things are clear:
Note: some people had the idea of not using keysyms but just the keycodes, thus circumventing the entire issue. But this doesn't work: a "semantic" shortcut like
Well a first rule which seems safe enough is that Before the
For the For the both So I think the problematic scenario left for Sorry for the length, “I didn't have time to write a short letter, so I wrote a long one instead.” :) |
Thanks for your explanation. I'm not sure whether I really got it. Because |
I'll tell you more: if you just press A with no active modifiers, Rephrasing your request: if While interesting (I haven't considered it too much) it already breaks several keymaps which rely on something called "capitalization transformation". Besides, the implicit rule behavior is what the keymap authors expected when they wrote the keymaps. Btw, wanted to mention something about 5417440 which I failed to mention in the commit message: the new behavior is actually a "superset" of the old one, since the old one is basically |
So what should applications do, which want to use the modifiers anyway in this specific case? Special-case all the keys that are affected by this? |
I'm tempted to say "that's just the way it is" but I'll try to resist :) GTK seem to use the following heuristic: only add to the consumed modifiers those which appear in a single-modifier entry (e.g. By seemingly sheer luck, this heuristic works well for the case you describe (couldn't break it in gimp at least); |
Yeah, this behaviour does seem to be correct, AFAICT. Maybe we could add the optional GTK+-style behaviour with a state flag? Seems to be a bit of a copout, but ... Funnily enough, this actually tripped me up: https://bugzilla.gnome.org/show_bug.cgi?id=754110 |
@bluetech Any opinion on whether new API, or updating the keymap to have explicit 'consumed' entries, would be better? |
@fooishbar I completely forgot about this, sorry. I replied in the gnome bug. |
@bluetech No problem. For what it's worth, my litmus test for when xkbcommon was 'done' was when we had something good enough to work for GTK+ shortcuts, so let's fix this and call it 1.0.0. :) |
@bluetech So, fun thing I just realised: xkb_state_key_get_consumed_mods() is actually a bit overambitious, returning modifiers which aren't in the state. Is this something we should fix as well, or just leave? The reason I ask is that if we were changing xkb_state_key_get_consumed_mods() to implement GTK+ style behaviour (i.e. only declare mods consumed if they actively contributed to a transformation of that key in the current state), then we'd need to filter down the output of xkb_state_key_get_consumed_mods() in general to key_get_consumed(state, key) & state->effective_mods; |
I've argued in 5417440 that we should keep them. Additionally, it is easy enough for the caller to do this AND, so by not doing it ourselves the function is more useful as it provides more information. That said, right now I can't think of any scenario where knowing that a non-active modifier is consumed is useful. BTW, looking carefully at GTK code, it is also possible to make it return non-active modifiers as consumed, though they probably didn't intend it (and doesn't trigger with existing keymaps in practice). |
@bluetech Ah yes, I remember that. I don't think there's any real right answer here: the right answer is to have preserve (and thus implicitly consumed) explicitly specified in all the key types, but that boat sailed about 20 years ago. Your reasoning in 5417440 is definitely correct for that case, but not for the Ctrl+Alt case. Given the rock vs. hard place scenario we find ourselves in, I think introducing a new entrypoint is the right thing to do, though for the new-style behaviour, we'd either need to special-case Caps+Shift ourselves, or put in HUGE SCREAMING CAPS that users really need to do that as well. (And, maybe lean on xkeyboard-config to add an explicit map[Shift+Lock] = Level1 to ALPHABETIC, though in order to do shortcuts correctly, e.g. Ctrl+Shift+W, you'd need to preserve Shift ...) |
The current functions dealing with consumed modifiers use the traditional XKB definition of consumed modifiers (see description in the added documentation). However, for several users of the library (e.g. GTK) this definition is unsuitable or too eager. This is exacerbate by some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems to cause most grief...). So, because we - want to enable alternative interpretations, but - don't want to expose too much internal details, and - want to keep things simple for all library users, we add a high-level "mode" parameter which selects the desired interpretation. New ones can be added as long as they make some sense. All of the old consumed-modifiers functions keep using the traditional ("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and xkb_state_mod_index_is_consumed() as deprecated without adding *2 variants for them because I don't think they are very useful (or used) in practice. Alternative modes are added in subsequent commits (this commit only adds mode for existing behavior). xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
This is more or less what is implemented here: https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131 The implementation here is more technically correct but should provide the same results. https://bugzilla.gnome.org/show_bug.cgi?id=754110 xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
@fooishbar If by special casing Caps+Shift you mean for the caps-lock capitalization transformation thing, then the new modes do not affect this, because internally we keep using the XKB mode when looking at consumed modifiers. |
@bluetech OK, this looks good to me - ship it! |
@fooishbar Thanks for reviewing. I'll add some tests when I have time - I did not test this at all yet. Would also be nice if the GTK developers try it and see if it solves the problem? |
@bluetech Sure, I'll try to get GTK+ over and see how that goes - if it works, we can throw it into git, let it bake for a short while, and then push out a 0.7.0. In the meantime, any objections to me pushing a 0.6.0.1 to include the LICENSE file? Apparently not having one hasn't been an issue before, but at least a couple of people have explicitly requested a tarball with one ... |
@fooishbar Sure, it must have been lost since autotools has magic only for the |
New test which tries to trigger Alt+F3 which does not work due to the behavior how xkbcommon calculates consumed modifers. The combination Ctrl+Alt+F3 generates a keysym (vt switching) so just pressing F3 already consumes ctrl and alt modifier. For more information see: * xkbcommon/libxkbcommon#17 * https://bugs.freedesktop.org/show_bug.cgi?id=92818 CCBUG: 368989
Any update on this? As you can see in the referenced commit (hey I didn't know that works) we just also run into that problem. |
@mgraesslin Due to backward compatibility whatever solution is going to require new API. The current proposal is in this pull request: #31 Would you consider testing it and see if it solves the problem and behaves as expected otherwise? You would need to replace calls to If we can agree on the approach I can prepare the PR for merging (it is missing tests) and do a release. Also, can you point me at the (old?) kwin code which uses Xlib? Particularly around the use of the |
I'll give it a try next week.
I'd suggest to change it as it's not GTK specific.
I cannot as the X11 code works differently. kglobalaccel uses xcb_grab_key for each of the shortcuts it's interested in. It might be that Qt has related code, though. |
I just gave it a try. Unfortunately I cannot do a 1:1 port as our code uses xkb_state_mod_index_is_consumed and for that one a new version is not available. The xkb_mod_mask_t doesn't help me as I there is no straight-forward way to get the modifiers from the mask. |
In case I got the mapping from mod_mask_t to mod_index_t correctly: patch works, my autotest passes |
The current functions dealing with consumed modifiers use the traditional XKB definition of consumed modifiers (see description in the added documentation). However, for several users of the library (e.g. GTK) this definition is unsuitable or too eager. This is exacerbated by some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems to cause most grief...). So, because we - want to enable alternative interpretations, but - don't want to expose too much internal details, and - want to keep things simple for all library users, we add a high-level "mode" parameter which selects the desired interpretation. New ones can be added as long as they make some sense. All of the old consumed-modifiers functions keep using the traditional ("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and as deprecated without adding a *2 variant because I don't it is very useful (or used) in practice. Alternative modes are added in subsequent commits (this commit only adds a mode for the existing behavior). xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
This is more or less what is implemented here: https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131 The implementation here is more technically correct but should provide the same results. Try it out with ./test/interactive-evdev -g (modifiers prefixed with "-" are consumed). https://bugzilla.gnome.org/show_bug.cgi?id=754110 xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
I have updated the PR, it is ready to merge. I will wait a few days if there are any comments. I can then do a release. @mgraesslin I have added |
The current functions dealing with consumed modifiers use the traditional XKB definition of consumed modifiers (see description in the added documentation). However, for several users of the library (e.g. GTK) this definition is unsuitable or too eager. This is exacerbated by some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems to cause most grief...). So, because we - want to enable alternative interpretations, but - don't want to expose too much internal details, and - want to keep things simple for all library users, we add a high-level "mode" parameter which selects the desired interpretation. New ones can be added as long as they make some sense. All of the old consumed-modifiers functions keep using the traditional ("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and as deprecated without adding a *2 variant because I don't it is very useful (or used) in practice. Alternative modes are added in subsequent commits (this commit only adds a mode for the existing behavior). xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
This is more or less what is implemented here: https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131 The implementation here is more technically correct but should provide the same results. Try it out with ./test/interactive-evdev -g (modifiers prefixed with "-" are consumed). https://bugzilla.gnome.org/show_bug.cgi?id=754110 xkbcommon#17 Signed-off-by: Ran Benita <[email protected]>
If you press e.g. the '+' key on the keypad, and the ctrl key is pressed, then the xkb API will report the ctrl modifier as consumed, even though ctrl doesn't change the interpretation of the key (i.e. same keysym).
I'd expect that ctrl is not considered consumed in this case.
The APIs I was looking at were the following:
active and consumed can both be 1 for
code==XKB_KEY_KP_Add
.The text was updated successfully, but these errors were encountered: