Created
December 19, 2023 16:12
-
-
Save p4p1/fd1c74ad19ae91035b851170bc00e7e9 to your computer and use it in GitHub Desktop.
📟📟📟📟
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
/* diff file to add a virtual keyboard to dwm thorugh a shortcut */ | |
diff -up a/config.def.h b/config.def.h | |
--- a/config.def.h 2023-12-19 17:08:29.127179493 +0100 | |
+++ b/config.def.h 2023-12-19 15:42:15.396789363 +0100 | |
@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; | |
static const unsigned int snap = 32; /* snap pixel */ | |
static const int showbar = 1; /* 0 means no bar */ | |
static const int topbar = 1; /* 0 means bottom bar */ | |
+static const int kb_height_div = 3; /* height of the keyboard */ | |
static const char *fonts[] = { "monospace:size=10" }; | |
static const char dmenufont[] = "monospace:size=10"; | |
static const char col_gray1[] = "#222222"; | |
@@ -58,6 +59,7 @@ static const Layout layouts[] = { | |
/* commands */ | |
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ | |
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; | |
+static const char *svkbdcmd[] = { "svkbd-mobile-intl", "-fn", dmenufont, "-g", "\n", NULL }; | |
static const char *termcmd[] = { "st", NULL }; | |
static const Key keys[] = { | |
@@ -85,6 +87,7 @@ static const Key keys[] = { | |
{ MODKEY, XK_period, focusmon, {.i = +1 } }, | |
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, | |
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, | |
+ { MODKEY, XK_n, openkeyboard, {0} }, | |
TAGKEYS( XK_1, 0) | |
TAGKEYS( XK_2, 1) | |
TAGKEYS( XK_3, 2) | |
diff -up a/dwm.c b/dwm.c | |
--- a/dwm.c 2023-12-19 17:08:29.127179493 +0100 | |
+++ b/dwm.c 2023-12-19 15:40:24.417567233 +0100 | |
@@ -119,6 +119,7 @@ struct Monitor { | |
int by; /* bar geometry */ | |
int mx, my, mw, mh; /* screen size */ | |
int wx, wy, ww, wh; /* window area */ | |
+ int gap_keyboard; | |
unsigned int seltags; | |
unsigned int sellt; | |
unsigned int tagset[2]; | |
@@ -233,6 +234,7 @@ static int xerror(Display *dpy, XErrorEv | |
static int xerrordummy(Display *dpy, XErrorEvent *ee); | |
static int xerrorstart(Display *dpy, XErrorEvent *ee); | |
static void zoom(const Arg *arg); | |
+static void openkeyboard(const Arg *arg); | |
/* variables */ | |
static const char broken[] = "broken"; | |
@@ -638,6 +640,7 @@ createmon(void) | |
m = ecalloc(1, sizeof(Monitor)); | |
m->tagset[0] = m->tagset[1] = 1; | |
m->mfact = mfact; | |
+ m->gap_keyboard = 0; | |
m->nmaster = nmaster; | |
m->showbar = showbar; | |
m->topbar = topbar; | |
@@ -1122,7 +1125,7 @@ monocle(Monitor *m) | |
if (n > 0) /* override layout symbol */ | |
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); | |
for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) | |
- resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); | |
+ resize(c, m->wx, m->wy, m->ww - 2 * c->bw, (m->wh - m->gap_keyboard) - 2 * c->bw, 0); | |
} | |
void | |
@@ -1700,12 +1703,12 @@ tile(Monitor *m) | |
mw = m->ww; | |
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) | |
if (i < m->nmaster) { | |
- h = (m->wh - my) / (MIN(n, m->nmaster) - i); | |
+ h = ((m->wh - m->gap_keyboard) - my) / (MIN(n, m->nmaster) - i); | |
resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); | |
if (my + HEIGHT(c) < m->wh) | |
my += HEIGHT(c); | |
} else { | |
- h = (m->wh - ty) / (n - i); | |
+ h = ((m->wh - m->gap_keyboard) - ty) / (n - i); | |
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); | |
if (ty + HEIGHT(c) < m->wh) | |
ty += HEIGHT(c); | |
@@ -2139,6 +2142,49 @@ zoom(const Arg *arg) | |
return; | |
pop(c); | |
} | |
+void | |
+openkeyboard(const Arg *arg) | |
+{ | |
+ struct sigaction sa; | |
+ static int pid = 0; | |
+ static int i = 0; | |
+ static char size_kb[20] = { | |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
+ }; | |
+ | |
+ if (selmon->gap_keyboard != 0) | |
+ selmon->gap_keyboard = 0; | |
+ if (pid != 0) { | |
+ kill(pid, SIGKILL); | |
+ pid = 0; | |
+ selmon->gap_keyboard = 0; | |
+ } else { | |
+ for (i = 0; svkbdcmd[i]; i++) | |
+ if (svkbdcmd[i][0] == '\n') | |
+ break; | |
+ if (svkbdcmd[i] && svkbdcmd[i][0] == '\n') { | |
+ memset(size_kb, 0, 20); | |
+ sprintf(size_kb, "%dx%d", sw, sh / kb_height_div); | |
+ svkbdcmd[i] = size_kb; | |
+ } | |
+ if ((pid = fork()) == 0) { | |
+ if (dpy) | |
+ close(ConnectionNumber(dpy)); | |
+ setsid(); | |
+ | |
+ sigemptyset(&sa.sa_mask); | |
+ sa.sa_flags = 0; | |
+ sa.sa_handler = SIG_DFL; | |
+ sigaction(SIGCHLD, &sa, NULL); | |
+ | |
+ execvp(((char **)svkbdcmd)[0], (char **)svkbdcmd); | |
+ die("dwm: execvp '%s' failed:", ((char **)svkbdcmd)[0]); | |
+ } else { | |
+ selmon->gap_keyboard = sh / 3; | |
+ } | |
+ } | |
+} | |
int | |
main(int argc, char *argv[]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment