Skip to content

Instantly share code, notes, and snippets.

@josefandersson
Last active March 18, 2021 09:20
Show Gist options
  • Save josefandersson/f26ed70fdddd5f508352f34d0911809d to your computer and use it in GitHub Desktop.
Save josefandersson/f26ed70fdddd5f508352f34d0911809d to your computer and use it in GitHub Desktop.
Method for bypassing bspwm 'focus' bug for chromium based apps. Build bspwmhacky.c, start it with bspwm, use xdotool to move hacky window to desktop before focusing on desktop.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
XEvent e;
Display *d = XOpenDisplay(NULL);
if (d == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
int s = DefaultScreen(d);
Window w = XCreateSimpleWindow(d, RootWindow(d, s), 0, 0, 1, 1, 1, 0, 0);
XMapWindow(d, w);
XClassHint *ch = XAllocClassHint();
ch->res_name = "bspwmhacky";
ch->res_class = "bspwmhacky";
XSetClassHint(d, w, ch);
XFree(ch);
XMoveWindow(d, w, 0, -10);
while (1) {
XNextEvent(d, &e);
usleep(10);
}
return 0;
}
bspc rule -a bspwmhacky state=floating
# Program has to be launched after rule is set
killall bspwmhacky ; bspwmhacky &
# Switch to a desktop on focused monitor (made for dual monitor)
super + {1-9}
D={0-8}; \
M=$((($(xdotool get_desktop) > 8))); \
T=$((($D + 9 * $M))); \
xdotool search --class hacky set_desktop_for_window %@ "$T"; \
xdotool set_desktop $T;
@josefandersson
Copy link
Author

josefandersson commented Oct 7, 2020

How to use:

  1. Build bspwmhacky.c (eg. gcc bspwmhacky.c -L/usr/X11R6/lib -lX11 -o bspwmhacky)
  2. Add rule to make bspwmhacky window floating (so that we can put it out of view)
  3. Launch bspwmhacky with bspwm
  4. Before switching desktop with sxhkd, send the bspwmhacky window to that desktop, then switch desktop (example above is using two monitors)

For single monitor this is sufficient:

    super + {1-9}
    D={0-8}; \
    xdotool search --class hacky set_desktop_for_window %@ $D; \
    xdotool set_desktop $D;

I will note that this fix of having a ghost window could be incompatible with some peoples hotkeys/scripts but this works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment