示例#1
0
        public static void PresentWithServerTime(this Gtk.Window window)
        {
            if (window == null)
            {
                return;
            }
            var gdkWindow = window.GdkWindow;

            if (gdkWindow == null || !IsGdkX11Available)
            {
                window.Present();
                return;
            }

            // HACK: disabled, see window.AddEvents() below

            /*
             * if ((gdkWindow.Events & Gdk.EventMask.PropertyChangeMask) == 0) {
             *  // GDK_PROPERTY_CHANGE_MASK is not set thus we have to bail out
             *  // else gdk_x11_get_server_time() will hang!
             *  window.Present();
             *  return;
             * }
             */

            // HACK: we can't obtain and check for GDK_PROPERTY_CHANGE_MASK as
            // gdk_window_x11_get_events() filters that mask, thus we have to
            // ignorantly set it using gtk_widget_add_events() else
            // gdk_x11_get_server_time() would hang if it wasn't set!
            window.AddEvents((int)Gdk.EventMask.PropertyChangeMask);

            try {
                // TODO: should we fallback to gdk_x11_display_get_user_time?
                var timestamp = gdk_x11_get_server_time(gdkWindow.Handle);
                window.PresentWithTime(timestamp);
            } catch (DllNotFoundException) {
                IsGdkX11Available = false;
                // no libgdk-x11 available (probably Mac OS X or Windows), thus
                // fallback to gtk_window_present() without a timestamp as they
                // don't require a timestamp to change the window focus
                window.Present();
            }
        }