3 * Query the current X pointer state
5 * (c) 2023 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the Edgeware X tools collection.
12 * X tools is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * X tools is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License
23 * along with X tools. If not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
36 #include <mLib/alloc.h>
37 #include <mLib/macros.h>
38 #include <mLib/mdwopt.h>
39 #include <mLib/quis.h>
40 #include <mLib/report.h>
42 /*----- Help and version information --------------------------------------*/
44 static void version(void)
45 { pquis(stdout, "$ version " VERSION "\n"); }
47 static void usage(FILE *fp)
48 { pquis(fp, "Usage: $ [-d DISPLAY] X Y\n"); }
50 static void help(void)
52 version(); putchar('\n');
55 Report the current pointer state, as SCREEN X Y MASK.\n\
57 Command-line options:\n\
59 -h, --help Display this help.\n\
60 -v, --version Display program's version number.\n\
61 -u, --usage Display short usage summary.\n\
63 -d, --display=DISPLAY Connect to X DISPLAY.\n",
67 /*----- Main program ------------------------------------------------------*/
69 int main(int argc, char *argv[])
71 const char *display = 0;
74 int i, screen, x, y, winx, winy;
82 /* Parse arguments. */
84 static struct option opt[] = {
85 { "help", 0, 0, 'h' },
86 { "usage", 0, 0, 'u' },
87 { "version", 0, 0, 'v' },
88 { "display", OPTF_ARGREQ, 0, 'd' },
92 i = mdwopt(argc, argv, "huvd:", opt, 0, 0, 0); if (i < 0) break;
94 case 'h': help(); exit(0);
95 case 'u': usage(stdout); exit(0);
96 case 'v': version(); exit(0);
97 case 'd': display = optarg; break;
98 default: f |= f_bogus; break;
101 if ((f&f_bogus) || argc - optind != 0) {
106 /* Open the display. */
107 if ((dpy = XOpenDisplay(display)) == 0)
108 die(EXIT_FAILURE, "couldn't open display");
110 /* Find and print where the pointer is. */
111 XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child,
112 &x, &y, &winx, &winy, &mask);
113 for (i = 0; i < ScreenCount(dpy); i++)
114 if (root == RootWindow(dpy, i)) { screen = i; goto found_root; }
115 die(2, "pointer is on unknown root window 0x%08lx", (unsigned long)root);
117 printf("%d %d %d 0x%08x\n", screen, x, y, mask);
124 /*----- That's all, folks -------------------------------------------------*/