Add authentication token support for wayland windows
authorLasse Holmstedt <lasse.holmstedt@nokia.com>
Wed, 25 May 2011 09:24:37 +0000 (11:24 +0200)
committerQt Continuous Integration System <qt-info@nokia.com>
Wed, 25 May 2011 15:05:49 +0000 (17:05 +0200)
For compositors that support it, the wayland clients can associate themselves
with an auth token, specified by WL_AUTHENTICATION_TOKEN env var, or by
directly specifying it in the wayland client plugin.

Change-Id: I74a50a27c7c61c2b2cf1e09868618f36edc94cb1
Reviewed-by: Samuel Rødal
Reviewed-on: http://codereview.qt.nokia.com/116
Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
src/plugins/platforms/wayland/qwaylanddisplay.cpp
src/plugins/platforms/wayland/qwaylandwindow.cpp
src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanager-client-protocol.h
src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp
src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h
src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c

index 13ee87f..83516e9 100644 (file)
@@ -140,6 +140,11 @@ QWaylandDisplay::QWaylandDisplay(void)
 #ifdef QT_WAYLAND_GL_SUPPORT
     mEglIntegration = QWaylandGLIntegration::createGLIntegration(this);
 #endif
+
+#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
+    mWindowManagerIntegration = QWaylandWindowManagerIntegration::createIntegration(this);
+#endif
+
     blockingReadEvents();
 
     qRegisterMetaType<uint32_t>("uint32_t");
@@ -148,10 +153,6 @@ QWaylandDisplay::QWaylandDisplay(void)
     mEglIntegration->initialize();
 #endif
 
-#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
-    mWindowManagerIntegration = QWaylandWindowManagerIntegration::createIntegration(this);
-#endif
-
     connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(flushRequests()));
 
     mFd = wl_display_get_fd(mDisplay, sourceUpdate, this);
index 3169b36..333a953 100644 (file)
@@ -67,6 +67,7 @@ QWaylandWindow::QWaylandWindow(QWidget *window)
 
 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
         mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid());
+        mDisplay->windowManagerIntegration()->authenticateWithToken();
 #endif
 
     mSurface = mDisplay->createSurface(this);
index ec776c5..73673ae 100644 (file)
@@ -36,16 +36,37 @@ struct wl_client;
 
 struct wl_windowmanager;
 
+struct wl_proxy;
+
+extern void
+wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
+extern struct wl_proxy *
+wl_proxy_create(struct wl_proxy *factory,
+                const struct wl_interface *interface);
+extern struct wl_proxy *
+wl_proxy_create_for_id(struct wl_display *display,
+                       const struct wl_interface *interface, uint32_t id);
+extern void
+wl_proxy_destroy(struct wl_proxy *proxy);
+
+extern int
+wl_proxy_add_listener(struct wl_proxy *proxy,
+                      void (**implementation)(void), void *data);
+
+extern void
+wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
+
+extern void *
+wl_proxy_get_user_data(struct wl_proxy *proxy);
+
 extern const struct wl_interface wl_windowmanager_interface;
 
-#define WL_WINDOWMANAGER_MAP_CLIENT_TO_PROCESS 0
+#define wl_WINDOWMANAGER_MAP_CLIENT_TO_PROCESS 0
+#define wl_WINDOWMANAGER_AUTHENTICATE_WITH_TOKEN       1
 
 static inline struct wl_windowmanager *
-wl_windowmanager_create(struct wl_display *display, uint32_t id, uint32_t /*version*/)
+wl_windowmanager_create(struct wl_display *display, uint32_t id)
 {
-        // ### does not run without latest wayland. must be enabled later
-        //wl_display_bind(display, id, "wl_windowmanager", version);
-
         return (struct wl_windowmanager *)
                 wl_proxy_create_for_id(display, &wl_windowmanager_interface, id);
 }
@@ -72,7 +93,14 @@ static inline void
 wl_windowmanager_map_client_to_process(struct wl_windowmanager *wl_windowmanager, uint32_t processid)
 {
         wl_proxy_marshal((struct wl_proxy *) wl_windowmanager,
-                         WL_WINDOWMANAGER_MAP_CLIENT_TO_PROCESS, processid);
+                         wl_WINDOWMANAGER_MAP_CLIENT_TO_PROCESS, processid);
+}
+
+static inline void
+wl_windowmanager_authenticate_with_token(struct wl_windowmanager *wl_windowmanager, const char *wl_authentication_token)
+{
+        wl_proxy_marshal((struct wl_proxy *) wl_windowmanager,
+                         wl_WINDOWMANAGER_AUTHENTICATE_WITH_TOKEN, wl_authentication_token);
 }
 
 #ifdef  __cplusplus
index bf83423..4236f39 100644 (file)
@@ -68,12 +68,11 @@ struct wl_windowmanager *QWaylandWindowManagerIntegration::windowManager() const
     return mWaylandWindowManager;
 }
 
-void QWaylandWindowManagerIntegration::wlHandleListenerGlobal(wl_display *display, uint32_t id, const char *interface,
-                                                              uint32_t version, void *data)
+void QWaylandWindowManagerIntegration::wlHandleListenerGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data)
 {
     if (strcmp(interface, "wl_windowmanager") == 0) {
         QWaylandWindowManagerIntegration *integration = static_cast<QWaylandWindowManagerIntegration *>(data);
-        integration->mWaylandWindowManager = wl_windowmanager_create(display,id, version);
+        integration->mWaylandWindowManager = wl_windowmanager_create(display, id);
     }
 }
 
@@ -83,3 +82,11 @@ void QWaylandWindowManagerIntegration::mapClientToProcess(long long processId)
         wl_windowmanager_map_client_to_process(mWaylandWindowManager, (uint32_t) processId);
 }
 
+void QWaylandWindowManagerIntegration::authenticateWithToken(const QByteArray &token)
+{
+    QByteArray authToken = token;
+    if (authToken.isEmpty())
+        authToken = qgetenv("WL_AUTHENTICATION_TOKEN");
+    if (mWaylandWindowManager)
+        wl_windowmanager_authenticate_with_token(mWaylandWindowManager, authToken.constData());
+}
index 01b814f..0e3781d 100644 (file)
@@ -56,6 +56,7 @@ public:
 
     void mapSurfaceToProcess(struct wl_surface *surface, long long processId);
     void mapClientToProcess(long long processId);
+    void authenticateWithToken(const QByteArray &token = QByteArray());
 
 private:
     static void wlHandleListenerGlobal(wl_display *display, uint32_t id,
index 48049d8..0250801 100644 (file)
@@ -26,7 +26,8 @@
 #include "wayland-util.h"
 
 static const struct wl_message wl_windowmanager_requests[] = {
-        { "map_client_to_process", "u", NULL },
+        { "map_client_to_process", "u" },
+        { "authenticate_with_token", "s" },
 };
 
 WL_EXPORT const struct wl_interface wl_windowmanager_interface = {