<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;}
@font-face
{font-family:"Cambria Math";
panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:Courier'>Hello, I
was hoping someone might be able to help me out with a <br>
problem I am having with the XTest Extension. </span><span style='font-size:
12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>What I am trying to do is select
on ButtonPress events that occur <br>
anywhere on the desktop. I am doing this by creating a transparent <br>
window that covers the entire desktop, and selects on ButtonPressMask. <br>
In my event loop I am unmapping this window (or moving it, both work). <br>
and then using XTestFakeMotionEvent to pass the event back to the <br>
desktop without this window in the way. </span><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>This seems to work well, but only
when I have a delay on the <br>
XTestFakeMotionEvent of more then 100. and sometimes at this value it <br>
is unreliable. CurrentTime, or 0 do not work atall. 200+, works all of <br>
the time, however there is a noticeable lag between the actual button <br>
press event and the time the underlying window recieves it. </span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>I have tried using XFlush() in
various places, but this doesn't seem <br>
to help. </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>Below is a test project that
should show my problem. Any assistance <br>
would be greatly appriciated. </span><span style='font-size:12.0pt;font-family:
"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>Thanks</span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>#include
<X11/extensions/XTest.h> <br>
#include <X11/Xutil.h> <br>
#include <stdio.h> </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>int main() <br>
{ </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>
Display* display = XOpenDisplay(NULL); <br>
int done; <br>
XSetWindowAttributes attr; <br>
attr.do_not_propagate_mask = 0; <br>
attr.override_redirect = True; <br>
attr.cursor = None; <br>
attr.border_pixel = BlackPixel(display, 0); <br>
attr.event_mask = PointerMotionMask | <br>
ButtonPressMask | ButtonReleaseMask | <br>
KeyPressMask | KeyReleaseMask | <br>
KeymapStateMask | PropertyChangeMask; </span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'> Window
root,child; <br>
int rootx,rooty,winx,winy; <br>
unsigned int maskret; <br>
XQueryPointer(display,DefaultRootWindow <br>
(display),&root,&child,&rootx,&rooty,&winx,&winy,&maskret);
<br>
Window window = XCreateWindow(display,
DefaultRootWindow(display), <br>
rootx, rooty,50, 50, 5, CopyFromParent , <br>
InputOutput, CopyFromParent, <br>
CWBorderPixel| CWDontPropagate
| CWEventMask | <br>
CWOverrideRedirect | CWCursor, <br>
&attr); <br>
XSelectInput(display,window,PointerMotionMask|LeaveWindowMask| <br>
ButtonPressMask); <br>
XMapRaised(display, window); </span><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'> for
(done =0;!done;) <br>
{ <br>
XEvent event; <br>
XNextEvent(display,&event); <br>
if (event.type == ButtonPress) <br>
{ </span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
style='font-size:12.0pt;font-family:Courier'>
XUnmapWindow(display,window); <br>
printf("%s\n","1"); <br>
XButtonEvent buttonEvent = *(XButtonEvent*)&event; <br>
printf("X : %d, Y :
%d\n",buttonEvent.x_root,buttonEvent.y_root); <br>
XTestFakeButtonEvent(display,buttonEvent.button,true,200); <br>
XTestFakeButtonEvent(display,buttonEvent.button,false,200); <br>
XFlush(display); <br>
XMapRaised(display,window); <br>
printf("%s\n","ButtonPress"); <br>
} <br>
} <br>
return 0; </span><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>