some code-style consistency changes + small tweaks
This commit is contained in:
parent
4983666e33
commit
73f0edf709
411
svkbd.c
411
svkbd.c
@ -1,12 +1,16 @@
|
|||||||
/* See LICENSE file for copyright and license details.
|
/* See LICENSE file for copyright and license details. */
|
||||||
*
|
#include <sys/select.h>
|
||||||
* To understand svkbd, start reading main().
|
#include <sys/time.h>
|
||||||
*/
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/keysymdef.h>
|
#include <X11/keysymdef.h>
|
||||||
#include <X11/XF86keysym.h>
|
#include <X11/XF86keysym.h>
|
||||||
@ -19,16 +23,10 @@
|
|||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
#include <X11/extensions/Xinerama.h>
|
#include <X11/extensions/Xinerama.h>
|
||||||
#endif
|
#endif
|
||||||
#include <signal.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "drw.h"
|
#include "drw.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define LENGTH(x) (sizeof x / sizeof x[0])
|
#define LENGTH(x) (sizeof x / sizeof x[0])
|
||||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)))
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)))
|
||||||
@ -57,14 +55,14 @@ typedef struct {
|
|||||||
} Buttonmod;
|
} Buttonmod;
|
||||||
|
|
||||||
/* function declarations */
|
/* function declarations */
|
||||||
static void printdbg(const char * fmt, ...);
|
static void printdbg(const char *fmt, ...);
|
||||||
static void motionnotify(XEvent *e);
|
static void motionnotify(XEvent *e);
|
||||||
static void buttonpress(XEvent *e);
|
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 countrows();
|
||||||
static int countkeys(Key *k);
|
static int countkeys(Key *layer);
|
||||||
static void drawkeyboard(void);
|
static void drawkeyboard(void);
|
||||||
static void drawkey(Key *k);
|
static void drawkey(Key *k);
|
||||||
static void expose(XEvent *e);
|
static void expose(XEvent *e);
|
||||||
@ -135,13 +133,13 @@ motionnotify(XEvent *e)
|
|||||||
XPointerMovedEvent *ev = &e->xmotion;
|
XPointerMovedEvent *ev = &e->xmotion;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].keysym && ev->x > keys[i].x
|
if (keys[i].keysym && ev->x > keys[i].x
|
||||||
&& ev->x < keys[i].x + keys[i].w
|
&& ev->x < keys[i].x + keys[i].w
|
||||||
&& ev->y > keys[i].y
|
&& ev->y > keys[i].y
|
||||||
&& ev->y < keys[i].y + keys[i].h) {
|
&& ev->y < keys[i].y + keys[i].h) {
|
||||||
if(keys[i].highlighted != True) {
|
if (keys[i].highlighted != True) {
|
||||||
if(ispressing) {
|
if (ispressing) {
|
||||||
keys[i].pressed = True;
|
keys[i].pressed = True;
|
||||||
} else {
|
} else {
|
||||||
keys[i].highlighted = True;
|
keys[i].highlighted = True;
|
||||||
@ -151,12 +149,12 @@ motionnotify(XEvent *e)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IsModifierKey(keys[i].keysym) && keys[i].pressed == True) {
|
if (!IsModifierKey(keys[i].keysym) && keys[i].pressed == True) {
|
||||||
unpress(&keys[i], 0);
|
unpress(&keys[i], 0);
|
||||||
|
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
if(keys[i].highlighted == True) {
|
if (keys[i].highlighted == True) {
|
||||||
keys[i].highlighted = False;
|
keys[i].highlighted = False;
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
@ -164,50 +162,53 @@ motionnotify(XEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buttonpress(XEvent *e) {
|
buttonpress(XEvent *e)
|
||||||
int i;
|
{
|
||||||
XButtonPressedEvent *ev = &e->xbutton;
|
XButtonPressedEvent *ev = &e->xbutton;
|
||||||
Key *k;
|
Key *k;
|
||||||
KeySym mod = 0;
|
KeySym mod = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
ispressing = True;
|
ispressing = True;
|
||||||
|
|
||||||
for(i = 0; i < LENGTH(buttonmods); i++) {
|
for (i = 0; i < LENGTH(buttonmods); i++) {
|
||||||
if(ev->button == buttonmods[i].button) {
|
if (ev->button == buttonmods[i].button) {
|
||||||
mod = buttonmods[i].mod;
|
mod = buttonmods[i].mod;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((k = findkey(ev->x, ev->y)))
|
if ((k = findkey(ev->x, ev->y)))
|
||||||
press(k, mod);
|
press(k, mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buttonrelease(XEvent *e) {
|
buttonrelease(XEvent *e)
|
||||||
int i;
|
{
|
||||||
XButtonPressedEvent *ev = &e->xbutton;
|
XButtonPressedEvent *ev = &e->xbutton;
|
||||||
Key *k;
|
Key *k;
|
||||||
KeySym mod = 0;
|
KeySym mod = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
ispressing = False;
|
ispressing = False;
|
||||||
|
|
||||||
for(i = 0; i < LENGTH(buttonmods); i++) {
|
for (i = 0; i < LENGTH(buttonmods); i++) {
|
||||||
if(ev->button == buttonmods[i].button) {
|
if (ev->button == buttonmods[i].button) {
|
||||||
mod = buttonmods[i].mod;
|
mod = buttonmods[i].mod;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ev->x < 0 || ev->y < 0) {
|
if (ev->x < 0 || ev->y < 0) {
|
||||||
unpress(NULL, mod);
|
unpress(NULL, mod);
|
||||||
} else {
|
} else {
|
||||||
if((k = findkey(ev->x, ev->y)))
|
if ((k = findkey(ev->x, ev->y)))
|
||||||
unpress(k, mod);
|
unpress(k, mod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cleanup(void) {
|
cleanup(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < SchemeLast; i++)
|
for (i = 0; i < SchemeLast; i++)
|
||||||
@ -222,10 +223,11 @@ cleanup(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
configurenotify(XEvent *e) {
|
configurenotify(XEvent *e)
|
||||||
|
{
|
||||||
XConfigureEvent *ev = &e->xconfigure;
|
XConfigureEvent *ev = &e->xconfigure;
|
||||||
|
|
||||||
if(ev->window == win && (ev->width != ww || ev->height != wh)) {
|
if (ev->window == win && (ev->width != ww || ev->height != wh)) {
|
||||||
ww = ev->width;
|
ww = ev->width;
|
||||||
wh = ev->height;
|
wh = ev->height;
|
||||||
drw_resize(drw, ww, wh);
|
drw_resize(drw, ww, wh);
|
||||||
@ -234,50 +236,52 @@ configurenotify(XEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
countrows() {
|
countrows(void)
|
||||||
int i = 0;
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
for(i = 0, rows = 1; i < numkeys; i++) {
|
for (i = 0, rows = 1; i < numkeys; i++) {
|
||||||
if(keys[i].keysym == 0)
|
if (keys[i].keysym == 0)
|
||||||
rows++;
|
rows++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
countkeys(Key * layer) {
|
countkeys(Key *layer)
|
||||||
int keys = 0;
|
{
|
||||||
int i;
|
int i, nkeys = 0;
|
||||||
|
|
||||||
for(i = 0; i < KEYS; i++) {
|
for (i = 0; i < KEYS; i++) {
|
||||||
if (i > 0 && layer[i].keysym == 0 && layer[i-1].keysym == 0) {
|
if (i > 0 && layer[i].keysym == 0 && layer[i - 1].keysym == 0) {
|
||||||
keys--;
|
nkeys--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
keys++;
|
nkeys++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return keys;
|
return nkeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
drawkeyboard(void) {
|
drawkeyboard(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].keysym != 0)
|
if (keys[i].keysym != 0)
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawkey(Key *k) {
|
drawkey(Key *k)
|
||||||
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
const char *l;
|
const char *l;
|
||||||
|
|
||||||
if(k->pressed)
|
if (k->pressed)
|
||||||
drw_setscheme(drw, scheme[SchemePress]);
|
drw_setscheme(drw, scheme[SchemePress]);
|
||||||
else if(k->highlighted)
|
else if (k->highlighted)
|
||||||
drw_setscheme(drw, scheme[SchemeHighlight]);
|
drw_setscheme(drw, scheme[SchemeHighlight]);
|
||||||
else
|
else
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
@ -290,7 +294,7 @@ drawkey(Key *k) {
|
|||||||
} else {
|
} else {
|
||||||
l = "≇";
|
l = "≇";
|
||||||
}
|
}
|
||||||
} else if(k->label) {
|
} else if (k->label) {
|
||||||
l = k->label;
|
l = k->label;
|
||||||
} else {
|
} else {
|
||||||
l = XKeysymToString(k->keysym);
|
l = XKeysymToString(k->keysym);
|
||||||
@ -304,10 +308,11 @@ drawkey(Key *k) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
expose(XEvent *e) {
|
expose(XEvent *e)
|
||||||
|
{
|
||||||
XExposeEvent *ev = &e->xexpose;
|
XExposeEvent *ev = &e->xexpose;
|
||||||
|
|
||||||
if(ev->count == 0 && (ev->window == win))
|
if (ev->count == 0 && (ev->window == win))
|
||||||
drawkeyboard();
|
drawkeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,8 +320,8 @@ Key *
|
|||||||
findkey(int x, int y) {
|
findkey(int x, int y) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].keysym && x > keys[i].x &&
|
if (keys[i].keysym && x > keys[i].x &&
|
||||||
x < keys[i].x + keys[i].w &&
|
x < keys[i].x + keys[i].w &&
|
||||||
y > keys[i].y && y < keys[i].y + keys[i].h) {
|
y > keys[i].y && y < keys[i].y + keys[i].h) {
|
||||||
return &keys[i];
|
return &keys[i];
|
||||||
@ -325,15 +330,16 @@ findkey(int x, int y) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
hasoverlay(KeySym keysym) {
|
hasoverlay(KeySym keysym)
|
||||||
|
{
|
||||||
int begin, i;
|
int begin, i;
|
||||||
|
|
||||||
begin = 0;
|
begin = 0;
|
||||||
for(i = 0; i < OVERLAYS; i++) {
|
for (i = 0; i < OVERLAYS; i++) {
|
||||||
if(overlay[i].keysym == XK_Cancel) {
|
if (overlay[i].keysym == XK_Cancel) {
|
||||||
begin = i+1;
|
begin = i+1;
|
||||||
} else if(overlay[i].keysym == keysym) {
|
} else if (overlay[i].keysym == keysym) {
|
||||||
return begin+1;
|
return begin+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,23 +347,28 @@ hasoverlay(KeySym keysym) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
leavenotify(XEvent *e) {
|
leavenotify(XEvent *e)
|
||||||
|
{
|
||||||
if (currentoverlay != -1) {
|
if (currentoverlay != -1) {
|
||||||
hideoverlay();
|
hideoverlay();
|
||||||
}
|
}
|
||||||
unpress(NULL, 0);
|
unpress(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void record_press_begin(KeySym ks) {
|
void
|
||||||
|
record_press_begin(KeySym ks)
|
||||||
|
{
|
||||||
/* record the begin of the press, don't simulate the actual keypress yet */
|
/* record the begin of the press, don't simulate the actual keypress yet */
|
||||||
gettimeofday(&pressbegin, NULL);
|
gettimeofday(&pressbegin, NULL);
|
||||||
ispressingkeysym = ks;
|
ispressingkeysym = ks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
press(Key *k, KeySym mod) {
|
press(Key *k, KeySym mod)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
int overlayidx = -1;
|
int overlayidx = -1;
|
||||||
|
|
||||||
k->pressed = !k->pressed;
|
k->pressed = !k->pressed;
|
||||||
|
|
||||||
if (debug) printdbg("Begin press: %ld\n", k->keysym);
|
if (debug) printdbg("Begin press: %ld\n", k->keysym);
|
||||||
@ -365,7 +376,7 @@ press(Key *k, KeySym mod) {
|
|||||||
pressbegin.tv_usec = 0;
|
pressbegin.tv_usec = 0;
|
||||||
ispressingkeysym = 0;
|
ispressingkeysym = 0;
|
||||||
|
|
||||||
if(!IsModifierKey(k->keysym)) {
|
if (!IsModifierKey(k->keysym)) {
|
||||||
if (enableoverlays && currentoverlay == -1)
|
if (enableoverlays && currentoverlay == -1)
|
||||||
overlayidx = hasoverlay(k->keysym);
|
overlayidx = hasoverlay(k->keysym);
|
||||||
if (enableoverlays && overlayidx != -1) {
|
if (enableoverlays && overlayidx != -1) {
|
||||||
@ -375,19 +386,19 @@ press(Key *k, KeySym mod) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (debug) printdbg("Simulating press: %ld\n", k->keysym);
|
if (debug) printdbg("Simulating press: %ld\n", k->keysym);
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
||||||
simulate_keypress(keys[i].keysym);
|
simulate_keypress(keys[i].keysym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pressedmod = mod;
|
pressedmod = mod;
|
||||||
if(pressedmod) {
|
if (pressedmod) {
|
||||||
simulate_keypress(mod);
|
simulate_keypress(mod);
|
||||||
}
|
}
|
||||||
simulate_keypress(k->keysym);
|
simulate_keypress(k->keysym);
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
||||||
simulate_keyrelease(keys[i].keysym);
|
simulate_keyrelease(keys[i].keysym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,18 +407,18 @@ press(Key *k, KeySym mod) {
|
|||||||
drawkey(k);
|
drawkey(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
tmp_remap(KeySym keysym)
|
||||||
|
{
|
||||||
|
|
||||||
int tmp_remap(KeySym keysym) {
|
|
||||||
XChangeKeyboardMapping(dpy, tmp_keycode, 1, &keysym, 1);
|
XChangeKeyboardMapping(dpy, tmp_keycode, 1, &keysym, 1);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|
||||||
return tmp_keycode;
|
return tmp_keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
simulate_keypress(KeySym keysym) {
|
simulate_keypress(KeySym keysym)
|
||||||
|
{
|
||||||
KeyCode code = XKeysymToKeycode(dpy, keysym);
|
KeyCode code = XKeysymToKeycode(dpy, keysym);
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
code = tmp_remap(keysym);
|
code = tmp_remap(keysym);
|
||||||
@ -415,25 +426,32 @@ simulate_keypress(KeySym keysym) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
simulate_keyrelease(KeySym keysym) {
|
simulate_keyrelease(KeySym keysym)
|
||||||
|
{
|
||||||
KeyCode code = XKeysymToKeycode(dpy, keysym);
|
KeyCode code = XKeysymToKeycode(dpy, keysym);
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
code = tmp_remap(keysym);
|
code = tmp_remap(keysym);
|
||||||
XTestFakeKeyEvent(dpy, code, False, 0);
|
XTestFakeKeyEvent(dpy, code, False, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
double get_press_duration() {
|
get_press_duration(void)
|
||||||
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
return (double) ((now.tv_sec * 1000000L + now.tv_usec) - (pressbegin.tv_sec * 1000000L + pressbegin.tv_usec)) / (double) 1000000L;
|
|
||||||
|
return (double) ((now.tv_sec * 1000000L + now.tv_usec) -
|
||||||
|
(pressbegin.tv_sec * 1000000L + pressbegin.tv_usec)) /
|
||||||
|
(double) 1000000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unpress(Key *k, KeySym mod) {
|
unpress(Key *k, KeySym mod)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(k != NULL) {
|
if (k != NULL) {
|
||||||
switch(k->keysym) {
|
switch(k->keysym) {
|
||||||
case XK_Cancel:
|
case XK_Cancel:
|
||||||
cyclelayer();
|
cyclelayer();
|
||||||
@ -451,19 +469,18 @@ unpress(Key *k, KeySym mod) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((pressbegin.tv_sec || pressbegin.tv_usec) && enableoverlays && k && k->keysym == ispressingkeysym) {
|
if ((pressbegin.tv_sec || pressbegin.tv_usec) && enableoverlays && k && k->keysym == ispressingkeysym) {
|
||||||
if (currentoverlay == -1) {
|
if (currentoverlay == -1) {
|
||||||
if (get_press_duration() < overlay_delay) {
|
if (get_press_duration() < overlay_delay) {
|
||||||
if (debug) printdbg("Delayed simulation of press after release: %ld\n", k->keysym);
|
if (debug) printdbg("Delayed simulation of press after release: %ld\n", k->keysym);
|
||||||
/* simulate the press event, as we postponed it earlier in press() */
|
/* simulate the press event, as we postponed it earlier in press() */
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && IsModifierKey(keys[i].keysym)) {
|
||||||
simulate_keypress(keys[i].keysym);
|
simulate_keypress(keys[i].keysym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pressedmod = mod;
|
pressedmod = mod;
|
||||||
if(pressedmod) {
|
if (pressedmod) {
|
||||||
simulate_keypress(mod);
|
simulate_keypress(mod);
|
||||||
}
|
}
|
||||||
simulate_keypress(k->keysym);
|
simulate_keypress(k->keysym);
|
||||||
@ -484,22 +501,22 @@ unpress(Key *k, KeySym mod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
||||||
simulate_keyrelease(keys[i].keysym);
|
simulate_keyrelease(keys[i].keysym);
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i != numkeys) {
|
if (i != numkeys) {
|
||||||
if(pressedmod) {
|
if (pressedmod) {
|
||||||
simulate_keyrelease(mod);
|
simulate_keyrelease(mod);
|
||||||
}
|
}
|
||||||
pressedmod = 0;
|
pressedmod = 0;
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed) {
|
if (keys[i].pressed) {
|
||||||
simulate_keyrelease(keys[i].keysym);
|
simulate_keyrelease(keys[i].keysym);
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
@ -517,7 +534,8 @@ unpress(Key *k, KeySym mod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run(void) {
|
run(void)
|
||||||
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
int xfd;
|
int xfd;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
@ -525,23 +543,21 @@ run(void) {
|
|||||||
double duration = 0.0;
|
double duration = 0.0;
|
||||||
int i, r;
|
int i, r;
|
||||||
|
|
||||||
|
|
||||||
xfd = ConnectionNumber(dpy);
|
xfd = ConnectionNumber(dpy);
|
||||||
tv.tv_usec = 0;
|
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
usleep(100000L);
|
usleep(100000L); /* 100ms */
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(xfd, &fds);
|
FD_SET(xfd, &fds);
|
||||||
r = select(xfd + 1, &fds, NULL, NULL, &tv);
|
r = select(xfd + 1, &fds, NULL, NULL, &tv);
|
||||||
if (r) {
|
if (r) {
|
||||||
while (XPending(dpy)) {
|
while (XPending(dpy)) {
|
||||||
XNextEvent(dpy, &ev);
|
XNextEvent(dpy, &ev);
|
||||||
if(handler[ev.type]) {
|
if (handler[ev.type]) {
|
||||||
(handler[ev.type])(&ev); /* call handler */
|
(handler[ev.type])(&ev); /* call handler */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -577,7 +593,8 @@ run(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setup(void) {
|
setup(void)
|
||||||
|
{
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
XTextProperty str;
|
XTextProperty str;
|
||||||
XSizeHints *sizeh = NULL;
|
XSizeHints *sizeh = NULL;
|
||||||
@ -586,43 +603,45 @@ setup(void) {
|
|||||||
int i, j, sh, sw;
|
int i, j, sh, sw;
|
||||||
XWMHints *wmh;
|
XWMHints *wmh;
|
||||||
|
|
||||||
#if XINERAMA
|
#ifdef XINERAMA
|
||||||
XineramaScreenInfo *info = NULL;
|
XineramaScreenInfo *info = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* init screen */
|
/* init screen */
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
#if XINERAMA
|
#ifdef XINERAMA
|
||||||
if(XineramaIsActive(dpy)) {
|
if (XineramaIsActive(dpy)) {
|
||||||
info = XineramaQueryScreens(dpy, &i);
|
info = XineramaQueryScreens(dpy, &i);
|
||||||
sw = info[0].width;
|
sw = info[0].width;
|
||||||
sh = info[0].height;
|
sh = info[0].height;
|
||||||
XFree(info);
|
XFree(info);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
sw = DisplayWidth(dpy, screen);
|
sw = DisplayWidth(dpy, screen);
|
||||||
sh = DisplayHeight(dpy, screen);
|
sh = DisplayHeight(dpy, screen);
|
||||||
}
|
}
|
||||||
drw = drw_create(dpy, screen, root, sw, sh);
|
drw = drw_create(dpy, screen, root, sw, sh);
|
||||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||||
die("no fonts could be loaded.");
|
die("no fonts could be loaded");
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
|
||||||
/* find an unused keycode to use as a temporary keycode (derived from source: https://stackoverflow.com/questions/44313966/c-xtest-emitting-key-presses-for-every-unicode-character) */
|
/* find an unused keycode to use as a temporary keycode (derived from source:
|
||||||
|
https://stackoverflow.com/questions/44313966/c-xtest-emitting-key-presses-for-every-unicode-character) */
|
||||||
KeySym *keysyms = NULL;
|
KeySym *keysyms = NULL;
|
||||||
int keysyms_per_keycode = 0;
|
int keysyms_per_keycode = 0;
|
||||||
int keycode_low, keycode_high;
|
int keycode_low, keycode_high;
|
||||||
Bool key_is_empty;
|
Bool key_is_empty;
|
||||||
int symindex;
|
int symindex;
|
||||||
|
|
||||||
XDisplayKeycodes(dpy, &keycode_low, &keycode_high);
|
XDisplayKeycodes(dpy, &keycode_low, &keycode_high);
|
||||||
keysyms = XGetKeyboardMapping(dpy, keycode_low, keycode_high - keycode_low, &keysyms_per_keycode);
|
keysyms = XGetKeyboardMapping(dpy, keycode_low, keycode_high - keycode_low, &keysyms_per_keycode);
|
||||||
for(i = keycode_low; i <= keycode_high; i++) {
|
for (i = keycode_low; i <= keycode_high; i++) {
|
||||||
key_is_empty = True;
|
key_is_empty = True;
|
||||||
for(j = 0; j < keysyms_per_keycode; j++) {
|
for (j = 0; j < keysyms_per_keycode; j++) {
|
||||||
symindex = (i - keycode_low) * keysyms_per_keycode + j;
|
symindex = (i - keycode_low) * keysyms_per_keycode + j;
|
||||||
if(keysyms[symindex] != 0) {
|
if (keysyms[symindex] != 0) {
|
||||||
key_is_empty = False;
|
key_is_empty = False;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -639,7 +658,7 @@ setup(void) {
|
|||||||
scheme[j] = drw_scm_create(drw, colors[j], 2);
|
scheme[j] = drw_scm_create(drw, colors[j], 2);
|
||||||
|
|
||||||
/* init atoms */
|
/* init atoms */
|
||||||
if(isdock) {
|
if (isdock) {
|
||||||
netatom[NetWMWindowType] = XInternAtom(dpy,
|
netatom[NetWMWindowType] = XInternAtom(dpy,
|
||||||
"_NET_WM_WINDOW_TYPE", False);
|
"_NET_WM_WINDOW_TYPE", False);
|
||||||
atype = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
|
atype = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
|
||||||
@ -647,21 +666,21 @@ setup(void) {
|
|||||||
|
|
||||||
/* init appearance */
|
/* init appearance */
|
||||||
countrows();
|
countrows();
|
||||||
if(!ww)
|
if (!ww)
|
||||||
ww = sw;
|
ww = sw;
|
||||||
if(!wh)
|
if (!wh)
|
||||||
wh = sh * rows / heightfactor;
|
wh = sh * rows / heightfactor;
|
||||||
|
|
||||||
if(!wx)
|
if (!wx)
|
||||||
wx = 0;
|
wx = 0;
|
||||||
if(wx < 0)
|
if (wx < 0)
|
||||||
wx = sw + wx - ww;
|
wx = sw + wx - ww;
|
||||||
if(!wy)
|
if (!wy)
|
||||||
wy = sh - wh;
|
wy = sh - wh;
|
||||||
if(wy < 0)
|
if (wy < 0)
|
||||||
wy = sh + wy - wh;
|
wy = sh + wy - wh;
|
||||||
|
|
||||||
for(i = 0; i < numkeys; i++)
|
for (i = 0; i < numkeys; i++)
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
|
|
||||||
wa.override_redirect = !wmborder;
|
wa.override_redirect = !wmborder;
|
||||||
@ -678,7 +697,7 @@ setup(void) {
|
|||||||
wmh = XAllocWMHints();
|
wmh = XAllocWMHints();
|
||||||
wmh->input = False;
|
wmh->input = False;
|
||||||
wmh->flags = InputHint;
|
wmh->flags = InputHint;
|
||||||
if(!isdock) {
|
if (!isdock) {
|
||||||
sizeh = XAllocSizeHints();
|
sizeh = XAllocSizeHints();
|
||||||
sizeh->flags = PMaxSize | PMinSize;
|
sizeh->flags = PMaxSize | PMinSize;
|
||||||
sizeh->min_width = sizeh->max_width = ww;
|
sizeh->min_width = sizeh->max_width = ww;
|
||||||
@ -696,10 +715,10 @@ setup(void) {
|
|||||||
XFree(ch);
|
XFree(ch);
|
||||||
XFree(wmh);
|
XFree(wmh);
|
||||||
XFree(str.value);
|
XFree(str.value);
|
||||||
if(sizeh != NULL)
|
if (sizeh != NULL)
|
||||||
XFree(sizeh);
|
XFree(sizeh);
|
||||||
|
|
||||||
if(isdock) {
|
if (isdock) {
|
||||||
XChangeProperty(dpy, win, netatom[NetWMWindowType], XA_ATOM,
|
XChangeProperty(dpy, win, netatom[NetWMWindowType], XA_ATOM,
|
||||||
32, PropModeReplace,
|
32, PropModeReplace,
|
||||||
(unsigned char *)&atype, 1);
|
(unsigned char *)&atype, 1);
|
||||||
@ -711,31 +730,32 @@ setup(void) {
|
|||||||
drawkeyboard();
|
drawkeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
updatekeys() {
|
updatekeys(void)
|
||||||
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
int x = 0, y = 0, h, base, r = rows;
|
int x = 0, y = 0, h, base, r = rows;
|
||||||
|
|
||||||
h = (wh - 1) / rows;
|
h = (wh - 1) / rows;
|
||||||
for(i = 0; i < numkeys; i++, r--) {
|
for (i = 0; i < numkeys; i++, r--) {
|
||||||
for(j = i, base = 0; j < numkeys && keys[j].keysym != 0; j++)
|
for (j = i, base = 0; j < numkeys && keys[j].keysym != 0; j++)
|
||||||
base += keys[j].width;
|
base += keys[j].width;
|
||||||
for(x = 0; i < numkeys && keys[i].keysym != 0; i++) {
|
for (x = 0; i < numkeys && keys[i].keysym != 0; i++) {
|
||||||
keys[i].x = x;
|
keys[i].x = x;
|
||||||
keys[i].y = y;
|
keys[i].y = y;
|
||||||
keys[i].w = keys[i].width * (ww - 1) / base;
|
keys[i].w = keys[i].width * (ww - 1) / base;
|
||||||
keys[i].h = r == 1 ? wh - y - 1 : h;
|
keys[i].h = r == 1 ? wh - y - 1 : h;
|
||||||
x += keys[i].w;
|
x += keys[i].w;
|
||||||
}
|
}
|
||||||
if(base != 0)
|
if (base != 0)
|
||||||
keys[i - 1].w = ww - 1 - keys[i - 1].x;
|
keys[i - 1].w = ww - 1 - keys[i - 1].x;
|
||||||
y += h;
|
y += h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(char *argv0) {
|
usage(char *argv0)
|
||||||
|
{
|
||||||
fprintf(stderr, "usage: %s [-hdvDO] [-g geometry] [-fn font] [-l layers] [-s initial_layer]\n", argv0);
|
fprintf(stderr, "usage: %s [-hdvDO] [-g geometry] [-fn font] [-l layers] [-s initial_layer]\n", argv0);
|
||||||
fprintf(stderr, "Options:\n");
|
fprintf(stderr, "Options:\n");
|
||||||
fprintf(stderr, " -d - Set Dock Window Type\n");
|
fprintf(stderr, " -d - Set Dock Window Type\n");
|
||||||
@ -748,13 +768,16 @@ usage(char *argv0) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setlayer() {
|
void
|
||||||
|
setlayer(void)
|
||||||
|
{
|
||||||
numkeys = countkeys(layers[currentlayer]);
|
numkeys = countkeys(layers[currentlayer]);
|
||||||
memcpy(&keys, layers[currentlayer], sizeof(Key) * numkeys);
|
memcpy(&keys, layers[currentlayer], sizeof(Key) * numkeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cyclelayer() {
|
cyclelayer(void)
|
||||||
|
{
|
||||||
currentlayer++;
|
currentlayer++;
|
||||||
if (currentlayer >= numlayers)
|
if (currentlayer >= numlayers)
|
||||||
currentlayer = 0;
|
currentlayer = 0;
|
||||||
@ -765,7 +788,8 @@ cyclelayer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
togglelayer() {
|
togglelayer(void)
|
||||||
|
{
|
||||||
if (currentlayer > 0) {
|
if (currentlayer > 0) {
|
||||||
currentlayer = 0;
|
currentlayer = 0;
|
||||||
} else if (numlayers > 1) {
|
} else if (numlayers > 1) {
|
||||||
@ -777,14 +801,15 @@ togglelayer() {
|
|||||||
drawkeyboard();
|
drawkeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
showoverlay(int idx) {
|
showoverlay(int idx)
|
||||||
|
{
|
||||||
if (debug) printdbg("Showing overlay %d\n", idx);
|
if (debug) printdbg("Showing overlay %d\n", idx);
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
/* unpress existing key (visually only) */
|
/* unpress existing key (visually only) */
|
||||||
for(i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if(keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i]);
|
drawkey(&keys[i]);
|
||||||
break;
|
break;
|
||||||
@ -808,7 +833,8 @@ showoverlay(int idx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hideoverlay() {
|
hideoverlay(void)
|
||||||
|
{
|
||||||
if (debug) printdbg("Hiding overlay %d\n", currentoverlay);
|
if (debug) printdbg("Hiding overlay %d\n", currentoverlay);
|
||||||
currentoverlay = -1;
|
currentoverlay = -1;
|
||||||
overlaykeysym = 0;
|
overlaykeysym = 0;
|
||||||
@ -816,19 +842,20 @@ hideoverlay() {
|
|||||||
cyclelayer();
|
cyclelayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sigterm(int sig)
|
sigterm(int signo)
|
||||||
{
|
{
|
||||||
running = False;
|
running = False;
|
||||||
sigtermd = True;
|
sigtermd = True;
|
||||||
if (debug) printdbg("Sigterm received\n");
|
if (debug) printdbg("Sigterm received\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_layers(char * layer_names_list, const char * initial_layer_name) {
|
init_layers(char *layer_names_list, const char *initial_layer_name)
|
||||||
int j;
|
{
|
||||||
|
char *s;
|
||||||
|
int j, found;
|
||||||
|
|
||||||
if (layer_names_list == NULL) {
|
if (layer_names_list == NULL) {
|
||||||
numlayers = LAYERS;
|
numlayers = LAYERS;
|
||||||
memcpy(&layers, &available_layers, sizeof(available_layers));
|
memcpy(&layers, &available_layers, sizeof(available_layers));
|
||||||
@ -841,11 +868,11 @@ init_layers(char * layer_names_list, const char * initial_layer_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char * s;
|
|
||||||
s = strtok(layer_names_list, ",");
|
s = strtok(layer_names_list, ",");
|
||||||
while (s != NULL) {
|
while (s != NULL) {
|
||||||
if (numlayers+1 > LAYERS) die("too many layers specified");
|
if (numlayers+1 > LAYERS)
|
||||||
int found = 0;
|
die("too many layers specified");
|
||||||
|
found = 0;
|
||||||
for (j = 0; j < LAYERS; j++) {
|
for (j = 0; j < LAYERS; j++) {
|
||||||
if (strcmp(layer_names[j], s) == 0) {
|
if (strcmp(layer_names[j], s) == 0) {
|
||||||
fprintf(stderr, "Adding layer %s\n", s);
|
fprintf(stderr, "Adding layer %s\n", s);
|
||||||
@ -869,87 +896,85 @@ init_layers(char * layer_names_list, const char * initial_layer_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
printdbg(const char * fmt, ...) {
|
printdbg(const char *fmt, ...)
|
||||||
va_list args;
|
{
|
||||||
va_start(args, fmt);
|
va_list ap;
|
||||||
vfprintf(stderr, fmt, args);
|
va_start(ap, fmt);
|
||||||
va_end(args);
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *initial_layer_name = NULL;
|
||||||
|
char *layer_names_list = NULL;
|
||||||
|
char *tmp;
|
||||||
int i, xr, yr, bitm;
|
int i, xr, yr, bitm;
|
||||||
unsigned int wr, hr;
|
unsigned int wr, hr;
|
||||||
char * initial_layer_name = NULL;
|
|
||||||
char * layer_names_list = NULL;
|
|
||||||
|
|
||||||
signal(SIGTERM, sigterm);
|
signal(SIGTERM, sigterm);
|
||||||
|
|
||||||
/* parse environment variables */
|
|
||||||
if (OVERLAYS <= 1) {
|
if (OVERLAYS <= 1) {
|
||||||
enableoverlays = 0;
|
enableoverlays = 0;
|
||||||
} else {
|
} else {
|
||||||
const char* enableoverlays_env = getenv("SVKBD_ENABLEOVERLAYS");
|
if ((tmp = getenv("SVKBD_ENABLEOVERLAYS")))
|
||||||
if (enableoverlays_env != NULL) enableoverlays = atoi(enableoverlays_env);
|
enableoverlays = atoi(tmp);
|
||||||
}
|
}
|
||||||
char *layers_env = getenv("SVKBD_LAYERS");
|
if ((tmp = getenv("SVKBD_LAYERS"))) {
|
||||||
if (layers_env != NULL) {
|
if (!(layer_names_list = strdup(tmp)))
|
||||||
if (!(layer_names_list = strdup(layers_env))) {
|
die("memory allocation error");
|
||||||
die("memory allocation error\n");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const char* heightfactor_s = getenv("SVKBD_HEIGHTFACTOR");
|
if ((tmp = getenv("SVKBD_HEIGHTFACTOR")))
|
||||||
if (heightfactor_s != NULL)
|
heightfactor = atoi(tmp);
|
||||||
heightfactor = atoi(heightfactor_s);
|
|
||||||
|
|
||||||
/* parse command line arguments */
|
/* parse command line arguments */
|
||||||
for (i = 1; argv[i]; i++) {
|
for (i = 1; argv[i]; i++) {
|
||||||
if(!strcmp(argv[i], "-v")) {
|
if (!strcmp(argv[i], "-v")) {
|
||||||
die("svkbd-"VERSION", © 2006-2020 svkbd engineers,"
|
die("svkbd-"VERSION);
|
||||||
" see LICENSE for details\n");
|
} else if (!strcmp(argv[i], "-d")) {
|
||||||
} else if(!strcmp(argv[i], "-d")) {
|
|
||||||
isdock = True;
|
isdock = True;
|
||||||
continue;
|
continue;
|
||||||
} else if(!strncmp(argv[i], "-g", 2)) {
|
} else if (!strncmp(argv[i], "-g", 2)) {
|
||||||
if(i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bitm = XParseGeometry(argv[i+1], &xr, &yr, &wr, &hr);
|
bitm = XParseGeometry(argv[i + 1], &xr, &yr, &wr, &hr);
|
||||||
if(bitm & XValue)
|
if (bitm & XValue)
|
||||||
wx = xr;
|
wx = xr;
|
||||||
if(bitm & YValue)
|
if (bitm & YValue)
|
||||||
wy = yr;
|
wy = yr;
|
||||||
if(bitm & WidthValue)
|
if (bitm & WidthValue)
|
||||||
ww = (int)wr;
|
ww = (int)wr;
|
||||||
if(bitm & HeightValue)
|
if (bitm & HeightValue)
|
||||||
wh = (int)hr;
|
wh = (int)hr;
|
||||||
if(bitm & XNegative && wx == 0)
|
if (bitm & XNegative && wx == 0)
|
||||||
wx = -1;
|
wx = -1;
|
||||||
if(bitm & YNegative && wy == 0)
|
if (bitm & YNegative && wy == 0)
|
||||||
wy = -1;
|
wy = -1;
|
||||||
i++;
|
i++;
|
||||||
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
|
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
|
||||||
fonts[0] = argv[++i];
|
fonts[0] = argv[++i];
|
||||||
} else if(!strcmp(argv[i], "-D")) {
|
} else if (!strcmp(argv[i], "-D")) {
|
||||||
debug = 1;
|
debug = 1;
|
||||||
} else if(!strcmp(argv[i], "-h")) {
|
} else if (!strcmp(argv[i], "-h")) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
} else if(!strcmp(argv[i], "-O")) {
|
} else if (!strcmp(argv[i], "-O")) {
|
||||||
enableoverlays = 0;
|
enableoverlays = 0;
|
||||||
} else if(!strcmp(argv[i], "-l")) {
|
} else if (!strcmp(argv[i], "-l")) {
|
||||||
if(i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
continue;
|
||||||
free(layer_names_list);
|
free(layer_names_list);
|
||||||
if (!(layer_names_list = strdup(argv[++i]))) {
|
if (!(layer_names_list = strdup(argv[++i])))
|
||||||
die("memory allocation error\n");
|
die("memory allocation error");
|
||||||
}
|
} else if (!strcmp(argv[i], "-s")) {
|
||||||
} else if(!strcmp(argv[i], "-s")) {
|
if (i >= argc - 1)
|
||||||
if(i >= argc - 1)
|
|
||||||
continue;
|
continue;
|
||||||
initial_layer_name = argv[++i];
|
initial_layer_name = argv[++i];
|
||||||
} else if(!strcmp(argv[i], "-H")) {
|
} else if (!strcmp(argv[i], "-H")) {
|
||||||
if(i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
continue;
|
||||||
heightfactor = atoi(argv[++i]);
|
heightfactor = atoi(argv[++i]);
|
||||||
} else {
|
} else {
|
||||||
@ -958,18 +983,20 @@ main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heightfactor <= 0) die("height factor must be a positive integer\n");
|
if (heightfactor <= 0)
|
||||||
|
die("height factor must be a positive integer");
|
||||||
|
|
||||||
init_layers(layer_names_list, initial_layer_name);
|
init_layers(layer_names_list, initial_layer_name);
|
||||||
|
|
||||||
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
fprintf(stderr, "warning: no locale support\n");
|
fprintf(stderr, "warning: no locale support");
|
||||||
if(!(dpy = XOpenDisplay(0)))
|
if (!(dpy = XOpenDisplay(0)))
|
||||||
die("svkbd: cannot open display\n");
|
die("cannot open display");
|
||||||
setup();
|
setup();
|
||||||
run();
|
run();
|
||||||
cleanup();
|
cleanup();
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
free(layer_names_list);
|
free(layer_names_list);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user