backends/native: Don't crash if keymap is misconfigured

xkb recently gained support for user-specified keymaps, which means we
can no longer assume that the configuration data is necessarily fully
complete or correct; and the configuration language is quite a labyrinth,
so it's easy to get wrong. If setting the keymap fails, leave it in
whatever state it previously had, since that seems preferable to crashing
with a NULL pointer dereference.

Resolves: https://gitlab.gnome.org/GNOME/mutter/-/issues/1555
Signed-off-by: Simon McVittie <smcv@debian.org>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1605>
This commit is contained in:
Simon McVittie
2020-11-26 11:54:48 +00:00
committed by Simon McVittie
parent 17dbb98811
commit 60f647df8e
3 changed files with 11 additions and 0 deletions

View File

@ -284,6 +284,14 @@ meta_backend_native_set_keymap (MetaBackend *backend,
keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_context_unref (context);
if (keymap == NULL)
{
g_warning ("Unable to load configured keymap: rules=%s, model=%s, layout=%s, variant=%s, options=%s",
DEFAULT_XKB_RULES_FILE, DEFAULT_XKB_MODEL, layouts,
variants, options);
return;
}
seat = clutter_backend_get_default_seat (clutter_backend);
meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat), keymap);