[nautilus/wip/antoniof/flow-box-preparation: 10/26] view-icon-controller: Fix selection when scrolled
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/flow-box-preparation: 10/26] view-icon-controller: Fix selection when scrolled
- Date: Sun, 26 Dec 2021 22:16:37 +0000 (UTC)
commit a94609751f845a838a184c492531fe01e20a2623
Author: António Fernandes <antoniof gnome org>
Date: Wed Dec 8 23:25:56 2021 +0000
view-icon-controller: Fix selection when scrolled
We add a click gesture to the scrolled window, not the view itself,
because we need to get background context menus on whitespace around
the flowbox (not only padding but bottom whitespace when the rows
don't fill the whole height).
Because of that, the selected item may not be the one which the user
had selected (e.g. if the view is scrolled away from the top).
Translate the coordinates properly to properly select the item where
the user had clicked. Do the same for the longpress gesture.
src/nautilus-view-icon-controller.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 569cbed51..48d30c294 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -698,6 +698,8 @@ on_button_press_event (GtkGestureMultiPress *gesture,
GdkEventSequence *sequence;
const GdkEvent *event;
g_autolist (NautilusFile) selection = NULL;
+ gint view_x;
+ gint view_y;
GtkFlowBoxChild *child_at_pos;
self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
@@ -707,7 +709,11 @@ on_button_press_event (GtkGestureMultiPress *gesture,
/* Need to update the selection so the popup has the right actions enabled */
selection = nautilus_view_get_selection (NAUTILUS_VIEW (self));
- child_at_pos = gtk_flow_box_get_child_at_pos (self->view_ui, x, y);
+
+ gtk_widget_translate_coordinates (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
+ GTK_WIDGET (self->view_ui),
+ x, y, &view_x, &view_y);
+ child_at_pos = gtk_flow_box_get_child_at_pos (self->view_ui, view_x, view_y);
if (child_at_pos != NULL)
{
NautilusFile *selected_file;
@@ -756,6 +762,8 @@ on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
GtkFlowBoxChild *child_at_pos;
GdkEventSequence *event_sequence;
GdkEvent *event;
+ gint view_x;
+ gint view_y;
event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
@@ -764,7 +772,10 @@ on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
/* Need to update the selection so the popup has the right actions enabled */
selection = nautilus_view_get_selection (NAUTILUS_VIEW (self));
- child_at_pos = gtk_flow_box_get_child_at_pos (self->view_ui, x, y);
+ gtk_widget_translate_coordinates (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
+ GTK_WIDGET (self->view_ui),
+ x, y, &view_x, &view_y);
+ child_at_pos = gtk_flow_box_get_child_at_pos (self->view_ui, view_x, view_y);
if (child_at_pos != NULL)
{
NautilusFile *selected_file;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]