Skip to content

Commit

Permalink
Implements touch support on QTWayland. Contributed by Thomas Perl.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabomdq committed Dec 27, 2013
1 parent 54a1f61 commit fce6257
Show file tree
Hide file tree
Showing 9 changed files with 733 additions and 1 deletion.
17 changes: 17 additions & 0 deletions configure
Expand Up @@ -818,6 +818,7 @@ enable_sndio_shared
enable_diskaudio
enable_dummyaudio
enable_video_wayland
enable_video_wayland_qt_touch
enable_video_x11
with_x
enable_x11_shared
Expand Down Expand Up @@ -1534,6 +1535,9 @@ Optional Features:
--enable-diskaudio support the disk writer audio driver [[default=yes]]
--enable-dummyaudio support the dummy audio driver [[default=yes]]
--enable-video-wayland use Wayland video driver [[default=yes]]
--enable-video-wayland-qt-touch
QtWayland server support for Wayland video driver
[[default=yes]]
--enable-video-x11 use X11 video driver [[default=yes]]
--enable-x11-shared dynamically load X11 support [[default=maybe]]
--enable-video-x11-xcursor
Expand Down Expand Up @@ -18645,6 +18649,14 @@ else
fi


# Check whether --enable-video-wayland-qt-touch was given.
if test "${enable_video_wayland_qt_touch+set}" = set; then :
enableval=$enable_video_wayland_qt_touch;
else
enable_video_wayland_qt_touch=yes
fi


if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
# Extract the first word of "pkg-config", so it can be a program name with args.
set dummy pkg-config; ac_word=$2
Expand Down Expand Up @@ -18704,6 +18716,11 @@ $as_echo "$video_wayland" >&6; }

$as_echo "#define SDL_VIDEO_DRIVER_WAYLAND 1" >>confdefs.h

if test x$enable_video_wayland_qt_touch = xyes; then

$as_echo "#define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1" >>confdefs.h

fi
SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS"
Expand Down
7 changes: 7 additions & 0 deletions configure.in
Expand Up @@ -1122,6 +1122,10 @@ CheckWayland()
AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes]]]),
,enable_video_wayland=yes)

AC_ARG_ENABLE(video-wayland-qt-touch,
AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for Wayland video driver [[default=yes]]]),
,enable_video_wayland_qt_touch=yes)

if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
AC_MSG_CHECKING(for Wayland support)
Expand All @@ -1137,6 +1141,9 @@ AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes

if test x$video_wayland = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND, 1, [ ])
if test x$enable_video_wayland_qt_touch = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH, 1, [ ])
fi
SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
dnl FIXME do dynamic loading code here.
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Expand Up @@ -261,6 +261,7 @@
#undef SDL_VIDEO_DRIVER_DUMMY
#undef SDL_VIDEO_DRIVER_WINDOWS
#undef SDL_VIDEO_DRIVER_WAYLAND
#undef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
#undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_RPI
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
Expand Down
253 changes: 253 additions & 0 deletions src/video/wayland/SDL_waylandtouch.c
@@ -0,0 +1,253 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/* Contributed by Thomas Perl <thomas.perl@jollamobile.com> */

#include "SDL_config.h"

#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH

#include "SDL_waylandtouch.h"
#include "SDL_log.h"
#include "../../events/SDL_touch_c.h"

struct SDL_WaylandTouch {
struct qt_touch_extension *touch_extension;
};


/**
* Qt TouchPointState
* adapted from qtbase/src/corelib/global/qnamespace.h
**/
enum QtWaylandTouchPointState {
QtWaylandTouchPointPressed = 0x01,
QtWaylandTouchPointMoved = 0x02,
/*
Never sent by the server:
QtWaylandTouchPointStationary = 0x04,
*/
QtWaylandTouchPointReleased = 0x08,
};

static void
touch_handle_touch(void *data,
struct qt_touch_extension *qt_touch_extension,
uint32_t time,
uint32_t id,
uint32_t state,
int32_t x,
int32_t y,
int32_t normalized_x,
int32_t normalized_y,
int32_t width,
int32_t height,
uint32_t pressure,
int32_t velocity_x,
int32_t velocity_y,
uint32_t flags,
struct wl_array *rawdata)
{
/**
* Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent
* (src/compositor/wayland_wrapper/qwltouch.cpp)
**/

float FIXED_TO_FLOAT = 1. / 10000.;
float xf = FIXED_TO_FLOAT * x;
float yf = FIXED_TO_FLOAT * y;

float PRESSURE_TO_FLOAT = 1. / 255.;
float pressuref = PRESSURE_TO_FLOAT * pressure;

uint32_t touchState = state & 0xFFFF;
/*
Other fields that are sent by the server (qwltouch.cpp),
but not used at the moment can be decoded in this way:
uint32_t sentPointCount = state >> 16;
uint32_t touchFlags = flags & 0xFFFF;
uint32_t capabilities = flags >> 16;
*/

SDL_TouchID deviceId = 0;
if (!SDL_GetTouch(deviceId)) {
if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
}
}

switch (touchState) {
case QtWaylandTouchPointPressed:
case QtWaylandTouchPointReleased:
SDL_SendTouch(deviceId, (SDL_FingerID)id,
(touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE,
xf, yf, pressuref);
break;
case QtWaylandTouchPointMoved:
SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref);
break;
default:
/* Should not happen */
break;
}
}

static void
touch_handle_configure(void *data,
struct qt_touch_extension *qt_touch_extension,
uint32_t flags)
{
}

/* wayland-qt-touch-extension.c BEGINS */

static const struct qt_touch_extension_listener touch_listener = {
touch_handle_touch,
touch_handle_configure,
};

static const struct wl_interface *qt_touch_extension_types[] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};

static const struct wl_message qt_touch_extension_requests[] = {
{ "dummy", "", qt_touch_extension_types + 0 },
};

static const struct wl_message qt_touch_extension_events[] = {
{ "touch", "uuuiiiiiiuiiua", qt_touch_extension_types + 0 },
{ "configure", "u", qt_touch_extension_types + 0 },
};

WL_EXPORT const struct wl_interface qt_touch_extension_interface = {
"qt_touch_extension", 1,
1, qt_touch_extension_requests,
2, qt_touch_extension_events,
};

/* wayland-qt-touch-extension.c ENDS */

/* wayland-qt-windowmanager.c BEGINS */
static const struct wl_interface *qt_windowmanager_types[] = {
NULL,
NULL,
};

static const struct wl_message qt_windowmanager_requests[] = {
{ "open_url", "us", qt_windowmanager_types + 0 },
};

static const struct wl_message qt_windowmanager_events[] = {
{ "hints", "i", qt_windowmanager_types + 0 },
{ "quit", "", qt_windowmanager_types + 0 },
};

WL_EXPORT const struct wl_interface qt_windowmanager_interface = {
"qt_windowmanager", 1,
1, qt_windowmanager_requests,
2, qt_windowmanager_events,
};
/* wayland-qt-windowmanager.c ENDS */

/* wayland-qt-surface-extension.c BEGINS */
extern const struct wl_interface qt_extended_surface_interface;
extern const struct wl_interface wl_surface_interface;

static const struct wl_interface *qt_surface_extension_types[] = {
NULL,
NULL,
&qt_extended_surface_interface,
&wl_surface_interface,
};

static const struct wl_message qt_surface_extension_requests[] = {
{ "get_extended_surface", "no", qt_surface_extension_types + 2 },
};

WL_EXPORT const struct wl_interface qt_surface_extension_interface = {
"qt_surface_extension", 1,
1, qt_surface_extension_requests,
0, NULL,
};

static const struct wl_message qt_extended_surface_requests[] = {
{ "update_generic_property", "sa", qt_surface_extension_types + 0 },
{ "set_content_orientation", "i", qt_surface_extension_types + 0 },
{ "set_window_flags", "i", qt_surface_extension_types + 0 },
};

static const struct wl_message qt_extended_surface_events[] = {
{ "onscreen_visibility", "i", qt_surface_extension_types + 0 },
{ "set_generic_property", "sa", qt_surface_extension_types + 0 },
{ "close", "", qt_surface_extension_types + 0 },
};

WL_EXPORT const struct wl_interface qt_extended_surface_interface = {
"qt_extended_surface", 1,
3, qt_extended_surface_requests,
3, qt_extended_surface_events,
};

/* wayland-qt-surface-extension.c ENDS */

void
Wayland_touch_create(SDL_VideoData *data, uint32_t id)
{
if (data->touch) {
Wayland_touch_destroy(data);
}

data->touch = malloc(sizeof(struct SDL_WaylandTouch));

struct SDL_WaylandTouch *touch = data->touch;
touch->touch_extension = wl_registry_bind(data->registry, id, &qt_touch_extension_interface, 1);
qt_touch_extension_add_listener(touch->touch_extension, &touch_listener, data);
}

void
Wayland_touch_destroy(SDL_VideoData *data)
{
if (data->touch) {
struct SDL_WaylandTouch *touch = data->touch;
if (touch->touch_extension) {
qt_touch_extension_destroy(touch->touch_extension);
}

free(data->touch);
data->touch = NULL;
}
}

#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */

0 comments on commit fce6257

Please sign in to comment.