Change copyrights from Nokia to Digia
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylanddisplay.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins 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 #ifndef QWAYLANDDISPLAY_H
43 #define QWAYLANDDISPLAY_H
44
45 #include <QtCore/QObject>
46 #include <QtCore/QRect>
47
48 #include <QtCore/QWaitCondition>
49
50 #include <wayland-client.h>
51
52 class QAbstractEventDispatcher;
53 class QWaylandInputDevice;
54 class QSocketNotifier;
55 class QWaylandBuffer;
56 class QPlatformScreen;
57 class QWaylandScreen;
58 class QWaylandGLIntegration;
59 class QWaylandWindowManagerIntegration;
60 class QWaylandDataDeviceManager;
61 class QWaylandShell;
62 class QWaylandSurfaceExtension;
63 class QWaylandSubSurfaceExtension;
64 class QWaylandOutputExtension;
65 class QWaylandTouchExtension;
66 class QWaylandQtKeyExtension;
67
68 class QWaylandDisplay : public QObject {
69     Q_OBJECT
70
71 public:
72     QWaylandDisplay(void);
73     ~QWaylandDisplay(void);
74
75     QList<QPlatformScreen *> screens() const { return mScreens; }
76
77     QWaylandScreen *screenForOutput(struct wl_output *output) const;
78
79     struct wl_surface *createSurface(void *handle);
80
81 #ifdef QT_WAYLAND_GL_SUPPORT
82     QWaylandGLIntegration *eglIntegration();
83 #endif
84
85 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
86     QWaylandWindowManagerIntegration *windowManagerIntegration();
87 #endif
88
89     void setCursor(wl_surface *surface, int32_t x, int32_t y);
90
91     struct wl_display *wl_display() const { return mDisplay; }
92     struct wl_compositor *wl_compositor() const { return mCompositor; }
93
94     QWaylandShell *shell() const { return mShell; }
95
96     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
97
98     QWaylandInputDevice *lastKeyboardFocusInputDevice() const;
99     void setLastKeyboardFocusInputDevice(QWaylandInputDevice *device);
100
101     QWaylandDataDeviceManager *dndSelectionHandler() const { return mDndSelectionHandler; }
102
103     QWaylandSurfaceExtension *windowExtension() const { return mWindowExtension; }
104     QWaylandSubSurfaceExtension *subSurfaceExtension() const { return mSubSurfaceExtension; }
105     QWaylandOutputExtension *outputExtension() const { return mOutputExtension; }
106     QWaylandTouchExtension *touchExtension() const { return mTouchExtension; }
107
108     struct wl_shm *shm() const { return mShm; }
109
110     static uint32_t currentTimeMillisec();
111
112     void forceRoundTrip();
113 public slots:
114     void createNewScreen(struct wl_output *output, QRect geometry);
115     void readEvents();
116     void blockingReadEvents();
117     void flushRequests();
118
119 private:
120     void waitForScreens();
121     void displayHandleGlobal(uint32_t id,
122                              const QByteArray &interface,
123                              uint32_t version);
124
125     struct wl_display *mDisplay;
126     struct wl_compositor *mCompositor;
127     struct wl_shm *mShm;
128     QWaylandShell *mShell;
129     QList<QPlatformScreen *> mScreens;
130     QList<QWaylandInputDevice *> mInputDevices;
131     QWaylandInputDevice *mLastKeyboardFocusInputDevice;
132     QWaylandDataDeviceManager *mDndSelectionHandler;
133     QWaylandSurfaceExtension *mWindowExtension;
134     QWaylandSubSurfaceExtension *mSubSurfaceExtension;
135     QWaylandOutputExtension *mOutputExtension;
136     QWaylandTouchExtension *mTouchExtension;
137     QWaylandQtKeyExtension *mQtKeyExtension;
138
139     QSocketNotifier *mReadNotifier;
140     int mFd;
141     int mWritableNotificationFd;
142     bool mScreensInitialized;
143
144     static const struct wl_output_listener outputListener;
145     static void displayHandleGlobal(struct wl_display *display,
146                                     uint32_t id,
147                                     const char *interface,
148                                     uint32_t version, void *data);
149     static void outputHandleGeometry(void *data,
150                                      struct wl_output *output,
151                                      int32_t x, int32_t y,
152                                      int32_t width, int32_t height,
153                                      int subpixel,
154                                      const char *make,
155                                      const char *model,
156                                      int32_t transform);
157     static void mode(void *data,
158                      struct wl_output *wl_output,
159                      uint32_t flags,
160                      int width,
161                      int height,
162                      int refresh);
163
164 #ifdef QT_WAYLAND_GL_SUPPORT
165     QWaylandGLIntegration *mEglIntegration;
166 #endif
167
168 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
169     QWaylandWindowManagerIntegration *mWindowManagerIntegration;
170 #endif
171
172     static void shellHandleConfigure(void *data, struct wl_shell *shell,
173                                      uint32_t time, uint32_t edges,
174                                      struct wl_surface *surface,
175                                      int32_t width, int32_t height);
176 };
177
178 #endif // QWAYLANDDISPLAY_H