char* xkbGetGroup(char* buf, int len) { int xkbEventType, xkbError, reason_rtrn, mjr, mnr; char *display_name; XkbStateRec xkbstate; static Display *dpy = NULL; static XkbDescPtr xkbdesc = NULL; /* Lets begin */ if (!dpy) { display_name = NULL; mjr = XkbMajorVersion; mnr = XkbMinorVersion; dpy = XkbOpenDisplay(display_name, &xkbEventType, &xkbError, &mjr, &mnr, &reason_rtrn); } if (dpy == NULL) { strcpy(buf, "?"); return buf; } if ( Success != XkbGetState(dpy, XkbUseCoreKbd, &xkbstate) ) { strcpy(buf, "?"); return buf; } if (!xkbdesc) xkbdesc = XkbAllocKeyboard(); if (!xkbdesc) { strcpy(buf, "?"); return buf; } /* get the names of the layout */ if ( Success == XkbGetNames(dpy, 1<<12, xkbdesc)) { Atom iatoms[4]; char *iatomnames[4]; int i, j; for (i = 0, j = 0; i < 4; i++) if (xkbdesc->names->groups[i] != None) iatoms[j++] = xkbdesc->names->groups[i]; if (XGetAtomNames(dpy, iatoms, j, iatomnames)) buf = strndup(iatomnames[xkbstate.locked_group], len); } return buf; }
/* Allocates memory for and returns a string containing the font's * registry and encoding separated by a dash, or NULL if it can't be * determined */ static char * alloc_font_code_set(Display *display, XFontStruct *font) { Atom ids[2]; char *names[2]; char *string; size_t length; /* Look up the font's CHARSET_REGISTRY property */ if (!XGetFontProperty(font, atoms[AN_CHARSET_REGISTRY], &ids[0])) { return NULL; } /* Look up the font's CHARSET_ENCODING property */ if (!XGetFontProperty(font, atoms[AN_CHARSET_ENCODING], &ids[1])) { return NULL; } /* Stringify the names */ if (!XGetAtomNames(display, ids, 2, names)) { return NULL; } /* Allocate some memory to hold the code set name */ length = strlen(names[0]) + 1 + strlen(names[1]) + 1; string = malloc(length); if (string == NULL) { XFree(names[0]); XFree(names[1]); return NULL; } /* Construct the code set name */ sprintf(string, "%s-%s", names[0], names[1]); /* Clean up a bit */ XFree(names[0]); XFree(names[1]); return string; }