<html><body bgcolor="#FFFFFF"><div><br><br><div style="text-align: left;direction: ltr; "><br></div></div><div><br>ב-13/03/2010, בשעה 13:03, Valery Reznic <<a href="mailto:valery_reznic@yahoo.com">valery_reznic@yahoo.com</a>> כתב/ה:<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> callback_A(); // create Window 'W'</span><br><span> 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</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> callback_A(); // create Window 'W'</span><br><span> handle_events();</span><br><span> 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> XFlush(display);</span><br><span> XSync(display, False);</span><br><span></span><br><span> while (XtAppPending(appContext))</span><br><span> {</span><br><span> XtAppProcessEvent(appContext,Mask );</span><br><span> }</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> callback_A(); // create Window 'W'</span><br><span> handle_events();</span><br><span></span><br><span> usleep(100000);</span><br><span> handle_events();</span><br><span></span><br><span> 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> The XSync function flushes the output buffer and then waits until all</span><br><span> requests have been received and processed by the X server. Any errors</span><br><span> generated must be handled by the error handler. For each protocol</span><br><span> error received by Xlib, XSync calls the client application’s error han-</span><br><span> dling routine (see section 11.8.2). Any events generated by the server</span><br><span> 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 <<a href="mailto:nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>> wrote:</span><br><span></span><br><blockquote type="cite"><span>From: Nadav Har'El <<a href="mailto:nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>></span><br></blockquote><blockquote type="cite"><span>Subject: Re: XWindows - how capture window ?</span><br></blockquote><blockquote type="cite"><span>To: "Erez D" <<a href="mailto:erez0001@gmail.com">erez0001@gmail.com</a>></span><br></blockquote><blockquote type="cite"><span>Cc: "Valery Reznic" <<a href="mailto:valery_reznic@yahoo.com">valery_reznic@yahoo.com</a>>, "linux-il." <<a href="mailto:linux-il@cs.huji.ac.il">linux-il@cs.huji.ac.il</a>></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 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 href="http://www.freedesktop.org/wiki/Software/XDamage"><a href="http://www.freedesktop.org/wiki/Software/XDamage">http://www.freedesktop.org/wiki/Software/XDamage</a></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 </span><br></blockquote><blockquote type="cite"><span> | </span><br></blockquote><blockquote type="cite"><span> Sunday, Mar 7 2010, 21 Adar 5770</span><br></blockquote><blockquote type="cite"><span><a href="mailto:nyh@math.technion.ac.il">nyh@math.technion.ac.il</a> </span><br></blockquote><blockquote type="cite"><span> </span><br></blockquote><blockquote type="cite"><span> |-----------------------------------------</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 href="http://nadav.harel.org.il">http://nadav.harel.org.il</a> </span><br></blockquote><blockquote type="cite"><span> |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 href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a></span><br><span><a 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></body></html>