74a6dad7ce03d9a23e6f3e873dec5f8fad931407
10 #include <X11/Xutil.h>
13 usage(const char *err
, ...)
18 fprintf(stderr
, "ERROR: ");
19 vfprintf(stderr
, err
, va
);
24 "usage: xwarppointer <command> <args>\n\n"
26 " screen <+/-> | <screen #> Move cursor to specific screen, or \n"
27 " relative to current one. Does not change \n"
28 " the cursor's position on the screen. \n"
30 " abspos <x|.> <y|.> Moves cursor to given X and Y coordinates.\n"
31 " If . is specified instead of a #, it \n"
32 " doesn't change that axis. \n"
34 " relpos <x offset> <y offset> Move the cursor relative to its current \n"
37 " get Return the cursors position. \n"
43 myatoi(const char *str
, int *ret
) {
55 main(int argc
, char *argv
[])
60 if ((display
= XOpenDisplay(NULL
)) == NULL
) {
61 fprintf(stderr
, "Cannot open local X-display.\n");
64 root
= DefaultRootWindow(display
);
66 if (argc
< 2) usage("wrong number of args");
68 if (!strcasecmp(argv
[1], "screen")) {
69 Window fromroot
, tmpwin
;
70 XWindowAttributes attr
;
71 int screen
= -1, rot
, x
, y
, tmp
;
74 usage("screen: wrong number of args");
78 else if (*argv
[2] == '-')
81 screen
= atoi(argv
[2]);
83 XQueryPointer(display
, root
, &fromroot
, &tmpwin
, &x
, &y
, &tmp
, &tmp
, &tmp
);
86 XGetWindowAttributes(display
, fromroot
, &attr
);
87 screen
= XScreenNumberOfScreen(attr
.screen
);
90 if (screen
>= ScreenCount(display
))
91 screen
-= ScreenCount(display
);
93 screen
+= ScreenCount(display
);
96 if (screen
>= ScreenCount(display
) || screen
< 0) {
97 fprintf(stderr
, "Cannot get root window of screen!\n");
102 root
= RootWindow(display
, screen
);
103 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
106 } else if (!strcasecmp(argv
[1], "abspos")) {
108 Window fromroot
, tmpwin
;
111 usage("abspos: wrong number of args");
113 XQueryPointer(display
, root
, &fromroot
, &tmpwin
, &x
, &y
, &tmp
, &tmp
, &tmp
);
115 if (argv
[2][0] != '.')
116 if (!myatoi(argv
[2], &x
))
117 usage("abspos: invalid x pos: %s", argv
[2]);
118 if (argv
[3][0] != '.')
119 if (!myatoi(argv
[3], &y
))
120 usage("abspos: invalid y pos: %s", argv
[3]);
122 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
125 } else if (!strcasecmp(argv
[1], "relpos")) {
126 int x
, y
, tmp
, x2
, y2
;
127 Window fromroot
, tmpwin
;
130 usage("relpos: wrong number of args");
132 XQueryPointer(display
, root
, &fromroot
, &tmpwin
, &x
, &y
, &tmp
, &tmp
, &tmp
);
134 if (!myatoi(argv
[2], &x2
)) usage("relpos: invalid x pos: %s", argv
[2]);
135 if (!myatoi(argv
[3], &y2
)) usage("relpos: invalid y pos: %s", argv
[3]);
139 XWarpPointer(display
, None
, root
, 0, 0, 0, 0, x
, y
);
142 } else if (!strcasecmp(argv
[1], "get")) {
144 Window fromroot
, tmpwin
;
147 usage("get: wrong number of args");
149 XQueryPointer(display
, root
, &fromroot
, &tmpwin
, &x
, &y
, &tmp
, &tmp
, &tmp
);
151 printf("%d %d\n", x
, y
);
154 usage("invalid command: %s", argv
[1]);
This page took 0.369553 seconds and 5 git commands to generate.