nasty gtk_window_present/gdk_window_focus race



hey owen,

i just discovered a nasty race under a heavily loaded
machine, doing:

      gtk_widget_show (window);
    }
  gtk_window_present (GTK_WINDOW (window));

might lead an XSetInputFocus() (from gdk_window_focus() from
gtk_window_present()) request be handled by the xserver before
it actually mapped the window, leading to a BadMatch error:

#4  0x40217d8c in gdk_x_error (display=0x8064c10, error=0xbfffe6fc)
    at gdkmain-x11.c:632
#5  0x40293a0d in _XError () from /usr/X11R6/lib/libX11.so.6
#6  0x402920db in _XReply () from /usr/X11R6/lib/libX11.so.6
#7  0x4028daf7 in XSync () from /usr/X11R6/lib/libX11.so.6
#8  0x4028db80 in _XSyncFunction () from /usr/X11R6/lib/libX11.so.6
#9  0x4028cb46 in XSetInputFocus () from /usr/X11R6/lib/libX11.so.6
#10 0x4021ccc1 in gdk_window_focus (window=0x80df010, timestamp=3328937901)
    at gdkwindow-x11.c:1103
#11 0x4018ef65 in gtk_window_present (window=0x80dec08) at gtkwindow.c:3150
#12 0x80504d7 in show_fft_scope (callback_data=0xbffff82c, callback_action=0,

while we might want to tell people to not use gdk_window_focus() directly
after gtk_widget_show() unless they use gtk_widget_show_now(), a sequence
like gtk_widget_show(); gtk_window_present(); definitely should work.

as a workaround (other than in the client-code via show_now())
gdk_window_focus() should prolly check whether the window was
actually mapped.
in order to still get gtk_window_present() working as advertised though,
i think it's prolly best to add a flag to gtkwindow.c that causes actuall
"present" action to be deferred untill after the map event arrived. comments?

  if (GTK_WIDGET_VISIBLE (window))
    {
      g_assert (widget->window != NULL);

      gdk_window_show (widget->window);

      /* note that gdk_window_focus() will also move the window to
       * the current desktop, for WM spec compliant window managers.
       */
      gdk_window_focus (widget->window,
                        gtk_get_current_event_time ());
    }


---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]