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

Key bindings don't work with groups #1775

Closed
WovenTales opened this issue Jul 1, 2015 · 7 comments
Closed

Key bindings don't work with groups #1775

WovenTales opened this issue Jul 1, 2015 · 7 comments

Comments

@WovenTales
Copy link

I've just customized my xkb options to include a secondary layout with a group switch key (grp:sclk_toggle), and most things seem to be working well enough. However, I use bindsym in my config file, and while the shortcuts do properly update to use the new key positions in the primary group, i3 doesn't seem to notice when I've toggled to Group 2 (QWERTY), so in order to run the command I have at Meta+h, I need to press the key that would otherwise print j, as that is where h is located in Group 1 (Dvorak).

I haven't worked with it enough yet to know whether it matters that I haven't completely integrated the new layout into my configs yet, and so use setxkbmap ... | xkbcomp ... from within X, after it starts with only a single group (if i3 maybe creates a database or something that isn't properly updated), but it's probably a bug either way.

@i3bot
Copy link

i3bot commented Jul 1, 2015

I don’t see a link to logs.i3wm.org. Did you follow http://i3wm.org/docs/debugging.html? (In case you actually provided a link to a logfile, please ignore me.)

@i3bot
Copy link

i3bot commented Jul 1, 2015

I don’t see a version number. Could you please copy & paste the output of i3 --version into this issue?

@i3bot i3bot added missing-log Read the CONTRIBUTING.md file for instructions missing-version labels Jul 1, 2015
@stapelberg
Copy link
Member

Please provide clear steps to reproduce. Also, does the problem go away when you restart i3?

@WovenTales
Copy link
Author

  • http://logs.i3wm.org/logs/5730450056151040.bz2
  • Binary i3 version: 4.10.2 (2015-04-16, branch "4.10.2") © 2009-2014 Michael Stapelberg and contributors

    Running i3 version: 4.10.2 (2015-04-16, branch "4.10.2") (pid 20563)


    The i3 binary you just called: /usr/bin/i3

    The i3 binary you are running: i3
  • Runsetxkbmap us,us -variant dvorak,intl -option grp:sclk_toggle,grp_led:scroll (also works with setxkbmap -I ~/.xkb us,us -variant dvorak,intl -option grp:sclk_toggle,grp_led:scroll -print | xkbcomp -I$HOME/.xkb - $DISPLAY or variants thereof), switch to Group 2 (with that command, hit Scroll Lock) and try to run some keyboard shortcut using a key that changes location between the layouts (Meta+w/Meta+e is a good pair – they move to where , and d are on QWERTY, respectively).
  • In an unhelpful way, it does, as I still haven't implemented any persistence for layouts between sessions (I manually run the equivalent of the above command each time I start i3), but as soon as I set up the proper xkb options for a session, I get the same behavior. As I said in the first post, there might be some mechanism in i3 that would produce a different behavior if I put the setxkbmap into my .xinitrc or wherever, rather than running it from Xterm, but the fact that the shortcuts update to the Dvorak key locations when I run it (X starts in QWERTY) means that, even if changing where I call the command fixes Group 2 shortcut locations, there's still some bug in that they aren't properly updated following this (perfectly valid) sequence of commands.

@i3bot i3bot added 4.10 and removed missing-log Read the CONTRIBUTING.md file for instructions missing-version labels Jul 1, 2015
@stapelberg
Copy link
Member

I don’t have time to reproduce this right now, but note that with “restart i3” I meant executing the “restart” command, e.g. by using i3-msg restart. This will not kill your session.

@Airblader Airblader added the bug label Jul 1, 2015
@WovenTales
Copy link
Author

Ah, I rarely use that, so I forgot it was there. Sorry! Anyway, it does persist even after (the proper form of) restarting i3.

@stapelberg
Copy link
Member

Got a chance to play around with this. In your setup, scroll_lock sends the ISO_Next_Group keysym, which has the same effect as using Mode_switch (but the former is sticky, the latter is temporary).

5 years ago, we actually added support for this case with commit c738b2e, but the way I see it, this only worked with the bindcode statement, never with bindsym, as i3 only looks at either column 0/1 (for bindings without Mode_switch) or column 2/3 (for bindings with Mode_switch).

Using bindcode works for me, i.e. the following binds to the key whose keycode is 53, regardless of whether scroll_lock was pressed or not:

bindcode Mod4+53 nop bar

Configuring an explicit Mode_switch keybinding works with scroll_lock as well:

bindsym Mode_switch+Mod4+x nop foo

I’ll push a commit to address this, see the commit description for details.

stapelberg added a commit to stapelberg/i3 that referenced this issue Aug 23, 2015
fixes i3#1835

This commit improves the translation of keysyms to keycodes by loading
keymaps using libxkbcommon-x11 and using libxkbcommon for figuring out
the keymap, depending on each keybinding’s modifiers. This way, the
upper layers of complex layouts are now usable with i3’s bindsym
directive, such as de_neo’s layer 3 and higher.

Furthermore, the commit generalizes the handling of different XKB
groups. We formerly had support only for two separate groups, the
default group 1, and group 2. While Mode_switch is only one way to
switch to group 2, we called the binding option Mode_switch. With this
commit, the new names Group1, Group2 (an alias for Mode_switch), Group3
and Group4 are introduced for configuring bindings. This is only useful
for advanced keyboard layouts, such as people loading two keyboard
layouts and switching between them (us, ru seems to be a popular
combination).

When grabbing keys, one can only specify the modifier mask, but not an
XKB state mask (or value), so we still dynamically unbind and re-bind
keys whenever the XKB group changes.

The commit was manually tested using the following i3 config:

    bindsym Group4+n nop heya from group 4
    bindsym Group3+n nop heya from group 3
    bindsym Group2+n nop heya from group 2
    bindsym n nop heya
    bindcode Group2+38 nop fallback overwritten in group 2 only
    bindcode 38 nop fallback

…with the following layout:

    setxkbmap -layout "us,ua,ru,de" -variant ",winkeys,,neo" \
      -option "grp:shift_caps_toggle,grp_led:scroll" \
      -model pc104 -rules evdev

By default (xkb group 1, us layout), pressing “n” will result in the
“heya” message appearing. Pressing “a” will result in the “fallback”
message appearing. “j” is not triggered.

By pressing Shift+CapsLock you switch to the next group (xkb group 2, ua
layout). Pressing “a” will result in the “fallback overwritten in group
2 only” message, pressing “n” will still result in “heya”. “j” is not
triggered.

In the next group (xkb group 3, ru layout), pressing “a” will result in
the “fallback” message again, pressing “n” will result in “heya”,
“j” is not triggered.

In the last group (xkb group 4, de_neo layout), pressing “a” will still
result in “fallback”, pressing “n” will result in “heya”, pressing “j”
will result in “heya from group 4”.

The fallback behavior ensures use-cases such as ticket i3#1775 are still
covered.

Only binding keys when the X server is in the corresponding XKB group
ensures use-cases such as ticket i3#585 are still covered.
stapelberg added a commit to stapelberg/i3 that referenced this issue Aug 23, 2015
fixes i3#1835

This commit improves the translation of keysyms to keycodes by loading
keymaps using libxkbcommon-x11 and using libxkbcommon for figuring out
the keymap, depending on each keybinding’s modifiers. This way, the
upper layers of complex layouts are now usable with i3’s bindsym
directive, such as de_neo’s layer 3 and higher.

Furthermore, the commit generalizes the handling of different XKB
groups. We formerly had support only for two separate groups, the
default group 1, and group 2. While Mode_switch is only one way to
switch to group 2, we called the binding option Mode_switch. With this
commit, the new names Group1, Group2 (an alias for Mode_switch), Group3
and Group4 are introduced for configuring bindings. This is only useful
for advanced keyboard layouts, such as people loading two keyboard
layouts and switching between them (us, ru seems to be a popular
combination).

When grabbing keys, one can only specify the modifier mask, but not an
XKB state mask (or value), so we still dynamically unbind and re-bind
keys whenever the XKB group changes.

The commit was manually tested using the following i3 config:

    bindsym Group4+n nop heya from group 4
    bindsym Group3+n nop heya from group 3
    bindsym Group2+n nop heya from group 2
    bindsym n nop heya
    bindcode Group2+38 nop fallback overwritten in group 2 only
    bindcode 38 nop fallback

…with the following layout:

    setxkbmap -layout "us,ua,ru,de" -variant ",winkeys,,neo" \
      -option "grp:shift_caps_toggle,grp_led:scroll" \
      -model pc104 -rules evdev

By default (xkb group 1, us layout), pressing “n” will result in the
“heya” message appearing. Pressing “a” will result in the “fallback”
message appearing. “j” is not triggered.

By pressing Shift+CapsLock you switch to the next group (xkb group 2, ua
layout). Pressing “a” will result in the “fallback overwritten in group
2 only” message, pressing “n” will still result in “heya”. “j” is not
triggered.

In the next group (xkb group 3, ru layout), pressing “a” will result in
the “fallback” message again, pressing “n” will result in “heya”,
“j” is not triggered.

In the last group (xkb group 4, de_neo layout), pressing “a” will still
result in “fallback”, pressing “n” will result in “heya”, pressing “j”
will result in “heya from group 4”.

The fallback behavior ensures use-cases such as ticket i3#1775 are still
covered.

Only binding keys when the X server is in the corresponding XKB group
ensures use-cases such as ticket i3#585 are still covered.
stapelberg added a commit that referenced this issue Aug 26, 2015
fixes #1835

This commit improves the translation of keysyms to keycodes by loading
keymaps using libxkbcommon-x11 and using libxkbcommon for figuring out
the keymap, depending on each keybinding’s modifiers. This way, the
upper layers of complex layouts are now usable with i3’s bindsym
directive, such as de_neo’s layer 3 and higher.

Furthermore, the commit generalizes the handling of different XKB
groups. We formerly had support only for two separate groups, the
default group 1, and group 2. While Mode_switch is only one way to
switch to group 2, we called the binding option Mode_switch. With this
commit, the new names Group1, Group2 (an alias for Mode_switch), Group3
and Group4 are introduced for configuring bindings. This is only useful
for advanced keyboard layouts, such as people loading two keyboard
layouts and switching between them (us, ru seems to be a popular
combination).

When grabbing keys, one can only specify the modifier mask, but not an
XKB state mask (or value), so we still dynamically unbind and re-bind
keys whenever the XKB group changes.

The commit was manually tested using the following i3 config:

    bindsym Group4+n nop heya from group 4
    bindsym Group3+n nop heya from group 3
    bindsym Group2+n nop heya from group 2
    bindsym n nop heya
    bindsym shift+N nop explicit shift binding
    bindsym shift+r nop implicit shift binding
    bindcode Group2+38 nop fallback overwritten in group 2 only
    bindcode 38 nop fallback

…with the following layout:

    setxkbmap -layout "us,ua,ru,de" -variant ",winkeys,,neo" \
      -option "grp:shift_caps_toggle,grp_led:scroll" \
      -model pc104 -rules evdev

By default (xkb group 1, us layout), pressing “n” will result in the
“heya” message appearing. Pressing “a” will result in the “fallback”
message appearing. “j” is not triggered.

By pressing Shift+CapsLock you switch to the next group (xkb group 2, ua
layout). Pressing “a” will result in the “fallback overwritten in group
2 only” message, pressing “n” will still result in “heya”. “j” is not
triggered.

In the next group (xkb group 3, ru layout), pressing “a” will result in
the “fallback” message again, pressing “n” will result in “heya”,
“j” is not triggered.

In the last group (xkb group 4, de_neo layout), pressing “a” will still
result in “fallback”, pressing “n” will result in “heya”, pressing “j”
will result in “heya from group 4”.

Pressing shift+n results in “explicit shift binding”, pressing shift+r
results in “implicit shift binding”. This ensures that keysym
translation falls back to looking at non-shift keys (“r” can be used
instead of ”R”) and that the order of keybindings doesn’t play a role
(“bindsym n” does not override “bindsym shift+n”, even though it’s
specified earlier in the config).

The fallback behavior ensures use-cases such as ticket #1775 are still
covered.

Only binding keys when the X server is in the corresponding XKB group
ensures use-cases such as ticket #585 are still covered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants