From 6c79372bfbd3ef1881fbd9e2c44e6562610fffac Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Tue, 28 Nov 2023 11:43:25 +0200 Subject: [PATCH] x11: Make XKB support optional at build time Allow disabling the XKB support in the x11 platform plug-in at build time. For this, introduce a new "x11_keyboard" Meson build option that can be set to use xkb, xcb-keysyms, both, or none. Preprocessor guards are introduced where needed to skip the XKB code. --- meson_options.txt | 9 +++++++++ platform/x11/cog-platform-x11.c | 26 +++++++++++++++++++------- platform/x11/meson.build | 17 +++++++++++++---- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 8ae9660f..7d24c6f5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -52,6 +52,15 @@ option( description: 'Build content-protection support in the Wayland platform plug-in' ) +# X11 platform-specifig features +option( + 'x11_keyboard', + type: 'array', + value: ['xkb'], + choices: ['xkb', 'xcb-keysyms'], + description: 'Keyboard handler (xkb recommended)', +) + # Additional cog/cogctl options option( 'cog_appid', diff --git a/platform/x11/cog-platform-x11.c b/platform/x11/cog-platform-x11.c index b0b31a0d..ac42b6ae 100644 --- a/platform/x11/cog-platform-x11.c +++ b/platform/x11/cog-platform-x11.c @@ -23,7 +23,9 @@ # include #endif /* COG_X11_USE_XCB_KEYSYMS */ -#include +#ifdef COG_X11_USE_XKB +# include +#endif #if COG_HAVE_LIBPORTAL # include "../common/cog-file-chooser.h" @@ -87,6 +89,7 @@ struct CogX11Display { GSource *source; } xcb; +#ifdef COG_X11_USE_XKB struct { int32_t device_id; struct xkb_context *context; @@ -98,6 +101,7 @@ struct CogX11Display { xkb_mod_mask_t num_lock; xkb_mod_mask_t caps_lock; } xkb; +#endif /* COG_X11_USE_XKB */ #ifdef COG_X11_USE_XCB_KEYSYMS xcb_key_symbols_t *xcb_keysyms; @@ -194,6 +198,7 @@ xcb_paint_image (struct wpe_fdo_egl_exported_image *image) eglSwapBuffers(s_display->egl.display, s_window->egl.surface); } +#ifdef COG_X11_USE_XKB static uint32_t xcb_update_xkb_modifiers(uint32_t event_state) { @@ -220,6 +225,7 @@ xcb_update_xkb_modifiers(uint32_t event_state) xkb_state_update_mask(s_display->xkb.state, depressed_mods, 0, locked_mods, 0, 0, 0); return wpe_modifiers; } +#endif /* COG_X11_USE_XKB */ #if COG_X11_USE_XCB_KEYSYMS /* @@ -271,11 +277,13 @@ key_event_fill(struct wpe_input_keyboard_event *wpe_event, xcb_key_press_event_t wpe_event->time = event->time; wpe_event->hardware_key_code = event->detail; +#if COG_X11_USE_XKB if (s_display->xkb.device_id >= 0 && s_display->xkb.state) { wpe_event->modifiers = xcb_update_xkb_modifiers(event->state); wpe_event->key_code = xkb_state_key_get_one_sym(s_display->xkb.state, event->detail); return; } +#endif /* COG_X11_USE_XKB */ #if COG_X11_USE_XCB_KEYSYMS if (s_display->xcb_keysyms) { @@ -662,6 +670,7 @@ clear_xcb (void) XCloseDisplay (s_display->display); } +#ifdef COG_X11_USE_XKB static gboolean init_xkb (void) { @@ -690,16 +699,20 @@ init_xkb (void) s_display->xkb.device_id = -1; return FALSE; } +#endif /* COG_X11_USE_XKB */ static gboolean init_keyboard(GError **error) { g_autoptr(GString) tried_impl = NULL; +#ifdef COG_X11_USE_XKB + tried_impl = g_string_new("XKB"); if (init_xkb()) { g_debug("%s: Using XKB", G_STRFUNC); return TRUE; } +#endif /* COG_X11_USE_XKB */ #ifdef COG_X11_USE_XCB_KEYSYMS tried_impl = tried_impl ? g_string_append(tried_impl, ", XCB-Keysyms") : g_string_new("XCB-Keysyms"); @@ -721,12 +734,11 @@ init_keyboard(GError **error) static void clear_keyboard(void) { - if (s_display->xkb.state) - xkb_state_unref (s_display->xkb.state); - if (s_display->xkb.keymap) - xkb_keymap_unref (s_display->xkb.keymap); - if (s_display->xkb.context) - xkb_context_unref (s_display->xkb.context); +#ifdef COG_X11_USE_XKB + g_clear_pointer(&s_display->xkb.state, xkb_state_unref); + g_clear_pointer(&s_display->xkb.keymap, xkb_keymap_unref); + g_clear_pointer(&s_display->xkb.context, xkb_context_unref); +#endif /* COG_X11_USE_XKB */ #ifdef COG_X11_USE_XCB_KEYSYMS g_clear_pointer(&s_display->xcb_keysyms, xcb_key_symbols_free); diff --git a/platform/x11/meson.build b/platform/x11/meson.build index 2d74c58a..389eb0c9 100644 --- a/platform/x11/meson.build +++ b/platform/x11/meson.build @@ -16,12 +16,21 @@ x11_platform_dependencies = [ dependency('xcb-cursor'), ] -xcb_keysyms_dep = dependency('xcb-keysyms', required: false) -if xcb_keysyms_dep.found() - x11_platform_dependencies += [xcb_keysyms_dep] - x11_platform_c_args += ['-DCOG_X11_USE_XCB_KEYSYMS'] +x11_platform_keyboard = get_option('x11_keyboard') +if x11_platform_keyboard.length() == 0 + warning('No X11 keyboard support chosen, keyboard input will NOT work') endif +x11_platform_keyboard_dep_names = { + 'xkb': 'xkbcommon-x11', + 'xcb-keysyms': 'xcb-keysyms', +} + +foreach item : x11_platform_keyboard + x11_platform_dependencies += [dependency(x11_platform_keyboard_dep_names[item])] + x11_platform_c_args += ['-DCOG_X11_USE_@0@=1'.format(item.underscorify().to_upper())] +endforeach + x11_platform_plugin = shared_module('cogplatform-x11', 'cog-platform-x11.c', x11_platform_sources,