1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
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 "compositor_api/waylandcompositor.h"
48 #include "wayland-server.h"
49 #include "wayland-windowmanager-server-protocol.h"
53 WindowManagerServerIntegration::WindowManagerServerIntegration(WaylandCompositor *compositor, QObject *parent)
55 , m_showIsFullScreen(false)
56 , m_compositor(compositor)
60 WindowManagerServerIntegration::~WindowManagerServerIntegration()
62 qDeleteAll(m_managedClients);
65 void WindowManagerServerIntegration::initialize(Wayland::Display *waylandDisplay)
67 wl_display_add_global(waylandDisplay->handle(),&wl_windowmanager_interface,this,WindowManagerServerIntegration::bind_func);
70 void WindowManagerServerIntegration::removeClient(wl_client *client)
72 WaylandManagedClient *managedClient = m_managedClients.take(client);
76 WaylandManagedClient *WindowManagerServerIntegration::managedClient(wl_client *client) const
78 return m_managedClients.value(client, 0);
81 void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint32_t processId)
83 WaylandManagedClient *managedClient = m_managedClients.value(client);
85 managedClient = new WaylandManagedClient;
86 managedClient->m_processId = processId;
87 m_managedClients.insert(client, managedClient);
90 void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, const char *token)
92 Q_ASSERT(token != 0 && *token != 0);
94 WaylandManagedClient *managedClient = m_managedClients.value(client);
96 managedClient = new WaylandManagedClient;
97 managedClient->m_authenticationToken = QByteArray(token);
98 m_managedClients.insert(client, managedClient);
100 emit clientAuthenticated(client);
103 void WindowManagerServerIntegration::setShowIsFullScreen(bool value)
105 m_showIsFullScreen = value;
106 struct wl_resource *resource;
107 wl_list_for_each(resource,&client_resources, link) {
108 wl_windowmanager_send_hints(resource, int32_t(m_showIsFullScreen));
112 void WindowManagerServerIntegration::sendQuitMessage(wl_client *client)
114 struct wl_resource *resource;
115 wl_list_for_each(resource, &client_resources, link) {
116 if (resource->client == client) {
117 wl_windowmanager_send_quit(resource);
123 struct WindowManagerServerIntegrationClientData
126 WindowManagerServerIntegration *integration;
129 void WindowManagerServerIntegration::bind_func(struct wl_client *client, void *data,
130 uint32_t version, uint32_t id)
134 WindowManagerServerIntegrationClientData *clientData = new WindowManagerServerIntegrationClientData;
135 clientData->integration = static_cast<WindowManagerServerIntegration *>(data);
137 wl_resource *resource = wl_client_add_object(client,&wl_windowmanager_interface,&windowmanager_interface,id,clientData);
138 resource->destroy = WindowManagerServerIntegration::destroy_resource;
139 clientData->integration->registerResource(resource);
140 wl_windowmanager_send_hints(resource, int32_t(clientData->integration->m_showIsFullScreen));
143 void WindowManagerServerIntegration::destroy_resource(wl_resource *resource)
145 WindowManagerServerIntegrationClientData *data = static_cast<WindowManagerServerIntegrationClientData *>(resource->data);
146 WindowManagerServerIntegration *window_mgr = data->integration;
148 window_mgr->removeClient(resource->client);
154 void WindowManagerServerIntegration::map_client_to_process(struct wl_client *client,
155 struct wl_resource *window_mgr_resource,
158 WindowManagerServerIntegration *window_mgr = static_cast<WindowManagerServerIntegrationClientData *>(window_mgr_resource->data)->integration;
159 window_mgr->mapClientToProcess(client,process_id);
162 void WindowManagerServerIntegration::authenticate_with_token(struct wl_client *client,
163 struct wl_resource *window_mgr_resource,
164 const char *wl_authentication_token)
166 WindowManagerServerIntegration *window_mgr = static_cast<WindowManagerServerIntegrationClientData *>(window_mgr_resource->data)->integration;
167 window_mgr->authenticateWithToken(client,wl_authentication_token);
170 void WindowManagerServerIntegration::open_url(struct wl_client *client,
171 struct wl_resource *window_mgr_resource,
175 WindowManagerServerIntegrationClientData *data = static_cast<WindowManagerServerIntegrationClientData *>(window_mgr_resource->data);
176 WindowManagerServerIntegration *window_mgr = data->integration;
178 data->url.append(url);
181 window_mgr->m_compositor->openUrl(client, QUrl(QString::fromUtf8(data->url)));
182 data->url = QByteArray();
186 const struct wl_windowmanager_interface WindowManagerServerIntegration::windowmanager_interface = {
187 WindowManagerServerIntegration::map_client_to_process,
188 WindowManagerServerIntegration::authenticate_with_token,
189 WindowManagerServerIntegration::open_url
194 /// / WaylandManagedClient
197 WaylandManagedClient::WaylandManagedClient()
202 qint64 WaylandManagedClient::processId() const
207 QByteArray WaylandManagedClient::authenticationToken() const
209 return m_authenticationToken;