sergei-mironov / xkb-switch

Switch your X keyboard layouts from the command line
MIT License
345 stars 37 forks source link

Doesn't recognise second group, causing range check failure #46

Open Vftdan opened 4 years ago

Vftdan commented 4 years ago

Reproduce:

Expected:

xkb-switch/build $ ./xkb-switch
ru

Got:

xkb-switch/build $ ./xkb-switch 
xkb-switch: vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
xkb-switch: layouts: [us]

(Exit code 2)

OS: Mint 19 tara

timqsh commented 4 years ago

I'm sometimes getting exactly same error on arch linux. Have not figured out how to reproduce it yet.

sergei-mironov commented 4 years ago

Got it. Probably we need a debug facility in xkb-switch to view the XKB string causing the failure . Will update on that.

Vftdan commented 4 years ago

Apparently xkbcomp, unlike setxkbmap, doesn't set these strings. Returned values are:

rules_file = evdev
model = pc105
layout = us
variant = us

Possible solution is calling setxkbmap us,ru before xkbcomp.

sergei-mironov commented 4 years ago

Looks like I couldn't reproduce this. What I've done:

  1. Save https://github.com/Vftdan/dotfiles/blob/030b0f36c505a6a5fad18cb4407651066f98a5c9/extra/xkb/my as bug.keyboard
  2. Run xkbcomp bug.keyboard $DISPLAY
  3. Run xkb-switch. It displayed the current group correctly.

Could you please review my actions?

I'm also going to add -d|--debug flag to print internal layout string.

I also tried running setxkbmap us,ru before running xkbcomp, with same result

ticalc-travis commented 4 years ago

I'm seeing a similar issue in an i3wm session with a custom layout setup. Here is the debug output I'm getting with xkb-switch:

# First layout (custom US QWERTY):
$ ./xkb-switch -d
[DEBUG] xkb-switch version 1.7.0
[DEBUG] layout: us
[DEBUG] variant: <empty>
us

# Second layout (custom US Dvorak):
$ ./xkb-switch -d
[DEBUG] xkb-switch version 1.7.0
[DEBUG] layout: us
[DEBUG] variant: <empty>
xkb-switch: vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
xkb-switch: layouts: [us]

This is the script I use to set the layouts:

#!/bin/bash
xset r rate 500 30
setxkbmap -I$HOME/.xkb us,'us(colemak)' -print -option grp:sclk_toggle,meqqnu_switch,compose:rwin-altgr | xkbcomp -I$HOME/.xkb - $DISPLAY

Attached is the keyboard layout file I'm using (in $HOME/.xkb/symbols/us).

As suggested in Vftdan's comment, if I run setxkbmap us,'us(colemak)', then xkb-switch recognizes the two layouts. However, it apparently loads the system versions of the layouts rather than my custom ones. But if I then re-run my above keyboard setup script (with the setxkbmap … | xkbcomp … call), it seems to install the right keymaps, and xkb-switch can recognize them too.

Maybe I'm doing something wrong in my config; I have no idea. XKB is just too flippin' complicated to understand. :-)

xkb_layout.txt

anasem commented 3 years ago

I have the same problem, I customized my keys with xmodmap

To reproduce

setxkbmap -model pc105 -layout us,ar -option grp:alt_shift_toggle
xmodmap -e "clear lock" 
xmodmap -e "keycode  9 = grave asciitilde Arabic_thal Arabic_shadda Arabic_percent U0609"
xmodmap -e "keycode 49 = Caps_Lock NoSymbol Caps_Lock"
xmodmap -e "keycode 66 = Escape NoSymbol Escape"

Switch with Alt+Shift and run xkb-switch, I get the same error.

[DEBUG] xkb-switch version 1.8.5
[DEBUG] layout: us,ar
[DEBUG] variant: <empty>
xkb-switch: vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
xkb-switch: layouts: [us ar]
tfendin commented 3 years ago

I too have the same problem. However, sometimes xkb-switch doesn't crash but instead it only reports the first layout as the selected one (even if it isn't).

$ cat .xkb/keymap/mykbd

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete" };
    xkb_compat    { include "complete" };
    xkb_symbols   { include "pc+us+se:2+inet(evdev)+ctrl(swapcaps)+mysym(swap_tab_shift_l)+mysym(lalt_rshift_toggle)" };
    xkb_geometry  { include "pc(pc105)" };
};

$ cat .xkb/symbols/mysym

partial modifier_keys
xkb_symbols "swap_tab_shift_l" {
    replace key <TAB>  { [ Shift_L, Shift_L ] };
    replace key <LFSH> { [ Tab, ISO_Left_Tab ] };
};

xkb_symbols "lalt_rshift_toggle" {
    virtual_modifiers Alt;
    key <LALT> {
        symbols[Group1] = [ NoSymbol, ISO_Next_Group ],
        virtualMods= Alt
    };
    key <RTSH> {
        type[Group1]="PC_ALT_LEVEL2",
        symbols[Group1] = [ Shift_R, ISO_Next_Group ]
    };
};

Switch with left alt and right shift. These are the resultsts I can get with xkb-switch 1.8.5. The first example it crashes on the first layout switch. In the second example I (successfully) switched layout 5 times.

$ xkb-switch -W vector::_M_range_check: __n (which is 1) >= this->size() (which is 1) $ xkb-switch -W us us us us us ^C

cnekmp commented 2 years ago

Apparently xkbcomp, unlike setxkbmap, doesn't set these strings. Returned values are:

rules_file = evdev
model = pc105
layout = us
variant = us

Possible solution is calling setxkbmap us,ru before xkbcomp.

This solves the issue. I've set setxkbmap -layout 'us,az,ru' -option 'grp:caps_toggle' in Qtile's autostart and the error was: vector::_M_range_check: __n (which is 1) >= this->size() (which is 1).

Solution: I've moved setxkbmap -layout 'us,az,ru' -option 'grp:caps_toggle' into ~/.xinitrc and it works normally.

sergei-mironov commented 2 years ago

Hi. I've pushed a new version of xkb-switch which prints more debug information. Could you please run it with -d flag?

cnekmp commented 2 years ago

Hi. I've pushed a new version of xkb-switch which prints more debug information. Could you please run it with -d flag?

Seems the issue is gone (at least is my case everything works again):

$ ./xkb-switch -d
[DEBUG] xkb-switch version 1.8.5
/home/farid/git/xkb-switch/src/XKeyboard.cpp:110: raw layout string "us,az,ru"
/home/farid/git/xkb-switch/src/XKeyboard.cpp:111: raw variant string "us
sergei-mironov commented 2 years ago

OK. The problem probably depends on smaller-scale details of your Xserver's configuration. I admit that the way in which xkb-switch reads the group information is unreliable. Parsing a pair of comma-separated strings is not the good way to interact with the server, but currently I am not aware of better approaches.. I'll leave the issue open for some time since and try to reproduce other reports.

Mandilynnp77 commented 2 years ago

[ ]()