From: Lasse Holmstedt Date: Wed, 25 May 2011 09:24:37 +0000 (+0200) Subject: Add authentication token support for wayland windows X-Git-Tag: qt-v5.0.0-alpha1~4264 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1909e038823f8dff9d18882b64e637b15234f837;p=profile%2Fivi%2Fqtbase.git Add authentication token support for wayland windows 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 --- diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 13ee87f..83516e9 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -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"); @@ -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); diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 3169b36..333a953 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -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); diff --git a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanager-client-protocol.h b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanager-client-protocol.h index ec776c5..73673ae 100644 --- a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanager-client-protocol.h +++ b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanager-client-protocol.h @@ -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 diff --git a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp index bf83423..4236f39 100644 --- a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp +++ b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp @@ -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(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()); +} diff --git a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h index 01b814f..0e3781d 100644 --- a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h +++ b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h @@ -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, diff --git a/src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c b/src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c index 48049d8..0250801 100644 --- a/src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c +++ b/src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c @@ -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 = {