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 "qwaylandextendedsurface.h"
44 #include "qwaylandwindow.h"
46 #include "wayland-client.h"
47 #include "wayland-surface-extension-client-protocol.h"
49 #include "qwaylanddisplay.h"
51 #include "qwaylandnativeinterface.h"
53 #include <QtGui/QGuiApplication>
54 #include <qpa/qplatformnativeinterface.h>
55 #include <QtGui/QWindowSystemInterface>
57 QWaylandSurfaceExtension::QWaylandSurfaceExtension(QWaylandDisplay *display, uint32_t id)
59 m_surface_extension = static_cast<struct wl_surface_extension *>(
60 wl_display_bind(display->wl_display(),id, &wl_surface_extension_interface));
63 QWaylandExtendedSurface *QWaylandSurfaceExtension::getExtendedWindow(QWaylandWindow *window)
65 struct wl_surface *surface = window->wl_surface();
67 struct wl_extended_surface *extended_surface =
68 wl_surface_extension_get_extended_surface(m_surface_extension,surface);
70 return new QWaylandExtendedSurface(window,extended_surface);
74 QWaylandExtendedSurface::QWaylandExtendedSurface(QWaylandWindow *window, struct wl_extended_surface *extended_surface)
76 , m_extended_surface(extended_surface)
79 wl_extended_surface_add_listener(m_extended_surface,&QWaylandExtendedSurface::extended_surface_listener,this);
82 void QWaylandExtendedSurface::updateGenericProperty(const QString &name, const QVariant &value)
86 QDataStream ds(&byteValue, QIODevice::WriteOnly);
90 data.size = byteValue.size();
91 data.data = (void*)byteValue.constData();
94 wl_extended_surface_update_generic_property(m_extended_surface,qPrintable(name),&data);
96 m_properties.insert(name,value);
97 QWaylandNativeInterface *nativeInterface = static_cast<QWaylandNativeInterface *>(
98 QGuiApplication::platformNativeInterface());
99 nativeInterface->emitWindowPropertyChanged(m_window,name);
102 static int32_t waylandRotationFromScreenOrientation(Qt::ScreenOrientation orientation)
104 switch (orientation) {
105 case Qt::PortraitOrientation: return WL_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
106 case Qt::InvertedPortraitOrientation: return WL_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
107 case Qt::LandscapeOrientation: return WL_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
108 case Qt::InvertedLandscapeOrientation: return WL_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
109 default: return WL_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
113 void QWaylandExtendedSurface::setWindowOrientation(Qt::ScreenOrientation orientation)
115 wl_extended_surface_set_window_orientation(m_extended_surface, waylandRotationFromScreenOrientation(orientation));
118 void QWaylandExtendedSurface::setContentOrientation(Qt::ScreenOrientation orientation)
120 wl_extended_surface_set_content_orientation(m_extended_surface, waylandRotationFromScreenOrientation(orientation));
123 QVariantMap QWaylandExtendedSurface::properties() const
128 QVariant QWaylandExtendedSurface::property(const QString &name)
130 return m_properties.value(name);
133 QVariant QWaylandExtendedSurface::property(const QString &name, const QVariant &defaultValue)
135 return m_properties.value(name,defaultValue);
138 void QWaylandExtendedSurface::onscreen_visibility(void *data, wl_extended_surface *wl_extended_surface, int32_t visible)
140 QWaylandExtendedSurface *extendedWindow = static_cast<QWaylandExtendedSurface *>(data);
141 Q_UNUSED(extendedWindow);
142 Q_UNUSED(wl_extended_surface);
144 // Do not send events when the state is not changing...
145 if (visible == extendedWindow->m_window->isExposed())
148 extendedWindow->m_exposed = visible;
149 QWaylandWindow *w = extendedWindow->m_window;
150 QWindowSystemInterface::handleSynchronousExposeEvent(w->window(),
152 ? QRegion(w->geometry())
156 void QWaylandExtendedSurface::set_generic_property(void *data, wl_extended_surface *wl_extended_surface, const char *name, wl_array *value)
158 Q_UNUSED(wl_extended_surface);
160 QWaylandExtendedSurface *extended_window = static_cast<QWaylandExtendedSurface *>(data);
162 QVariant variantValue;
163 QByteArray baValue = QByteArray((const char*)value->data, value->size);
164 QDataStream ds(&baValue, QIODevice::ReadOnly);
167 QString qstring_name = QString::fromLatin1(name);
168 extended_window->m_properties.insert(qstring_name,variantValue);
170 QWaylandNativeInterface *nativeInterface = static_cast<QWaylandNativeInterface *>(
171 QGuiApplication::platformNativeInterface());
172 nativeInterface->emitWindowPropertyChanged(extended_window->m_window,QString::fromLatin1(name));
175 Qt::WindowFlags QWaylandExtendedSurface::setWindowFlags(Qt::WindowFlags flags)
178 if (flags & Qt::WindowStaysOnTopHint) wlFlags |= WL_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP;
179 if (flags & Qt::WindowOverridesSystemGestures) wlFlags |= WL_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES;
181 wl_extended_surface_set_window_flags(m_extended_surface, wlFlags);
184 Qt::WindowStaysOnTopHint
185 | Qt::WindowOverridesSystemGestures
189 const struct wl_extended_surface_listener QWaylandExtendedSurface::extended_surface_listener = {
190 QWaylandExtendedSurface::onscreen_visibility,
191 QWaylandExtendedSurface::set_generic_property