merging __20h__s changes.

This commit is contained in:
Enno Boland (tox) 2011-03-25 15:14:12 +01:00
parent e485fdb9eb
commit 6ad5403859
4 changed files with 88 additions and 57 deletions

View File

@ -4,7 +4,7 @@
include config.mk include config.mk
SRC = svkbd.c SRC = svkbd.c
OBJ = ${SRC:.c=.o} LAYOUTS = en de arrows
all: options svkbd all: options svkbd
@ -15,29 +15,32 @@ options:
@echo "CC = ${CC}" @echo "CC = ${CC}"
@echo "LAYOUT = ${LAYOUT}" @echo "LAYOUT = ${LAYOUT}"
.c.o: config.h: config.mk
@echo CC $<
@${CC} ${CPPFLAGS} -c ${CFLAGS} $<
${OBJ}: config.h config.mk
config.h:
@echo creating $@ from config.def.h @echo creating $@ from config.def.h
@cp config.def.h $@ @cp config.def.h $@
svkbd: ${OBJ}
svkbd: svkbd.en
@echo CP $@
@cp $< $@
svkbd.%: layout.%.h config.h ${SRC}
@echo creating layout.h from $<
@cp $< layout.h
@echo CC -o $@ @echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS} @${CC} -o $@ ${SRC} ${LDFLAGS} ${CFLAGS}
clean: clean:
@echo cleaning @echo cleaning
@rm -f svkbd ${OBJ} svkbd-${VERSION}.tar.gz @for i in ${LAYOUTS}; do rm svkbd.$$i 2> /dev/null; done; true
@rm -f svkbd ${OBJ} svkbd-${VERSION}.tar.gz 2> /dev/null; true
dist: clean dist: clean
@echo creating dist tarball @echo creating dist tarball
@mkdir -p svkbd-${VERSION} @mkdir -p svkbd-${VERSION}
@cp -R LICENSE Makefile README config.def.h config.mk \ @cp LICENSE Makefile README config.def.h config.mk \
${SRC} layouts svkbd-${VERSION} ${SRC} svkbd-${VERSION}
@for i in ${LAYOUTS}; do cp layout.$$i.h svkbd.${VERSION} || exit 1; done
@tar -cf svkbd-${VERSION}.tar svkbd-${VERSION} @tar -cf svkbd-${VERSION}.tar svkbd-${VERSION}
@gzip svkbd-${VERSION}.tar @gzip svkbd-${VERSION}.tar
@rm -rf svkbd-${VERSION} @rm -rf svkbd-${VERSION}

View File

@ -1,3 +1,4 @@
static const Bool wmborder = True;
static const char font[] = "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"; static const char font[] = "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*";
static const char normbgcolor[] = "#cccccc"; static const char normbgcolor[] = "#cccccc";
static const char normfgcolor[] = "#000000"; static const char normfgcolor[] = "#000000";
@ -5,4 +6,3 @@ static const char hovbgcolor[] = "#ffffff";
static const char hovfgcolor[] = "#000000"; static const char hovfgcolor[] = "#000000";
static const char pressbgcolor[] = "#0000cc"; static const char pressbgcolor[] = "#0000cc";
static const char pressfgcolor[] = "#ffffff"; static const char pressfgcolor[] = "#ffffff";

View File

@ -1,7 +1,7 @@
# svkbd version # svkbd version
VERSION = 0.1 VERSION = 0.1
LAYOUT?=def LAYOUT ?= en
# Customize below to fit your system # Customize below to fit your system
@ -18,7 +18,6 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXtst
# flags # flags
CPPFLAGS = -DVERSION=\"${VERSION}\" \ CPPFLAGS = -DVERSION=\"${VERSION}\" \
-DCONFIGLAYOUT_H=\"layout.${LAYOUT}.h\" \
${XINERAMAFLAGS} ${XINERAMAFLAGS}
CFLAGS = -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} CFLAGS = -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -g ${LIBS} LDFLAGS = -g ${LIBS}

111
svkbd.c
View File

@ -20,6 +20,7 @@
/* enums */ /* enums */
enum { ColFG, ColBG, ColLast }; enum { ColFG, ColBG, ColLast };
enum { NetWMWindowType, NetLast };
/* typedefs */ /* typedefs */
typedef unsigned int uint; typedef unsigned int uint;
@ -57,6 +58,7 @@ static void buttonpress(XEvent *e);
static void buttonrelease(XEvent *e); static void buttonrelease(XEvent *e);
static void cleanup(void); static void cleanup(void);
static void configurenotify(XEvent *e); static void configurenotify(XEvent *e);
static void countrows();
static void unmapnotify(XEvent *e); static void unmapnotify(XEvent *e);
static void die(const char *errstr, ...); static void die(const char *errstr, ...);
static void drawkeyboard(void); static void drawkeyboard(void);
@ -83,13 +85,18 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[Expose] = expose, [Expose] = expose,
[LeaveNotify] = leavenotify, [LeaveNotify] = leavenotify,
}; };
static Atom netatom[NetLast];
static Display *dpy; static Display *dpy;
static DC dc; static DC dc;
static Window root, win; static Window root, win;
static Bool running = True; static Bool running = True;
static KeySym pressedmod = 0; static KeySym pressedmod = 0;
static int rows, ww = 0, wh = 0, wx = 0, wy = 0;
static char *name = "svkbd";
static char *wintype = "_NET_WM_WINDOW_TYPE_TOOLBAR";
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
#include "layout.h"
void void
buttonpress(XEvent *e) { buttonpress(XEvent *e) {
@ -142,6 +149,15 @@ configurenotify(XEvent *e) {
} }
} }
void
countrows() {
int i = 0;
for(i = 0, rows = 1; i < LENGTH(keys); i++)
if(keys[i].keysym == 0)
rows++;
}
void void
die(const char *errstr, ...) { die(const char *errstr, ...) {
va_list ap; va_list ap;
@ -308,30 +324,32 @@ run(void) {
void void
setup(void) { setup(void) {
int i;
XWMHints *wmh;
XSetWindowAttributes wa; XSetWindowAttributes wa;
XTextProperty str;
XClassHint *ch;
int i, sh, sw;
XWMHints *wmh;
/* init screen */ /* init screen */
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen); root = RootWindow(dpy, screen);
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
initfont(font); initfont(font);
/* init atoms */
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
/* init appearance */ /* init appearance */
if (!ww) countrows();
ww = DisplayWidth(dpy, screen); if(!ww)
if (ww < 0) ww = sw - wx;
ww = DisplayWidth(dpy, screen) / (ww * -1); if(!wx)
wx = 0;
if (wh < 0) if(!wh)
wh = DisplayHeight(dpy, screen) / (wh * -1); wh = sh * rows / 32;
if(!wy)
if (wy < 0) wy = sh - wh;
wy = DisplayHeight(dpy, screen) + wy;
if (wx < 0)
wx = DisplayWidth(dpy, screen) + wx;
dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColBG] = getcolor(normbgcolor);
dc.norm[ColFG] = getcolor(normfgcolor); dc.norm[ColFG] = getcolor(normfgcolor);
dc.press[ColBG] = getcolor(pressbgcolor); dc.press[ColBG] = getcolor(pressbgcolor);
@ -343,7 +361,7 @@ setup(void) {
for(i = 0; i < LENGTH(keys); i++) for(i = 0; i < LENGTH(keys); i++)
keys[i].pressed = 0; keys[i].pressed = 0;
wa.override_redirect = True; wa.override_redirect = !wmborder;
wa.border_pixel = dc.norm[ColFG]; wa.border_pixel = dc.norm[ColFG];
wa.background_pixel = dc.norm[ColBG]; wa.background_pixel = dc.norm[ColBG];
win = XCreateWindow(dpy, root, wx, wy, ww, wh, 0, win = XCreateWindow(dpy, root, wx, wy, ww, wh, 0,
@ -351,11 +369,27 @@ setup(void) {
CWOverrideRedirect | CWBorderPixel | CWBackingPixel, &wa); CWOverrideRedirect | CWBorderPixel | CWBackingPixel, &wa);
XSelectInput(dpy, win, StructureNotifyMask|ButtonReleaseMask| XSelectInput(dpy, win, StructureNotifyMask|ButtonReleaseMask|
ButtonPressMask|ExposureMask|LeaveWindowMask); ButtonPressMask|ExposureMask|LeaveWindowMask);
wmh = XAllocWMHints(); wmh = XAllocWMHints();
wmh->input = False; wmh->input = False;
wmh->flags = InputHint; wmh->flags = InputHint;
XSetWMHints(dpy, win, wmh); XSetWMHints(dpy, win, wmh);
XStringListToTextProperty(&name, 1, &str);
ch = XAllocClassHint();
ch->res_class = name;
ch->res_name = name;
XSetWMProperties(dpy, win, &str, &str, NULL, 0, NULL, wmh,
ch);
XFree(ch);
XFree(wmh); XFree(wmh);
XFree(str.value);
XStringListToTextProperty(&wintype, 1, &str);
XSetTextProperty(dpy, win, &str, netatom[NetWMWindowType]);
XFree(str.value);
XMapRaised(dpy, win); XMapRaised(dpy, win);
updatekeys(); updatekeys();
drawkeyboard(); drawkeyboard();
@ -399,12 +433,9 @@ unpress() {
void void
updatekeys() { updatekeys() {
int rows, i, j; int i, j;
int x = 0, y = 0, h, base; int x = 0, y = 0, h, base;
for(i = 0, rows = 1; i < LENGTH(keys); i++)
if(keys[i].keysym == 0)
rows++;
h = wh / rows; h = wh / rows;
for(i = 0; i < LENGTH(keys); i++, rows--) { for(i = 0; i < LENGTH(keys); i++, rows--) {
for(j = i, base = 0; j < LENGTH(keys) && keys[j].keysym != 0; j++) for(j = i, base = 0; j < LENGTH(keys) && keys[j].keysym != 0; j++)
@ -441,27 +472,25 @@ main(int argc, char *argv[]) {
die("svkbd-"VERSION", © 2006-2010 svkbd engineers," die("svkbd-"VERSION", © 2006-2010 svkbd engineers,"
" see LICENSE for details\n"); " see LICENSE for details\n");
} }
if(!strcmp(argv[i], "-wh")) { else if(argv[i][0] == '-' && argv[i][1] == 'w') {
wh = atoi(argv[i+1]); switch(i >= argc - 1 ? 0 : argv[i][2]) {
i++; case 'h':
continue; wh = atoi(argv[i+1]);
break;
case 'w':
ww = atoi(argv[i+1]);
break;
case 'x':
wx = atoi(argv[i+1]);
break;
case 'y':
wy = atoi(argv[i+1]);
break;
default:
usage(argv[0]);
}
} }
if(!strcmp(argv[i], "-ww")) { else if(!strcmp(argv[i], "-h"))
ww = atoi(argv[i+1]);
i++;
continue;
}
if(!strcmp(argv[i], "-wx")) {
wx = atoi(argv[i+1]);
i++;
continue;
}
if(!strcmp(argv[i], "-wy")) {
wy = atoi(argv[i+1]);
i++;
continue;
}
if(!strcmp(argv[i], "-h"))
usage(argv[0]); usage(argv[0]);
} }