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)
63 , mDisplay(QWaylandScreen::waylandScreenFromWindow(window)->display())
65 , mWaitingForFrameSync(false)
70 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
71 mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid());
72 mDisplay->windowManagerIntegration()->authenticateWithToken();
76 QWaylandWindow::~QWaylandWindow()
79 wl_surface_destroy(mSurface);
81 QList<QWaylandInputDevice *> inputDevices = mDisplay->inputDevices();
82 for (int i = 0; i < inputDevices.size(); ++i)
83 inputDevices.at(i)->handleWindowDestroyed(this);
86 WId QWaylandWindow::winId() const
91 void QWaylandWindow::setParent(const QPlatformWindow *parent)
94 qWarning("Sub window is not supported");
97 void QWaylandWindow::setVisible(bool visible)
99 if (!mSurface && visible) {
100 mSurface = mDisplay->createSurface(this);
105 wl_surface_destroy(mSurface);
110 void QWaylandWindow::configure(uint32_t time, uint32_t edges,
111 int32_t x, int32_t y,
112 int32_t width, int32_t height)
117 QRect geometry = QRect(x, y, width, height);
118 setGeometry(geometry);
120 QWindowSystemInterface::handleGeometryChange(window(), geometry);
123 void QWaylandWindow::attach(QWaylandBuffer *buffer)
127 wl_surface_attach(mSurface, buffer->buffer(),0,0);
128 QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size()));
132 void QWaylandWindow::damage(const QRect &rect)
134 //We have to do sync stuff before calling damage, or we might
135 //get a frame callback before we get the timestamp
136 if (!mWaitingForFrameSync) {
137 mDisplay->frameCallback(QWaylandWindow::frameCallback, mSurface, this);
138 mWaitingForFrameSync = true;
141 wl_surface_damage(mSurface,
142 rect.x(), rect.y(), rect.width(), rect.height());
145 void QWaylandWindow::newSurfaceCreated()
148 wl_surface_attach(mSurface,mBuffer->buffer(),0,0);
149 // do not damage the surface here, as this leads to graphical corruptions in the compositor until
150 // the first frame has been rendered
154 void QWaylandWindow::frameCallback(struct wl_surface *surface, void *data, uint32_t time)
158 QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
159 self->mWaitingForFrameSync = false;
162 void QWaylandWindow::waitForFrameSync()
164 mDisplay->flushRequests();
165 while (mWaitingForFrameSync)
166 mDisplay->blockingReadEvents();