Last active
July 24, 2025 03:01
-
-
Save gavine99/83fa35aaa0903c02d27e16a7292e522a to your computer and use it in GitHub Desktop.
block mouse clicks to window by window id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <signal.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <X11/extensions/shape.h> | |
| #include <X11/extensions/Xfixes.h> | |
| #include <X11/Xlib.h> | |
| #include <poll.h> | |
| #include <sys/select.h> | |
| sig_atomic_t running; | |
| void restore(int signum) | |
| { | |
| (void)signum; | |
| running = 0; | |
| } | |
| int main(int argc, char **argv) | |
| { | |
| Display *display; | |
| Window window; | |
| if (argc != 2) { | |
| fprintf(stderr, "Usage: %s <window_id>\n", argv[0]); | |
| return 1; | |
| } | |
| display = XOpenDisplay(NULL); | |
| if (!display) { | |
| fprintf(stderr, "Failed to open display\n"); | |
| return 1; | |
| } | |
| window = strtoul(argv[1], NULL, 0); | |
| int event_base, error_base; | |
| if (!XFixesQueryExtension(display, &event_base, &error_base)) { | |
| fprintf(stderr, "XFixes extension not available\n"); | |
| XCloseDisplay(display); | |
| return 1; | |
| } | |
| XserverRegion empty_region = XFixesCreateRegion(display, NULL, 0); | |
| XFixesSetWindowShapeRegion(display, window, ShapeInput, 0, 0, empty_region); | |
| XFixesDestroyRegion(display, empty_region); | |
| XSelectInput(display, window, StructureNotifyMask); | |
| XFlush(display); | |
| struct pollfd pollFds; | |
| pollFds.fd = ConnectionNumber(display); | |
| pollFds.events = POLLIN; | |
| pollFds.revents = 0; | |
| signal(SIGINT, restore); | |
| signal(SIGTERM, restore); | |
| running = 1; | |
| while (running) { | |
| int ready = poll(&pollFds, 1, -1); | |
| if (ready <= 0) { | |
| running = 0; | |
| break; | |
| } | |
| // Handle XEvents and flush the input | |
| while (XPending(display)) { | |
| XEvent event; | |
| XNextEvent(display, &event); | |
| if (event.type == DestroyNotify) { | |
| window = None; | |
| running = 0; | |
| } | |
| } | |
| } | |
| if (window) { | |
| XFixesSetWindowShapeRegion(display, window, ShapeInput, 0, 0, None); | |
| } | |
| XCloseDisplay(display); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment