Qt 4.8
qwaylandwindow.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the config.tests of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwaylandwindow.h"
43 
44 #include "qwaylandbuffer.h"
45 #include "qwaylanddisplay.h"
46 #include "qwaylandinputdevice.h"
47 #include "qwaylandscreen.h"
48 
49 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
51 #endif
52 
53 #include <QCoreApplication>
54 #include <QtGui/QWidget>
55 #include <QtGui/QWindowSystemInterface>
56 
57 #include <QDebug>
58 
60  : QPlatformWindow(window)
61  , mSurface(0)
62  , mDisplay(QWaylandScreen::waylandScreenFromWidget(window)->display())
63  , mBuffer(0)
64  , mWaitingForFrameSync(false)
65 {
66  static WId id = 1;
67  mWindowId = id++;
68 
69 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
70  mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid());
71  mDisplay->windowManagerIntegration()->authenticateWithToken();
72 #endif
73 }
74 
76 {
77  if (mSurface)
78  wl_surface_destroy(mSurface);
79 
81  for (int i = 0; i < inputDevices.size(); ++i)
82  inputDevices.at(i)->handleWindowDestroyed(this);
83 }
84 
86 {
87  return mWindowId;
88 }
89 
91 {
92  Q_UNUSED(parent);
93  qWarning("Sub window is not supported");
94 }
95 
96 void QWaylandWindow::setVisible(bool visible)
97 {
98  if (!mSurface && visible) {
101  }
102 
103  if (!visible) {
104  wl_surface_destroy(mSurface);
105  mSurface = NULL;
106  }
107 }
108 
109 void QWaylandWindow::configure(uint32_t time, uint32_t edges,
110  int32_t x, int32_t y,
111  int32_t width, int32_t height)
112 {
113  Q_UNUSED(time);
114  Q_UNUSED(edges);
115  QRect geometry = QRect(x, y, width, height);
116 
117  setGeometry(geometry);
118 
120 }
121 
123 {
124  mBuffer = buffer;
125  if (mSurface) {
126  wl_surface_attach(mSurface, buffer->buffer(),0,0);
127  }
128 }
129 
130 void QWaylandWindow::damage(const QRect &rect)
131 {
132  //We have to do sync stuff before calling damage, or we might
133  //get a frame callback before we get the timestamp
134  if (!mWaitingForFrameSync) {
136  mWaitingForFrameSync = true;
137  }
138 
139  wl_surface_damage(mSurface,
140  rect.x(), rect.y(), rect.width(), rect.height());
141 }
142 
144 {
145  if (mBuffer) {
146  wl_surface_attach(mSurface,mBuffer->buffer(),0,0);
147  wl_surface_damage(mSurface,
148  0,0,mBuffer->size().width(),mBuffer->size().height());
149  }
150 }
151 
152 void QWaylandWindow::frameCallback(struct wl_surface *surface, void *data, uint32_t time)
153 {
154  Q_UNUSED(time);
155  Q_UNUSED(surface);
156  QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
157  self->mWaitingForFrameSync = false;
158 }
159 
161 {
163  while (mWaitingForFrameSync)
165 }
unsigned long WId
Definition: qwindowdefs.h:119
void configure(uint32_t time, uint32_t edges, int32_t x, int32_t y, int32_t width, int32_t height)
struct wl_surface * wl_surface() const
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
virtual QRect geometry() const
Returnes the current geometry of a window.
struct wl_surface * mSurface
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QPlatformWindow class provides an abstraction for top-level windows.
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void frameCallback(wl_display_frame_func_t func, struct wl_surface *surface, void *data)
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
struct wl_surface * createSurface(void *handle)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
void setParent(const QPlatformWindow *parent)
This function is called to enable native child widgets in QPA.
void attach(QWaylandBuffer *buffer)
QWaylandWindow(QWidget *window)
WId winId() const
Reimplement in subclasses to return a handle to the native window.
bool mWaitingForFrameSync
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void setVisible(bool visible)
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false...
static void frameCallback(struct wl_surface *surface, void *data, uint32_t time)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
wl_buffer * buffer()
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static void handleGeometryChange(QWidget *w, const QRect &newRect)
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual QSize size() const =0
void handleWindowDestroyed(QWaylandWindow *window)
QWaylandDisplay * mDisplay
QWaylandBuffer * mBuffer
void damage(const QRect &rect)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QList< QWaylandInputDevice * > inputDevices() const
virtual void newSurfaceCreated()
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.