Handle really global selection offers in wayland clipboard.
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Fri, 10 Jun 2011 09:59:01 +0000 (11:59 +0200)
committerQt Continuous Integration System <qt-info@nokia.com>
Fri, 10 Jun 2011 12:27:32 +0000 (14:27 +0200)
Handle selection offer globals properly even if they arrive during the
initial blocking read. If such a global arrives so early, the platform
integration is not yet available from QApplicationPrivate (as it is
just being constructed). Therefore the handling of the selection
offer has to be delayed. At the moment selection offers are typically
posted as globals and not added to the global list, but that is likely
to change in the future.

Change-Id: Ib4ae804ad7f19e05978ee08828b88e028a3bf7b2
Reviewed-on: http://codereview.qt.nokia.com/446
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
src/plugins/platforms/wayland/qwaylanddisplay.cpp
src/plugins/platforms/wayland/qwaylanddisplay.h

index 83516e9..e6d3968 100644 (file)
@@ -129,6 +129,8 @@ const struct wl_shell_listener QWaylandDisplay::shellListener = {
 QWaylandDisplay::QWaylandDisplay(void)
     : argb_visual(0), premultiplied_argb_visual(0), rgb_visual(0)
 {
+    qRegisterMetaType<uint32_t>("uint32_t");
+
     mDisplay = wl_display_connect(NULL);
     if (mDisplay == NULL) {
         qErrnoWarning(errno, "Failed to create display");
@@ -147,8 +149,6 @@ QWaylandDisplay::QWaylandDisplay(void)
 
     blockingReadEvents();
 
-    qRegisterMetaType<uint32_t>("uint32_t");
-
 #ifdef QT_WAYLAND_GL_SUPPORT
     mEglIntegration->initialize();
 #endif
@@ -291,11 +291,24 @@ void QWaylandDisplay::displayHandleGlobal(uint32_t id,
         mInputDevices.append(inputDevice);
     } else if (interface == "wl_selection_offer") {
         QPlatformIntegration *plat = QApplicationPrivate::platformIntegration();
-        QWaylandClipboard *clipboard = static_cast<QWaylandClipboard *>(plat->clipboard());
-        clipboard->createSelectionOffer(id);
+        mSelectionOfferId = id;
+        if (plat)
+            handleSelectionOffer(id);
+        else
+            QMetaObject::invokeMethod(this, "handleSelectionOffer",
+                                      Qt::QueuedConnection, Q_ARG(uint32_t, id));
     }
 }
 
+void QWaylandDisplay::handleSelectionOffer(uint32_t id)
+{
+    if (mSelectionOfferId != id)
+        return;
+    QPlatformIntegration *plat = QApplicationPrivate::platformIntegration();
+    QWaylandClipboard *clipboard = static_cast<QWaylandClipboard *>(plat->clipboard());
+    clipboard->createSelectionOffer(id);
+}
+
 void QWaylandDisplay::handleVisual(void *data,
                                    struct wl_compositor *compositor,
                                    uint32_t id, uint32_t token)
index 765be62..ff8c760 100644 (file)
@@ -97,6 +97,9 @@ public slots:
     void blockingReadEvents();
     void flushRequests();
 
+private slots:
+    void handleSelectionOffer(uint32_t id);
+
 private:
     void waitForScreens();
     void displayHandleGlobal(uint32_t id,
@@ -115,6 +118,7 @@ private:
     bool mScreensInitialized;
 
     uint32_t mSocketMask;
+    uint32_t mSelectionOfferId;
 
     struct wl_visual *argb_visual, *premultiplied_argb_visual, *rgb_visual;