Skip to content

Commit c764e88

Browse files
committed
wayland: Update xkbcommon to avoid using deprecated modifier names
xkbcommon 1.10.0 declared certain modifier names to be deprecated, and the current plan is to remove them in 1.12.0. Use the new recommended names and modifier mask retrieval function when building against version 1.10.0 and higher.
1 parent b61586b commit c764e88

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

cmake/sdlchecks.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,18 @@ macro(CheckWayland)
594594
sdl_link_dependency(wayland LIBS PkgConfig::PC_WAYLAND PKG_CONFIG_PREFIX PC_WAYLAND PKG_CONFIG_SPECS ${WAYLAND_PKG_CONFIG_SPEC})
595595
endif()
596596

597+
# xkbcommon doesn't provide internal version defines, so generate them here.
598+
if (PC_WAYLAND_xkbcommon_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
599+
set(SDL_XKBCOMMON_VERSION_MAJOR ${CMAKE_MATCH_1})
600+
set(SDL_XKBCOMMON_VERSION_MINOR ${CMAKE_MATCH_2})
601+
set(SDL_XKBCOMMON_VERSION_PATCH ${CMAKE_MATCH_3})
602+
else()
603+
message(WARNING "Failed to parse xkbcommon version; defaulting to lowest supported (0.5.0)")
604+
set(SDL_XKBCOMMON_VERSION_MAJOR 0)
605+
set(SDL_XKBCOMMON_VERSION_MINOR 5)
606+
set(SDL_XKBCOMMON_VERSION_PATCH 0)
607+
endif()
608+
597609
if(SDL_WAYLAND_LIBDECOR)
598610
set(LibDecor_PKG_CONFIG_SPEC libdecor-0)
599611
pkg_check_modules(PC_LIBDECOR IMPORTED_TARGET ${LibDecor_PKG_CONFIG_SPEC})

include/build_config/SDL_build_config.h.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,11 @@
548548
#cmakedefine SDL_VIDEO_VITA_PVR 1
549549
#cmakedefine SDL_VIDEO_VITA_PVR_OGL 1
550550

551+
/* xkbcommon version info */
552+
#define SDL_XKBCOMMON_VERSION_MAJOR @SDL_XKBCOMMON_VERSION_MAJOR@
553+
#define SDL_XKBCOMMON_VERSION_MINOR @SDL_XKBCOMMON_VERSION_MINOR@
554+
#define SDL_XKBCOMMON_VERSION_PATCH @SDL_XKBCOMMON_VERSION_PATCH@
555+
551556
/* Libdecor version info */
552557
#define SDL_LIBDECOR_VERSION_MAJOR @SDL_LIBDECOR_VERSION_MAJOR@
553558
#define SDL_LIBDECOR_VERSION_MINOR @SDL_LIBDECOR_VERSION_MINOR@

src/video/wayland/SDL_waylanddyn.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ enum libdecor_window_state;
5959
(WAYLAND_VERSION_MAJOR == x && WAYLAND_VERSION_MINOR > y) || \
6060
(WAYLAND_VERSION_MAJOR == x && WAYLAND_VERSION_MINOR == y && WAYLAND_VERSION_MICRO >= z))
6161

62+
#define SDL_XKBCOMMON_CHECK_VERSION(x, y, z) \
63+
(SDL_XKBCOMMON_VERSION_MAJOR > x || \
64+
(SDL_XKBCOMMON_VERSION_MAJOR == x && SDL_XKBCOMMON_VERSION_MINOR > y) || \
65+
(SDL_XKBCOMMON_VERSION_MAJOR == x && SDL_XKBCOMMON_VERSION_MINOR == y && SDL_XKBCOMMON_VERSION_PATCH >= z))
66+
6267
#ifdef HAVE_LIBDECOR_H
6368
#define SDL_LIBDECOR_CHECK_VERSION(x, y, z) \
6469
(SDL_LIBDECOR_VERSION_MAJOR > x || \

src/video/wayland/SDL_waylandevents.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,16 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
14891489
return;
14901490
}
14911491

1492+
#if SDL_XKBCOMMON_CHECK_VERSION(1, 10, 0)
1493+
seat->keyboard.xkb.idx_shift = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_MOD_NAME_SHIFT);
1494+
seat->keyboard.xkb.idx_ctrl = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_MOD_NAME_CTRL);
1495+
seat->keyboard.xkb.idx_alt = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_VMOD_NAME_ALT);
1496+
seat->keyboard.xkb.idx_gui = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_VMOD_NAME_SUPER);
1497+
seat->keyboard.xkb.idx_mod5 = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_VMOD_NAME_LEVEL3);
1498+
seat->keyboard.xkb.idx_mod3 = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_VMOD_NAME_LEVEL5);
1499+
seat->keyboard.xkb.idx_num = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_VMOD_NAME_NUM);
1500+
seat->keyboard.xkb.idx_caps = WAYLAND_xkb_keymap_mod_get_mask(seat->keyboard.xkb.keymap, XKB_MOD_NAME_CAPS);
1501+
#else
14921502
#define GET_MOD_INDEX(mod) \
14931503
WAYLAND_xkb_keymap_mod_get_index(seat->keyboard.xkb.keymap, XKB_MOD_NAME_##mod)
14941504
seat->keyboard.xkb.idx_shift = 1 << GET_MOD_INDEX(SHIFT);
@@ -1500,6 +1510,7 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
15001510
seat->keyboard.xkb.idx_num = 1 << GET_MOD_INDEX(NUM);
15011511
seat->keyboard.xkb.idx_caps = 1 << GET_MOD_INDEX(CAPS);
15021512
#undef GET_MOD_INDEX
1513+
#endif
15031514

15041515
if (seat->keyboard.xkb.state != NULL) {
15051516
/* if there's already a state, throw it away rather than leaking it before

src/video/wayland/SDL_waylandsym.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ SDL_WAYLAND_SYM(uint32_t, xkb_keysym_to_utf32, (xkb_keysym_t) )
159159
SDL_WAYLAND_SYM(uint32_t, xkb_keymap_mod_get_index, (struct xkb_keymap *,
160160
const char *) )
161161
SDL_WAYLAND_SYM(const char *, xkb_keymap_layout_get_name, (struct xkb_keymap*, xkb_layout_index_t))
162+
#if SDL_XKBCOMMON_CHECK_VERSION(1, 10, 0)
163+
SDL_WAYLAND_SYM(xkb_mod_mask_t, xkb_keymap_mod_get_mask, (struct xkb_keymap*, const char*))
164+
#endif
162165

163166
#ifdef HAVE_LIBDECOR_H
164167
SDL_WAYLAND_MODULE(WAYLAND_LIBDECOR)

0 commit comments

Comments
 (0)