Skip to content

Commit

Permalink
wayland: Implemented xdg-wm-base support.
Browse files Browse the repository at this point in the history
This is just in parity with the existing zxdg-shell-unstable-v6 code. Making
the Wayland target robust (and uh, with title bars) is going to take a lot
of work on top of this.
  • Loading branch information
icculus committed Jun 25, 2018
1 parent e8237e2 commit c8ac909
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 28 deletions.
37 changes: 29 additions & 8 deletions configure
Expand Up @@ -19228,6 +19228,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 xdg-shell-unstable-v6"
WAYLAND_PROTOCOLS_STABLE="xdg-shell"

SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
Expand Down Expand Up @@ -24712,21 +24713,21 @@ SDLTEST_SOURCES="$srcdir/src/test/*.c"
if test x$video_wayland = xyes; then
WAYLAND_CORE_PROTOCOL_SOURCE='$(gen)/wayland-protocol.c'
WAYLAND_CORE_PROTOCOL_HEADER='$(gen)/wayland-client-protocol.h'
WAYLAND_PROTOCOLS_UNSTABLE_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
WAYLAND_PROTOCOLS_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
sed 's,[^ ]\+,\\$(gen)/&-protocol.c,g'`
WAYLAND_PROTOCOLS_UNSTABLE_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
WAYLAND_PROTOCOLS_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
sed 's,[^ ]\+,\\$(gen)/&-client-protocol.h,g'`
GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_UNSTABLE_SOURCES"
GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_UNSTABLE_HEADERS"
GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_SOURCES"
GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_HEADERS"

WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS="
$WAYLAND_CORE_PROTOCOL_SOURCE: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) code \$< \$@"

WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS="
$WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) client-header \$< \$@"

WAYLAND_CORE_PROTOCOL_OBJECT="
Expand All @@ -24736,27 +24737,47 @@ $WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`

WAYLAND_PROTOCOLS_OBJECTS_STABLE=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([a-z\\-]\\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`

WAYLAND_PROTOCOLS_DEPENDS="
$WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS
$WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS
$WAYLAND_CORE_PROTOCOL_OBJECT
$WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS
$WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS
$WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS
$WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS
$WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE
$WAYLAND_PROTOCOLS_OBJECTS_STABLE
"
fi

Expand Down
37 changes: 29 additions & 8 deletions configure.in
Expand Up @@ -1417,6 +1417,7 @@ AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for
fi

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

SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
Expand Down Expand Up @@ -3979,21 +3980,21 @@ SDLTEST_SOURCES="$srcdir/src/test/*.c"
if test x$video_wayland = xyes; then
WAYLAND_CORE_PROTOCOL_SOURCE='$(gen)/wayland-protocol.c'
WAYLAND_CORE_PROTOCOL_HEADER='$(gen)/wayland-client-protocol.h'
WAYLAND_PROTOCOLS_UNSTABLE_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
WAYLAND_PROTOCOLS_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
sed 's,[[^ ]]\+,\\$(gen)/&-protocol.c,g'`
WAYLAND_PROTOCOLS_UNSTABLE_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
WAYLAND_PROTOCOLS_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
sed 's,[[^ ]]\+,\\$(gen)/&-client-protocol.h,g'`
GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_UNSTABLE_SOURCES"
GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_UNSTABLE_HEADERS"
GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_SOURCES"
GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_HEADERS"

WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS="
$WAYLAND_CORE_PROTOCOL_SOURCE: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) code \$< \$@"

WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS="
$WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) client-header \$< \$@"

WAYLAND_CORE_PROTOCOL_OBJECT="
Expand All @@ -4003,27 +4004,47 @@ $WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`

WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`

WAYLAND_PROTOCOLS_OBJECTS_STABLE=`for p in $WAYLAND_PROTOCOLS_STABLE;\
do echo ; echo \$p | sed\
"s,^\\([[a-z\\-]]\\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`

WAYLAND_PROTOCOLS_DEPENDS="
$WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS
$WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS
$WAYLAND_CORE_PROTOCOL_OBJECT
$WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS
$WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS
$WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS
$WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS
$WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE
$WAYLAND_PROTOCOLS_OBJECTS_STABLE
"
fi

Expand Down
9 changes: 7 additions & 2 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-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h"

#include <linux/input.h>
Expand Down Expand Up @@ -263,7 +264,9 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)

switch (rc) {
case SDL_HITTEST_DRAGGABLE:
if (input->display->shell.zxdg) {
if (input->display->shell.xdg) {
xdg_toplevel_move(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial);
} else 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);
Expand All @@ -278,7 +281,9 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
case SDL_HITTEST_RESIZE_BOTTOM:
case SDL_HITTEST_RESIZE_BOTTOMLEFT:
case SDL_HITTEST_RESIZE_LEFT:
if (input->display->shell.zxdg) {
if (input->display->shell.xdg) {
xdg_toplevel_resize(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
} else 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]);
Expand Down
18 changes: 18 additions & 0 deletions src/video/wayland/SDL_waylandvideo.c
Expand Up @@ -45,6 +45,7 @@
#include "SDL_waylanddyn.h"
#include <wayland-util.h>

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

#define WAYLANDVID_DRIVER_NAME "wayland"
Expand Down Expand Up @@ -327,6 +328,17 @@ static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
};


static void
handle_ping_xdg_wm_base(void *data, struct xdg_wm_base *xdg, uint32_t serial)
{
xdg_wm_base_pong(xdg, serial);
}

static const struct xdg_wm_base_listener shell_listener_xdg = {
handle_ping_xdg_wm_base
};


static void
display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
const char *interface, uint32_t version)
Expand All @@ -339,6 +351,9 @@ 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, "xdg_wm_base") == 0) {
d->shell.xdg = wl_registry_bind(d->registry, id, &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(d->shell.xdg, &shell_listener_xdg, NULL);
} 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);
Expand Down Expand Up @@ -475,6 +490,9 @@ Wayland_VideoQuit(_THIS)
if (data->shell.wl)
wl_shell_destroy(data->shell.wl);

if (data->shell.xdg)
xdg_wm_base_destroy(data->shell.xdg);

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

Expand Down
12 changes: 11 additions & 1 deletion src/video/wayland/SDL_waylandvideo.h
Expand Up @@ -24,6 +24,16 @@
#ifndef SDL_waylandvideo_h_
#define SDL_waylandvideo_h_


/*
!!! FIXME: xdg_wm_base is the stable replacement for zxdg_shell_v6. While it's
!!! FIXME: harmless to leave it here, consider deleting the obsolete codepath
!!! FIXME: soon, since Wayland (with xdg_wm_base) will probably be mainline
!!! FIXME: by the time people are relying on this SDL target. It's available
!!! FIXME: in Ubuntu 18.04 (and other distros).
*/


#include <EGL/egl.h>
#include "wayland-util.h"

Expand All @@ -44,7 +54,7 @@ typedef struct {
struct wl_cursor_theme *cursor_theme;
struct wl_pointer *pointer;
struct {
/* !!! FIXME: add stable xdg_shell from 1.12 */
struct xdg_wm_base *xdg;
struct zxdg_shell_v6 *zxdg;
struct wl_shell *wl;
} shell;
Expand Down

0 comments on commit c8ac909

Please sign in to comment.