Buggy Xlib window manager destroys contextual menus

50 Views Asked by At

I'm writing a minuscule window manager using Xlib. So far, it does all I expected. However, it has a bug, where contextual menus in Chromium disappear. This starts to happen immediately after closing a Chromium notification window and stops happening randomly afterward. I tested with other window managers (OpenBox, JWM) and Firefox (in Firefox, the menus disappear as soon as the mouse pointer enters them, regardless of notifications having been shown before). The only window manager where this also happens is twm.

Given that other major window managers don't behave like this, I understand it is a bug in mine. So my question is: what am I doing wrong?


*Edit: For some reason, if I open a link with Ctrl + Left Click, the menus will reappear correctly, until I go fullscreen or a notification shows up.


Here's the code of the window manager:

#include <X11/Xlib.h>
#include <stdlib.h>

#define strtok(s)   XKeysymToKeycode(dpy, XStringToKeysym(s))
#define grab(m, k)  XGrabKey(dpy, strtok(k), m, r, 1, 1, 1)
#define map(k, c)   if (e.xkey.keycode == strtok(k)) { c; continue; }

int main () {
  Display *dpy = XOpenDisplay(0);
  Window r = DefaultRootWindow(dpy);
  XEvent e;

  XSelectInput(dpy, r, SubstructureNotifyMask|SubstructureRedirectMask);
  grab(Mod4Mask, "q");
  grab(Mod4Mask, "Left");
  grab(Mod4Mask, "Right");
  grab(Mod4Mask, "Return");
  grab(Mod4Mask, "space");

  while (!XNextEvent(dpy, &e)) {
    if (e.type == KeyPress) {
      map("q",      XKillClient(dpy, e.xkey.subwindow););
      map("Left",   XCirculateSubwindowsDown(dpy, r));
      map("Right",  XCirculateSubwindowsUp(dpy, r));
      map("Return", system("xterm &"));
      map("space",  system("chromium &"));
    }

    if (e.type == ConfigureRequest) {  /* Nasty hack that "works". I'm sure this is wrong. */
      XMoveResizeWindow(dpy, e.xconfigure.window, 0, 0, 1920, 1080);
      XMapWindow(dpy, e.xconfigure.window);
    }
  }
}
0

There are 0 best solutions below