Introduction
Introduction Statistics Contact Development Disclaimer Help
Add Xresources support. - svkbd - simple virtual keyboard
git clone git://git.suckless.org/svkbd
Log
Files
Refs
README
LICENSE
---
commit 8c28fd15f33d37cbb424cae3e0c306f55380bee6
parent 869a4328c970b4cfbfcf86ab535f68caaa8a9e00
Author: tetrakist <[email protected]>
Date: Mon, 8 Mar 2021 23:10:59 -0800
Add Xresources support.
Signed-off-by: Maarten van Gompel <[email protected]>
Diffstat:
M config.def.h | 4 ++--
M svkbd.c | 95 +++++++++++++++++++++++++++++…
2 files changed, 96 insertions(+), 3 deletions(-)
---
diff --git a/config.def.h b/config.def.h
@@ -4,10 +4,10 @@ static double overlay_delay = 1.0; //in seconds
static double repeat_delay = 0.75; //in seconds, will not work on keys with ov…
static int scan_rate = 50; //scan rate in microseconds, affects key repetition…
static int heightfactor = 14; //one row of keys takes up 1/x of the screen hei…
-static const char *fonts[] = {
+static const char *defaultfonts[] = {
"DejaVu Sans:bold:size=22"
};
-static const char *colors[SchemeLast][2] = {
+static const char *defaultcolors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#132a33" },
[SchemeNormShift] = { "#008ac0", "#132a33" },
diff --git a/svkbd.c b/svkbd.c
@@ -21,6 +21,7 @@
#include <X11/Xproto.h>
#include <X11/extensions/XTest.h>
#include <X11/Xft/Xft.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
@@ -117,6 +118,9 @@ static int debug = 0;
static int numlayers = 0;
static int numkeys = 0;
+static char *colors[10][2]; /* 10 schemes, 2 colors each */
+static char *fonts[] = {0};
+
static KeySym ispressingkeysym;
Bool ispressing = False;
@@ -691,6 +695,75 @@ run(void)
}
void
+readxresources(void) {
+ XrmInitialize();
+
+ char* xrm;
+ if ((xrm = XResourceManagerString(drw->dpy))) {
+ char *type;
+ XrmDatabase xdb = XrmGetStringDatabase(xrm);
+ XrmValue xval;
+
+ if (XrmGetResource(xdb, "svkbd.font", "*", &type, &xval) && !f…
+ fonts[0] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.background", "*", &type, &xval)…
+ colors[SchemeNorm][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.foreground", "*", &type, &xval)…
+ colors[SchemeNorm][ColFg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.shiftforeground", "*", &type, &…
+ colors[SchemeNormShift][ColFg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.shiftbackground", "*", &type, &…
+ colors[SchemeNormShift][ColBg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.ABCforeground", "*", &type, &xv…
+ colors[SchemeNormABC][ColFg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.ABCbackground", "*", &type, &xv…
+ colors[SchemeNormABC][ColBg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.ABCshiftforeground", "*", &type…
+ colors[SchemeNormShift][ColFg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.ABCshiftbackground", "*", &type…
+ colors[SchemeNormShift][ColBg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.pressbackground", "*", &type, &…
+ colors[SchemePress][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.pressforeground", "*", &type, &…
+ colors[SchemePress][ColFg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.pressshiftbackground", "*", &ty…
+ colors[SchemePressShift][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.pressshiftforeground", "*", &ty…
+ colors[SchemePressShift][ColFg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.highlightbackground", "*", &typ…
+ colors[SchemeHighlight][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.highlightforeground", "*", &typ…
+ colors[SchemeHighlight][ColFg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.highlightshiftbackground", "*",…
+ colors[SchemeHighlightShift][ColBg] = strdup(xval.addr…
+ if (XrmGetResource(xdb, "svkbd.highlightshiftforeground", "*",…
+ colors[SchemeHighlightShift][ColFg] = strdup(xval.addr…
+
+ if (XrmGetResource(xdb, "svkbd.overlaybackground", "*", &type,…
+ colors[SchemeOverlay][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.overlayforeground", "*", &type,…
+ colors[SchemeOverlay][ColFg] = strdup(xval.addr);
+
+ if (XrmGetResource(xdb, "svkbd.overlayshiftbackground", "*", &…
+ colors[SchemeOverlayShift][ColBg] = strdup(xval.addr);
+ if (XrmGetResource(xdb, "svkbd.overlayshiftforeground", "*", &…
+ colors[SchemeOverlayShift][ColFg] = strdup(xval.addr);
+
+
+ XrmDestroyDatabase(xdb);
+ }
+}
+
+
+void
setup(void)
{
XSetWindowAttributes wa;
@@ -721,8 +794,23 @@ setup(void)
sh = DisplayHeight(dpy, screen);
}
drw = drw_create(dpy, screen, root, sw, sh);
+
+ readxresources();
+
+ /* Apply defaults to font and colors*/
+ if ( !fonts[0] )
+ fonts[0] = strdup(defaultfonts[0]);
+ for (i = 0; i < SchemeLast; ++i){
+ for (j = 0; j < 2; ++j){
+ if ( !colors[i][j] )
+ colors[i][j] = strdup(defaultcolors[i][j]);
+ }
+ }
+
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded");
+ free(fonts[0]);
+
drw_setscheme(drw, scheme[SchemeNorm]);
/* find an unused keycode to use as a temporary keycode (derived from …
@@ -755,6 +843,11 @@ setup(void)
for (j = 0; j < SchemeLast; j++)
scheme[j] = drw_scm_create(drw, colors[j], 2);
+ for (j = 0; j < SchemeLast; ++j) {
+ free(colors[j][ColFg]);
+ free(colors[j][ColBg]);
+ }
+
/* init atoms */
if (isdock) {
netatom[NetWMWindowType] = XInternAtom(dpy,
@@ -1067,7 +1160,7 @@ main(int argc, char *argv[])
wy = -1;
i++;
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
- fonts[0] = argv[++i];
+ fonts[0] = strdup(argv[++i]);
} else if (!strcmp(argv[i], "-D")) {
debug = 1;
} else if (!strcmp(argv[i], "-h")) {
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.