Stop specifying xkb_rule_names

If a NULL xkb_rule_names pointer is passed to
xkb_keymap_new_from_names, libxkbcommon will default to reading
the XKB_* env variables. So there's no need to do it ourselves.

Also s/xkb_map_new_from_names/xkb_keymap_new_from_names/ since the
latter is more consistent with the returned struct name.

[1]: https://xkbcommon.org/doc/current/structxkb__rule__names.html
This commit is contained in:
Simon Ser 2021-04-16 09:05:39 +02:00
parent 83670fce65
commit fbc2182b9f
8 changed files with 8 additions and 51 deletions

View file

@ -211,18 +211,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -229,18 +229,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -298,18 +298,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -179,18 +179,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -138,18 +138,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -288,18 +288,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -200,18 +200,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
keyboard->destroy.notify = keyboard_destroy_notify; keyboard->destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_signal_add(&device->keyboard->events.key, &keyboard->key);
keyboard->key.notify = keyboard_key_notify; keyboard->key.notify = keyboard_key_notify;
struct xkb_rule_names rules = { 0 };
rules.rules = getenv("XKB_DEFAULT_RULES");
rules.model = getenv("XKB_DEFAULT_MODEL");
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { if (!context) {
wlr_log(WLR_ERROR, "Failed to create XKB context"); wlr_log(WLR_ERROR, "Failed to create XKB context");
exit(1); exit(1);
} }
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) { if (!keymap) {
wlr_log(WLR_ERROR, "Failed to create XKB keymap"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");

View file

@ -222,9 +222,8 @@ static void server_new_keyboard(struct tinywl_server *server,
/* We need to prepare an XKB keymap and assign it to the keyboard. This /* We need to prepare an XKB keymap and assign it to the keyboard. This
* assumes the defaults (e.g. layout = "us"). */ * assumes the defaults (e.g. layout = "us"). */
struct xkb_rule_names rules = { 0 };
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(device->keyboard, keymap);