Adding xkb patch as per request #111

This commit is contained in:
bakkeby
2021-04-07 15:35:56 +02:00
parent 0c88a49e27
commit ac737f9dfc
8 changed files with 193 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);

67
patch/xkb.c Normal file
View File

@@ -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;
}

7
patch/xkb.h Normal file
View File

@@ -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);