salman-abedin / devour

X11 window swallower
GNU General Public License v2.0
415 stars 30 forks source link

Devour working incorrectly on LeftWM #29

Closed steveonlinux closed 3 years ago

steveonlinux commented 3 years ago

Not sure if this issue is WM specific. When I open a new window in LeftWM with devour, it opens as if the terminal window wasn't devoured. As in, the new window is the size it would be without devour, but the terminal window disappears. And even more strangely, the window still exists( or technically replaced); and when I kill the new window the terminal window isn't visible but a window still exists. But its not actually the terminal window according to xprop. This window also doesn't resize itself. Has anyone else experienced similar issues? I'm using the version from the AUR.

steveonlinux commented 3 years ago

So a contributor of LeftWM @AethanFoot explained that the reason for the bugs was that Left handles Xlib send events, whereas Devour uses XUnmapWindow(), which generates an event, but it isn't sent to the root window. The altered code is below.

/*
 * devour
 * X11 window swallower
 */

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

#define UNSAFE_CHARS "`\"'()[]& "

void run_command(char **argv) {
  char arg_char;
  char *arg;
  char cmd[1024] = {0};

  while ((arg = *++argv)) {
    while ((arg_char = *arg++)) {
      if (strchr(UNSAFE_CHARS, arg_char))
        strcat(cmd, "\\");
      strncat(cmd, &arg_char, 1);
    }
    strcat(cmd, " ");
  }
  system(cmd);
}

int main(int argc, char **argv) {
  int rev;
  Window win;
  Display *dis = XOpenDisplay(0);
  int snum = DefaultScreen(dis);

  XGetInputFocus(dis, &win, &rev);
  XWithdrawWindow(dis, win, snum);
  XFlush(dis);
  run_command(argv);
  XMapWindow(dis, win);
  XCloseDisplay(dis);

  (void)argc;
  return 0;
}