2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
22 /* Contributed by Thomas Perl <thomas.perl@jollamobile.com> */
24 #include "../../SDL_internal.h"
26 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
29 #include "SDL_waylandtouch.h"
30 #include "../../events/SDL_touch_c.h"
32 struct SDL_WaylandTouch {
33 struct qt_touch_extension *touch_extension;
39 * adapted from qtbase/src/corelib/global/qnamespace.h
41 enum QtWaylandTouchPointState {
42 QtWaylandTouchPointPressed = 0x01,
43 QtWaylandTouchPointMoved = 0x02,
45 Never sent by the server:
46 QtWaylandTouchPointStationary = 0x04,
48 QtWaylandTouchPointReleased = 0x08,
52 touch_handle_touch(void *data,
53 struct qt_touch_extension *qt_touch_extension,
67 struct wl_array *rawdata)
70 * Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent
71 * (src/compositor/wayland_wrapper/qwltouch.cpp)
74 float FIXED_TO_FLOAT = 1. / 10000.;
75 float xf = FIXED_TO_FLOAT * x;
76 float yf = FIXED_TO_FLOAT * y;
78 float PRESSURE_TO_FLOAT = 1. / 255.;
79 float pressuref = PRESSURE_TO_FLOAT * pressure;
81 uint32_t touchState = state & 0xFFFF;
83 Other fields that are sent by the server (qwltouch.cpp),
84 but not used at the moment can be decoded in this way:
86 uint32_t sentPointCount = state >> 16;
87 uint32_t touchFlags = flags & 0xFFFF;
88 uint32_t capabilities = flags >> 16;
91 SDL_TouchID deviceId = 1;
92 if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
93 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
97 case QtWaylandTouchPointPressed:
98 case QtWaylandTouchPointReleased:
99 SDL_SendTouch(deviceId, (SDL_FingerID)id,
100 (touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE,
103 case QtWaylandTouchPointMoved:
104 SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref);
107 /* Should not happen */
113 touch_handle_configure(void *data,
114 struct qt_touch_extension *qt_touch_extension,
120 /* wayland-qt-touch-extension.c BEGINS */
122 static const struct qt_touch_extension_listener touch_listener = {
124 touch_handle_configure,
127 static const struct wl_interface *qt_touch_extension_types[] = {
144 static const struct wl_message qt_touch_extension_requests[] = {
145 { "dummy", "", qt_touch_extension_types + 0 },
148 static const struct wl_message qt_touch_extension_events[] = {
149 { "touch", "uuuiiiiiiuiiua", qt_touch_extension_types + 0 },
150 { "configure", "u", qt_touch_extension_types + 0 },
153 WL_EXPORT const struct wl_interface qt_touch_extension_interface = {
154 "qt_touch_extension", 1,
155 1, qt_touch_extension_requests,
156 2, qt_touch_extension_events,
159 /* wayland-qt-touch-extension.c ENDS */
161 /* wayland-qt-windowmanager.c BEGINS */
162 static const struct wl_interface *qt_windowmanager_types[] = {
167 static const struct wl_message qt_windowmanager_requests[] = {
168 { "open_url", "us", qt_windowmanager_types + 0 },
171 static const struct wl_message qt_windowmanager_events[] = {
172 { "hints", "i", qt_windowmanager_types + 0 },
173 { "quit", "", qt_windowmanager_types + 0 },
176 WL_EXPORT const struct wl_interface qt_windowmanager_interface = {
177 "qt_windowmanager", 1,
178 1, qt_windowmanager_requests,
179 2, qt_windowmanager_events,
181 /* wayland-qt-windowmanager.c ENDS */
183 /* wayland-qt-surface-extension.c BEGINS */
184 extern const struct wl_interface qt_extended_surface_interface;
185 #ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
186 extern const struct wl_interface wl_surface_interface;
189 static const struct wl_interface *qt_surface_extension_types[] = {
192 &qt_extended_surface_interface,
193 #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
194 /* FIXME: Set this dynamically to (*WAYLAND_wl_surface_interface) ?
195 * The value comes from auto generated code and does
196 * not appear to actually be used anywhere
200 &wl_surface_interface,
204 static const struct wl_message qt_surface_extension_requests[] = {
205 { "get_extended_surface", "no", qt_surface_extension_types + 2 },
208 WL_EXPORT const struct wl_interface qt_surface_extension_interface = {
209 "qt_surface_extension", 1,
210 1, qt_surface_extension_requests,
214 static const struct wl_message qt_extended_surface_requests[] = {
215 { "update_generic_property", "sa", qt_surface_extension_types + 0 },
216 { "set_content_orientation", "i", qt_surface_extension_types + 0 },
217 { "set_window_flags", "i", qt_surface_extension_types + 0 },
220 static const struct wl_message qt_extended_surface_events[] = {
221 { "onscreen_visibility", "i", qt_surface_extension_types + 0 },
222 { "set_generic_property", "sa", qt_surface_extension_types + 0 },
223 { "close", "", qt_surface_extension_types + 0 },
226 WL_EXPORT const struct wl_interface qt_extended_surface_interface = {
227 "qt_extended_surface", 1,
228 3, qt_extended_surface_requests,
229 3, qt_extended_surface_events,
232 /* wayland-qt-surface-extension.c ENDS */
235 Wayland_touch_create(SDL_VideoData *data, uint32_t id)
237 struct SDL_WaylandTouch *touch;
240 Wayland_touch_destroy(data);
243 /* !!! FIXME: check for failure, call SDL_OutOfMemory() */
244 data->touch = SDL_malloc(sizeof(struct SDL_WaylandTouch));
247 touch->touch_extension = wl_registry_bind(data->registry, id, &qt_touch_extension_interface, 1);
248 qt_touch_extension_add_listener(touch->touch_extension, &touch_listener, data);
252 Wayland_touch_destroy(SDL_VideoData *data)
255 struct SDL_WaylandTouch *touch = data->touch;
256 if (touch->touch_extension) {
257 qt_touch_extension_destroy(touch->touch_extension);
260 SDL_free(data->touch);
265 #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */