some code-style consistency changes + small tweaks
This commit is contained in:
parent
4983666e33
commit
73f0edf709
227
svkbd.c
227
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)))
|
||||||
|
@ -64,7 +62,7 @@ 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);
|
||||||
|
@ -164,11 +162,12 @@ 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;
|
||||||
|
|
||||||
|
@ -183,11 +182,12 @@ buttonpress(XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -207,7 +207,8 @@ buttonrelease(XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cleanup(void) {
|
cleanup(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < SchemeLast; i++)
|
for (i = 0; i < SchemeLast; i++)
|
||||||
|
@ -222,7 +223,8 @@ 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)) {
|
||||||
|
@ -234,8 +236,9 @@ 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)
|
||||||
|
@ -244,24 +247,24 @@ countrows() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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++) {
|
||||||
|
@ -271,7 +274,8 @@ drawkeyboard(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawkey(Key *k) {
|
drawkey(Key *k)
|
||||||
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
const char *l;
|
const char *l;
|
||||||
|
|
||||||
|
@ -304,7 +308,8 @@ 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))
|
||||||
|
@ -325,10 +330,11 @@ 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) {
|
||||||
|
@ -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);
|
||||||
|
@ -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,22 +426,29 @@ 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) {
|
||||||
|
@ -451,7 +469,6 @@ 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) {
|
||||||
|
@ -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,16 +543,14 @@ 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);
|
||||||
|
@ -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,14 +603,14 @@ 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;
|
||||||
|
@ -607,15 +624,17 @@ setup(void) {
|
||||||
}
|
}
|
||||||
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++) {
|
||||||
|
@ -711,9 +730,9 @@ 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;
|
||||||
|
|
||||||
|
@ -735,7 +754,8 @@ updatekeys() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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,11 +801,12 @@ 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)) {
|
||||||
|
@ -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,45 +896,44 @@ 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[])
|
||||||
int i, xr, yr, bitm;
|
{
|
||||||
unsigned int wr, hr;
|
|
||||||
char *initial_layer_name = NULL;
|
char *initial_layer_name = NULL;
|
||||||
char *layer_names_list = NULL;
|
char *layer_names_list = NULL;
|
||||||
|
char *tmp;
|
||||||
|
int i, xr, yr, bitm;
|
||||||
|
unsigned int wr, hr;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -941,9 +967,8 @@ main(int argc, char *argv[]) {
|
||||||
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;
|
||||||
|
@ -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