Obtain window in Linux by coordinates (C / C ++)

1

I would like to know if someone can tell me if there is any way to obtain information from a window that exists on the desktop given certain coordinates.

That is, if there is an alternative to the Windows "WindowFromPoint" function but for Linux, more specifically LinuxMint.

    
asked by Germán Martínez 22.05.2018 в 02:42
source

2 answers

0

Finally I found a solution using the XQueryPointer () function.

Following the example I found on this link .

The search window is found in the variable ret_child .

The link code is as follows:

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

int main(int argc, char **argv)
{
    // Gave a warning.
    // unsigned int snooze_time = 100000;
    Display *dpy;
    Window root;
    Window ret_root;
    Window ret_child;
    int root_x;
    int root_y;
    int win_x;
    int win_y;
    unsigned int mask;

    dpy = XOpenDisplay(NULL);
    root = XDefaultRootWindow(dpy);

    if(XQueryPointer(dpy, root, &ret_root, &ret_child, &root_x, &root_y,
                     &win_x, &win_y, &mask))
    {   
        // original version
        //    printf("root loc: %4d,%4d win loc: %3d,%3d mask: 0x%08X\n",
        //           root_x, root_y, win_x, win_y, mask);

        // This returns in -geometry format
        // I added \n so it actually shows something so people who test it know it works.
        printf("+%d+%d\n", root_x, root_y);
    }
    else
    {
        // your script will break with this output, send it to stderr and let the script
        // return something sensible like +10+10 
        printf("hmmmm, where is that sneaky pointer?\n");
    }
    return 0;
}
    
answered by 28.05.2018 / 13:53
source
0

Searching a bit on the Internet you can reach this link , where they tell you that you have at your disposal a series of functions for such a task:

  • getyx : Cooperators of the cursor in the window passed as parameter
  • getparyx : Coordinates of the andidated window with respect to the parent window.
  • getbegyx : Coordinates of the window.
  • getmaxyx : Size of the window.

You have not put any code example so it is not clear if you already have the pointer to the window or if (by some mismatch) these functions are not useful in your case.

    
answered by 22.05.2018 в 08:40