summaryrefslogtreecommitdiffhomepage
path: root/patch
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2021-04-07 15:35:56 +0200
committerbakkeby <[email protected]>2021-04-07 15:35:56 +0200
commitac737f9dfc427e0713176fc35373cd9410320f19 (patch)
tree8d2c55e04e21cc044dbf435e573884302e09cc07 /patch
parent0c88a49e27fd0888c81aea5dd3eef1c537164a6a (diff)
downloaddwm-flexipatch-ac737f9dfc427e0713176fc35373cd9410320f19.tar.gz
dwm-flexipatch-ac737f9dfc427e0713176fc35373cd9410320f19.zip
Adding xkb patch as per request #111
Diffstat (limited to 'patch')
-rw-r--r--patch/include.c3
-rw-r--r--patch/include.h3
-rw-r--r--patch/ipc.c9
-rw-r--r--patch/xkb.c67
-rw-r--r--patch/xkb.h7
5 files changed, 89 insertions, 0 deletions
diff --git a/patch/include.c b/patch/include.c
index 9e93ded..e4f121d 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -298,6 +298,9 @@
#if ZOOMSWAP_PATCH
#include "zoomswap.c"
#endif
+#if XKB_PATCH
+#include "xkb.c"
+#endif
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
#include "xrdb.c"
#endif
diff --git a/patch/include.h b/patch/include.h
index 5cf6e70..9df14fc 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -294,6 +294,9 @@
#if ZOOMSWAP_PATCH
#include "zoomswap.h"
#endif
+#if XKB_PATCH
+#include "xkb.h"
+#endif
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
#include "xrdb.h"
#endif
diff --git a/patch/ipc.c b/patch/ipc.c
index e863afc..ef0e577 100644
--- a/patch/ipc.c
+++ b/patch/ipc.c
@@ -9,6 +9,15 @@ handlexevent(struct epoll_event *ev)
XEvent ev;
while (running && XPending(dpy)) {
XNextEvent(dpy, &ev);
+ #if XKB_PATCH
+ /* Unfortunately the xkbEventType is not constant hence it can't be part of the
+ * normal event handler below */
+ if (ev.type == xkbEventType) {
+ xkbeventnotify(&ev);
+ continue;
+ }
+ #endif // XKB_PATCH
+
if (handler[ev.type]) {
handler[ev.type](&ev); /* call handler */
ipc_send_events(mons, &lastselmon, selmon);
diff --git a/patch/xkb.c b/patch/xkb.c
new file mode 100644
index 0000000..0ce2cec
--- /dev/null
+++ b/patch/xkb.c
@@ -0,0 +1,67 @@
+static XkbInfo xkbGlobal;
+static XkbInfo *xkbSaved = NULL;
+
+static XkbInfo *
+createxkb(Window w)
+{
+ XkbInfo *xkb;
+
+ xkb = malloc(sizeof *xkb);
+ if (xkb == NULL)
+ die("fatal: could not malloc() %u bytes\n", sizeof *xkb);
+ xkb->group = xkbGlobal.group;
+ xkb->w = w;
+ xkb->next = xkbSaved;
+ if (xkbSaved != NULL)
+ xkbSaved->prev = xkb;
+ xkb->prev = NULL;
+ xkbSaved = xkb;
+
+ return xkb;
+}
+
+XkbInfo *
+findxkb(Window w)
+{
+ XkbInfo *xkb;
+ for (xkb = xkbSaved; xkb != NULL; xkb = xkb->next)
+ if (xkb->w == w)
+ return xkb;
+ return NULL;
+}
+
+void
+xkbeventnotify(XEvent *e)
+{
+ XkbEvent *ev;
+
+ ev = (XkbEvent *) e;
+ switch (ev->any.xkb_type) {
+ case XkbStateNotify:
+ xkbGlobal.group = ev->state.locked_group;
+ if (selmon != NULL && selmon->sel != NULL)
+ selmon->sel->xkb->group = xkbGlobal.group;
+ drawbars();
+ break;
+ }
+}
+
+/* xkb bar module */
+int
+width_xkb(Bar *bar, BarArg *a)
+{
+ return TEXTW(xkb_layouts[xkbGlobal.group]);
+}
+
+int
+draw_xkb(Bar *bar, BarArg *a)
+{
+ drw_text(drw, a->x, a->y, a->w, a->h, lrpad / 2, xkb_layouts[xkbGlobal.group], 0, False);
+ return 1;
+}
+
+int
+click_xkb(Bar *bar, Arg *arg, BarArg *a)
+{
+ return ClkXKB;
+}
diff --git a/patch/xkb.h b/patch/xkb.h
new file mode 100644
index 0000000..abe7c2c
--- /dev/null
+++ b/patch/xkb.h
@@ -0,0 +1,7 @@
+static XkbInfo *createxkb(Window w);
+static XkbInfo *findxkb(Window w);
+static void xkbeventnotify(XEvent *e);
+
+static int width_xkb(Bar *bar, BarArg *a);
+static int draw_xkb(Bar *bar, BarArg *a);
+static int click_xkb(Bar *bar, Arg *arg, BarArg *a); \ No newline at end of file