Follow protocol changes in pointer attach
[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 setCursor(wl_surface *surface, 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     uint32_t mTime;
105
106     static const struct wl_seat_listener seatListener;
107
108     static void seat_capabilities(void *data,
109                                   struct wl_seat *seat,
110                                   uint32_t caps);
111
112     static const struct wl_pointer_listener pointerListener;
113
114     static void pointer_enter(void *data,
115                               struct wl_pointer *pointer,
116                               uint32_t time, struct wl_surface *surface,
117                               wl_fixed_t sx, wl_fixed_t sy);
118     static void pointer_leave(void *data,
119                               struct wl_pointer *pointer,
120                               uint32_t time, struct wl_surface *surface);
121     static void pointer_motion(void *data,
122                                struct wl_pointer *pointer,
123                                uint32_t time,
124                                wl_fixed_t sx, wl_fixed_t sy);
125     static void pointer_button(void *data,
126                                struct wl_pointer *pointer,
127                                uint32_t serial, uint32_t time,
128                                uint32_t button, uint32_t state);
129     static void pointer_axis(void *data,
130                              struct wl_pointer *pointer,
131                              uint32_t time,
132                              uint32_t axis,
133                              wl_fixed_t value);
134
135     static const struct wl_keyboard_listener keyboardListener;
136
137     static void keyboard_keymap(void *data,
138                                 struct wl_keyboard *keyboard,
139                                 uint32_t format,
140                                 int32_t fd,
141                                 uint32_t size);
142     static void keyboard_enter(void *data,
143                                struct wl_keyboard *keyboard,
144                                uint32_t time,
145                                struct wl_surface *surface,
146                                struct wl_array *keys);
147     static void keyboard_leave(void *data,
148                                struct wl_keyboard *keyboard,
149                                uint32_t time,
150                                struct wl_surface *surface);
151     static void keyboard_key(void *data,
152                              struct wl_keyboard *keyboard,
153                              uint32_t serial, uint32_t time,
154                              uint32_t key, uint32_t state);
155     static void keyboard_modifiers(void *data,
156                                    struct wl_keyboard *keyboard,
157                                    uint32_t serial,
158                                    uint32_t mods_depressed,
159                                    uint32_t mods_latched,
160                                    uint32_t mods_locked,
161                                    uint32_t group);
162
163     static const struct wl_touch_listener touchListener;
164
165     static void touch_down(void *data,
166                            struct wl_touch *touch,
167                            uint32_t serial,
168                            uint32_t time,
169                            struct wl_surface *surface,
170                            int32_t id,
171                            wl_fixed_t x,
172                            wl_fixed_t y);
173     static void touch_up(void *data,
174                          struct wl_touch *touch,
175                          uint32_t serial,
176                          uint32_t time,
177                          int32_t id);
178     static void touch_motion(void *data,
179                              struct wl_touch *touch,
180                              uint32_t time,
181                              int32_t id,
182                              wl_fixed_t x,
183                              wl_fixed_t y);
184     static void touch_frame(void *data,
185                             struct wl_touch *touch);
186     static void touch_cancel(void *data,
187                              struct wl_touch *touch);
188
189     void handleTouchPoint(int id, double x, double y, Qt::TouchPointState state);
190     void handleTouchFrame();
191     QList<QWindowSystemInterface::TouchPoint> mTouchPoints;
192     QList<QWindowSystemInterface::TouchPoint> mPrevTouchPoints;
193     QTouchDevice *mTouchDevice;
194
195 #ifndef QT_NO_WAYLAND_XKB
196     xkb_context *mXkbContext;
197     xkb_keymap *mXkbMap;
198     xkb_state *mXkbState;
199 #endif
200
201     friend class QWaylandTouchExtension;
202     friend class QWaylandQtKeyExtension;
203 };
204
205 QT_END_NAMESPACE
206
207 #endif