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 plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qwaylandwindowmanagerintegration.h"
43 #include "wayland-windowmanager-client-protocol.h"
44 #include "qwaylandscreen.h"
45 #include "qwaylandwindow.h"
48 #include <QtCore/QEvent>
49 #include <QtCore/QHash>
50 #include <QtCore/QUrl>
51 #include <qpa/qplatformnativeinterface.h>
52 #include <qpa/qplatformwindow.h>
53 #include <QtGui/QtEvents>
54 #include <QtGui/QGuiApplication>
58 class QWaylandWindowManagerIntegrationPrivate {
60 QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay);
61 bool m_blockPropertyUpdates;
62 QWaylandDisplay *m_waylandDisplay;
63 struct wl_windowmanager *m_waylandWindowManager;
64 QHash<QWindow*, QVariantMap> m_queuedProperties;
65 bool m_showIsFullScreen;
68 QWaylandWindowManagerIntegrationPrivate::QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay)
69 : m_blockPropertyUpdates(false)
70 , m_waylandDisplay(waylandDisplay)
71 , m_waylandWindowManager(0)
72 , m_showIsFullScreen(false)
77 QWaylandWindowManagerIntegration *QWaylandWindowManagerIntegration::m_instance = 0;
79 QWaylandWindowManagerIntegration *QWaylandWindowManagerIntegration::createIntegration(QWaylandDisplay *waylandDisplay)
81 return new QWaylandWindowManagerIntegration(waylandDisplay);
84 QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay)
85 : d_ptr(new QWaylandWindowManagerIntegrationPrivate(waylandDisplay))
89 wl_display_add_global_listener(d_ptr->m_waylandDisplay->wl_display(),
90 QWaylandWindowManagerIntegration::wlHandleListenerGlobal,
94 QWaylandWindowManagerIntegration::~QWaylandWindowManagerIntegration()
99 QWaylandWindowManagerIntegration *QWaylandWindowManagerIntegration::instance()
104 struct wl_windowmanager *QWaylandWindowManagerIntegration::windowManager() const
106 Q_D(const QWaylandWindowManagerIntegration);
107 return d->m_waylandWindowManager;
110 bool QWaylandWindowManagerIntegration::showIsFullScreen() const
112 Q_D(const QWaylandWindowManagerIntegration);
113 return d->m_showIsFullScreen;
116 void QWaylandWindowManagerIntegration::wlHandleListenerGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data)
119 if (strcmp(interface, "wl_windowmanager") == 0) {
120 QWaylandWindowManagerIntegration *integration = static_cast<QWaylandWindowManagerIntegration *>(data);
121 integration->d_ptr->m_waylandWindowManager =
122 static_cast<struct wl_windowmanager *>(wl_display_bind(display, id, &wl_windowmanager_interface));
123 wl_windowmanager_add_listener(integration->d_ptr->m_waylandWindowManager, &windowmanager_listener, integration);
127 const struct wl_windowmanager_listener QWaylandWindowManagerIntegration::windowmanager_listener = {
128 QWaylandWindowManagerIntegration::handle_hints,
129 QWaylandWindowManagerIntegration::handle_quit
132 void QWaylandWindowManagerIntegration::handle_hints(void *data, wl_windowmanager *ext, int32_t showIsFullScreen)
135 QWaylandWindowManagerIntegration *self = static_cast<QWaylandWindowManagerIntegration *>(data);
136 self->d_func()->m_showIsFullScreen = showIsFullScreen;
139 void QWaylandWindowManagerIntegration::handle_quit(void *data, wl_windowmanager *ext)
143 QGuiApplication::quit();
146 void QWaylandWindowManagerIntegration::mapClientToProcess(long long processId)
148 Q_D(QWaylandWindowManagerIntegration);
149 if (d->m_waylandWindowManager)
150 wl_windowmanager_map_client_to_process(d->m_waylandWindowManager, (uint32_t) processId);
153 void QWaylandWindowManagerIntegration::authenticateWithToken(const QByteArray &token)
155 Q_D(QWaylandWindowManagerIntegration);
156 QByteArray authToken = token;
157 if (authToken.isEmpty())
158 authToken = qgetenv("WL_AUTHENTICATION_TOKEN");
160 if (d->m_waylandWindowManager && !authToken.isEmpty()) {
161 wl_windowmanager_authenticate_with_token(d->m_waylandWindowManager, authToken.constData());
165 void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url)
167 Q_D(QWaylandWindowManagerIntegration);
168 if (d->m_waylandWindowManager) {
169 QByteArray data = url.toString().toUtf8();
171 static const int chunkSize = 128;
172 while (!data.isEmpty()) {
173 QByteArray chunk = data.left(chunkSize);
174 data = data.mid(chunkSize);
175 wl_windowmanager_open_url(d->m_waylandWindowManager, !data.isEmpty(), chunk.constData());
180 bool QWaylandWindowManagerIntegration::openUrl(const QUrl &url)
186 bool QWaylandWindowManagerIntegration::openDocument(const QUrl &url)