From 571dc980782480ae88386166f3b9278f7aa5308e Mon Sep 17 00:00:00 2001 From: mallum Date: Tue, 14 Jun 2005 09:51:54 +0000 Subject: Add initial dragging code --- ChangeLog | 7 +++++++ README | 7 +++++++ xresponse.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index deb95ff..4f6404c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-06-14 mallum,,, + + * README: + * xresponse.c: (handle_xerror), (fake_event), (wait_response), + (usage), (main): + Add initial dragging code + 2005-03-07 mallum,,, * README: diff --git a/README b/README index b4ebcec..501aa10 100644 --- a/README +++ b/README @@ -23,6 +23,7 @@ xresponse <-o|--logfile output> [commands..] Commands are any combination/order of; -c|--click Send click and await damage response +-d|--drag Simulate mouse drag and collect damage -m|--monitor Watch area for damage ( default fullscreen ) -w|--wait Max time to wait for damage, set to 0 to monitor for ever. @@ -39,6 +40,12 @@ Click mouse at 100,100 and collect max 5 seconds of damage events; % xresponse -c 100x100 +Click and hold mouse at 100,100, then move to 101,100, then 105,100, +then 110,100 and finally release mouse. Damage is collected between +each point with max 5 seconds. + +% xresponse -d 100x100,101x100,105x100,110x100 + Click the mouse at 100x100, 100x150 and 200x200 colecting a max second of damage for each only in 240x320+0+0; diff --git a/xresponse.c b/xresponse.c index 68c5621..94991bb 100644 --- a/xresponse.c +++ b/xresponse.c @@ -40,6 +40,7 @@ int DamageEventNum; /* Damage Ext Event ID */ Atom AtomTimestamp; /* Atom for getting server time */ int DamageWaitSecs = 5; /* Max time to collect damamge */ Rectangle InterestedDamageRect; /* Damage rect to monitor */ +Bool MouseButtonIsLocked = False; /* For drag code */ int handle_xerror(Display *dpy, XErrorEvent *e) @@ -53,6 +54,18 @@ handle_xerror(Display *dpy, XErrorEvent *e) exit(1); } +/* for 'dragging' */ +void +lock_mouse_button_down(void) +{ + MouseButtonIsLocked = True; +} + +void +unlock_mouse_button_down(void) +{ + MouseButtonIsLocked = False; +} /** * Perform simple logging with timestamp and diff from last log @@ -244,7 +257,9 @@ fake_event(Display *dpy, int x, int y) /* Sent click */ XTestFakeButtonEvent(dpy, Button1, True, CurrentTime); - XTestFakeButtonEvent(dpy, Button1, False, CurrentTime); + + if (!MouseButtonIsLocked) /* only release if not dragging */ + XTestFakeButtonEvent(dpy, Button1, False, CurrentTime); return start; } @@ -301,6 +316,8 @@ usage(char *progname) fprintf(stderr, "%s: usage, %s <-o|--logfile output> [commands..]\n" "Commands are any combination/order of;\n" "-c|--click Send click and await damage response\n" + "-d|--drag Simulate mouse drag and collect damage\n" + "-m|--monitor Watch area for damage ( default fullscreen )\n" "-w|--wait Max time to wait for damage ( default 5 secs)\n" "-s|--stamp Write 'string' to log file\n\n" @@ -402,6 +419,51 @@ main(int argc, char **argv) continue; } + if (streq("-d", argv[i]) || streq("--drag", argv[i])) + { + char *s = NULL, *p = NULL; + + if (++i>=argc) usage (argv[0]); + + s = p = argv[i]; + + + + while (*p != '\0') + { + if (*p == ',') + { + lock_mouse_button_down(); + + *p = '\0'; + + cnt = sscanf(s, "%ux%u", &x, &y); + if (cnt != 2) + { + fprintf(stderr, "*** failed to parse '%s'\n", argv[i]); + usage(argv[0]); + } + + /* last passed point make sure button released */ + if (*(p+1) != ',') + unlock_mouse_button_down(); + + /* Send the event */ + log_action(fake_event(dpy, x, y), 0, + "Dragged to %ix%i\n", x, y); + + /* .. and wait for the damage response */ + wait_response(dpy); + + s = p+1; + } + p++; + } + + + continue; + } + if (streq("-i", argv[i]) || streq("--inspect", argv[i])) { wait_response(dpy); -- cgit v1.2.3