<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br><br>--- On <b>Sat, 3/13/10, Micha <i>&lt;michf@post.tau.ac.il&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Micha &lt;michf@post.tau.ac.il&gt;<br>Subject: Re: XWindows - how capture window ?<br>To: <br>Cc: "linux-il." &lt;linux-il@cs.huji.ac.il&gt;<br>Date: Saturday, March 13, 2010, 4:00 PM<br><br><div id="yiv941306094"><div><br><br><div style="text-align: left; direction: ltr;"><br></div></div><div><br>ב-13/03/2010, בשעה 13:03, Valery Reznic &lt;<a rel="nofollow" ymailto="mailto:valery_reznic@yahoo.com" target="_blank" href="/mc/compose?to=valery_reznic@yahoo.com">valery_reznic@yahoo.com</a>&gt; כתב/ה:<br><br></div><div></div><blockquote type="cite"><div><span>OK, I found something interesting.</span><br><span>It's turn out that for some reason on-screen rendering
 is a problem too.</span><br><span></span><br><span>Greatly oversimplified description of my application:</span><br><span>There is a mai windows with 2 buttons ('A', and 'B')</span><br><span>When buttons 'A' pressed Windows 'W' (with a lot of child windows) created and shown on the screen. It's done with function 'callback_A'</span><br><span></span><br><span>When I press button 'B' I want following to happened:</span><br><span>1. Window 'W" created, like it was created, when button 'A' pressed</span><br><span>2. Window 'W" content is captured.</span><br><span></span><br><span>So I have callback_B like this:</span><br><span>void callback_B()</span><br><span>{</span><br><span> &nbsp;&nbsp;&nbsp;callback_A(); // create Window 'W'</span><br><span> &nbsp;&nbsp;&nbsp;capture_window();</span><br><span>}</span><br><span></span><br></div></blockquote><div><br></div>Problem is, like you stated that you to wait for all the drawing callbacks to
 finish<div><br></div><div>The best approach for such a thing is to post and event to do the capture that will go on the queue after the draw events and then process the capture in that callback<br><br>I though about this but it's looks like events reported to be processed, while them still not - or I misunderstood meaning of XSync function.<br><br>Valery.<br></div><div><br><blockquote type="cite"><div><span>So far so good. The only trouble is that requests sent to XServer in the function callback_A have no chance to be processed before call to capture_window() function, because application does not retirned to it's main application loop, which process events.</span><br><span>To get XServer chance to process events callback_B was modified as following:</span><br><span></span><br><span>void callback_B()</span><br><span>{</span><br><span> &nbsp;&nbsp;&nbsp;callback_A(); // create Window 'W'</span><br><span>
 &nbsp;&nbsp;&nbsp;handle_events();</span><br><span> &nbsp;&nbsp;&nbsp;capture_window();</span><br><span>}</span><br><span></span><br><span>Where handle_events looks like:</span><br><span>void handle_events()</span><br><span>{</span><br><span> &nbsp;&nbsp;XFlush(display);</span><br><span> &nbsp;&nbsp;XSync(display, False);</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;while (XtAppPending(appContext))</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;{</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XtAppProcessEvent(appContext,Mask );</span><br><span> &nbsp;&nbsp;}</span><br><span>}</span><br><span></span><br><span>This functions used in this application in other cases when events should be handled and it's works OK.</span><br><span>But in this case, Window 'W' was only partially drawn.</span><br><span></span><br><span>I found workaround modifie callback_B</span><br><span>void callback_B()</span><br><span>{</span><br><span>
 &nbsp;&nbsp;&nbsp;callback_A(); // create Window 'W'</span><br><span> &nbsp;&nbsp;&nbsp;handle_events();</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;usleep(100000);</span><br><span> &nbsp;&nbsp;&nbsp;handle_events();</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;capture_window();</span><br><span>}</span><br><span></span><br><span>After some sleep and addition handle_events call Window 'W' rendered on screen as expected.</span><br><span></span><br><span>But I don't why first approach didn't work.</span><br><span>From the XSync man page:</span><br><span>-------------------------------------------------------------------------</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The XSync function flushes the output buffer and then waits until all</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requests have been received and processed by the X server. &nbsp;Any errors</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generated must
 be handled by the error handler. &nbsp;For each protocol</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error received by Xlib, XSync calls the client application’s error han-</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dling routine (see section 11.8.2). &nbsp;Any events generated by the server</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;are enqueued into the library’s event queue.</span><br><span>-------------------------------------------------------------------</span><br><span>So it's looks like XSync alone should do the job.</span><br><span>Obviously it was not - and it was a reason, that event_handle function was written.</span><br><span></span><br><span>What I did with sleep and two calls to even_handle is work, but it's ugly.</span><br><span>Anyone has idea why XSync alone is not enough and how I can wait to all requests to be processed by XServer
 ?</span><br><span></span><br><span>Regards,</span><br><span>Valery.</span><br><span></span><br><span></span><br><span>--- On Sun, 3/7/10, Nadav Har'El &lt;<a rel="nofollow" ymailto="mailto:nyh@math.technion.ac.il" target="_blank" href="/mc/compose?to=nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>&gt; wrote:</span><br><span></span><br><blockquote type="cite"><span>From: Nadav Har'El &lt;<a rel="nofollow" ymailto="mailto:nyh@math.technion.ac.il" target="_blank" href="/mc/compose?to=nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>&gt;</span><br></blockquote><blockquote type="cite"><span>Subject: Re: XWindows - how capture window ?</span><br></blockquote><blockquote type="cite"><span>To: "Erez D" &lt;<a rel="nofollow" ymailto="mailto:erez0001@gmail.com" target="_blank" href="/mc/compose?to=erez0001@gmail.com">erez0001@gmail.com</a>&gt;</span><br></blockquote><blockquote type="cite"><span>Cc: "Valery Reznic" &lt;<a rel="nofollow"
 ymailto="mailto:valery_reznic@yahoo.com" target="_blank" href="/mc/compose?to=valery_reznic@yahoo.com">valery_reznic@yahoo.com</a>&gt;, "linux-il." &lt;<a rel="nofollow" ymailto="mailto:linux-il@cs.huji.ac.il" target="_blank" href="/mc/compose?to=linux-il@cs.huji.ac.il">linux-il@cs.huji.ac.il</a>&gt;</span><br></blockquote><blockquote type="cite"><span>Date: Sunday, March 7, 2010, 10:38 AM</span><br></blockquote><blockquote type="cite"><span>On Thu, Mar 04, 2010, Erez D wrote</span><br></blockquote><blockquote type="cite"><span>about "Re: XWindows - how capture window ?":</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>composite window managers (i.e. compiz, baryl) work by</span><br></blockquote></blockquote><blockquote type="cite"><span>drawing the original</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>window off screen, then read it as a 2D picture,
 and</span><br></blockquote></blockquote><blockquote type="cite"><span>render it back to the</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>screen with certain effects.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>So i know it is possible to grab an off screen window.</span><br></blockquote></blockquote><blockquote type="cite"><span>I do not know however</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>how to make it off screen.</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>This is done using the "Composite" extension. See</span><br></blockquote><blockquote type="cite"><span><a rel="nofollow" target="_blank" href="http://www.freedesktop.org/wiki/Software/CompositeExt">http://www.freedesktop.org/wiki/Software/CompositeExt</a></span><br></blockquote><blockquote
 type="cite"><span></span><br></blockquote><blockquote type="cite"><span>But please note that all these "extensions", as their title</span><br></blockquote><blockquote type="cite"><span>implies, are</span><br></blockquote><blockquote type="cite"><span>not available in every installation of X. The "right way"</span><br></blockquote><blockquote type="cite"><span>to use them is</span><br></blockquote><blockquote type="cite"><span>to use them when they're available, but fall back to some</span><br></blockquote><blockquote type="cite"><span>slower or uglier</span><br></blockquote><blockquote type="cite"><span>alternative when they aren't.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>There is an X Extension called XDamage, which reports</span><br></blockquote></blockquote><blockquote type="cite"><span>changes on the window</span><br></blockquote><blockquote
 type="cite"><blockquote type="cite"><span>so you do not have to poll it for changes. These</span><br></blockquote></blockquote><blockquote type="cite"><span>window managers use it.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Right. <a rel="nofollow" target="_blank" href="http://www.freedesktop.org/wiki/Software/XDamage"></a><a rel="nofollow" target="_blank" href="http://www.freedesktop.org/wiki/Software/XDamage">http://www.freedesktop.org/wiki/Software/XDamage</a></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>-- </span><br></blockquote><blockquote type="cite"><span>Nadav Har'El&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br></blockquote><blockquote type="cite"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp;</span><br></blockquote><blockquote
 type="cite"><span>&nbsp; &nbsp; Sunday, Mar&nbsp; 7 2010, 21 Adar 5770</span><br></blockquote><blockquote type="cite"><span><a rel="nofollow" ymailto="mailto:nyh@math.technion.ac.il" target="_blank" href="/mc/compose?to=nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>&nbsp;</span><br></blockquote><blockquote type="cite"><span>&nbsp; &nbsp; &nbsp; &nbsp;</span><br></blockquote><blockquote type="cite"><span>&nbsp;&nbsp;&nbsp;|-----------------------------------------</span><br></blockquote><blockquote type="cite"><span>Phone +972-523-790466, ICQ 13349191 |Business jargon is the</span><br></blockquote><blockquote type="cite"><span>art of saying</span><br></blockquote><blockquote type="cite"><span><a rel="nofollow" target="_blank" href="http://nadav.harel.org.il">http://nadav.harel.org.il</a>&nbsp; &nbsp; &nbsp; &nbsp;</span><br></blockquote><blockquote type="cite"><span>&nbsp;&nbsp;&nbsp;|nothing while appearing to say a
 lot.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br><span></span><br><span></span><br><span></span><br><span>_______________________________________________</span><br><span>Linux-il mailing list</span><br><span><a rel="nofollow" ymailto="mailto:Linux-il@cs.huji.ac.il" target="_blank" href="/mc/compose?to=Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a></span><br><span><a rel="nofollow" target="_blank" href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a></span><br></div></blockquote></div></div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Linux-il mailing list<br><a ymailto="mailto:Linux-il@cs.huji.ac.il" href="/mc/compose?to=Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br><a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il"
 target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br></div></blockquote></td></tr></table><br>