Skip to content

Commit

Permalink
wayland: Add support for xdg-shell protocol (unstable v6).
Browse files Browse the repository at this point in the history
This is meant to be the desktop-enhanced version of wl_shell. Right now we
just match what the existing wl_shell code does, but there are other areas of
functionality available to us now, that we can fill in later.

This uses the "unstable" API, since this is what ships in Ubuntu 17.10 (as
part of Wayland 1.10), but Wayland 1.12 promotes this to stable with extremely
minor changes. We will add support for the stable version when it makes sense
to do so.
  • Loading branch information
icculus committed Feb 7, 2018
1 parent 32d421d commit cd53220
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cmake/sdlchecks.cmake
Expand Up @@ -685,7 +685,7 @@ macro(CheckWayland)

WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")

foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1, xdg-shell-unstable-v6)
string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -19220,7 +19220,7 @@ $as_echo "#define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1" >>confdefs.h

fi

WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"

SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -1409,7 +1409,7 @@ AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for
AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH, 1, [ ])
fi

WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"

SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
Expand Down
22 changes: 19 additions & 3 deletions src/video/wayland/SDL_waylandevents.c
Expand Up @@ -40,6 +40,7 @@

#include "pointer-constraints-unstable-v1-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h"

#include <linux/input.h>
#include <sys/select.h>
Expand Down Expand Up @@ -248,15 +249,25 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
if (window->hit_test) {
const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
static const uint32_t directions[] = {

static const uint32_t directions_wl[] = {
WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
};

/* the names are different (ZXDG_TOPLEVEL_V6_RESIZE_EDGE_* vs
WL_SHELL_SURFACE_RESIZE_*), but the values are the same. */
const uint32_t *directions_zxdg = directions_wl;

switch (rc) {
case SDL_HITTEST_DRAGGABLE:
wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
if (input->display->shell.zxdg) {
zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial);
} else {
wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial);
}
return SDL_TRUE;

case SDL_HITTEST_RESIZE_TOPLEFT:
Expand All @@ -267,7 +278,11 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
case SDL_HITTEST_RESIZE_BOTTOM:
case SDL_HITTEST_RESIZE_BOTTOMLEFT:
case SDL_HITTEST_RESIZE_LEFT:
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
if (input->display->shell.zxdg) {
zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
} else {
wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
}
return SDL_TRUE;

default: return SDL_FALSE;
Expand Down Expand Up @@ -950,6 +965,7 @@ SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input)
return input->data_device;
}

/* !!! FIXME: just merge these into display_handle_global(). */
void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id)
{
d->relative_pointer_manager =
Expand Down
33 changes: 30 additions & 3 deletions src/video/wayland/SDL_waylandvideo.c
Expand Up @@ -45,6 +45,8 @@
#include "SDL_waylanddyn.h"
#include <wayland-util.h>

#include "xdg-shell-unstable-v6-client-protocol.h"

#define WAYLANDVID_DRIVER_NAME "wayland"

/* Initialization/Query functions */
Expand All @@ -64,6 +66,12 @@ Wayland_VideoQuit(_THIS);
static char *
get_classname()
{
/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec:
"The surface class identifies the general class of applications
to which the surface belongs. A common convention is to use the
file name (or the full path if it is a non-standard location) of
the application's .desktop file as the class." */

char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
char procfile[1024];
Expand Down Expand Up @@ -307,6 +315,18 @@ static const struct qt_windowmanager_listener windowmanager_listener = {
};
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */


static void
handle_ping_zxdg_shell(void *data, struct zxdg_shell_v6 *zxdg, uint32_t serial)
{
zxdg_shell_v6_pong(zxdg, serial);
}

static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
handle_ping_zxdg_shell
};


static void
display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
const char *interface, uint32_t version)
Expand All @@ -319,8 +339,11 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
Wayland_add_display(d, id);
} else if (strcmp(interface, "wl_seat") == 0) {
Wayland_display_add_input(d, id);
} else if (strcmp(interface, "zxdg_shell_v6") == 0) {
d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1);
zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL);
} else if (strcmp(interface, "wl_shell") == 0) {
d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
d->shell.wl = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
} else if (strcmp(interface, "wl_shm") == 0) {
d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
Expand All @@ -330,6 +353,7 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
Wayland_display_add_pointer_constraints(d, id);
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);

#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
} else if (strcmp(interface, "qt_touch_extension") == 0) {
Wayland_touch_create(d, id);
Expand Down Expand Up @@ -448,8 +472,11 @@ Wayland_VideoQuit(_THIS)
if (data->cursor_theme)
WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);

if (data->shell)
wl_shell_destroy(data->shell);
if (data->shell.wl)
wl_shell_destroy(data->shell.wl);

if (data->shell.zxdg)
zxdg_shell_v6_destroy(data->shell.zxdg);

if (data->compositor)
wl_compositor_destroy(data->compositor);
Expand Down
6 changes: 5 additions & 1 deletion src/video/wayland/SDL_waylandvideo.h
Expand Up @@ -43,7 +43,11 @@ typedef struct {
struct wl_shm *shm;
struct wl_cursor_theme *cursor_theme;
struct wl_pointer *pointer;
struct wl_shell *shell;
struct {
/* !!! FIXME: add stable xdg_shell from 1.12 */
struct zxdg_shell_v6 *zxdg;
struct wl_shell *wl;
} shell;
struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
struct zwp_pointer_constraints_v1 *pointer_constraints;
struct wl_data_device_manager *data_device_manager;
Expand Down

0 comments on commit cd53220

Please sign in to comment.