wmii/cmd/click/main.c

63 lines
1016 B
C
Raw Normal View History

/* Copyright ©2006-2010 Kris Maglione <maglione.k at Gmail>
2008-12-01 15:43:20 +03:00
* See LICENSE file for license details.
*/
#define EXTERN
#include "dat.h"
#include <X11/Xproto.h>
#include <X11/extensions/XTest.h>
#include <locale.h>
#include <string.h>
#include "fns.h"
2010-05-17 21:59:30 +04:00
static const char version[] = "click-"VERSION", ©2010 Kris Maglione\n";
2008-12-01 15:43:20 +03:00
static void
usage(void) {
fatal("usage: %s [window]\n", argv0);
}
static void
click(Window *w, Point p) {
2008-12-24 08:24:23 +03:00
Rectangle r;
Point rp;
2008-12-01 15:43:20 +03:00
2008-12-24 08:24:23 +03:00
r = getwinrect(w);
rp = subpt(r.max, p);
2008-12-01 15:43:20 +03:00
XTestFakeMotionEvent(display, 0, rp.x, rp.y, 0);
XTestFakeButtonEvent(display, 1, true, 0);
XTestFakeButtonEvent(display, 1, false, 0);
2008-12-24 08:24:23 +03:00
XTestFakeMotionEvent(display, 0, r.max.x, r.max.y, 0);
2008-12-01 15:43:20 +03:00
}
int
main(int argc, char *argv[]) {
char *s;
ARGBEGIN{
default:
usage();
}ARGEND;
setlocale(LC_CTYPE, "");
initdisplay();
s = ARGF();
2010-05-22 06:52:47 +04:00
if(s && !getulong(s, &win.xid))
2008-12-01 15:43:20 +03:00
usage();
if (!s)
2010-05-22 06:52:47 +04:00
win.xid = getfocus();
2008-12-01 15:43:20 +03:00
if(argc)
usage();
2008-12-24 08:24:23 +03:00
click(&win, Pt(1, 1));
2008-12-01 15:43:20 +03:00
XCloseDisplay(display);
return 0;
}