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

kbd plugin fails to load flags when some options are set #51

Open
mcz opened this issue Apr 16, 2023 · 0 comments
Open

kbd plugin fails to load flags when some options are set #51

mcz opened this issue Apr 16, 2023 · 0 comments

Comments

@mcz
Copy link

mcz commented Apr 16, 2023

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:

$ setxkbmap -print | grep xkb_symbols
xkb_symbols   { include "pc+eu+ru(phonetic_YAZHERTY):2+inet(evdev)+group(alts_toggle):1+group(alts_toggle):2"   };

The elements are separated using '+' signs, so the count comes to 6.
With this setup, the `symbol_names' array gets filled correctly:

(gdb) p xkb->group_names
$5 = {"EurKEY (US based layout with European letters)", "Russian (phonetic, YAZHERTY)", "Unknown", "Unknown"}

But symbol_names has garbage:

(gdb) p xkb->symbol_names
$4 = {"GROUP", "GROUP(ALTS", "INET(EVDEV)", "None"}

Doing the thing, where I add another grp: option, gives the following xkb_symbols string:

pc+eu+ru(phonetic_YAZHERTY):2+inet(evdev)+group(ctrl_shift_toggle)+group(alts_toggle):1+group(alts_toggle):2

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:

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>

int
main(void)
{
        Display *dpy;
        dpy = XOpenDisplay(NULL);
        XkbRF_VarDefsRec vd;
        XkbRF_GetNamesProp(dpy, NULL, &vd);
        puts(vd.layout);
        puts(vd.variant);
}
$ gcc -lX11 -lxkbfile test.c
$ ./a.out
eu,ru
,phonetic_YAZHERTY

Using this would be far easier and much less error prone than whatever lxpanel is currently doing.

wandrien added a commit to lxde-continued/lxpanel that referenced this issue May 10, 2023
wandrien added a commit to lxde-continued/lxpanel that referenced this issue May 11, 2023
Fixes issue lxde#51

Also fixes parsing of layout names like us(basic), rs(latinyz)
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

No branches or pull requests

1 participant