-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
902288f
commit dfd23a4
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.o | ||
|
||
# Vim swap files | ||
*swp | ||
*~ | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# pylint: disable=C0111,R0903 | ||
|
||
"""Displays the current keyboard layout | ||
Parameters: | ||
* layout.device: The device ID of the keyboard (as reported by `xinput -list`), defaults to the core device | ||
""" | ||
|
||
import re | ||
|
||
import core.widget | ||
import core.module | ||
|
||
import util.cli | ||
|
||
from bumblebee_status.discover import utility | ||
|
||
class Module(core.module.Module): | ||
def __init__(self, config, theme): | ||
super().__init__(config=config, theme=theme, widgets=core.widget.Widget(self.get_layout)) | ||
|
||
self._cmd = utility("get-kbd-layout") | ||
keyboard = self.parameter("device", None) | ||
if keyboard: | ||
self._cmd += " {}".format(keyboard) | ||
|
||
def get_layout(self, widget): | ||
result = util.cli.execute(self._cmd, ignore_errors=True) | ||
|
||
m = re.search("([a-zA-Z]+_)?([a-zA-Z]+)(\(([\w-]+)\))?", result) | ||
|
||
if m: | ||
layout = m.group(2) | ||
variant = m.group(3) | ||
return layout if not variant else "{} {}".format(layout, variant) | ||
|
||
return "n/a" | ||
|
||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CC=gcc | ||
CFLAGS= | ||
|
||
%.o: %.c | ||
$(CC) -c -o $@ $< $(CFLAGS) | ||
|
||
../bin/get-kbd-layout: layout.o | ||
$(CC) -o $@ layout.o -lX11 | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
rm -f *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <X11/XKBlib.h> | ||
|
||
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; | ||
} | ||
|