[nautilus/2101-tabs-are-missing-context-menu] notebook: Translate coordinates to find clicked tab



commit 6f9b41972ad6dde8ac92158ca489d9eace34f2bb
Author: António Fernandes <antoniof gnome org>
Date:   Mon Jan 10 11:51:46 2022 +0000

    notebook: Translate coordinates to find clicked tab
    
    In GTK3, the tab label allocation was given in coordinates which were
    relative to the parent widget's allocation.
    
    In GTK4 the allocation is for the widget's own coordinates instead.
    
    Translate the event coordinates accordingly to make this logic work
    again. Also, test for the lower limit in addition to the upper limit.

 src/nautilus-notebook.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 96a8ca97b..5767d22a9 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -49,7 +49,7 @@ find_tab_num_at_pos (GtkNotebook *notebook,
     while ((page = gtk_notebook_get_nth_page (notebook, page_num)))
     {
         GtkWidget *tab;
-        gint max_x, max_y;
+        gdouble tab_x, tab_y;
 
         tab = gtk_notebook_get_tab_label (notebook, page);
         g_return_val_if_fail (tab != NULL, -1);
@@ -61,11 +61,11 @@ find_tab_num_at_pos (GtkNotebook *notebook,
         }
 
         gtk_widget_get_allocation (tab, &allocation);
+        gtk_widget_translate_coordinates (GTK_WIDGET (notebook), tab,
+                                          abs_x, abs_y, &tab_x, &tab_y);
 
-        max_x = allocation.x + allocation.width;
-        max_y = allocation.y + allocation.height;
-
-        if (abs_x <= max_x && abs_y <= max_y)
+        if (tab_x >= allocation.x && tab_x <= allocation.x + allocation.width &&
+            tab_y >= allocation.y && tab_y <= allocation.y + allocation.height)
         {
             return page_num;
         }


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