Add files

master v1.0
Nakidai 2024-02-19 23:11:14 +03:00
commit 5afd9290c0
4 changed files with 62 additions and 0 deletions

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
Copyright 2024 Nakidai
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

14
Makefile Normal file
View File

@ -0,0 +1,14 @@
PREFIX ?= /usr
all: getlayout
install: getlayout
install -m 555 getlayout ${PREFIX}/bin/getlayout
clean:
rm -f getlayout
getlayout:
cc -lX11 -lxkbfile getlayout.c -o getlayout
.PHONY: all install clean

4
README.md Normal file
View File

@ -0,0 +1,4 @@
getlayout
--
Some small utility to get current layout. Depends on X11.
Edited version of [this script](https://gist.github.com/fikovnik/ef428e82a26774280c4fdf8f96ce8eeb)

35
getlayout.c Normal file
View File

@ -0,0 +1,35 @@
/* cc -lX11 -lxkbfile getlayout.c */
#include <stdio.h>
#include <string.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.h>
int main(void)
{
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL)
{
fputs("Cannot open display\n", stderr);
return 1;
}
XkbStateRec state;
XkbGetState(dpy, XkbUseCoreKbd, &state);
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;
}
fputs(tok, stdout);
}