Commit a6d34dc0c8715c461fa47da76f5615df60f7b61a

Improved a qt_x11_wait_for_window_manager.

In addition to waiting until the window manager maps and reparents the
window, also wait until we get initial expose event.

The window manager will most probably send us several ConfigureNotify
events, so wait until all of them are handled in addition to the Expose
event (as one might rely on another).

Also, we shouldn't wait for the ReparentNotify event if the window has
X11BypassWindowManagerHint.

Reviewed-by: Olivier Goffart
  
346346 qt_x11_enforce_cursor(w, false);
347347}
348348
349static Bool checkForConfigureAndExpose(Display *, XEvent *e, XPointer)
350{
351 return e->type == ConfigureNotify || e->type == Expose;
352}
349353
350354Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w)
351355{
359359 XEvent ev;
360360 QTime t;
361361 t.start();
362 static const int maximumWaitTime = 2000;
362363 if (!w->testAttribute(Qt::WA_WState_Created))
363364 return;
364 while (!XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), ReparentNotify, &ev)) {
365 if (t.elapsed() > 2000)
366 return;
367 qApp->syncX(); // non-busy wait
365
366 if (!(w->windowFlags() & Qt::X11BypassWindowManagerHint)) {
367 // if the window is not override-redirect, then the window manager
368 // will reparent us to the frame decoration window.
369 while (!XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), ReparentNotify, &ev)) {
370 if (t.elapsed() > maximumWaitTime)
371 return;
372 qApp->syncX(); // non-busy wait
373 }
368374 }
369375
370376 while (!XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), MapNotify, &ev)) {
371 if (t.elapsed() > 2000)
377 if (t.elapsed() > maximumWaitTime)
372378 return;
373379 qApp->syncX(); // non-busy wait
374380 }
375381
376382 qApp->x11ProcessEvent(&ev);
377 if (XCheckTypedWindowEvent(X11->display, w->effectiveWinId(), ConfigureNotify, &ev))
378 qApp->x11ProcessEvent(&ev);
383
384 // ok, seems like the window manager successfully reparented us, we'll wait
385 // for the first paint event to arrive, while handling ConfigureNotify in
386 // the arrival order
387 while(1)
388 {
389 if (XCheckIfEvent(X11->display, &ev, checkForConfigureAndExpose, 0)) {
390 qApp->x11ProcessEvent(&ev);
391 if (ev.type == Expose)
392 return;
393 }
394 if (t.elapsed() > maximumWaitTime)
395 return;
396 qApp->syncX(); // non-busy wait
397 }
379398}
380399
381400void qt_change_net_wm_state(const QWidget* w, bool set, Atom one, Atom two = 0)