Skip to content
Advertisement

X11: XQueryPointer gives me fuzzy Windows

I am currently trying to find if one of my Windows is underneath the Mouse cursor. This is not done in my process that creates the window, but in another process.

What I am currently doing is finding the Window via the process PID (and I made sure _NET_WM_PID is set correctly by my program). This basically works via XQueryTree and XGetWindowProperty. This works fine and is not the problem.

The problem is that XQueryPointer gives me fuzzy Windows back. I wrote a simple test program to show what I mean. First gather an ID from any Window you like using the command xprop via bash. It will give you the Window ID.

Then run this simple test program I wrote (quick and dirty), it gives you every 0,5s the current ID from the Window underneath the mouse cursor:

#include <X11/Xlib.h>
#include <iostream>
#include <unistd.h>
#include <stdint.h>

int main()
{
    Display *display = XOpenDisplay(0);

    Window root = XDefaultRootWindow(display);
    Window root_return;
    Window child_return;
    int root_x_return;
    int root_y_return;
    int win_x_return;
    int win_y_return;
    uint32_t mask_return;

    while (true)
    {
        if (::XQueryPointer(display, root, &root_return, &child_return, &root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return) == True)
        {
            std::cout << "Window ID: " << child_return << std::endl;
        }
        usleep(500000);
    }
    return 0;
}

Can somebody tell me what the problem is?

And here is my example output: My program finds Window ID 73400324 xprop finds Window ID 73400324 The test program finds Window ID 20996726

Advertisement

Answer

Could be child windows, or the decoration that the window manager adds to a plain window.

By the way, the normal way to detect if your window is under the mouse is by catching the XEnterWindowEvent and XLeaveWindowEvent, but this is normally done within the program itself, not externally.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement