[nautilus/wip/antoniof/new-list-view: 3/9] view-icon-controller: Don't share click handlers
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view: 3/9] view-icon-controller: Don't share click handlers
- Date: Sat, 21 May 2022 22:24:05 +0000 (UTC)
commit 331bd151e8eddc46ba7cd35d64d4bd7a3c369e9e
Author: António Fernandes <antoniof gnome org>
Date: Sat May 21 20:20:19 2022 +0100
view-icon-controller: Don't share click handlers
In the past, there used to be a single click event handler for the
whole view. The coordinates would be used to detect whether the click
happened on an item or the background.
Nowadays, with a list model widget, we can't use the coordinates to
find clicked items, so we have instead:
- 1 click gesture for the whole view;
- multiple click gestures for each item widget.
Despite multiple gestures, their signal handlers still share a
common path. This makes for long callback definitions and loss of
clarity.
Split the click callbacks into item callback from view callback.
The view's ::release callback is no-op for now, but it's going to
be populated in the next commit.
src/nautilus-view-icon-controller.c | 159 +++++++++++++++++++++---------------
1 file changed, 93 insertions(+), 66 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index d6ff24f33..517be020a 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -777,11 +777,11 @@ activate_selection_on_click (NautilusViewIconController *self,
}
static void
-on_click_pressed (GtkGestureClick *gesture,
- gint n_press,
- gdouble x,
- gdouble y,
- gpointer user_data)
+on_item_click_pressed (GtkGestureClick *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
{
NautilusViewIconController *self;
GtkWidget *event_widget;
@@ -801,74 +801,58 @@ on_click_pressed (GtkGestureClick *gesture,
gtk_widget_translate_coordinates (event_widget, GTK_WIDGET (self),
x, y,
&view_x, &view_y);
- if (NAUTILUS_IS_VIEW_ICON_ITEM_UI (event_widget))
+
+ self->activate_on_release = (self->single_click_mode &&
+ button == GDK_BUTTON_PRIMARY &&
+ n_press == 1 &&
+ !selection_mode);
+
+ /* GtkGridView changes selection only with the primary button, but we
+ * need that to happen with all buttons, otherwise e.g. opening context
+ * menus would require two clicks: a primary click to select the item,
+ * followed by a secondary click to open the menu.
+ * When holding Ctrl and Shift, GtkGridView does a good job, let's not
+ * interfere in that case. */
+ if (!selection_mode && button != GDK_BUTTON_PRIMARY)
{
- self->activate_on_release = (self->single_click_mode &&
- button == GDK_BUTTON_PRIMARY &&
- n_press == 1 &&
- !selection_mode);
-
- /* GtkGridView changes selection only with the primary button, but we
- * need that to happen with all buttons, otherwise e.g. opening context
- * menus would require two clicks: a primary click to select the item,
- * followed by a secondary click to open the menu.
- * When holding Ctrl and Shift, GtkGridView does a good job, let's not
- * interfere in that case. */
- if (!selection_mode && button != GDK_BUTTON_PRIMARY)
- {
- GtkSelectionModel *selection_model = GTK_SELECTION_MODEL (self->model);
- NautilusViewItemModel *item_model;
- guint position;
+ GtkSelectionModel *selection_model = GTK_SELECTION_MODEL (self->model);
+ NautilusViewItemModel *item_model;
+ guint position;
- item_model = nautilus_view_icon_item_ui_get_model (NAUTILUS_VIEW_ICON_ITEM_UI (event_widget));
- position = nautilus_view_model_get_index (self->model, item_model);
- if (!gtk_selection_model_is_selected (selection_model, position))
- {
- gtk_selection_model_select_item (selection_model, position, TRUE);
- }
- }
+ item_model = nautilus_view_icon_item_ui_get_model (NAUTILUS_VIEW_ICON_ITEM_UI (event_widget));
+ position = nautilus_view_model_get_index (self->model, item_model);
- if (button == GDK_BUTTON_PRIMARY && n_press == 2)
- {
- activate_selection_on_click (self, modifiers & GDK_SHIFT_MASK);
- gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
- self->activate_on_release = FALSE;
- }
- else if (button == GDK_BUTTON_MIDDLE && n_press == 1 && !selection_mode)
+ if (!gtk_selection_model_is_selected (selection_model, position))
{
- activate_selection_on_click (self, TRUE);
- gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
- }
- else if (button == GDK_BUTTON_SECONDARY)
- {
- nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
- view_x, view_y);
- gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+ gtk_selection_model_select_item (selection_model, position, TRUE);
}
}
- else
- {
- /* Don't interfere with GtkGridView default selection handling when
- * holding Ctrl and Shift. */
- if (!selection_mode && !self->activate_on_release)
- {
- nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
- }
- if (button == GDK_BUTTON_SECONDARY)
- {
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
- view_x, view_y);
- }
+ if (button == GDK_BUTTON_PRIMARY && n_press == 2)
+ {
+ activate_selection_on_click (self, modifiers & GDK_SHIFT_MASK);
+ gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+ self->activate_on_release = FALSE;
+ }
+ else if (button == GDK_BUTTON_MIDDLE && n_press == 1 && !selection_mode)
+ {
+ activate_selection_on_click (self, TRUE);
+ gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+ }
+ else if (button == GDK_BUTTON_SECONDARY)
+ {
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
+ view_x, view_y);
+ gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
}
}
static void
-on_click_released (GtkGestureClick *gesture,
- gint n_press,
- gdouble x,
- gdouble y,
- gpointer user_data)
+on_item_click_released (GtkGestureClick *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
{
NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
@@ -879,6 +863,49 @@ on_click_released (GtkGestureClick *gesture,
}
}
+static void
+on_view_click_pressed (GtkGestureClick *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+ NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
+ guint button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
+ GdkModifierType modifiers = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER
(gesture));
+ gboolean selection_mode = (modifiers & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
+
+ /* Don't interfere with GtkGridView default selection handling when
+ * holding Ctrl and Shift. */
+ if (!selection_mode && !self->activate_on_release)
+ {
+ nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
+ }
+
+ if (button == GDK_BUTTON_SECONDARY)
+ {
+ GtkWidget *event_widget;
+ gdouble view_x;
+ gdouble view_y;
+
+ event_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
+ gtk_widget_translate_coordinates (event_widget, GTK_WIDGET (self),
+ x, y,
+ &view_x, &view_y);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
+ view_x, view_y);
+ }
+}
+
+static void
+on_view_click_released (GtkGestureClick *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+}
+
static void
on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
gdouble x,
@@ -1415,8 +1442,8 @@ setup_item_ui (GtkSignalListItemFactory *factory,
gtk_widget_add_controller (GTK_WIDGET (item_ui), controller);
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_BUBBLE);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (controller), 0);
- g_signal_connect (controller, "pressed", G_CALLBACK (on_click_pressed), self);
- g_signal_connect (controller, "released", G_CALLBACK (on_click_released), self);
+ g_signal_connect (controller, "pressed", G_CALLBACK (on_item_click_pressed), self);
+ g_signal_connect (controller, "released", G_CALLBACK (on_item_click_released), self);
controller = GTK_EVENT_CONTROLLER (gtk_gesture_long_press_new ());
gtk_widget_add_controller (GTK_WIDGET (item_ui), controller);
@@ -1490,9 +1517,9 @@ constructed (GObject *object)
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_BUBBLE);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (controller), 0);
g_signal_connect (controller, "pressed",
- G_CALLBACK (on_click_pressed), self);
+ G_CALLBACK (on_view_click_pressed), self);
g_signal_connect (controller, "released",
- G_CALLBACK (on_click_released), self);
+ G_CALLBACK (on_view_click_released), self);
controller = GTK_EVENT_CONTROLLER (gtk_gesture_long_press_new ());
gtk_widget_add_controller (GTK_WIDGET (self->view_ui), controller);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]