Hello!

As a user of multiple (3) keyboard layouts, I have always wanted dwm
to behave like many non-suckless WMs do: to have per-window keyboard
layouts, not just a global one.
That's what this patch is for. It is not intended for inclusion in
vanilla dwm, because majority of it's users probably use just one
keyboard layout.
If you have the possibility to, please test this. Expected behavior is
that newly created windows inherit keyboard layout of currently
focused window.
If you have any comments or suggestions, please share - this is my
first patch for dwm.

-- 
Evgeny
diff -r 406003e3a01f dwm.c
--- a/dwm.c	Mon Sep 27 07:53:44 2010 +0000
+++ b/dwm.c	Tue Oct 12 20:38:27 2010 +0300
@@ -36,6 +36,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xproto.h>
 #include <X11/Xutil.h>
+#include <X11/XKBlib.h>
 #ifdef XINERAMA
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
@@ -93,6 +94,7 @@
 	Client *snext;
 	Monitor *mon;
 	Window win;
+	unsigned char kbdgrp;
 };
 
 typedef struct {
@@ -821,6 +823,7 @@
 			selmon = c->mon;
 		if(c->isurgent)
 			clearurgent(c);
+		XkbLockGroup (dpy, XkbUseCoreKbd, c->kbdgrp);
 		detachstack(c);
 		attachstack(c);
 		grabbuttons(c, True);
@@ -857,7 +860,7 @@
 void
 focusstack(const Arg *arg) {
 	Client *c = NULL, *i;
-
+	
 	if(!selmon->sel)
 		return;
 	if(arg->i > 0) {
@@ -1092,6 +1095,7 @@
 	Client *c, *t = NULL;
 	Window trans = None;
 	XWindowChanges wc;
+	XkbStateRec kbd_state;
 
 	if(!(c = malloc(sizeof(Client))))
 		die("fatal: could not malloc() %u bytes\n", sizeof(Client));
@@ -1146,6 +1150,8 @@
 	XMapWindow(dpy, c->win);
 	setclientstate(c, NormalState);
 	arrange(c->mon);
+	XkbGetState (dpy, XkbUseCoreKbd, &kbd_state);
+	c->kbdgrp = kbd_state.group;
 }
 
 void
@@ -1700,12 +1706,16 @@
 
 void
 unfocus(Client *c, Bool setfocus) {
+	XkbStateRec kbd_state;
+	
 	if(!c)
 		return;
 	grabbuttons(c, False);
 	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
 	if(setfocus)
 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+	XkbGetState (dpy, XkbUseCoreKbd, &kbd_state);
+	c->kbdgrp = kbd_state.group;
 }
 
 void

Reply via email to