From 78b9762016e2b0c96b7eaa40f15d5b7b22b0fd8e Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Sun, 4 Dec 2022 14:17:00 -0700 Subject: [PATCH] input/keyboard: enable user xkb configs with cap_sys_nice --- include/sway/input/keyboard.h | 2 ++ sway/config.c | 5 ++++ sway/input/keyboard.c | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h index 571d9e6fa..44b3f3539 100644 --- a/include/sway/input/keyboard.h +++ b/include/sway/input/keyboard.h @@ -81,6 +81,8 @@ struct sway_keyboard_group { struct wl_list link; // sway_seat::keyboard_groups }; +int xkb_context_include_path_append_default_unsecured(struct xkb_context *ctx); + struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, char **error); diff --git a/sway/config.c b/sway/config.c index b41dd871b..e72f66f5d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include "sway/input/input-manager.h" #include "sway/input/seat.h" +#include "sway/input/keyboard.h" #include "sway/input/switch.h" #include "sway/commands.h" #include "sway/config.h" @@ -38,6 +40,9 @@ struct sway_config *config = NULL; static struct xkb_state *keysym_translation_state_create( struct xkb_rule_names rules) { struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + if (getauxval(AT_SECURE) > 0) { + xkb_context_include_path_append_default_unsecured(context); + } struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names( context, &rules, diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 96d5b72df..88c05cfc1 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -1,12 +1,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include "sway/commands.h" #include "sway/input/input-manager.h" @@ -752,6 +754,45 @@ static void handle_xkb_context_log(struct xkb_context *context, } } +int xkb_context_include_path_append_default_unsecured(struct xkb_context *ctx) { + char *user_path; + int ret = 0; + + const char *home = getenv("HOME"); + const char *xdg = getenv("XDG_CONFIG_HOME"); + + if (xdg != NULL) { + int len = strlen(xdg) + strlen("/xkb") + 1; + user_path = calloc(len, sizeof(char)); + if (user_path) { + snprintf(user_path, len, "%s/xkb", xdg); + ret |= xkb_context_include_path_append(ctx, user_path); + free(user_path); + } + } else if (home != NULL) { + int len = strlen(home) + strlen("/.config/xkb") + 1; + user_path = calloc(len, sizeof(char)); + if (user_path) { + snprintf(user_path, len, "%s/.config/xkb", home); + ret |= xkb_context_include_path_append(ctx, user_path); + free(user_path); + } + } + + if (home != NULL) { + int len = strlen(home) + strlen("/.xkb") + 1; + user_path = calloc(len, sizeof(char)); + if (user_path) { + snprintf(user_path, len, "%s/.xkb", home); + ret |= xkb_context_include_path_append(ctx, user_path); + free(user_path); + } + } + + return ret; +} + + struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, char **error) { struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); @@ -761,6 +802,10 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, xkb_context_set_user_data(context, error); xkb_context_set_log_fn(context, handle_xkb_context_log); + if (getauxval(AT_SECURE) > 0) { + xkb_context_include_path_append_default_unsecured(context); + } + struct xkb_keymap *keymap = NULL; if (ic && ic->xkb_file) {