Migrate from wl_input_device to wl_seat
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylandinputdevice.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 QWAYLANDINPUTDEVICE_H
43 #define QWAYLANDINPUTDEVICE_H
44
45 #include "qwaylandwindow.h"
46
47 #include <QSocketNotifier>
48 #include <QObject>
49 #include <qpa/qplatformintegration.h>
50 #include <qpa/qplatformscreen.h>
51 #include <QWindowSystemInterface>
52
53 #include <wayland-client.h>
54
55 #ifndef QT_NO_WAYLAND_XKB
56 struct xkb_context;
57 struct xkb_keymap;
58 struct xkb_state;
59 #endif
60
61 QT_BEGIN_NAMESPACE
62
63 class QWaylandWindow;
64 class QWaylandDisplay;
65
66 class QWaylandInputDevice {
67 public:
68     QWaylandInputDevice(QWaylandDisplay *display, uint32_t id);
69     ~QWaylandInputDevice();
70
71     uint32_t capabilities() const { return mCaps; }
72
73     struct wl_seat *wl_seat() const { return mSeat; }
74
75     void attach(QWaylandBuffer *buffer, int x, int y);
76     void handleWindowDestroyed(QWaylandWindow *window);
77
78     void setTransferDevice(struct wl_data_device *device);
79     struct wl_data_device *transferDevice() const;
80
81     void removeMouseButtonFromState(Qt::MouseButton button);
82
83 private:
84     QWaylandDisplay *mQDisplay;
85     struct wl_display *mDisplay;
86
87     struct wl_seat *mSeat;
88     uint32_t mCaps;
89
90     struct {
91         struct wl_pointer *pointer;
92         struct wl_keyboard *keyboard;
93         struct wl_touch *touch;
94     } mDeviceInterfaces;
95
96     struct wl_data_device *mTransferDevice;
97     QWaylandWindow *mPointerFocus;
98     QWaylandWindow *mKeyboardFocus;
99     QWaylandWindow *mTouchFocus;
100
101     Qt::MouseButtons mButtons;
102     QPointF mSurfacePos;
103     QPointF mGlobalPos;
104     Qt::KeyboardModifiers mModifiers;
105     uint32_t mTime;
106
107     static const struct wl_seat_listener seatListener;
108
109     static void seat_capabilities(void *data,
110                                   struct wl_seat *seat,
111                                   uint32_t caps);
112
113     static const struct wl_pointer_listener pointerListener;
114
115     static void pointer_enter(void *data,
116                               struct wl_pointer *pointer,
117                               uint32_t time, struct wl_surface *surface,
118                               wl_fixed_t sx, wl_fixed_t sy);
119     static void pointer_leave(void *data,
120                               struct wl_pointer *pointer,
121                               uint32_t time, struct wl_surface *surface);
122     static void pointer_motion(void *data,
123                                struct wl_pointer *pointer,
124                                uint32_t time,
125                                wl_fixed_t sx, wl_fixed_t sy);
126     static void pointer_button(void *data,
127                                struct wl_pointer *pointer,
128                                uint32_t serial, uint32_t time,
129                                uint32_t button, uint32_t state);
130     static void pointer_axis(void *data,
131                              struct wl_pointer *pointer,
132                              uint32_t time,
133                              uint32_t axis,
134                              int32_t value);
135
136     static const struct wl_keyboard_listener keyboardListener;
137
138     static void keyboard_enter(void *data,
139                                struct wl_keyboard *keyboard,
140                                uint32_t time,
141                                struct wl_surface *surface,
142                                struct wl_array *keys);
143     static void keyboard_leave(void *data,
144                                struct wl_keyboard *keyboard,
145                                uint32_t time,
146                                struct wl_surface *surface);
147     static void keyboard_key(void *data,
148                              struct wl_keyboard *keyboard,
149                              uint32_t serial, uint32_t time,
150                              uint32_t key, uint32_t state);
151
152     static const struct wl_touch_listener touchListener;
153
154     static void touch_down(void *data,
155                            struct wl_touch *touch,
156                            uint32_t serial,
157                            uint32_t time,
158                            struct wl_surface *surface,
159                            int32_t id,
160                            wl_fixed_t x,
161                            wl_fixed_t y);
162     static void touch_up(void *data,
163                          struct wl_touch *touch,
164                          uint32_t serial,
165                          uint32_t time,
166                          int32_t id);
167     static void touch_motion(void *data,
168                              struct wl_touch *touch,
169                              uint32_t time,
170                              int32_t id,
171                              wl_fixed_t x,
172                              wl_fixed_t y);
173     static void touch_frame(void *data,
174                             struct wl_touch *touch);
175     static void touch_cancel(void *data,
176                              struct wl_touch *touch);
177
178     void handleTouchPoint(int id, double x, double y, Qt::TouchPointState state);
179     void handleTouchFrame();
180     QList<QWindowSystemInterface::TouchPoint> mTouchPoints;
181     QList<QWindowSystemInterface::TouchPoint> mPrevTouchPoints;
182     QTouchDevice *mTouchDevice;
183
184 #ifndef QT_NO_WAYLAND_XKB
185     xkb_context *mXkbContext;
186     xkb_keymap *mXkbMap;
187     xkb_state *mXkbState;
188 #endif
189
190     friend class QWaylandTouchExtension;
191     friend class QWaylandQtKeyExtension;
192 };
193
194 QT_END_NAMESPACE
195
196 #endif