You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I set grp:alts_toggle (switching layouts by pressing both alt keys), instead of flags, the kbd plugin shows the text "GROUP" for one layout and the text "GROUP(ALTS" for the other. Hovering over the text shows the correct names in the tooltip. Adding another grp: option to my setting (such as grp:ctrl_shift_toggle) fixes this behaviour.
I had a look at the code, and I think the problem is caused in initialize_keyboard_description(). There two arrays get populated: group_names and symbol_names. I understand the group_names is the names of the 4 xkb groups (what could also be called layouts), but I'm not sure what symbol_names is for. I noticed that symbol_names is 4 elements long, but the string that is parsed to find those 4 elements has more thatn that on my machine, which uses only 2 of the 4 layouts:
But for some reason, it gets truncated when it is read XGetAtomName() (xkb.c:179). I assume this is because the X Atom has a set length of 100 characters:
(gdb) p symbol_string
$5 = "pc+eu+ru(phonetic_YAZHERTY):2+inet(evdev)+group(ctrl_shift_toggle)+group(alts_toggle):1+group(alts_"
When that truncated string gets parsed the results are as follows:
(gdb) p xkb->group_names
$6 = {"EurKEY (US based layout with European letters)", "Russian (phonetic, YAZHERTY)", "Unknown", "Unknown"}
(gdb) p xkb->symbol_names
$7 = {"EU", "RU", "INET(EVDEV)", "GROUP(CTRL"}
group_names still has the correct contents and symbol_names, while having garbage in the last two fields, happens to have the correct contents in the first two.
Aside from trying to fit a 6-or-more-element array into a 4-element one, another problem I noticed was one added in 7dbea37. Before that commit, "group(alts_toggle)" would be turned into "group\0alts\0toggle\0" = "group" which would be recognized by the logic in xkb.c:192, that filters "pc", "inet", and "group" from the symbols string. Now however, it gets turned into "group(alts\0toggle)" = "group(alts" which is no longer caught by the code, and is probably where the garbage in symbol_names came from.
I think, that parsing xkb_symbols at all is a bad idea. A better solution for getting the short names of the layouts (EU, RU, US, etc.) is to do what setxkbmap does and use XkbRF_GetNamesProp() from X11/extensions/XKBrules.h. That function returns a struct which contains, among other things, both the layout and the variant.
A short example program:
When I set
grp:alts_toggle
(switching layouts by pressing both alt keys), instead of flags, the kbd plugin shows the text "GROUP" for one layout and the text "GROUP(ALTS" for the other. Hovering over the text shows the correct names in the tooltip. Adding anothergrp:
option to my setting (such asgrp:ctrl_shift_toggle
) fixes this behaviour.I had a look at the code, and I think the problem is caused in
initialize_keyboard_description()
. There two arrays get populated:group_names
andsymbol_names
. I understand thegroup_names
is the names of the 4 xkb groups (what could also be called layouts), but I'm not sure whatsymbol_names
is for. I noticed thatsymbol_names
is 4 elements long, but the string that is parsed to find those 4 elements has more thatn that on my machine, which uses only 2 of the 4 layouts:The elements are separated using '+' signs, so the count comes to 6.
With this setup, the `symbol_names' array gets filled correctly:
But
symbol_names
has garbage:Doing the thing, where I add another
grp:
option, gives the followingxkb_symbols
string:But for some reason, it gets truncated when it is read
XGetAtomName()
(xkb.c:179). I assume this is because the X Atom has a set length of 100 characters:When that truncated string gets parsed the results are as follows:
group_names
still has the correct contents andsymbol_names
, while having garbage in the last two fields, happens to have the correct contents in the first two.Aside from trying to fit a 6-or-more-element array into a 4-element one, another problem I noticed was one added in 7dbea37. Before that commit,
"group(alts_toggle)"
would be turned into"group\0alts\0toggle\0" = "group"
which would be recognized by the logic in xkb.c:192, that filters "pc", "inet", and "group" from the symbols string. Now however, it gets turned into"group(alts\0toggle)" = "group(alts"
which is no longer caught by the code, and is probably where the garbage insymbol_names
came from.I think, that parsing
xkb_symbols
at all is a bad idea. A better solution for getting the short names of the layouts (EU, RU, US, etc.) is to do what setxkbmap does and useXkbRF_GetNamesProp()
fromX11/extensions/XKBrules.h
. That function returns a struct which contains, among other things, both the layout and the variant.A short example program:
Using this would be far easier and much less error prone than whatever lxpanel is currently doing.
The text was updated successfully, but these errors were encountered: