x11: the caps lock state is asked for when it is first needed instead of being unknown until the next key event, and the translate queue is freed with its display, as in GTK+ 3

This commit is contained in:
Daemonratte 2026-10-18 10:41:33 +02:00
commit f6a18ffb89
No known key found for this signature in database
4 changed files with 37 additions and 1 deletions

View file

@ -859,6 +859,9 @@ gdk_display_x11_finalize (GObject *object)
_gdk_x11_cursor_display_finalize (GDK_DISPLAY_OBJECT(display_x11));
_gdk_x11_scroll_finalize (GDK_DISPLAY_OBJECT(display_x11));
/* Empty the translate/antiexpose queue */
_gdk_x11_display_free_translate_queue (GDK_DISPLAY_OBJECT (display_x11));
/* Atom Hashtable */
g_hash_table_destroy (display_x11->atom_from_virtual);
g_hash_table_destroy (display_x11->atom_to_virtual);

View file

@ -159,6 +159,19 @@ queue_item_free (GdkWindowQueueItem *item)
g_free (item);
}
void
_gdk_x11_display_free_translate_queue (GdkDisplay *display)
{
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
if (display_x11->translate_queue)
{
g_queue_foreach (display_x11->translate_queue, (GFunc) queue_item_free, NULL);
g_queue_free (display_x11->translate_queue);
display_x11->translate_queue = NULL;
}
}
static void
gdk_window_queue (GdkWindow *window,
GdkWindowQueueItem *item)

View file

@ -86,6 +86,7 @@ struct _GdkKeymapX11
PangoDirection current_direction;
guint sun_keypad : 1;
guint have_direction : 1;
guint have_lock_state : 1;
guint caps_lock_state : 1;
guint current_serial;
@ -166,6 +167,7 @@ gdk_keymap_x11_init (GdkKeymapX11 *keymap)
keymap->group_switch_mask = 0;
keymap->lock_keysym = GDK_Caps_Lock;
keymap->have_direction = FALSE;
keymap->have_lock_state = FALSE;
keymap->current_serial = 0;
#ifdef HAVE_XKB
@ -704,13 +706,17 @@ static gboolean
update_lock_state (GdkKeymapX11 *keymap_x11,
gint locked_mods)
{
gboolean have_lock_state;
gboolean caps_lock_state;
have_lock_state = keymap_x11->have_lock_state;
caps_lock_state = keymap_x11->caps_lock_state;
keymap_x11->have_lock_state = TRUE;
keymap_x11->caps_lock_state = (locked_mods & GDK_LOCK_MASK) != 0;
return caps_lock_state != keymap_x11->caps_lock_state;
return !have_lock_state
|| caps_lock_state != keymap_x11->caps_lock_state;
}
/* keep this in sync with the XkbSelectEventDetails() call
@ -852,6 +858,19 @@ gdk_keymap_get_caps_lock_state (GdkKeymap *keymap)
keymap_x11 = GDK_KEYMAP_X11 (keymap);
#ifdef HAVE_XKB
/* The lock state is otherwise only tracked from XkbStateNotify
* events, so query it explicitly the first time.
*/
if (KEYMAP_USE_XKB (keymap) && !keymap_x11->have_lock_state)
{
XkbStateRec state_rec;
XkbGetState (KEYMAP_XDISPLAY (keymap), XkbUseCoreKbd, &state_rec);
update_lock_state (keymap_x11, state_rec.locked_mods);
}
#endif /* HAVE_XKB */
return keymap_x11->caps_lock_state;
}

View file

@ -144,6 +144,7 @@ void _gdk_x11_window_set_root_origin (GdkWindow *window,
gint y);
gboolean _gdk_x11_window_queue_antiexpose (GdkWindow *window,
GdkRegion *area);
void _gdk_x11_display_free_translate_queue (GdkDisplay *display);
void _gdk_x11_window_queue_translation (GdkWindow *window,
GdkGC *gc,
GdkRegion *area,