From dfd23a44de8964dcd4ae9e1971c24c6efed71664 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 16 May 2021 21:09:58 +0200 Subject: [PATCH] [modules/layout] add a new - generic - layout module Add a new module "layout" that will eventually evolve into the only keyboard layout module. Right now, it uses an external binary (get-kbd-layout) to determine the layout of a keyboard device (because I did not manage to call libX11 with ctypes correctly). see #788 see #790 --- .gitignore | 2 ++ bin/get-kbd-layout | Bin 0 -> 21512 bytes bumblebee_status/modules/core/layout.py | 39 ++++++++++++++++++++++++ util/Makefile | 13 ++++++++ util/layout.c | 39 ++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100755 bin/get-kbd-layout create mode 100644 bumblebee_status/modules/core/layout.py create mode 100644 util/Makefile create mode 100644 util/layout.c diff --git a/.gitignore b/.gitignore index 2bf1ac8..c21fe43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.o + # Vim swap files *swp *~ diff --git a/bin/get-kbd-layout b/bin/get-kbd-layout new file mode 100755 index 0000000000000000000000000000000000000000..7ce6ccf1f0f105b58ed302f5950b540abfcf4a6f GIT binary patch literal 21512 zcmeHPeUMw#b-z#2uC&(fTY1+QgDI9BLv29X5A4N!tgT&pZ7tYfuuYr>^U$uey9!!q zD?ORD6PhI^l&$07P^O`ol3@tRkaVC9O(~>&81V4bk^x%4O+#4-G;5&LkU&iXY=7t8 zd$do_QYXxG`bS51M)#cayXTyH-+A|5-TS`2+P87N$1nsZuUIWeIvP?)Ocw+$(hNvU ztP(-wOU36zJ!GH6RC!Dhl&Uo1DW?IAdqK(WE?w@Xr)WK<+(M#cS1pBg1x$rL4zjBw zBQ3k>K57sWQ!X#n7na3Bxah5to9Cq?pj}koM=M>rh6CDd|$${HC2Gep#5L<0vjz`8XL<_lSr#$X?Xb7Fc4Hs_{-@R_mo15NVwZ^*r zuKX__`zUt93-|sdwVT>N{z!)s>2vsra=AP%<2q9D5H=UT=Tko$J@@^++#RW`ERo-E z8KQ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*5{@E-tQQo+w-z$WW?-s|!U~Y6Qld@CEXnSQ1 z`cOmKO62p2T~;b<=XZ&rJeJW`vN$@r3nmT;>+-Z+riyPxc zywY~b!cIxH`G5RK2A0THdPsh>A{KLgPr^#cb-wds819c+%o?oFAIdoH6Be^7^o{O(h7A%zI zQ<(%AXl^WHi>M4_6l`=j2hmQABd0+CrJU>>(bS0U_O$0HNy=39e`UcuYQTna5Y^{w z@{GpOW-^NNBcd3AqZnAgQUk?dm?W~p7_M5ByLK)b7|5q~atZAmnMb&o)#epumCp{* z$_`U9{&Q90eFf7~G|q%{orx~!&^<`DKcpF^OP$K#`G14qE-+4e-ls4Pv!bSM`*pxS z#63x_pZ7CNX+1}YE{0OV_06(GSNXBpD7ByWJxmYi1Ey^Zv20J56e(SfA8nzy{wdu+ zrhFfmbSb&xcO@|F6-({seH7EB(rUK-To2Q$QBL=8S?2u~({^p|Zoh`bZZOnjwr z)5BWP9X~$)>$QEa*5muqOlh4*iR`i3J1&0T1V$>QZ6dGxG$k8n(%~&Zli-~8VQt6s zU`bOkF8AUVm;IDhV9Mv4-LTB`HkUnL&}I594y<;-^|Qb4x$Jo#%9QWlv%dTIf2i$C z)r7UCrl)I>iQAs`5fneR=XE;Mb!@1q+x`)k{a9EjGNtvfGjZG)dm0SxM#wQl81EnW zJ8N!zmYKc?n`VbSKgTf@A#bz&O-Zvd+rNea>U(?{g!eW49lN8t{oFsR zrb;HN*oRedDgP84)vwh{INQ6g9FQ(0rhYKYs}hypt{onAg5X0gnQkanvftmK6!-AN zrS06hORCtno}&z|aT&No(O$*=PgW`WlX+lOss93P?~dP{bh8lY0X{KGEFCMiV?&kt zuUf4PCbS(Bcl^kYtBF!|O4}dP4;U>0O8?c|?|A-i0Oo3 +#include + +#include + +void err_if(int condition, const char* msg) +{ + if (condition) { + fprintf(stderr, "fatal: %s\n", msg); + exit(1); + } +} + +int main(int argc, char** argv) +{ + Display* display = XOpenDisplay(NULL); + err_if(!display, "unable to open display"); + + int kbd = argc == 1 ? XkbUseCoreKbd : atoi(argv[1]); + + XkbStateRec state; + XkbGetState(display, kbd, &state); + + XkbDescPtr desc = XkbGetKeyboard(display, XkbAllComponentsMask, kbd); + char* symbols = XGetAtomName(display, desc->names->symbols); + printf("%s\n", symbols); + +#if 0 + char *group = XGetAtomName(display, desc->names->groups[state.group]); + XFree(group); +#endif + XFree(symbols); + XFree(desc); + + XCloseDisplay(display); + + return 0; +} +