Bug 635134 - Adds X11 run-time check for Gtk3 backend. r=karlt
authorMartin Stransky <stransky@redhat.com>
Thu, 05 Mar 2015 03:56:00 +0100
changeset 262586 53503035a93d5b733bd87ad85c1d07bf63e4032d
parent 262585 16da3471411737e09292274390ae968dd846a501
child 262587 97ab1c1874753b58cfe70860a269565670414807
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs635134
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 635134 - Adds X11 run-time check for Gtk3 backend. r=karlt
gfx/thebes/gfxPlatformGtk.cpp
toolkit/xre/nsAppRunner.cpp
widget/gtk/compat/gdk/gdkx.h
widget/gtk/mozgtk/mozgtk.c
widget/gtk/nsClipboard.cpp
widget/gtk/nsGtkKeyUtils.cpp
widget/gtk/nsIdleServiceGTK.cpp
widget/gtk/nsScreenManagerGtk.cpp
widget/gtk/nsWindow.cpp
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -58,17 +58,18 @@ static cairo_user_data_key_t cairo_gdk_d
     bool gfxPlatformGtk::sUseXRender = true;
 #endif
 
 gfxPlatformGtk::gfxPlatformGtk()
 {
     if (!sFontconfigUtils)
         sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
 #ifdef MOZ_X11
-    sUseXRender = mozilla::Preferences::GetBool("gfx.xrender.enabled");
+    sUseXRender = (GDK_IS_X11_DISPLAY(gdk_display_get_default())) ? 
+                    mozilla::Preferences::GetBool("gfx.xrender.enabled") : false;
 #endif
 
     uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
     uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
     InitBackendPrefs(canvasMask, BackendType::CAIRO,
                      contentMask, BackendType::CAIRO);
 }
 
@@ -271,21 +272,25 @@ gfxPlatformGtk::GetScreenDepth() const
 
 void
 gfxPlatformGtk::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
 {
     mem = nullptr;
     size = 0;
 
 #ifdef MOZ_X11
+    GdkDisplay *display = gdk_display_get_default();
+    if (!GDK_IS_X11_DISPLAY(display))
+        return;
+
     const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
     const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
 
     Atom edidAtom, iccAtom;
-    Display *dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+    Display *dpy = GDK_DISPLAY_XDISPLAY(display);
     // In xpcshell tests, we never initialize X and hence don't have a Display.
     // In this case, there's no output colour management to be done, so we just
     // return with nullptr.
     if (!dpy)
         return;
  
     Window root = gdk_x11_get_default_root_xwindow();
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3605,23 +3605,56 @@ XREMain::XRE_mainStartup(bool* aExitFlag
   } else {
     display_name = PR_GetEnv("DISPLAY");
     if (!display_name) {
       PR_fprintf(PR_STDERR, "Error: no display specified\n");
       return 1;
     }
   }
 #endif /* MOZ_WIDGET_GTK */
-
+#ifdef MOZ_X11
+  // Init X11 in thread-safe mode. Must be called prior to the first call to XOpenDisplay 
+  // (called inside gdk_display_open). This is a requirement for off main tread compositing.
+  // This is done only on X11 platforms if the environment variable MOZ_USE_OMTC is set so 
+  // as to avoid overhead when omtc is not used. 
+  //
+  // On nightly builds, we call this by default to enable OMTC for Electrolysis testing. On
+  // aurora, beta, and release builds, there is a small tpaint regression from enabling this
+  // call, so it sits behind an environment variable.
+  //
+  // An environment variable is used instead of a pref on X11 platforms because we start having 
+  // access to prefs long after the first call to XOpenDisplay which is hard to change due to 
+  // interdependencies in the initialization.
+# ifndef NIGHTLY_BUILD
+  if (PR_GetEnv("MOZ_USE_OMTC") ||
+      PR_GetEnv("MOZ_OMTC_ENABLED"))
+# endif
+  {
+    XInitThreads();
+  }
+#endif
+#if defined(MOZ_WIDGET_GTK)
+  {
+    mGdkDisplay = gdk_display_open(display_name);
+    if (!mGdkDisplay) {
+      PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
+      return 1;
+    }
+    gdk_display_manager_set_default_display (gdk_display_manager_get(),
+                                             mGdkDisplay);
+    if (!GDK_IS_X11_DISPLAY(mGdkDisplay))
+      mDisableRemote = true;
+  }
+#endif
 #ifdef MOZ_ENABLE_XREMOTE
   // handle --remote now that xpcom is fired up
   bool newInstance;
   {
     char *e = PR_GetEnv("MOZ_NO_REMOTE");
-    mDisableRemote = (e && *e);
+    mDisableRemote = (mDisableRemote || (e && *e));
     if (mDisableRemote) {
       newInstance = true;
     } else {
       e = PR_GetEnv("MOZ_NEW_INSTANCE");
       newInstance = (e && *e);
     }
   }
 
@@ -3634,46 +3667,17 @@ XREMain::XRE_mainStartup(bool* aExitFlag
     if (rr == REMOTE_FOUND) {
       *aExitFlag = true;
       return 0;
     }
     else if (rr == REMOTE_ARG_BAD)
       return 1;
   }
 #endif
-#ifdef MOZ_X11
-  // Init X11 in thread-safe mode. Must be called prior to the first call to XOpenDisplay 
-  // (called inside gdk_display_open). This is a requirement for off main tread compositing.
-  // This is done only on X11 platforms if the environment variable MOZ_USE_OMTC is set so 
-  // as to avoid overhead when omtc is not used. 
-  //
-  // On nightly builds, we call this by default to enable OMTC for Electrolysis testing. On
-  // aurora, beta, and release builds, there is a small tpaint regression from enabling this
-  // call, so it sits behind an environment variable.
-  //
-  // An environment variable is used instead of a pref on X11 platforms because we start having 
-  // access to prefs long after the first call to XOpenDisplay which is hard to change due to 
-  // interdependencies in the initialization.
-# ifndef NIGHTLY_BUILD
-  if (PR_GetEnv("MOZ_USE_OMTC") ||
-      PR_GetEnv("MOZ_OMTC_ENABLED"))
-# endif
-  {
-    XInitThreads();
-  }
-#endif
 #if defined(MOZ_WIDGET_GTK)
-  mGdkDisplay = gdk_display_open(display_name);
-  if (!mGdkDisplay) {
-    PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
-    return 1;
-  }
-  gdk_display_manager_set_default_display (gdk_display_manager_get(),
-                                           mGdkDisplay);
-    
   // g_set_application_name () is only defined in glib2.2 and higher.
   _g_set_application_name_fn _g_set_application_name =
     (_g_set_application_name_fn)FindFunction("g_set_application_name");
   if (_g_set_application_name) {
     _g_set_application_name(mAppData->name);
   }
   _gtk_window_set_auto_startup_notification_fn _gtk_window_set_auto_startup_notification =
     (_gtk_window_set_auto_startup_notification_fn)FindFunction("gtk_window_set_auto_startup_notification");
--- a/widget/gtk/compat/gdk/gdkx.h
+++ b/widget/gtk/compat/gdk/gdkx.h
@@ -17,9 +17,14 @@ gdk_x11_window_lookup_for_display(GdkDis
   return gdk_window_lookup_for_display(display, window);
 }
 
 static inline Window
 gdk_x11_window_get_xid(GdkWindow *window)
 {
   return(GDK_WINDOW_XWINDOW(window));
 }
+
+#ifndef GDK_IS_X11_DISPLAY
+#define GDK_IS_X11_DISPLAY(a)   (true)
+#endif
+
 #endif /* GDKX_WRAPPER_H */
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -48,16 +48,18 @@ STUB(gdk_keyval_name)
 STUB(gdk_keyval_to_unicode)
 STUB(gdk_pango_context_get)
 STUB(gdk_pointer_grab)
 STUB(gdk_pointer_ungrab)
 STUB(gdk_property_get)
 STUB(gdk_screen_get_default)
 STUB(gdk_screen_get_display)
 STUB(gdk_screen_get_font_options)
+STUB(gdk_screen_get_height)
+STUB(gdk_screen_get_height_mm)
 STUB(gdk_screen_get_number)
 STUB(gdk_screen_get_resolution)
 STUB(gdk_screen_get_rgba_visual)
 STUB(gdk_screen_get_root_window)
 STUB(gdk_screen_get_system_visual)
 STUB(gdk_screen_height)
 STUB(gdk_screen_is_composited)
 STUB(gdk_screen_width)
@@ -485,16 +487,17 @@ STUB(gtk_window_unmaximize)
 #ifdef GTK3_SYMBOLS
 STUB(gdk_device_get_source)
 STUB(gdk_device_manager_get_client_pointer)
 STUB(gdk_display_get_device_manager)
 STUB(gdk_error_trap_pop_ignored)
 STUB(gdk_event_get_source_device)
 STUB(gdk_window_get_type)
 STUB(gdk_x11_window_get_xid)
+STUB(gdk_x11_display_get_type)
 STUB(gtk_cairo_should_draw_window)
 STUB(gtk_cairo_transform_to_window)
 STUB(gtk_combo_box_text_append)
 STUB(gtk_get_major_version)
 STUB(gtk_get_micro_version)
 STUB(gtk_get_minor_version)
 STUB(gtk_menu_button_new)
 STUB(gtk_paned_new)
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -906,62 +906,64 @@ void *
 RetrievalContext::Wait()
 {
     if (mState == COMPLETED) { // the request completed synchronously
         void *data = mData;
         mData = nullptr;
         return data;
     }
 
-    Display *xDisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) ;
-    checkEventContext context;
-    context.cbWidget = nullptr;
-    context.selAtom = gdk_x11_atom_to_xatom(gdk_atom_intern("GDK_SELECTION",
-                                                            FALSE));
+    GdkDisplay *gdkDisplay = gdk_display_get_default();
+    if (GDK_IS_X11_DISPLAY(gdkDisplay)) {
+        Display *xDisplay = GDK_DISPLAY_XDISPLAY(gdkDisplay);
+        checkEventContext context;
+        context.cbWidget = nullptr;
+        context.selAtom = gdk_x11_atom_to_xatom(gdk_atom_intern("GDK_SELECTION",
+                                                                FALSE));
 
-    // Send X events which are relevant to the ongoing selection retrieval
-    // to the clipboard widget.  Wait until either the operation completes, or
-    // we hit our timeout.  All other X events remain queued.
+        // Send X events which are relevant to the ongoing selection retrieval
+        // to the clipboard widget.  Wait until either the operation completes, or
+        // we hit our timeout.  All other X events remain queued.
 
-    int select_result;
+        int select_result;
 
-    int cnumber = ConnectionNumber(xDisplay);
-    fd_set select_set;
-    FD_ZERO(&select_set);
-    FD_SET(cnumber, &select_set);
-    ++cnumber;
-    TimeStamp start = TimeStamp::Now();
+        int cnumber = ConnectionNumber(xDisplay);
+        fd_set select_set;
+        FD_ZERO(&select_set);
+        FD_SET(cnumber, &select_set);
+        ++cnumber;
+        TimeStamp start = TimeStamp::Now();
 
-    do {
-        XEvent xevent;
+        do {
+            XEvent xevent;
 
-        while (XCheckIfEvent(xDisplay, &xevent, checkEventProc,
-                             (XPointer) &context)) {
+            while (XCheckIfEvent(xDisplay, &xevent, checkEventProc,
+                                 (XPointer) &context)) {
 
-            if (xevent.xany.type == SelectionNotify)
-                DispatchSelectionNotifyEvent(context.cbWidget, &xevent);
-            else
-                DispatchPropertyNotifyEvent(context.cbWidget, &xevent);
+                if (xevent.xany.type == SelectionNotify)
+                    DispatchSelectionNotifyEvent(context.cbWidget, &xevent);
+                else
+                    DispatchPropertyNotifyEvent(context.cbWidget, &xevent);
 
-            if (mState == COMPLETED) {
-                void *data = mData;
-                mData = nullptr;
-                return data;
+                if (mState == COMPLETED) {
+                    void *data = mData;
+                    mData = nullptr;
+                    return data;
+                }
             }
-        }
 
-        TimeStamp now = TimeStamp::Now();
-        struct timeval tv;
-        tv.tv_sec = 0;
-        tv.tv_usec = std::max<int32_t>(0,
-            kClipboardTimeout - (now - start).ToMicroseconds());
-        select_result = select(cnumber, &select_set, nullptr, nullptr, &tv);
-    } while (select_result == 1 ||
-             (select_result == -1 && errno == EINTR));
-
+            TimeStamp now = TimeStamp::Now();
+            struct timeval tv;
+            tv.tv_sec = 0;
+            tv.tv_usec = std::max<int32_t>(0,
+                kClipboardTimeout - (now - start).ToMicroseconds());
+            select_result = select(cnumber, &select_set, nullptr, nullptr, &tv);
+        } while (select_result == 1 ||
+                 (select_result == -1 && errno == EINTR));
+    }
 #ifdef DEBUG_CLIPBOARD
     printf("exceeded clipboard timeout\n");
 #endif
     mState = TIMED_OUT;
     return nullptr;
 }
 
 static void
--- a/widget/gtk/nsGtkKeyUtils.cpp
+++ b/widget/gtk/nsGtkKeyUtils.cpp
@@ -170,17 +170,18 @@ KeymapWrapper::KeymapWrapper() :
 
     g_signal_connect(mGdkKeymap, "keys-changed",
                      (GCallback)OnKeysChanged, this);
 
     // This is necessary for catching the destroying timing.
     g_object_weak_ref(G_OBJECT(mGdkKeymap),
                       (GWeakNotify)OnDestroyKeymap, this);
 
-    InitXKBExtension();
+    if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
+        InitXKBExtension();
 
     Init();
 }
 
 void
 KeymapWrapper::Init()
 {
     if (mInitialized) {
@@ -190,17 +191,18 @@ KeymapWrapper::Init()
 
     PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS,
         ("KeymapWrapper(%p): Init, mGdkKeymap=%p",
          this, mGdkKeymap));
 
     mModifierKeys.Clear();
     memset(mModifierMasks, 0, sizeof(mModifierMasks));
 
-    InitBySystemSettings();
+    if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
+        InitBySystemSettings();
 
     gdk_window_add_filter(nullptr, FilterEvents, this);
 
     PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS,
         ("KeymapWrapper(%p): Init, CapsLock=0x%X, NumLock=0x%X, "
          "ScrollLock=0x%X, Level3=0x%X, Level5=0x%X, "
          "Shift=0x%X, Ctrl=0x%X, Alt=0x%X, Meta=0x%X, Super=0x%X, Hyper=0x%X",
          this,
@@ -892,19 +894,20 @@ KeymapWrapper::InitKeyEvent(WidgetKeyboa
     // NOTE: The state of given key event indicates adjacent state of
     // modifier keys.  E.g., even if the event is Shift key press event,
     // the bit for Shift is still false.  By the same token, even if the
     // event is Shift key release event, the bit for Shift is still true.
     // Unfortunately, gdk_keyboard_get_modifiers() returns current modifier
     // state.  It means if there're some pending modifier key press or
     // key release events, the result isn't what we want.
     guint modifierState = aGdkKeyEvent->state;
-    if (aGdkKeyEvent->is_modifier) {
+    GdkDisplay* gdkDisplay = gdk_display_get_default();
+    if (aGdkKeyEvent->is_modifier && GDK_IS_X11_DISPLAY(gdkDisplay)) {
         Display* display =
-            gdk_x11_display_get_xdisplay(gdk_display_get_default());
+            gdk_x11_display_get_xdisplay(gdkDisplay);
         if (XEventsQueued(display, QueuedAfterReading)) {
             XEvent nextEvent;
             XPeekEvent(display, &nextEvent);
             if (nextEvent.type == keymapWrapper->mXKBBaseEventCode) {
                 XkbEvent* XKBEvent = (XkbEvent*)&nextEvent;
                 if (XKBEvent->any.xkb_type == XkbStateNotify) {
                     XkbStateNotifyEvent* stateNotifyEvent =
                         (XkbStateNotifyEvent*)XKBEvent;
--- a/widget/gtk/nsIdleServiceGTK.cpp
+++ b/widget/gtk/nsIdleServiceGTK.cpp
@@ -29,16 +29,19 @@ static bool sInitialized = false;
 static _XScreenSaverQueryExtension_fn _XSSQueryExtension = nullptr;
 static _XScreenSaverAllocInfo_fn _XSSAllocInfo = nullptr;
 static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nullptr;
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceGTK, nsIdleService)
 
 static void Initialize()
 {
+    if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()))
+        return;
+
     // This will leak - See comments in ~nsIdleServiceGTK().
     PRLibrary* xsslib = PR_LoadLibrary("libXss.so.1");
     if (!xsslib) // ouch.
     {
 #ifdef PR_LOGGING
         PR_LOG(sIdleLog, PR_LOG_WARNING, ("Failed to find libXss.so!\n"));
 #endif
         return;
@@ -131,9 +134,8 @@ nsIdleServiceGTK::PollIdleTime(uint32_t 
     return false;
 }
 
 bool
 nsIdleServiceGTK::UsePollMode()
 {
     return sInitialized;
 }
-
--- a/widget/gtk/nsScreenManagerGtk.cpp
+++ b/widget/gtk/nsScreenManagerGtk.cpp
@@ -48,16 +48,17 @@ root_window_event_filter(GdkXEvent *aGdk
 #endif
 
   return GDK_FILTER_CONTINUE;
 }
 
 nsScreenManagerGtk :: nsScreenManagerGtk ( )
   : mXineramalib(nullptr)
   , mRootWindow(nullptr)
+  , mNetWorkareaAtom(0)
 {
   // nothing else to do. I guess we could cache a bunch of information
   // here, but we want to ask the device at runtime in case anything
   // has changed.
 }
 
 
 nsScreenManagerGtk :: ~nsScreenManagerGtk()
@@ -95,31 +96,34 @@ nsScreenManagerGtk :: EnsureInit()
   // GDK_STRUCTURE_MASK ==> StructureNotifyMask, for ConfigureNotify
   // GDK_PROPERTY_CHANGE_MASK ==> PropertyChangeMask, for PropertyNotify
   gdk_window_set_events(mRootWindow,
                         GdkEventMask(gdk_window_get_events(mRootWindow) |
                                      GDK_STRUCTURE_MASK |
                                      GDK_PROPERTY_CHANGE_MASK));
   gdk_window_add_filter(mRootWindow, root_window_event_filter, this);
 #ifdef MOZ_X11
-  mNetWorkareaAtom =
-    XInternAtom(GDK_WINDOW_XDISPLAY(mRootWindow), "_NET_WORKAREA", False);
+  if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
+      mNetWorkareaAtom =
+        XInternAtom(GDK_WINDOW_XDISPLAY(mRootWindow), "_NET_WORKAREA", False);
 #endif
 
   return Init();
 }
 
 nsresult
 nsScreenManagerGtk :: Init()
 {
 #ifdef MOZ_X11
   XineramaScreenInfo *screenInfo = nullptr;
   int numScreens;
 
-  if (!mXineramalib) {
+  bool useXinerama = GDK_IS_X11_DISPLAY(gdk_display_get_default());
+
+  if (useXinerama && !mXineramalib) {
     mXineramalib = PR_LoadLibrary("libXinerama.so.1");
     if (!mXineramalib) {
       mXineramalib = SCREEN_MANAGER_LIBRARY_LOAD_FAILED;
     }
   }
   if (mXineramalib && mXineramalib != SCREEN_MANAGER_LIBRARY_LOAD_FAILED) {
     _XnrmIsActive_fn _XnrmIsActive = (_XnrmIsActive_fn)
         PR_FindFunctionSymbol(mXineramalib, "XineramaIsActive");
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -723,24 +723,23 @@ nsIWidget *
 nsWindow::GetParent(void)
 {
     return mParent;
 }
 
 float
 nsWindow::GetDPI()
 {
-    Display *dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
-    int defaultScreen = DefaultScreen(dpy);
-    double heightInches = DisplayHeightMM(dpy, defaultScreen)/MM_PER_INCH_FLOAT;
+    GdkScreen *screen = gdk_display_get_default_screen(gdk_display_get_default());
+    double heightInches = gdk_screen_get_height_mm(screen)/MM_PER_INCH_FLOAT;
     if (heightInches < 0.25) {
         // Something's broken, but we'd better not crash.
         return 96.0f;
     }
-    return float(DisplayHeight(dpy, defaultScreen)/heightInches);
+    return float(gdk_screen_get_height(screen)/heightInches);
 }
 
 double
 nsWindow::GetDefaultScaleInternal()
 {
 #if (MOZ_WIDGET_GTK == 3)
     return GdkScaleFactor();
 #else
@@ -1937,32 +1936,35 @@ nsWindow::HasPendingInputEvent()
     // This sucks, but gtk/gdk has no way to answer the question we want while
     // excluding paint events, and there's no X API that will let us peek
     // without blocking or removing.  To prevent event reordering, peek
     // anything except expose events.  Reordering expose and others should be
     // ok, hopefully.
     bool haveEvent;
 #ifdef MOZ_X11
     XEvent ev;
-    Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
-    haveEvent =
-        XCheckMaskEvent(display,
-                        KeyPressMask | KeyReleaseMask | ButtonPressMask |
-                        ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
-                        PointerMotionMask | PointerMotionHintMask |
-                        Button1MotionMask | Button2MotionMask |
-                        Button3MotionMask | Button4MotionMask |
-                        Button5MotionMask | ButtonMotionMask | KeymapStateMask |
-                        VisibilityChangeMask | StructureNotifyMask |
-                        ResizeRedirectMask | SubstructureNotifyMask |
-                        SubstructureRedirectMask | FocusChangeMask |
-                        PropertyChangeMask | ColormapChangeMask |
-                        OwnerGrabButtonMask, &ev);
-    if (haveEvent) {
-        XPutBackEvent(display, &ev);
+    GdkDisplay* gdkDisplay = gdk_display_get_default();
+    if (GDK_IS_X11_DISPLAY(gdkDisplay)) {
+        Display *display = GDK_DISPLAY_XDISPLAY(gdkDisplay);
+        haveEvent =
+            XCheckMaskEvent(display,
+                            KeyPressMask | KeyReleaseMask | ButtonPressMask |
+                            ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
+                            PointerMotionMask | PointerMotionHintMask |
+                            Button1MotionMask | Button2MotionMask |
+                            Button3MotionMask | Button4MotionMask |
+                            Button5MotionMask | ButtonMotionMask | KeymapStateMask |
+                            VisibilityChangeMask | StructureNotifyMask |
+                            ResizeRedirectMask | SubstructureNotifyMask |
+                            SubstructureRedirectMask | FocusChangeMask |
+                            PropertyChangeMask | ColormapChangeMask |
+                            OwnerGrabButtonMask, &ev);
+        if (haveEvent) {
+            XPutBackEvent(display, &ev);
+        }
     }
 #else
     haveEvent = false;
 #endif
     return haveEvent;
 }
 
 #if 0
@@ -2593,33 +2595,36 @@ nsWindow::OnMotionNotifyEvent(GdkEventMo
 {
     // see if we can compress this event
     // XXXldb Why skip every other motion event when we have multiple,
     // but not more than that?
     bool synthEvent = false;
 #ifdef MOZ_X11
     XEvent xevent;
 
-    while (XPending (GDK_WINDOW_XDISPLAY(aEvent->window))) {
-        XEvent peeked;
-        XPeekEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &peeked);
-        if (peeked.xany.window != gdk_x11_window_get_xid(aEvent->window)
-            || peeked.type != MotionNotify)
-            break;
-
-        synthEvent = true;
-        XNextEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &xevent);
-    }
+    bool isX11Display = GDK_IS_X11_DISPLAY(gdk_display_get_default());
+    if (isX11Display) {
+        while (XPending (GDK_WINDOW_XDISPLAY(aEvent->window))) {
+            XEvent peeked;
+            XPeekEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &peeked);
+            if (peeked.xany.window != gdk_x11_window_get_xid(aEvent->window)
+                || peeked.type != MotionNotify)
+                break;
+
+            synthEvent = true;
+            XNextEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &xevent);
+        }
 #if (MOZ_WIDGET_GTK == 2)
-    // if plugins still keeps the focus, get it back
-    if (gPluginFocusWindow && gPluginFocusWindow != this) {
-        nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
-        gPluginFocusWindow->LoseNonXEmbedPluginFocus();
-    }
+        // if plugins still keeps the focus, get it back
+        if (gPluginFocusWindow && gPluginFocusWindow != this) {
+            nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
+            gPluginFocusWindow->LoseNonXEmbedPluginFocus();
+        }
 #endif /* MOZ_WIDGET_GTK2 */
+    }
 #endif /* MOZ_X11 */
 
     WidgetMouseEvent event(true, NS_MOUSE_MOVE, this, WidgetMouseEvent::eReal);
 
     gdouble pressure = 0;
     gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure);
     // Sometime gdk generate 0 pressure value between normal values
     // We have to ignore that and use last valid value
@@ -3923,30 +3928,33 @@ nsWindow::SetWindowClass(const nsAString
   }
   res_name[0] = toupper(res_name[0]);
   if (!role) role = res_name;
 
   GdkWindow *shellWindow = gtk_widget_get_window(GTK_WIDGET(mShell));
   gdk_window_set_role(shellWindow, role);
 
 #ifdef MOZ_X11
-  XClassHint *class_hint = XAllocClassHint();
-  if (!class_hint) {
-    nsMemory::Free(res_name);
-    return NS_ERROR_OUT_OF_MEMORY;
+  GdkDisplay *display = gdk_display_get_default();
+  if (GDK_IS_X11_DISPLAY(display)) {
+      XClassHint *class_hint = XAllocClassHint();
+      if (!class_hint) {
+        nsMemory::Free(res_name);
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+      class_hint->res_name = res_name;
+      class_hint->res_class = const_cast<char*>(res_class);
+
+      // Can't use gtk_window_set_wmclass() for this; it prints
+      // a warning & refuses to make the change.
+      XSetClassHint(GDK_DISPLAY_XDISPLAY(display),
+                    gdk_x11_window_get_xid(shellWindow),
+                    class_hint);
+      XFree(class_hint);
   }
-  class_hint->res_name = res_name;
-  class_hint->res_class = const_cast<char*>(res_class);
-
-  // Can't use gtk_window_set_wmclass() for this; it prints
-  // a warning & refuses to make the change.
-  XSetClassHint(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
-                gdk_x11_window_get_xid(shellWindow),
-                class_hint);
-  XFree(class_hint);
 #endif /* MOZ_X11 */
 
   nsMemory::Free(res_name);
 
   return NS_OK;
 }
 
 void
@@ -5653,30 +5661,32 @@ key_press_event_cb(GtkWidget *widget, Gd
     // Keyboard repeat can cause key press events to queue up when there are
     // slow event handlers (bug 301029).  Throttle these events by removing
     // consecutive pending duplicate KeyPress events to the same window.
     // We use the event time of the last one.
     // Note: GDK calls XkbSetDetectableAutorepeat so that KeyRelease events
     // are generated only when the key is physically released.
 #define NS_GDKEVENT_MATCH_MASK 0x1FFF /* GDK_SHIFT_MASK .. GDK_BUTTON5_MASK */
     GdkDisplay* gdkDisplay = gtk_widget_get_display(widget);
-    Display* dpy = GDK_DISPLAY_XDISPLAY(gdkDisplay);
-    while (XPending(dpy)) {
-        XEvent next_event;
-        XPeekEvent(dpy, &next_event);
-        GdkWindow* nextGdkWindow =
-            gdk_x11_window_lookup_for_display(gdkDisplay, next_event.xany.window);
-        if (nextGdkWindow != event->window ||
-            next_event.type != KeyPress ||
-            next_event.xkey.keycode != event->hardware_keycode ||
-            next_event.xkey.state != (event->state & NS_GDKEVENT_MATCH_MASK)) {
-            break;
+    if (GDK_IS_X11_DISPLAY(gdkDisplay)) {
+        Display* dpy = GDK_DISPLAY_XDISPLAY(gdkDisplay);
+        while (XPending(dpy)) {
+            XEvent next_event;
+            XPeekEvent(dpy, &next_event);
+            GdkWindow* nextGdkWindow =
+                gdk_x11_window_lookup_for_display(gdkDisplay, next_event.xany.window);
+            if (nextGdkWindow != event->window ||
+                next_event.type != KeyPress ||
+                next_event.xkey.keycode != event->hardware_keycode ||
+                next_event.xkey.state != (event->state & NS_GDKEVENT_MATCH_MASK)) {
+                break;
+            }
+            XNextEvent(dpy, &next_event);
+            event->time = next_event.xkey.time;
         }
-        XNextEvent(dpy, &next_event);
-        event->time = next_event.xkey.time;
     }
 #endif
 
     return focusWindow->OnKeyPressEvent(event);
 }
 
 static gboolean
 key_release_event_cb(GtkWidget *widget, GdkEventKey *event)