backends: Allow XKB model to be configured

This allows GNOME Shell to communicate the user desired XKB model
to the compositor instead of sticking with the pc105 default.

Particularly useful for those with a custom keyboard layout/irregular
keyboards.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2760>
This commit is contained in:
Leorize 2022-12-01 06:55:52 +00:00 committed by Carlos Garnacho
parent 1ab4faaf18
commit 8e39398d05
9 changed files with 44 additions and 19 deletions

View File

@ -89,7 +89,8 @@ struct _MetaBackendClass
void (* set_keymap) (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options);
const char *options,
const char *model);
gboolean (* is_lid_closed) (MetaBackend *backend);

View File

@ -1546,9 +1546,10 @@ void
meta_backend_set_keymap (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
META_BACKEND_GET_CLASS (backend)->set_keymap (backend, layouts, variants, options);
META_BACKEND_GET_CLASS (backend)->set_keymap (backend, layouts, variants, options, model);
}
/**

View File

@ -317,14 +317,15 @@ static void
meta_backend_native_set_keymap (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
ClutterSeat *seat;
seat = clutter_backend_get_default_seat (clutter_backend);
meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat),
layouts, variants, options);
layouts, variants, options, model);
meta_backend_notify_keymap_changed (backend);
}

View File

@ -157,7 +157,7 @@ meta_seat_native_constructed (GObject *object)
seat->core_pointer = meta_seat_impl_get_pointer (seat->impl);
seat->core_keyboard = meta_seat_impl_get_keyboard (seat->impl);
meta_seat_native_set_keyboard_map (seat, "us", "", "");
meta_seat_native_set_keyboard_map (seat, "us", "", "", DEFAULT_XKB_MODEL);
if (G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed)
G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed (object);
@ -480,14 +480,15 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
static struct xkb_keymap *
create_keymap (const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
struct xkb_rule_names names;
struct xkb_keymap *keymap;
struct xkb_context *context;
names.rules = DEFAULT_XKB_RULES_FILE;
names.model = DEFAULT_XKB_MODEL;
names.model = model;
names.layout = layouts;
names.variant = variants;
names.options = options;
@ -513,17 +514,18 @@ void
meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
struct xkb_keymap *keymap, *impl_keymap;
keymap = create_keymap (layouts, variants, options);
impl_keymap = create_keymap (layouts, variants, options);
keymap = create_keymap (layouts, variants, options, model);
impl_keymap = create_keymap (layouts, variants, options, model);
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,
DEFAULT_XKB_RULES_FILE, model, layouts,
variants, options);
return;
}

View File

@ -103,7 +103,8 @@ void meta_seat_native_reclaim_devices (MetaSeatNative *seat);
void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
const char *layouts,
const char *variants,
const char *options);
const char *options,
const char *model);
struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat);

View File

@ -57,6 +57,7 @@ struct _MetaBackendX11Cm
char *keymap_layouts;
char *keymap_variants;
char *keymap_options;
char *keymap_model;
int locked_group;
MetaInputSettings *input_settings;
@ -223,6 +224,7 @@ get_xkbrf_var_defs (Display *xdisplay,
const char *layouts,
const char *variants,
const char *options,
const char *model,
char **rules_p,
XkbRF_VarDefsRec *var_defs)
{
@ -232,7 +234,7 @@ get_xkbrf_var_defs (Display *xdisplay,
if (!XkbRF_GetNamesProp (xdisplay, &rules, var_defs) || !rules)
{
rules = strdup (DEFAULT_XKB_RULES_FILE);
var_defs->model = strdup (DEFAULT_XKB_MODEL);
var_defs->model = NULL;
var_defs->layout = NULL;
var_defs->variant = NULL;
var_defs->options = NULL;
@ -245,6 +247,8 @@ get_xkbrf_var_defs (Display *xdisplay,
var_defs->variant = strdup (variants);
free (var_defs->options);
var_defs->options = strdup (options);
free (var_defs->model);
var_defs->model = strdup (model);
/* Sometimes, the property is a file path, and sometimes it's
not. Normalize it so it's always a file path. */
@ -319,13 +323,15 @@ apply_keymap (MetaBackendX11 *x11)
if (!x11_cm->keymap_layouts ||
!x11_cm->keymap_variants ||
!x11_cm->keymap_options)
!x11_cm->keymap_options ||
!x11_cm->keymap_model)
return;
get_xkbrf_var_defs (xdisplay,
x11_cm->keymap_layouts,
x11_cm->keymap_variants,
x11_cm->keymap_options,
x11_cm->keymap_model,
&rules_file_path,
&xkb_var_defs);
@ -353,7 +359,8 @@ static void
meta_backend_x11_cm_set_keymap (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (x11);
@ -364,6 +371,8 @@ meta_backend_x11_cm_set_keymap (MetaBackend *backend,
x11_cm->keymap_variants = g_strdup (variants);
g_free (x11_cm->keymap_options);
x11_cm->keymap_options = g_strdup (options);
g_free (x11_cm->keymap_model);
x11_cm->keymap_model = g_strdup (model);
apply_keymap (x11);
}

View File

@ -174,7 +174,8 @@ static void
meta_backend_x11_nested_set_keymap (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options)
const char *options,
const char *model)
{
}

View File

@ -374,6 +374,7 @@ init_keymap (MetaDefaultPlugin *self,
g_autofree char *x11_layout = NULL;
g_autofree char *x11_options = NULL;
g_autofree char *x11_variant = NULL;
g_autofree char *x11_model = NULL;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
@ -421,7 +422,14 @@ init_keymap (MetaDefaultPlugin *self,
if (!g_variant_lookup (props, "X11Variant", "s", &x11_variant))
x11_variant = g_strdup ("");
meta_backend_set_keymap (backend, x11_layout, x11_variant, x11_options);
if (!g_variant_lookup (props, "X11Model", "s", &x11_model))
x11_model = g_strdup ("");
meta_backend_set_keymap (backend,
x11_layout,
x11_variant,
x11_options,
x11_model);
}
static void

View File

@ -44,7 +44,8 @@ META_EXPORT
void meta_backend_set_keymap (MetaBackend *backend,
const char *layouts,
const char *variants,
const char *options);
const char *options,
const char *model);
META_EXPORT
void meta_backend_lock_layout_group (MetaBackend *backend,