diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index aa787386c..4e75f28fd 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1470,7 +1470,6 @@ struct weston_compositor { struct xkb_rule_names xkb_names; struct xkb_context *xkb_context; - struct weston_xkb_info *xkb_info; int32_t kb_repeat_rate; int32_t kb_repeat_delay; diff --git a/libweston/input.c b/libweston/input.c index e51faf78a..de445fda8 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -3931,6 +3931,9 @@ WL_EXPORT int weston_compositor_set_xkb_rule_names(struct weston_compositor *ec, struct xkb_rule_names *names) { + struct weston_seat *seat; + struct xkb_keymap *keymap; + if (ec->xkb_context == NULL) { ec->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (ec->xkb_context == NULL) { @@ -3948,6 +3951,14 @@ weston_compositor_set_xkb_rule_names(struct weston_compositor *ec, if (!ec->xkb_names.layout) ec->xkb_names.layout = strdup("us"); + keymap = xkb_keymap_new_from_names(ec->xkb_context, names, 0); + if (!keymap) { + weston_log("failed to create XKB keymap\n"); + return -1; + } + wl_list_for_each(seat, &ec->seat_list, link) + weston_seat_update_keymap(seat, keymap); + xkb_keymap_unref(keymap); return 0; } @@ -3972,8 +3983,6 @@ weston_compositor_xkb_destroy(struct weston_compositor *ec) free((char *) ec->xkb_names.variant); free((char *) ec->xkb_names.options); - if (ec->xkb_info) - weston_xkb_info_destroy(ec->xkb_info); xkb_context_unref(ec->xkb_context); } @@ -4044,14 +4053,11 @@ err_keymap: return NULL; } -static int -weston_compositor_build_global_keymap(struct weston_compositor *ec) +static struct xkb_keymap * +weston_compositor_build_keymap_from_names(struct weston_compositor *ec) { struct xkb_keymap *keymap; - if (ec->xkb_info != NULL) - return 0; - keymap = xkb_keymap_new_from_names(ec->xkb_context, &ec->xkb_names, 0); @@ -4062,15 +4068,10 @@ weston_compositor_build_global_keymap(struct weston_compositor *ec) ec->xkb_names.rules, ec->xkb_names.model, ec->xkb_names.layout, ec->xkb_names.variant, ec->xkb_names.options); - return -1; + return NULL; } - ec->xkb_info = weston_xkb_info_create(keymap); - xkb_keymap_unref(keymap); - if (ec->xkb_info == NULL) - return -1; - - return 0; + return keymap; } WL_EXPORT void @@ -4111,10 +4112,14 @@ weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) if (keyboard->xkb_info == NULL) goto err; } else { - if (weston_compositor_build_global_keymap(seat->compositor) < 0) + keymap = weston_compositor_build_keymap_from_names( + seat->compositor); + if (keymap == NULL) + goto err; + keyboard->xkb_info = weston_xkb_info_create(keymap); + xkb_keymap_unref(keymap); + if (!keyboard->xkb_info) goto err; - keyboard->xkb_info = seat->compositor->xkb_info; - keyboard->xkb_info->ref_count++; } keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap);