From 8f75df1cb38fa2f59104a7280f3846873bd7fd4c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 14 Apr 2020 15:03:57 -0400 Subject: [PATCH] flowbox: Add a private api to disable move-cursor Without this, it seems impossible to make cross-section keynav in the Emoji chooser work. I've tried, but got lost between the focus, grab_focus, move_cursor and keynav-failed vfuncs and signals, and their competing implementations GtkFlowBox and GtkEmojiChooser. --- gtk/gtkemojichooser.c | 3 +++ gtk/gtkflowbox.c | 14 ++++++++++++++ gtk/gtkflowboxprivate.h | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 gtk/gtkflowboxprivate.h diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c index 57c92cb735..e17cabeca2 100644 --- a/gtk/gtkemojichooser.c +++ b/gtk/gtkemojichooser.c @@ -766,6 +766,8 @@ stop_search (GtkEntry *entry, gtk_popover_popdown (GTK_POPOVER (data)); } +extern void gtk_flow_box_disable_move_cursor (GtkFlowBox *box); + static void setup_section (GtkEmojiChooser *chooser, EmojiSection *section, @@ -781,6 +783,7 @@ setup_section (GtkEmojiChooser *chooser, adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window)); gtk_container_set_focus_vadjustment (GTK_CONTAINER (section->box), adj); + gtk_flow_box_disable_move_cursor (GTK_FLOW_BOX (section->box)); gtk_flow_box_set_filter_func (GTK_FLOW_BOX (section->box), filter_func, section, NULL); g_signal_connect_swapped (section->button, "clicked", G_CALLBACK (scroll_to_section), section); } diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index da379f3a8a..84ba41df2f 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -76,6 +76,7 @@ #include #include "gtkflowbox.h" +#include "gtkflowboxprivate.h" #include "gtkadjustment.h" #include "gtkcontainerprivate.h" @@ -640,6 +641,8 @@ struct _GtkFlowBoxPrivate { GtkFlowBoxCreateWidgetFunc create_widget_func; gpointer create_widget_func_data; GDestroyNotify create_widget_func_data_destroy; + + gboolean disable_move_cursor; }; #define BOX_PRIV(box) ((GtkFlowBoxPrivate*)gtk_flow_box_get_instance_private ((GtkFlowBox*)(box))) @@ -3005,6 +3008,14 @@ gtk_flow_box_toggle_cursor_child (GtkFlowBox *box) gtk_flow_box_select_and_activate (box, priv->cursor_child); } +void +gtk_flow_box_disable_move_cursor (GtkFlowBox *box) +{ + GtkFlowBoxPrivate *priv = BOX_PRIV (box); + + priv->disable_move_cursor = TRUE; +} + static gboolean gtk_flow_box_move_cursor (GtkFlowBox *box, GtkMovementStep step, @@ -3023,6 +3034,9 @@ gtk_flow_box_move_cursor (GtkFlowBox *box, GtkAdjustment *adjustment; gboolean vertical; + if (priv->disable_move_cursor) + return FALSE; + vertical = priv->orientation == GTK_ORIENTATION_VERTICAL; if (vertical) diff --git a/gtk/gtkflowboxprivate.h b/gtk/gtkflowboxprivate.h new file mode 100644 index 0000000000..c609da36a3 --- /dev/null +++ b/gtk/gtkflowboxprivate.h @@ -0,0 +1,26 @@ +/* GTK - The GIMP Toolkit + * + * Copyright (C) 2020 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_FLOW_BOX_PRIVATE_H__ +#define __GTK_FLOW_BOX_PRIVATE_H__ + +#include "gtkflowbox.h" + +void gtk_flow_box_disable_move_cursor (GtkFlowBox *box); + +#endif