diff options
| author | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-06-14 08:59:25 -0700 |
|---|---|---|
| committer | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-06-14 08:59:25 -0700 |
| commit | 3376b6420d3b6cc965890e46e7bbd06fbc9fd037 (patch) | |
| tree | 67b59ce0f9ba016db62067a081c0535d064d2a3f /src/slstatus/slstatus-1.1/components/keymap.c | |
| parent | d533343af750dcfda2321f33953b66396e767f10 (diff) | |
layout reorg
Diffstat (limited to 'src/slstatus/slstatus-1.1/components/keymap.c')
| -rw-r--r-- | src/slstatus/slstatus-1.1/components/keymap.c | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/slstatus/slstatus-1.1/components/keymap.c b/src/slstatus/slstatus-1.1/components/keymap.c deleted file mode 100644 index 22224f3..0000000 --- a/src/slstatus/slstatus-1.1/components/keymap.c +++ /dev/null @@ -1,86 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include <X11/XKBlib.h> -#include <X11/Xlib.h> - -#include "../slstatus.h" -#include "../util.h" - -static int -valid_layout_or_variant(char *sym) -{ - size_t i; - /* invalid symbols from xkb rules config */ - static const char *invalid[] = { "evdev", "inet", "pc", "base" }; - - for (i = 0; i < LEN(invalid); i++) - if (!strncmp(sym, invalid[i], strlen(invalid[i]))) - return 0; - - return 1; -} - -static char * -get_layout(char *syms, int grp_num) -{ - char *tok, *layout; - int grp; - - layout = NULL; - tok = strtok(syms, "+:_"); - for (grp = 0; tok && grp <= grp_num; tok = strtok(NULL, "+:_")) { - if (!valid_layout_or_variant(tok)) { - continue; - } else if (strlen(tok) == 1 && isdigit(tok[0])) { - /* ignore :2, :3, :4 (additional layout groups) */ - continue; - } - layout = tok; - grp++; - } - - return layout; -} - -const char * -keymap(const char *unused) -{ - Display *dpy; - XkbDescRec *desc; - XkbStateRec state; - char *symbols; - const char *layout; - - layout = NULL; - - if (!(dpy = XOpenDisplay(NULL))) { - warn("XOpenDisplay: Failed to open display"); - return NULL; - } - if (!(desc = XkbAllocKeyboard())) { - warn("XkbAllocKeyboard: Failed to allocate keyboard"); - goto end; - } - if (XkbGetNames(dpy, XkbSymbolsNameMask, desc)) { - warn("XkbGetNames: Failed to retrieve key symbols"); - goto end; - } - if (XkbGetState(dpy, XkbUseCoreKbd, &state)) { - warn("XkbGetState: Failed to retrieve keyboard state"); - goto end; - } - if (!(symbols = XGetAtomName(dpy, desc->names->symbols))) { - warn("XGetAtomName: Failed to get atom name"); - goto end; - } - layout = bprintf("%s", get_layout(symbols, state.group)); - XFree(symbols); -end: - XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1); - if (XCloseDisplay(dpy)) - warn("XCloseDisplay: Failed to close display"); - - return layout; -} |
