1 | #include <stdio.h>
|
2 | #include <X11/Xlib.h>
|
3 |
|
4 | int main()
|
5 | {
|
6 | Display *d;
|
7 | Window inwin; /* root window the pointer is in */
|
8 | Window inchildwin; /* child win the pointer is in */
|
9 | int rootx, rooty; /* relative to the "root" window; we are not interested in these,
|
10 | but we can't pass NULL */
|
11 | int childx, childy; /* the values we are interested in */
|
12 | Atom atom_type_prop; /* not interested */
|
13 | int actual_format; /* should be 32 after the call */
|
14 | unsigned int mask; /* status of the buttons */
|
15 | unsigned long n_items, bytes_after_ret;
|
16 | Window *props; /* since we are interested just in the first value, which is
|
17 | a Window id */
|
18 |
|
19 | /* default DISPLAY */
|
20 | d = XOpenDisplay(NULL);
|
21 |
|
22 | /* ask for active window (no error check); the client must be freedesktop
|
23 | compliant */
|
24 | (void)XGetWindowProperty(d, DefaultRootWindow(d),
|
25 | XInternAtom(d, "_NET_ACTIVE_WINDOW", True),
|
26 | 0, 1, False, AnyPropertyType,
|
27 | &atom_type_prop, &actual_format,
|
28 | &n_items, &bytes_after_ret, (unsigned char**)&props);
|
29 |
|
30 | XQueryPointer(d, props[0], &inwin, &inchildwin,
|
31 | &rootx, &rooty, &childx, &childy, &mask);
|
32 | printf("relative to active window: %d,%d\n", childx, childy);
|
33 |
|
34 | XFree(props); /* free mem */
|
35 | (void)XCloseDisplay(d); /* and close the display */
|
36 | return 0;
|
37 | }
|