xss

Screensaver utilities for the X Windowing System
git clone https://git.woozle.org/neale/xss.git

Neale Pickett  ·  2008-04-15

xcursorpos.c

 1/* xcursorpos -- print current cursor coordinates
 2 * Copyright (C) 2008  Neale Pickett <neale@woozle.org>
 3 *
 4 * This program is free software: you can redistribute it and/or modify
 5 * it under the terms of the GNU General Public License as published by
 6 * the Free Software Foundation, either version 3 of the License, or (at
 7 * your option) any later version.
 8 *
 9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <X11/Xlib.h>
20#include "obj.h"
21
22int
23main(int argc, char *argv[])
24{
25  Display *display = NULL;
26
27  if (argc != 1) {
28    (void)fprintf(stderr, "Usage: %s\n", argv[0]);
29    return 64;                  /* EX_USAGE */
30  }
31
32  try {
33    Window       root, win;
34    int          x, y, win_x, win_y;
35    unsigned int mask;
36
37    if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
38    root = DefaultRootWindow(display);
39    if (! XQueryPointer(display, root, &root, &win, &x, &y, &win_x, &win_y, &mask)) {
40      raise("unable to query pointer");
41    }
42    (void)printf("%d %d\n", x, y);
43  } while (0);
44
45  if (display) {
46    (void)XCloseDisplay(display);
47  }
48
49  except {
50    (void)fprintf(stderr, "Error: %s\n", exception);
51    return 69;                  /* EX_UNAVAILABLE */
52  }
53
54  return 0;
55}