From 4429a63ef0b8a3255bb8a85aa63b134785329f80 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 6 Jun 2009 02:07:31 +0100 Subject: [PATCH] WIP XTest stuff --- pctb/Makefile | 8 ++++---- pctb/x-manip-window.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/pctb/Makefile b/pctb/Makefile index 3707d81..c28e00b 100644 --- a/pctb/Makefile +++ b/pctb/Makefile @@ -1,9 +1,9 @@ -LDLIBS += -lnetpbm CFLAGS += -Wall -Wwrite-strings -Wpointer-arith -Wmissing-prototypes \ -Wstrict-prototypes -Werror -g -all: convert - -convert: convert.o ocr.o +all: convert x-manip-window +convert: convert.o ocr.o -lnetpbm convert.o ocr.o: ocr.h + +x-manip-window: -lXtst -lX11 diff --git a/pctb/x-manip-window.c b/pctb/x-manip-window.c index 2ff1135..7dd15a7 100644 --- a/pctb/x-manip-window.c +++ b/pctb/x-manip-window.c @@ -5,17 +5,13 @@ #include #include +#include #define eassert assert static Display *disp; static long id; -static void kmevent(XEvent *ev) { - int r; - r= XSendEvent(disp,id,False,0,ev); assert(r); -} - static KeyCode keycode(const char *s) { KeySym sym= XStringToKeysym(s); return XKeysymToKeycode(disp,sym); @@ -24,13 +20,33 @@ static KeyCode keycode(const char *s) { int main(int argc, const char *const *argv) { char *ep; XWindowAttributes attr; - XEvent ev; + Window dummy; + int xpos,ypos; + unsigned width,height,bd,depth; int r; id= strtoul(*++argv,&ep,0); disp= XOpenDisplay(0); eassert(disp); + r= XRaiseWindow(disp, id); eassert(r); + r= XGetWindowAttributes(disp, id, &attr); eassert(r); + r= XGetGeometry(disp,id, &attr.root,&xpos,&ypos,&width,&height, &bd,&depth); + eassert(r); + + r= XTranslateCoordinates(disp, id,attr.root, 160,160, &xpos,&ypos, + &dummy); + eassert(r); + + int screen= XScreenNumberOfScreen(attr.screen); + XTestFakeMotionEvent(disp,screen, xpos, ypos, 0); + XTestFakeButtonEvent(disp,1,1, 0); + XTestFakeButtonEvent(disp,1,0, 100); + + XTestFakeKeyEvent(disp, keycode("Next"),1, 100); + XTestFakeKeyEvent(disp, keycode("Next"),0, 100); + +#if 0 while (*++argv) { @@ -40,7 +56,6 @@ int main(int argc, const char *const *argv) { switch (**argv) { case 'r': - r= XRaiseWindow(disp, id); eassert(r); break; #define KMEVENT(e,t) \ @@ -55,7 +70,7 @@ int main(int argc, const char *const *argv) { kmevent(&ev); \ break; - case 'K': KE.keycode= keycode(*++argv); KMEVENT(KE,KeyPress); + case 'K': KE.keycode= ; KMEVENT(KE,KeyPress); case 'k': KE.keycode= keycode(*++argv); KMEVENT(KE,KeyRelease); case 'M': ME.button=1; KMEVENT(ME,ButtonPress); case 'm': ME.button=1; ME.state=Button1Mask; KMEVENT(ME,ButtonRelease); @@ -63,7 +78,8 @@ int main(int argc, const char *const *argv) { abort(); } } - + +#endif r= XSync(disp, False); eassert(r); exit(0); } -- 2.30.2