Bug 1417890 - Install nsClipboard hook at nsWindow init, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Mon, 18 Dec 2017 13:39:00 +0100
changeset 715679 e52aafd79f55bbeeeb178582dcab1cce22ca49a6
parent 715678 a27dbd80addba32035d5537269356d8a6e7a15af
child 744853 ec0765421517f33ef02995c80ef22966845dcfe8
push id94226
push userstransky@redhat.com
push dateThu, 04 Jan 2018 11:44:20 +0000
reviewersjhorak
bugs1417890
milestone59.0a1
Bug 1417890 - Install nsClipboard hook at nsWindow init, r?jhorak MozReview-Commit-ID: GA3USkXtEhe
widget/gtk/nsWindow.cpp
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -123,16 +123,19 @@ using namespace mozilla::widget;
 
 #ifdef MOZ_X11
 #include "X11CompositorWidget.h"
 #include "gfxXlibSurface.h"
 #include "WindowSurfaceX11Image.h"
 #include "WindowSurfaceX11SHM.h"
 #include "WindowSurfaceXRender.h"
 #endif // MOZ_X11
+#ifdef MOZ_WAYLAND
+#include "nsIClipboard.h"
+#endif
 
 #include "nsShmImage.h"
 
 #include "nsIDOMWheelEvent.h"
 
 #include "NativeKeyBindings.h"
 
 #include <dlfcn.h>
@@ -452,21 +455,33 @@ nsWindow::nsWindow()
 #ifdef MOZ_X11
     mOldFocusWindow      = 0;
 
     mXDisplay = nullptr;
     mXWindow  = X11None;
     mXVisual  = nullptr;
     mXDepth   = 0;
 #endif /* MOZ_X11 */
+
     if (!gGlobalsInitialized) {
         gGlobalsInitialized = true;
 
         // It's OK if either of these fail, but it may not be one day.
         initialize_prefs();
+
+#ifdef MOZ_WAYLAND
+        // Wayland provides clipboard data to application on focus-in event
+        // so we need to init our clipboard hooks before we create window
+        // and get focus.
+        if (!mIsX11Display) {
+            nsCOMPtr<nsIClipboard> clipboard =
+                do_GetService("@mozilla.org/widget/clipboard;1");
+            NS_ASSERTION(clipboard, "Failed to init clipboard!");
+        }
+#endif
     }
 
     mLastMotionPressure = 0;
 
 #ifdef ACCESSIBILITY
     mRootAccessible  = nullptr;
 #endif