[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 8/29] list-view: Translate coordinates for underline on hover




commit fa8735e441af2020dc0114017c96490b0e4b4e69
Author: António Fernandes <antoniof gnome org>
Date:   Sat Aug 7 22:38:42 2021 +0100

    list-view: Translate coordinates for underline on hover
    
    gtk_tree_view_get_path_at_pos() requires bin_window coordinates, which
    happened to be what the ::event coordinates were (because bin_window
    was the event's GdkWindow).
    
    However, with GtkEventControllerMotion we get widget coordinates. This
    causes glytches with the underline.
    
    Translating the coordinates fixes the regression.

 src/nautilus-list-view.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 0bba76860..12c7b8af5 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -327,6 +327,8 @@ on_event_controller_motion_motion (GtkEventControllerMotion *controller,
     NautilusListView *view;
     GtkWidget *widget;
     GtkTreePath *old_hover_path;
+    int x_in_bin;
+    int y_in_bin;
 
     if (get_click_policy () != NAUTILUS_CLICK_POLICY_SINGLE)
     {
@@ -337,8 +339,11 @@ on_event_controller_motion_motion (GtkEventControllerMotion *controller,
     widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
     old_hover_path = view->details->hover_path;
 
+    gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (widget),
+                                                       x, y,
+                                                       &x_in_bin, &y_in_bin);
     gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
-                                   x, y,
+                                   x_in_bin, y_in_bin,
                                    &view->details->hover_path,
                                    NULL, NULL, NULL);
 
@@ -386,6 +391,8 @@ on_event_controller_motion_enter (GtkEventControllerMotion *controller,
 {
     NautilusListView *view;
     GtkWidget *widget;
+    int x_in_bin;
+    int y_in_bin;
 
     if (get_click_policy () != NAUTILUS_CLICK_POLICY_SINGLE)
     {
@@ -399,8 +406,11 @@ on_event_controller_motion_enter (GtkEventControllerMotion *controller,
     }
     widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
 
+    gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (widget),
+                                                       x, y,
+                                                       &x_in_bin, &y_in_bin);
     gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
-                                   x, y,
+                                   x_in_bin, y_in_bin,
                                    &view->details->hover_path,
                                    NULL, NULL, NULL);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]