I'm writting a program on Linux/X that kills the application to which the mouse is pointing.
While it is running I launch xterm and execute "surf duckdcukgo.com &" or "leafpad &". Then I kill xterm with my program using Alt+Escape and both the xterm and the application launched from within it die. Only the xterm should die. If I launch "mupdf some.pdf &" it works as expected. I don't know how the choice of launched application affects the problem. Also sometimes it takes several seconds for "surf" to eventually die.
Is there anything else in addtion to XKillClient that I should do? Should I use something else instead of XKillClient?
Here's the code.
#include <X11/keysym.h>
#include <X11/Xlib.h>
int main(void)
{
Display *display;
XEvent event;
Window root;
signed int trash;
Window wtrash;
Window wfocused = 0;
display = XOpenDisplay(NULL);
if(display == NULL)
{
return 1;
}
root = DefaultRootWindow(display);
XGrabKey(display, XKeysymToKeycode(display, XK_Escape), Mod1Mask, root, True, GrabModeAsync, GrabModeAsync);
while(1)
{
XNextEvent(display, &event);
if(event.type == KeyPress)
{
if(event.xkey.keycode == XKeysymToKeycode(display, XK_Escape))
{
XQueryPointer(display, root, &wtrash, &wfocused, &trash, &trash, &trash, &trash, (unsigned int*)&trash);
XKillClient(display, wfocused);
}
}
}
}