[oi-dev] x11 keyboard layouts

Alexander Pyhalov alp at rsu.ru
Wed Apr 26 13:10:21 UTC 2017


Hello.

I'm a bit confused.
I'm trying to get keyboard layout from xscreensaver-lock and see 
unexpected results.

I have a function which returns current layout (see below), which works 
fine when compiled standalone. But when I compile it as part of 
xscreensaver-lock , I suddenly find out that it sees two XKB groups
'English (US)' instead of 'English (US)' and 'Russian'.
So I see that we use group number 0 or 1, but their names are masked.

Do you have any suggestions where xscreensaver-lock can manage to do it? :)

static gchar*
getGroup()
{
   XkbStateRec state;
   Display *dpy;
   XkbDescRec desc[1];
   char *names[XkbNumKbdGroups];
   int i;
   gchar *s1 = NULL;

   dpy = gdk_x11_get_default_xdisplay();
   memset(desc, 0, sizeof(desc));
   desc->device_spec = XkbUseCoreKbd;
   if (XkbGetControls(dpy, XkbGroupsWrapMask, desc) == Success) {
     if (XkbGetNames(dpy, XkbGroupNamesMask, desc) == Success) {
       if (XkbGetState(dpy, XkbUseCoreKbd, &state) == Success) {
         XGetAtomNames(dpy, desc->names->groups, 
desc->ctrls->num_groups, names);
         for(i=0; i< desc->ctrls->num_groups; i++){
           fprintf(stderr, names[i]);
         }
         if (names[state.group]) {
           if(strlen(names[state.group]) > 2) {
              names[state.group][2]='\0';
           }

           s1 = g_ascii_strdown (names[state.group], -1);
           fprintf(stderr, "Got group %d %s\n", state.group, s1);
           fflush(stderr);
         }
       }
       XkbFreeNames(desc, XkbGroupNamesMask, True);
     }
     XkbFreeControls(desc, XkbGroupsWrapMask, True);
   }
   return s1;
}


-- 
Best regards,
Alexander Pyhalov,
system administrator of Southern Federal University IT department




More information about the oi-dev mailing list