XTestExtension Problem.
Robin Watson
rmawatson at hotmail.com
Sun Jan 10 09:31:33 PST 2010
Hello, I was hoping someone might be able to help me out with a
problem I am having with the XTest Extension.
What I am trying to do is select on ButtonPress events that occur
anywhere on the desktop. I am doing this by creating a transparent
window that covers the entire desktop, and selects on ButtonPressMask.
In my event loop I am unmapping this window (or moving it, both work).
and then using XTestFakeMotionEvent to pass the event back to the
desktop without this window in the way.
This seems to work well, but only when I have a delay on the
XTestFakeMotionEvent of more then 100. and sometimes at this value it
is unreliable. CurrentTime, or 0 do not work atall. 200+, works all of
the time, however there is a noticeable lag between the actual button
press event and the time the underlying window recieves it.
I have tried using XFlush() in various places, but this doesn't seem
to help.
Below is a test project that should show my problem. Any assistance
would be greatly appriciated.
Thanks
#include <X11/extensions/XTest.h>
#include <X11/Xutil.h>
#include <stdio.h>
int main()
{
Display* display = XOpenDisplay(NULL);
int done;
XSetWindowAttributes attr;
attr.do_not_propagate_mask = 0;
attr.override_redirect = True;
attr.cursor = None;
attr.border_pixel = BlackPixel(display, 0);
attr.event_mask = PointerMotionMask |
ButtonPressMask |
ButtonReleaseMask |
KeyPressMask |
KeyReleaseMask |
KeymapStateMask |
PropertyChangeMask;
Window root,child;
int rootx,rooty,winx,winy;
unsigned int maskret;
XQueryPointer(display,DefaultRootWindow
(display),&root,&child,&rootx,&rooty,&winx,&winy,&maskret);
Window window = XCreateWindow(display, DefaultRootWindow(display),
rootx, rooty,50, 50, 5, CopyFromParent ,
InputOutput,
CopyFromParent,
CWBorderPixel|
CWDontPropagate | CWEventMask |
CWOverrideRedirect |
CWCursor,
&attr);
XSelectInput(display,window,PointerMotionMask|LeaveWindowMask|
ButtonPressMask);
XMapRaised(display, window);
for (done =0;!done;)
{
XEvent event;
XNextEvent(display,&event);
if (event.type == ButtonPress)
{
XUnmapWindow(display,window);
printf("%s\n","1");
XButtonEvent buttonEvent = *(XButtonEvent*)&event;
printf("X : %d, Y :
%d\n",buttonEvent.x_root,buttonEvent.y_root);
XTestFakeButtonEvent(display,buttonEvent.button,true,200);
XTestFakeButtonEvent(display,buttonEvent.button,false,200);
XFlush(display);
XMapRaised(display,window);
printf("%s\n","ButtonPress");
}
}
return 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20100110/16ac7e5c/attachment.html>
More information about the xorg
mailing list