1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the config.tests of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qwaylandwindow.h"
44 #include "qwaylandbuffer.h"
45 #include "qwaylanddisplay.h"
46 #include "qwaylandinputdevice.h"
47 #include "qwaylandscreen.h"
49 #include <QtGui/QWindow>
51 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
52 #include "windowmanager_integration/qwaylandwindowmanagerintegration.h"
55 #include <QCoreApplication>
56 #include <QtGui/QWindowSystemInterface>
60 QWaylandWindow::QWaylandWindow(QWindow *window)
61 : QPlatformWindow(window)
62 , mDisplay(QWaylandScreen::waylandScreenFromWindow(window)->display())
64 , mWaitingForFrameSync(false)
69 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
70 mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid());
71 mDisplay->windowManagerIntegration()->authenticateWithToken();
74 mSurface = mDisplay->createSurface(this);
77 QWaylandWindow::~QWaylandWindow()
80 wl_surface_destroy(mSurface);
82 QList<QWaylandInputDevice *> inputDevices = mDisplay->inputDevices();
83 for (int i = 0; i < inputDevices.size(); ++i)
84 inputDevices.at(i)->handleWindowDestroyed(this);
87 WId QWaylandWindow::winId() const
92 void QWaylandWindow::setParent(const QPlatformWindow *parent)
95 qWarning("Sub window is not supported");
98 void QWaylandWindow::setVisible(bool visible)
100 if (!mSurface && visible) {
101 mSurface = mDisplay->createSurface(this);
106 wl_surface_map_toplevel(mSurface);
107 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
109 wl_surface_destroy(mSurface);
114 void QWaylandWindow::configure(uint32_t time, uint32_t edges,
115 int32_t x, int32_t y,
116 int32_t width, int32_t height)
121 QRect geometry = QRect(x, y, width, height);
122 setGeometry(geometry);
124 QWindowSystemInterface::handleGeometryChange(window(), geometry);
127 void QWaylandWindow::attach(QWaylandBuffer *buffer)
131 wl_surface_attach(mSurface, buffer->buffer(),0,0);
135 void QWaylandWindow::damage(const QRegion ®ion)
137 //We have to do sync stuff before calling damage, or we might
138 //get a frame callback before we get the timestamp
139 mDisplay->frameCallback(QWaylandWindow::frameCallback, mSurface, this);
140 mWaitingForFrameSync = true;
142 QVector<QRect> rects = region.rects();
143 for (int i = 0; i < rects.size(); i++) {
144 const QRect rect = rects.at(i);
145 wl_buffer_damage(mBuffer->buffer(), rect.x(), rect.y(), rect.width(), rect.height());
146 wl_surface_damage(mSurface,
147 rect.x(), rect.y(), rect.width(), rect.height());
151 void QWaylandWindow::newSurfaceCreated()
154 wl_surface_attach(mSurface,mBuffer->buffer(),0,0);
158 void QWaylandWindow::frameCallback(struct wl_surface *surface, void *data, uint32_t time)
162 QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
163 self->mWaitingForFrameSync = false;
166 void QWaylandWindow::waitForFrameSync()
168 mDisplay->flushRequests();
169 while (mWaitingForFrameSync)
170 mDisplay->blockingReadEvents();