1c6c411874e7b8afdab9064817094bb98a0274f0
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylanddisplay.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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(QWaylandBuffer *buffer, 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     static void mode(void *data,
157                      struct wl_output *wl_output,
158                      uint32_t flags,
159                      int width,
160                      int height,
161                      int refresh);
162
163 #ifdef QT_WAYLAND_GL_SUPPORT
164     QWaylandGLIntegration *mEglIntegration;
165 #endif
166
167 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
168     QWaylandWindowManagerIntegration *mWindowManagerIntegration;
169 #endif
170
171     static void shellHandleConfigure(void *data, struct wl_shell *shell,
172                                      uint32_t time, uint32_t edges,
173                                      struct wl_surface *surface,
174                                      int32_t width, int32_t height);
175 };
176
177 #endif // QWAYLANDDISPLAY_H