From 63a655e345dd4fdcd742d217f77bcae10671dbf6 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 29 Nov 2022 14:57:19 -0800 Subject: [PATCH 1/5] treeexpander: Fix typo and GestureClick type "canceled" should be "cancelled". Also, "cancel" is a signal on GtkGesture. --- gtk/gtktreeexpander.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gtk/gtktreeexpander.c b/gtk/gtktreeexpander.c index e06557d07f..cde27a330d 100644 --- a/gtk/gtktreeexpander.c +++ b/gtk/gtktreeexpander.c @@ -150,9 +150,9 @@ gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture, } static void -gtk_tree_expander_click_gesture_canceled (GtkGestureClick *gesture, - GdkEventSequence *sequence, - gpointer unused) +gtk_tree_expander_click_gesture_cancelled (GtkGesture *gesture, + GdkEventSequence *sequence, + gpointer unused) { gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)), GTK_STATE_FLAG_ACTIVE); @@ -207,7 +207,7 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self) g_signal_connect (gesture, "released", G_CALLBACK (gtk_tree_expander_click_gesture_released), NULL); g_signal_connect (gesture, "cancel", - G_CALLBACK (gtk_tree_expander_click_gesture_canceled), NULL); + G_CALLBACK (gtk_tree_expander_click_gesture_cancelled), NULL); gtk_widget_add_controller (self->expander_icon, GTK_EVENT_CONTROLLER (gesture)); gtk_widget_insert_before (self->expander_icon, From 847b3261fcb400488bb54bea9557a797c653b048 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 29 Nov 2022 14:58:29 -0800 Subject: [PATCH 2/5] treeexpander: Toggle expand on release instead of pressed With the introduction of the hide-expander property, I noticed that the active state would persist in many cases because the release signal was never emitted. In gtk3 tree expanders, expanded on release. gtk4 expanded on press to match window explorer. Per irc chat, the designers didn't have a strong preference for press or release. In order to keep consistency and fix this bug, let's move back to release. --- gtk/gtktreeexpander.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gtk/gtktreeexpander.c b/gtk/gtktreeexpander.c index cde27a330d..d2cce546a3 100644 --- a/gtk/gtktreeexpander.c +++ b/gtk/gtktreeexpander.c @@ -127,8 +127,6 @@ gtk_tree_expander_click_gesture_pressed (GtkGestureClick *gesture, { GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); - gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL); - gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE); @@ -143,8 +141,12 @@ gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture, double y, gpointer unused) { - gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)), - GTK_STATE_FLAG_ACTIVE); + GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); + + gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_ACTIVE); + + if (gtk_widget_contains (widget, x, y)) + gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL); gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); } From 7eac27e5eef069a7d90b96bb18cb18994d4a1c85 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 29 Nov 2022 19:58:25 -0800 Subject: [PATCH 3/5] listitemwidget: Add listitem.scroll-to action This is the matching action for list.scroll-to-item --- gtk/gtklistitemwidget.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c index 2fb5e1633c..7ce0f30af1 100644 --- a/gtk/gtklistitemwidget.c +++ b/gtk/gtklistitemwidget.c @@ -302,6 +302,20 @@ gtk_list_item_widget_select_action (GtkWidget *widget, priv->position, modify, extend); } +static void +gtk_list_item_widget_scroll_to_action (GtkWidget *widget, + const char *action_name, + GVariant *parameter) +{ + GtkListItemWidget *self = GTK_LIST_ITEM_WIDGET (widget); + GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self); + + gtk_widget_activate_action (GTK_WIDGET (self), + "list.scroll-to-item", + "u", + priv->position); +} + static void gtk_list_item_widget_class_init (GtkListItemWidgetClass *klass) { @@ -359,6 +373,17 @@ gtk_list_item_widget_class_init (GtkListItemWidgetClass *klass) "(bb)", gtk_list_item_widget_select_action); + /** + * GtkListItem|listitem.scroll-to: + * + * Moves the visible area of the list to this item with the minimum amount + * of scrolling required. If the item is already visible, nothing happens. + */ + gtk_widget_class_install_action (widget_class, + "listitem.scroll-to", + NULL, + gtk_list_item_widget_scroll_to_action); + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0, "activate-keybinding", 0); gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0, From fdfd76774e9e2e0b704f455026f63e93f42d3c04 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 29 Nov 2022 20:00:48 -0800 Subject: [PATCH 4/5] treeexpander: Scroll to expanded item If the anchor is below the expanded item, the expanded item will go out of view if there are sufficient children items. This is not ideal, so make sure to scroll to the item to ensure it remains in view. --- gtk/gtktreeexpander.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gtk/gtktreeexpander.c b/gtk/gtktreeexpander.c index d2cce546a3..a89a51eb0b 100644 --- a/gtk/gtktreeexpander.c +++ b/gtk/gtktreeexpander.c @@ -503,11 +503,17 @@ gtk_tree_expander_toggle_expand (GtkWidget *widget, GVariant *parameter) { GtkTreeExpander *self = GTK_TREE_EXPANDER (widget); + gboolean expand; if (self->list_row == NULL) return; - gtk_tree_list_row_set_expanded (self->list_row, !gtk_tree_list_row_get_expanded (self->list_row)); + expand = !gtk_tree_list_row_get_expanded (self->list_row); + + if (expand) + gtk_widget_activate_action (widget, "listitem.scroll-to", NULL); + + gtk_tree_list_row_set_expanded (self->list_row, expand); } static gboolean From c541de3e051dd86e7e996df324c5e795d9dce73f Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Wed, 30 Nov 2022 10:48:14 -0800 Subject: [PATCH 5/5] list: Remove active state handling in listitemwidget and treeexpander Active state is handled by main now. It appears that listitem and treeexpander handled it manually (probably before main did). This is unnecessary now, so let's remove it. --- gtk/gtklistitemwidget.c | 14 -------------- gtk/gtktreeexpander.c | 39 ++++----------------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c index 7ce0f30af1..a90bceda1b 100644 --- a/gtk/gtklistitemwidget.c +++ b/gtk/gtklistitemwidget.c @@ -443,8 +443,6 @@ gtk_list_item_widget_click_gesture_pressed (GtkGestureClick *gesture, } } - gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE); - if (gtk_widget_get_focus_on_click (widget)) gtk_widget_grab_focus (widget); } @@ -488,8 +486,6 @@ gtk_list_item_widget_click_gesture_released (GtkGestureClick *gesture, "(ubb)", priv->position, modify, extend); } - - gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE); } static void @@ -525,14 +521,6 @@ gtk_list_item_widget_hover_cb (GtkEventControllerMotion *controller, } } -static void -gtk_list_item_widget_click_gesture_canceled (GtkGestureClick *gesture, - GdkEventSequence *sequence, - GtkListItemWidget *self) -{ - gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE); -} - static void gtk_list_item_widget_init (GtkListItemWidget *self) { @@ -552,8 +540,6 @@ gtk_list_item_widget_init (GtkListItemWidget *self) G_CALLBACK (gtk_list_item_widget_click_gesture_pressed), self); g_signal_connect (gesture, "released", G_CALLBACK (gtk_list_item_widget_click_gesture_released), self); - g_signal_connect (gesture, "cancel", - G_CALLBACK (gtk_list_item_widget_click_gesture_canceled), self); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); controller = gtk_event_controller_focus_new (); diff --git a/gtk/gtktreeexpander.c b/gtk/gtktreeexpander.c index a89a51eb0b..d4dbfe9596 100644 --- a/gtk/gtktreeexpander.c +++ b/gtk/gtktreeexpander.c @@ -118,21 +118,6 @@ G_DEFINE_TYPE (GtkTreeExpander, gtk_tree_expander, GTK_TYPE_WIDGET) static GParamSpec *properties[N_PROPS] = { NULL, }; -static void -gtk_tree_expander_click_gesture_pressed (GtkGestureClick *gesture, - int n_press, - double x, - double y, - gpointer unused) -{ - GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); - - gtk_widget_set_state_flags (widget, - GTK_STATE_FLAG_ACTIVE, - FALSE); - - gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); -} static void gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture, @@ -143,23 +128,11 @@ gtk_tree_expander_click_gesture_released (GtkGestureClick *gesture, { GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); - gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_ACTIVE); - if (gtk_widget_contains (widget, x, y)) - gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL); - - gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); -} - -static void -gtk_tree_expander_click_gesture_cancelled (GtkGesture *gesture, - GdkEventSequence *sequence, - gpointer unused) -{ - gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)), - GTK_STATE_FLAG_ACTIVE); - - gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); + { + gtk_widget_activate_action (widget, "listitem.toggle-expand", NULL); + gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); + } } static void @@ -204,12 +177,8 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self) FALSE); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY); - g_signal_connect (gesture, "pressed", - G_CALLBACK (gtk_tree_expander_click_gesture_pressed), NULL); g_signal_connect (gesture, "released", G_CALLBACK (gtk_tree_expander_click_gesture_released), NULL); - g_signal_connect (gesture, "cancel", - G_CALLBACK (gtk_tree_expander_click_gesture_cancelled), NULL); gtk_widget_add_controller (self->expander_icon, GTK_EVENT_CONTROLLER (gesture)); gtk_widget_insert_before (self->expander_icon,