[wiki] [sites] Added setxkbgroup patch for dwm-6.4 || Anton Yabchinskiy

From: <git_AT_suckless.org>
Date: Sun, 01 Oct 2023 22:21:24 +0200

commit 9d1c182ee12279f8b5fcd610ce458987bdf47d2e
Author: Anton Yabchinskiy <arn_AT_bestmx.net>
Date: Sun Oct 1 23:19:28 2023 +0300

    Added setxkbgroup patch for dwm-6.4

diff --git a/dwm.suckless.org/patches/setxkbgroup/dwm-setxkbgroup-6.4.diff b/dwm.suckless.org/patches/setxkbgroup/dwm-setxkbgroup-6.4.diff
new file mode 100644
index 00000000..269768a1
--- /dev/null
+++ b/dwm.suckless.org/patches/setxkbgroup/dwm-setxkbgroup-6.4.diff
_AT_@ -0,0 +1,54 @@
+From cbaa365a336355712e3c63a550f903b2cd46ab58 Mon Sep 17 00:00:00 2001
+From: Anton Yabchinskiy <arn_AT_bestmx.net>
+Date: Sun, 1 Oct 2023 22:42:59 +0300
+Subject: [PATCH] Add setxkbgroup() function to be used in keys[]
+
+---
+ dwm.c | 17 +++++++++++++++++
+ 1 file changed, 17 insertions(+)
+
+diff --git a/dwm.c b/dwm.c
+index e5efb6a2..4a6632f3 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -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 */
+_AT_@ -234,6 +235,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
+ static int xerrordummy(Display *dpy, XErrorEvent *ee);
+ static int xerrorstart(Display *dpy, XErrorEvent *ee);
+ static void zoom(const Arg *arg);
++static void setxkbgroup(const Arg *arg);
+
+ /* variables */
+ static const char broken[] = "broken";
+_AT_@ -2122,6 +2124,21 @@ zoom(const Arg *arg)
+ pop(c);
+ }
+
++void
++setxkbgroup(const Arg *arg) {
++ static int hasxkb = -1;
++ if (hasxkb < 0) {
++ int major = XkbMajorVersion;
++ int minor = XkbMinorVersion;
++ hasxkb = XkbQueryExtension(dpy, NULL, NULL, NULL, &major, &minor);
++ }
++ if (hasxkb > 0) {
++ if (arg != NULL && arg->ui < 4) {
++ XkbLockGroup(dpy, XkbUseCoreKbd, arg->ui);
++ }
++ }
++}
++
+ int
+ main(int argc, char *argv[])
+ {
+--
+2.39.2
+
diff --git a/dwm.suckless.org/patches/setxkbgroup/index.md b/dwm.suckless.org/patches/setxkbgroup/index.md
new file mode 100644
index 00000000..3b53db79
--- /dev/null
+++ b/dwm.suckless.org/patches/setxkbgroup/index.md
_AT_@ -0,0 +1,35 @@
+setxkbgroup
+===========
+
+Description
+-----------
+The patch adds a new `setxkbgroup` function to be used inside
+`keys[]`. It allows idempotent keyboard layout switching from dwm
+itself.
+
+Suppose you've configured keyboard layouts in X server like this:
+
+`setxkbmap -option 'grp:rctrl_toggle' -layout 'us,ru,epo,gr(bare)'`
+
+And then have defined a few key bindings in the `keys[]` array in dwm
+`config.h` like this:
+
+ ...
+ { MODKEY, XK_u, setxkbgroup, {.ui = 0 } },
+ { MODKEY, XK_r, setxkbgroup, {.ui = 1 } },
+ { MODKEY, XK_e, setxkbgroup, {.ui = 2 } },
+ { MODKEY, XK_g, setxkbgroup, {.ui = 3 } },
+ ...
+
+Configured like this, `MOD+r` in dwm immediately activates Russian
+layout, `MOD+g` switches to Greek and `MOD+u` gets the US layout. You
+don't need to track how many times to press Right Ctrl (or whatever)
+key to use a desired layout.
+
+Download
+--------
+* [dwm-setxkbgroup-6.4.diff](dwm-setxkbgroup-6.4.diff)
+
+Author
+------
+* Anton Yabchinskiy <arn+53a4f52_AT_bestmx.net>
Received on Sun Oct 01 2023 - 22:21:24 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 01 2023 - 22:24:48 CEST