From bfad7693bfeb483929047fcd32a4837fc7ffbeb5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 1 Oct 2020 23:35:06 -0400 Subject: [PATCH] emojichooser: Allow inserting multiple Emoji Don't close the Emoji chooser when the Control key is held while clicking. So you can insert multiple Emoji without having to reopen the chooser every time. Fixes: #1002 --- gtk/gtkemojichooser.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c index 1aa7c445df..e3538b10ca 100644 --- a/gtk/gtkemojichooser.c +++ b/gtk/gtkemojichooser.c @@ -220,6 +220,23 @@ add_recent_item (GtkEmojiChooser *chooser, g_variant_unref (item); } +static gboolean +should_close (GtkEmojiChooser *chooser) +{ + GdkDisplay *display; + GdkSeat *seat; + GdkDevice *device; + GdkModifierType state; + + display = gtk_widget_get_display (GTK_WIDGET (chooser)); + seat = gdk_display_get_default_seat (display); + device = gdk_seat_get_pointer (seat); + gdk_device_get_state (device, gtk_widget_get_window (GTK_WIDGET (chooser)), + NULL, &state); + + return (state & GDK_CONTROL_MASK) == 0; +} + static void emoji_activated (GtkFlowBox *box, GtkFlowBoxChild *child, @@ -232,7 +249,16 @@ emoji_activated (GtkFlowBox *box, GVariant *item; gunichar modifier; - gtk_popover_popdown (GTK_POPOVER (chooser)); + if (should_close (chooser)) + gtk_popover_popdown (GTK_POPOVER (chooser)); + else + { + GtkWidget *popover; + + popover = gtk_widget_get_ancestor (GTK_WIDGET (box), GTK_TYPE_POPOVER); + if (popover != GTK_WIDGET (chooser)) + gtk_popover_popdown (GTK_POPOVER (popover)); + } ebox = gtk_bin_get_child (GTK_BIN (child)); label = gtk_bin_get_child (GTK_BIN (ebox));