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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qwaylandwindow.h"
44 #include "qwaylandbuffer.h"
45 #include "qwaylanddisplay.h"
46 #include "qwaylandinputdevice.h"
47 #include "qwaylandscreen.h"
49 #include <QtGui/QWidget>
50 #include <QtGui/QWindowSystemInterface>
54 QWaylandWindow::QWaylandWindow(QWidget *window)
55 : QPlatformWindow(window)
56 , mDisplay(QWaylandScreen::waylandScreenFromWidget(window)->display())
58 , mWaitingForFrameSync(false)
63 mSurface = mDisplay->createSurface(this);
66 QWaylandWindow::~QWaylandWindow()
69 wl_surface_destroy(mSurface);
71 QList<QWaylandInputDevice *> inputDevices = mDisplay->inputDevices();
72 for (int i = 0; i < inputDevices.size(); ++i)
73 inputDevices.at(i)->handleWindowDestroyed(this);
76 WId QWaylandWindow::winId() const
81 void QWaylandWindow::setParent(const QPlatformWindow *parent)
84 qWarning("Sub window is not supported");
87 void QWaylandWindow::setVisible(bool visible)
89 if (!mSurface && visible) {
90 mSurface = mDisplay->createSurface(this);
95 wl_surface_map_toplevel(mSurface);
97 wl_surface_destroy(mSurface);
102 void QWaylandWindow::configure(uint32_t time, uint32_t edges,
103 int32_t x, int32_t y,
104 int32_t width, int32_t height)
108 QRect geometry = QRect(x, y, width, height);
110 setGeometry(geometry);
112 QWindowSystemInterface::handleGeometryChange(widget(), geometry);
115 void QWaylandWindow::attach(QWaylandBuffer *buffer)
119 wl_surface_attach(mSurface, buffer->buffer(),0,0);
124 void QWaylandWindow::damage(const QRegion ®ion)
126 //We have to do sync stuff before calling damage, or we might
127 //get a frame callback before we get the timestamp
128 mDisplay->frameCallback(QWaylandWindow::frameCallback, this);
129 mWaitingForFrameSync = true;
131 QVector<QRect> rects = region.rects();
132 for (int i = 0; i < rects.size(); i++) {
133 const QRect rect = rects.at(i);
134 wl_surface_damage(mSurface,
135 rect.x(), rect.y(), rect.width(), rect.height());
139 void QWaylandWindow::newSurfaceCreated()
142 wl_surface_attach(mSurface,mBuffer->buffer(),0,0);
146 void QWaylandWindow::frameCallback(void *data, uint32_t time)
149 QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
150 self->mWaitingForFrameSync = false;
153 void QWaylandWindow::waitForFrameSync()
155 mDisplay->flushRequests();
156 while (mWaitingForFrameSync)
157 mDisplay->readEvents();