mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 17:10:40 -05:00
backends/native: Seal MetaKeymapNative xkb usage
Don't let the vfuncs (meant to be called from the UI thread) deal with xkb state itself. Instead store the current state in struct fields, which is then fetched in vfuncs. This makes the keymap able to be used from the UI thread, while being maintained by the input thread. Same caveats apply than clutter_seat_query_state(), you are asking for the most up-to-date state, but it still may be changing under your feet. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403
This commit is contained in:
parent
6704e986a0
commit
4b88a769d2
@ -36,6 +36,8 @@ struct _MetaKeymapNative
|
||||
ClutterKeymap parent_instance;
|
||||
|
||||
struct xkb_keymap *keymap;
|
||||
gboolean num_lock;
|
||||
gboolean caps_lock;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaKeymapNative, meta_keymap_native,
|
||||
@ -54,31 +56,17 @@ meta_keymap_native_finalize (GObject *object)
|
||||
static gboolean
|
||||
meta_keymap_native_get_num_lock_state (ClutterKeymap *keymap)
|
||||
{
|
||||
struct xkb_state *xkb_state;
|
||||
ClutterSeat *seat;
|
||||
MetaKeymapNative *keymap_native = META_KEYMAP_NATIVE (keymap);
|
||||
|
||||
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
||||
xkb_state = meta_seat_impl_get_xkb_state (META_SEAT_NATIVE (seat)->impl);
|
||||
|
||||
return xkb_state_mod_name_is_active (xkb_state,
|
||||
XKB_MOD_NAME_NUM,
|
||||
XKB_STATE_MODS_LATCHED |
|
||||
XKB_STATE_MODS_LOCKED);
|
||||
return keymap_native->num_lock;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_keymap_native_get_caps_lock_state (ClutterKeymap *keymap)
|
||||
{
|
||||
struct xkb_state *xkb_state;
|
||||
ClutterSeat *seat;
|
||||
MetaKeymapNative *keymap_native = META_KEYMAP_NATIVE (keymap);
|
||||
|
||||
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
||||
xkb_state = meta_seat_impl_get_xkb_state (META_SEAT_NATIVE (seat)->impl);
|
||||
|
||||
return xkb_state_mod_name_is_active (xkb_state,
|
||||
XKB_MOD_NAME_CAPS,
|
||||
XKB_STATE_MODS_LATCHED |
|
||||
XKB_STATE_MODS_LOCKED);
|
||||
return keymap_native->caps_lock;
|
||||
}
|
||||
|
||||
static PangoDirection
|
||||
@ -132,3 +120,24 @@ meta_keymap_native_get_keyboard_map (MetaKeymapNative *keymap)
|
||||
{
|
||||
return keymap->keymap;
|
||||
}
|
||||
|
||||
void
|
||||
meta_keymap_native_update (MetaKeymapNative *keymap)
|
||||
{
|
||||
struct xkb_state *xkb_state;
|
||||
ClutterSeat *seat;
|
||||
|
||||
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
||||
xkb_state = meta_seat_impl_get_xkb_state (META_SEAT_NATIVE (seat)->impl);
|
||||
|
||||
keymap->num_lock =
|
||||
xkb_state_mod_name_is_active (xkb_state,
|
||||
XKB_MOD_NAME_NUM,
|
||||
XKB_STATE_MODS_LATCHED |
|
||||
XKB_STATE_MODS_LOCKED);
|
||||
keymap->caps_lock =
|
||||
xkb_state_mod_name_is_active (xkb_state,
|
||||
XKB_MOD_NAME_CAPS,
|
||||
XKB_STATE_MODS_LATCHED |
|
||||
XKB_STATE_MODS_LOCKED);
|
||||
}
|
||||
|
@ -32,5 +32,6 @@ G_DECLARE_FINAL_TYPE (MetaKeymapNative, meta_keymap_native,
|
||||
void meta_keymap_native_set_keyboard_map (MetaKeymapNative *keymap,
|
||||
struct xkb_keymap *xkb_keymap);
|
||||
struct xkb_keymap * meta_keymap_native_get_keyboard_map (MetaKeymapNative *keymap);
|
||||
void meta_keymap_native_update (MetaKeymapNative *keymap);
|
||||
|
||||
#endif /* META_KEYMAP_NATIVE_H */
|
||||
|
@ -2863,6 +2863,7 @@ meta_seat_impl_update_xkb_state (MetaSeatImpl *seat)
|
||||
seat->scroll_lock_led = xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_SCROLL);
|
||||
|
||||
meta_seat_impl_sync_leds (seat);
|
||||
meta_keymap_native_update (seat->keymap);
|
||||
|
||||
g_rw_lock_writer_unlock (&seat->state_lock);
|
||||
}
|
||||
@ -3034,6 +3035,7 @@ meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat,
|
||||
locked_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED);
|
||||
|
||||
xkb_state_update_mask (state, depressed_mods, latched_mods, locked_mods, 0, 0, idx);
|
||||
meta_keymap_native_update (seat->keymap);
|
||||
|
||||
seat->layout_idx = idx;
|
||||
|
||||
@ -3095,6 +3097,7 @@ meta_seat_impl_set_keyboard_numlock (MetaSeatImpl *seat,
|
||||
group_mods);
|
||||
|
||||
meta_seat_impl_sync_leds (seat);
|
||||
meta_keymap_native_update (seat->keymap);
|
||||
|
||||
g_rw_lock_writer_unlock (&seat->state_lock);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user