diff options
author | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2011-05-25 09:24:37 (GMT) |
---|---|---|
committer | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2011-05-25 12:24:16 (GMT) |
commit | dffe4d8d180e34955ebe23540e37ce7ba0d76853 (patch) | |
tree | b4be69feccf4bc9f016402bf8f307ecd7817c5db | |
parent | a6642e4659b3d45ffa94f9a3c6413124d49f2b91 (diff) | |
download | Qt-dffe4d8d180e34955ebe23540e37ce7ba0d76853.zip Qt-dffe4d8d180e34955ebe23540e37ce7ba0d76853.tar.gz Qt-dffe4d8d180e34955ebe23540e37ce7ba0d76853.tar.bz2 |
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.
Reviewed-by: Samuel Rødal
6 files changed, 53 insertions, 14 deletions
diff --git a/src/3rdparty/wayland/qwaylandwindowmanager-client-protocol.h b/src/3rdparty/wayland/qwaylandwindowmanager-client-protocol.h index ec776c5..73673ae 100644 --- a/src/3rdparty/wayland/qwaylandwindowmanager-client-protocol.h +++ b/src/3rdparty/wayland/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/3rdparty/wayland/wayland-windowmanager-protocol.c b/src/3rdparty/wayland/wayland-windowmanager-protocol.c index 48049d8..0250801 100644 --- a/src/3rdparty/wayland/wayland-windowmanager-protocol.c +++ b/src/3rdparty/wayland/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 = { diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index dcfaf0f..da908fb 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -137,6 +137,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"); @@ -145,10 +150,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 d2a7647..2bfc643 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/qwaylandwindowmanagerintegration.cpp b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp index b93e6d2..e4a6218 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<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()); +} diff --git a/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h b/src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h index 01a7bdd..a79f205 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, |