aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-06-26 14:10:25 +0200
committerMattias Andrée <maandree@kth.se>2021-06-26 14:10:25 +0200
commit37f398160ba387b84e811b2f2d69d467d793e3da (patch)
treee0c8cb2a4cf9fb864fd7170407fe901759066da9
parentAdd radharc wrapper, iswork bin, and secret bins (diff)
downloaddotfiles-37f398160ba387b84e811b2f2d69d467d793e3da.tar.gz
dotfiles-37f398160ba387b84e811b2f2d69d467d793e3da.tar.bz2
dotfiles-37f398160ba387b84e811b2f2d69d467d793e3da.tar.xz
Add xmonad-autofocus-output
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--common.mk2
-rw-r--r--xmonad/.gitignore1
-rw-r--r--xmonad/Makefile9
-rw-r--r--xmonad/xmonad-autofocus-output.c93
4 files changed, 103 insertions, 2 deletions
diff --git a/common.mk b/common.mk
index a990201..f716eaf 100644
--- a/common.mk
+++ b/common.mk
@@ -1 +1,3 @@
CHECK_INSTALLED = false
+
+CC = gcc
diff --git a/xmonad/.gitignore b/xmonad/.gitignore
index 48adae9..4e800a7 100644
--- a/xmonad/.gitignore
+++ b/xmonad/.gitignore
@@ -1 +1,2 @@
/xmonad.hs
+/xmonad-autofocus-output
diff --git a/xmonad/Makefile b/xmonad/Makefile
index 4003b95..2265823 100644
--- a/xmonad/Makefile
+++ b/xmonad/Makefile
@@ -3,7 +3,7 @@ include ../common.mk
XINITRC_ORDER = 80
-install:
+install: xmonad-autofocus-output
$(CHECK_INSTALLED) xwallpaper
$(CHECK_INSTALLED) xcman
$(CHECK_INSTALLED) pdeath
@@ -18,6 +18,11 @@ install:
test ! -d ~/.xmonad/xmonad.hs
ln -sf -- ~/.dotfiles/xmonad/xmonad.hs ~/.xmonad/xmonad.hs
make xmonad.hs
+ mkdir -p ~/.local/bin
+ ln -sf -- ~/.dotfiles/xmonad/xmonad-autofocus-output ~/.local/bin
+
+xmonad-autofocus-output: xmonad-autofocus-output.c
+ $(CC) -o $@ $@.c -Wall -s -lX11 -lXtst
include xmonad.mk
@@ -30,6 +35,6 @@ uninstall:
-make clean
clean:
- -rm -f xmonad.hs
+ -rm -f xmonad.hs xmonad-autofocus-output
.PHONY: install uninstall clean
diff --git a/xmonad/xmonad-autofocus-output.c b/xmonad/xmonad-autofocus-output.c
new file mode 100644
index 0000000..853e18b
--- /dev/null
+++ b/xmonad/xmonad-autofocus-output.c
@@ -0,0 +1,93 @@
+/* -lX11 -lXtst */
+#include <sys/select.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#include <X11/Xlib.h>
+#include <X11/keysymdef.h>
+#include <X11/extensions/XTest.h>
+
+static Display *disp;
+static KeyCode mod, key[2];
+
+static inline int
+get_output(int x, int y)
+{
+ return x < 1920;
+}
+
+static inline void
+set_output(int output)
+{
+ XTestFakeKeyEvent(disp, mod, 1, 0);
+ XTestFakeKeyEvent(disp, key[output], 1, 0);
+ XTestFakeKeyEvent(disp, key[output], 0, 0);
+ XTestFakeKeyEvent(disp, mod, 0, 0);
+ XFlush(disp);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd, scrn;
+ Window root;
+ fd_set fds;
+ XEvent ev;
+ int output, prev_output = -1;
+
+ XSetLocaleModifiers("");
+ if (!(disp = XOpenDisplay(NULL))) {
+ fprintf(stderr, "%s: cannot open display\n", *argv);
+ return 1;
+ }
+
+ fd = XConnectionNumber(disp);
+ scrn = XDefaultScreen(disp);
+ root = XRootWindow(disp, scrn);
+ XSelectInput(disp, root, PointerMotionMask | EnterWindowMask);
+ XSync(disp, False);
+
+ mod = XKeysymToKeycode(disp, XK_Super_L);
+ key[0] = XKeysymToKeycode(disp, XK_W);
+ key[1] = XKeysymToKeycode(disp, XK_E);
+
+ for (;;) {
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ if (select(fd + 1, &fds, NULL, NULL, NULL) < 0) {
+ if (errno == EINTR)
+ continue;
+ perror(*argv);
+ return 1;
+ }
+
+ if (!FD_ISSET(fd, &fds))
+ continue;
+
+ while (XPending(disp)) {
+ XNextEvent(disp, &ev);
+ if (XFilterEvent(&ev, None))
+ continue;
+ switch (ev.type) {
+ case MotionNotify:
+ output = get_output(ev.xmotion.x_root, ev.xmotion.y_root);
+ if (output == prev_output)
+ continue;
+ prev_output = output;
+ set_output(output);
+ break;
+ case EnterNotify:
+ prev_output = -1;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ return 0;
+ (void) argc;
+}