Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Last active December 2, 2018 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luzifer/dccae45747a1dad41f011a01c75296a3 to your computer and use it in GitHub Desktop.
Save Luzifer/dccae45747a1dad41f011a01c75296a3 to your computer and use it in GitHub Desktop.
pkgbase = getxkblayout
pkgdesc = Simple CLI command to read current active KB map from X server
pkgver = 0.0.1
pkgrel = 1
url = https://gist.github.com/Luzifer/dccae45747a1dad41f011a01c75296a3
arch = x86_64
license = Apache
makedepends = gcc
makedepends = libx11
makedepends = libxkbfile
source = getxkblayout.c
sha512sums = 74566dbe5b3d249c79155cecdd7ba60cff97272f8c6468741a676e7e6876a8fd2cac8a89058e2b7d4cff7a47174c4187649110da69fdb4a7c59e6b11c3fd7291
pkgname = getxkblayout
// Source: https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(int argc, char **argv) {
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
XkbStateRec state;
XkbGetState(dpy, XkbUseCoreKbd, &state);
XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd);
char *group = XGetAtomName(dpy, desc->names->groups[state.group]);
printf("full: %s\n", group);
XkbRF_VarDefsRec vd;
XkbRF_GetNamesProp(dpy, NULL, &vd);
char *tok = strtok(vd.layout, ",");
for (int i = 0; i < state.group; i++) {
tok = strtok(NULL, ",");
if (tok == NULL) {
return 1;
}
}
printf("short: %s\n", tok);
XFree(group);
XCloseDisplay(dpy);
return 0;
}
# Maintainer: Knut Ahlers <knut at ahlers dot me>
pkgname=getxkblayout
pkgver=0.0.1
pkgrel=1
pkgdesc="Simple CLI command to read current active KB map from X server"
url="https://gist.github.com/Luzifer/dccae45747a1dad41f011a01c75296a3"
makedepends=('gcc' 'libx11' 'libxkbfile')
arch=('x86_64')
license=('Apache')
source=("getxkblayout.c")
sha512sums=('70ed5e05254aac3cb45ce341f4b8fc6f1d4c08a0e420109f4bd4c4a10428c7d6ba0473a789fbbfa512337dd823f720a5143077116ea38379809bdb99a8a334c8')
build() {
gcc -I/usr/include getxkblayout.c -lX11 -lxkbfile
}
package() {
install -Dm755 "a.out" "$pkgdir/usr/bin/$pkgname"
}
# vim:set ts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment