clutter: Move scattered x11 keymap code into ClutterKeymapX11

https://gitlab.gnome.org/GNOME/mutter/merge_requests/672
This commit is contained in:
Carlos Garnacho 2019-03-26 14:53:11 +01:00 committed by Jonas Ådahl
parent f304fa4869
commit 829d9c863c
3 changed files with 24 additions and 33 deletions

View File

@ -105,9 +105,6 @@ struct _ClutterBackendX11
Window xsettings_xwin;
ClutterKeymapX11 *keymap;
gboolean use_xkb;
gboolean have_xkb_autorepeat;
guint keymap_serial;
};
struct _ClutterBackendX11Class

View File

@ -79,9 +79,14 @@ struct _ClutterKeymapX11
GHashTable *reserved_keycodes;
GQueue *available_keycodes;
guint keymap_serial;
guint caps_lock_state : 1;
guint num_lock_state : 1;
guint has_direction : 1;
guint use_xkb : 1;
guint have_xkb_autorepeat : 1;
};
struct _ClutterKeymapX11Class
@ -179,7 +184,7 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
update_modmap (backend_x11->xdpy, keymap_x11);
}
else if (keymap_x11->xkb_map_serial != backend_x11->keymap_serial)
else if (keymap_x11->xkb_map_serial != keymap_x11->keymap_serial)
{
int flags = XkbKeySymsMask
| XkbKeyTypesMask
@ -195,7 +200,7 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
update_modmap (backend_x11->xdpy, keymap_x11);
keymap_x11->xkb_map_serial = backend_x11->keymap_serial;
keymap_x11->xkb_map_serial = keymap_x11->keymap_serial;
}
if (keymap_x11->num_lock_mask == 0)
@ -376,7 +381,7 @@ clutter_keymap_x11_constructed (GObject *gobject)
{
Bool detectable_autorepeat_supported;
backend_x11->use_xkb = TRUE;
keymap_x11->use_xkb = TRUE;
XkbSelectEvents (backend_x11->xdpy,
XkbUseCoreKbd,
@ -393,11 +398,7 @@ clutter_keymap_x11_constructed (GObject *gobject)
True,
&detectable_autorepeat_supported);
backend_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
CLUTTER_NOTE (BACKEND, "Detectable autorepeat: %s",
backend_x11->have_xkb_autorepeat ? "supported"
: "not supported");
keymap_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
}
}
}
@ -453,7 +454,7 @@ clutter_keymap_x11_replace_keycode (ClutterKeymapX11 *keymap_x11,
KeyCode keycode,
KeySym keysym)
{
if (CLUTTER_BACKEND_X11 (keymap_x11->backend)->use_xkb)
if (keymap_x11->use_xkb)
{
Display *dpy = clutter_x11_get_default_display ();
XkbDescPtr xkb = get_xkb (keymap_x11);
@ -575,12 +576,10 @@ clutter_keymap_x11_translate_event (ClutterEventTranslator *translator,
ClutterEvent *event)
{
ClutterKeymapX11 *keymap_x11 = CLUTTER_KEYMAP_X11 (translator);
ClutterBackendX11 *backend_x11;
ClutterTranslateReturn retval;
XEvent *xevent;
backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend);
if (!backend_x11->use_xkb)
if (!keymap_x11->use_xkb)
return CLUTTER_TRANSLATE_CONTINUE;
xevent = native;
@ -605,7 +604,7 @@ clutter_keymap_x11_translate_event (ClutterEventTranslator *translator,
case XkbMapNotify:
CLUTTER_NOTE (EVENT, "Updating keyboard mapping");
XkbRefreshKeyboardMapping (&xkb_event->map);
backend_x11->keymap_serial += 1;
keymap_x11->keymap_serial += 1;
retval = CLUTTER_TRANSLATE_REMOVE;
break;
@ -613,6 +612,12 @@ clutter_keymap_x11_translate_event (ClutterEventTranslator *translator,
break;
}
}
else if (xevent->type == MappingNotify)
{
XRefreshKeyboardMapping (&xevent->xmapping);
keymap_x11->keymap_serial += 1;
retval = CLUTTER_TRANSLATE_REMOVE;
}
return retval;
}
@ -659,16 +664,13 @@ _clutter_keymap_x11_translate_key_state (ClutterKeymapX11 *keymap,
ClutterModifierType *modifier_state_p,
ClutterModifierType *mods_p)
{
ClutterBackendX11 *backend_x11;
ClutterModifierType unconsumed_modifiers = 0;
ClutterModifierType modifier_state = *modifier_state_p;
gint retval;
g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), 0);
backend_x11 = CLUTTER_BACKEND_X11 (keymap->backend);
if (backend_x11->use_xkb)
if (keymap->use_xkb)
{
XkbDescRec *xkb = get_xkb (keymap);
KeySym tmp_keysym;
@ -704,7 +706,7 @@ _clutter_keymap_x11_get_is_modifier (ClutterKeymapX11 *keymap,
if (keycode < keymap->min_keycode || keycode > keymap->max_keycode)
return FALSE;
if (CLUTTER_BACKEND_X11 (keymap->backend)->use_xkb)
if (keymap->use_xkb)
{
XkbDescRec *xkb = get_xkb (keymap);
@ -720,7 +722,7 @@ _clutter_keymap_x11_get_direction (ClutterKeymapX11 *keymap)
{
g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL);
if (CLUTTER_BACKEND_X11 (keymap->backend)->use_xkb)
if (keymap->use_xkb)
{
if (!keymap->has_direction)
{
@ -743,7 +745,7 @@ clutter_keymap_x11_get_entries_for_keyval (ClutterKeymapX11 *keymap_x11,
ClutterKeymapKey **keys,
gint *n_keys)
{
if (CLUTTER_BACKEND_X11 (keymap_x11->backend)->use_xkb)
if (keymap_x11->use_xkb)
{
XkbDescRec *xkb = get_xkb (keymap_x11);
GArray *retval;
@ -823,7 +825,7 @@ clutter_keymap_x11_get_entries_for_keyval (ClutterKeymapX11 *keymap_x11,
static guint
clutter_keymap_x11_get_available_keycode (ClutterKeymapX11 *keymap_x11)
{
if (CLUTTER_BACKEND_X11 (keymap_x11->backend)->use_xkb)
if (keymap_x11->use_xkb)
{
clutter_keymap_x11_refresh_reserved_keycodes (keymap_x11);
@ -891,7 +893,6 @@ clutter_keymap_x11_latch_modifiers (ClutterKeymapX11 *keymap_x11,
uint32_t level,
gboolean enable)
{
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend);
uint32_t modifiers[] = {
0,
ShiftMask,
@ -900,7 +901,7 @@ clutter_keymap_x11_latch_modifiers (ClutterKeymapX11 *keymap_x11,
};
uint32_t value = 0;
if (!backend_x11->use_xkb)
if (!keymap_x11->use_xkb)
return;
level = CLAMP (level, 0, G_N_ELEMENTS (modifiers) - 1);

View File

@ -1024,13 +1024,6 @@ clutter_stage_x11_translate_event (ClutterEventTranslator *translator,
}
break;
case MappingNotify:
CLUTTER_NOTE (EVENT, "Refresh keyboard mapping");
XRefreshKeyboardMapping (&xevent->xmapping);
backend_x11->keymap_serial += 1;
res = CLUTTER_TRANSLATE_REMOVE;
break;
default:
res = CLUTTER_TRANSLATE_CONTINUE;
break;