1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the Qt Compositor.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 ** the names of its contributors may be used to endorse or promote
22 ** products derived from this software without specific prior written
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
41 #include "waylandwindowmanagerintegration.h"
43 #include "wayland_wrapper/wldisplay.h"
44 #include "wayland_wrapper/wlcompositor.h"
46 #include "wayland-server.h"
47 #include "wayland-windowmanager-server-protocol.h"
49 WindowManagerServerIntegration::WindowManagerServerIntegration(QObject *parent)
54 WindowManagerServerIntegration::~WindowManagerServerIntegration()
56 qDeleteAll(m_managedClients);
59 void WindowManagerServerIntegration::initialize(Wayland::Display *waylandDisplay)
61 wl_display_add_global(waylandDisplay->handle(),&wl_windowmanager_interface,this,WindowManagerServerIntegration::bind_func);
64 void WindowManagerServerIntegration::removeClient(wl_client *client)
66 WaylandManagedClient *managedClient = m_managedClients.take(client);
70 WaylandManagedClient *WindowManagerServerIntegration::managedClient(wl_client *client) const
72 return m_managedClients.value(client, 0);
75 void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint32_t processId)
77 WaylandManagedClient *managedClient = m_managedClients.value(client);
79 managedClient = new WaylandManagedClient;
80 managedClient->m_processId = processId;
81 m_managedClients.insert(client, managedClient);
84 void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, const char *token)
86 Q_ASSERT(token != 0 && *token != 0);
88 WaylandManagedClient *managedClient = m_managedClients.value(client);
90 managedClient = new WaylandManagedClient;
91 managedClient->m_authenticationToken = QByteArray(token);
92 m_managedClients.insert(client, managedClient);
94 emit clientAuthenticated(client);
97 void WindowManagerServerIntegration::bind_func(struct wl_client *client, void *data,
98 uint32_t version, uint32_t id)
101 WindowManagerServerIntegration *win_mgr = static_cast<WindowManagerServerIntegration *>(data);
102 struct wl_resource *resource = wl_client_add_object(client,&wl_windowmanager_interface,&windowmanager_interface,id,data);
103 win_mgr->registerResource(resource);
107 void WindowManagerServerIntegration::map_client_to_process(struct wl_client *client,
108 struct wl_resource *window_mgr_resource,
111 WindowManagerServerIntegration *window_mgr = static_cast<WindowManagerServerIntegration *>(window_mgr_resource->data);
112 window_mgr->mapClientToProcess(client,process_id);
115 void WindowManagerServerIntegration::authenticate_with_token(struct wl_client *client,
116 struct wl_resource *window_mgr_resource,
117 const char *wl_authentication_token)
119 WindowManagerServerIntegration *window_mgr = static_cast<WindowManagerServerIntegration *>(window_mgr_resource->data);
120 window_mgr->authenticateWithToken(client,wl_authentication_token);
123 const struct wl_windowmanager_interface WindowManagerServerIntegration::windowmanager_interface = {
124 WindowManagerServerIntegration::map_client_to_process,
125 WindowManagerServerIntegration::authenticate_with_token,
130 /// / WaylandManagedClient
133 WaylandManagedClient::WaylandManagedClient()
138 qint64 WaylandManagedClient::processId() const
143 QByteArray WaylandManagedClient::authenticationToken() const
145 return m_authenticationToken;