swarp

simple pointer warp for X
git clone git://git.suckless.org/swarp
Log | Files | Refs | README | LICENSE

swarp.c (896B)


      1 /* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
      2  * See LICENSE file for license details.
      3  */
      4 
      5 #include <stdlib.h>
      6 #include <stdio.h>
      7 #include <string.h>
      8 #include <errno.h>
      9 #include <X11/Xlib.h>
     10 
     11 int
     12 main(int argc, char **argv) {
     13 	int x, y;
     14 	Display *dpy;
     15 
     16 	if((argc == 2) && !strncmp(argv[1], "-v", 3)) {
     17 		fputs("swarp-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
     18 		exit(EXIT_SUCCESS);
     19 	}
     20 	if(argc != 3)
     21 		goto Usage;
     22 	if(!(dpy = XOpenDisplay(0))) {
     23 		fputs("swarp: cannot open display\n", stderr);
     24 		exit(EXIT_FAILURE);
     25 	}
     26 	if((sscanf(argv[1], "%d", &x) != 1) || (sscanf(argv[2], "%d", &y) != 1)) {
     27 Usage:
     28 		fputs("usage: swarp <x> <y> [-v]\n", stderr);
     29 		exit(EXIT_FAILURE);
     30 	}
     31 	XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 0, 0, x, y);
     32 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
     33 	XCloseDisplay(dpy);
     34 	return 0;
     35 }