[gtk/gtk-3-24: 1/2] gtk: Properly calculate device offset for DnD



commit 77e0d830009a6450c2e3d6c8062e264d0baf96a7
Author: Robert Mader <robert mader posteo de>
Date:   Sun Sep 22 15:58:28 2019 +0200

    gtk: Properly calculate device offset for DnD
    
    We need to take the device scale into account, like it is done in
    gdkwindow.c.
    
    This fixes wrongly placed DnD surfaces in scaled contexts on X11
    as well as Wayland.

 examples/listbox-dnd.c | 4 +++-
 gtk/gtkentry.c         | 6 ++++--
 gtk/gtkiconview.c      | 4 +++-
 gtk/gtktreeview.c      | 6 ++++--
 tests/testlist3.c      | 4 +++-
 5 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/examples/listbox-dnd.c b/examples/listbox-dnd.c
index ab77209629..6f333934d6 100644
--- a/examples/listbox-dnd.c
+++ b/examples/listbox-dnd.c
@@ -14,6 +14,7 @@ drag_begin (GtkWidget      *widget,
   cairo_surface_t *surface;
   cairo_t *cr;
   int x, y;
+  double sx, sy;
 
   row = gtk_widget_get_ancestor (widget, GTK_TYPE_LIST_BOX_ROW);
   gtk_widget_get_allocation (row, &alloc);
@@ -25,7 +26,8 @@ drag_begin (GtkWidget      *widget,
   gtk_style_context_remove_class (gtk_widget_get_style_context (row), "drag-icon");
 
   gtk_widget_translate_coordinates (widget, row, 0, 0, &x, &y);
-  cairo_surface_set_device_offset (surface, -x, -y);
+  cairo_surface_get_device_scale (surface, &sx, &sy);
+  cairo_surface_set_device_offset (surface, -x * sx, -y * sy);
   gtk_drag_set_icon_surface (context, surface);
 
   cairo_destroy (cr);
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 54a8bcd3ff..eec28a5ba9 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -9911,13 +9911,15 @@ gtk_entry_drag_begin (GtkWidget      *widget,
     {
       gint *ranges, n_ranges;
       cairo_surface_t *surface;
+      double sx, sy;
 
       surface = _gtk_text_util_create_drag_icon (widget, text, -1);
 
       gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
+      cairo_surface_get_device_scale (surface, &sx, &sy);
       cairo_surface_set_device_offset (surface,
-                                       -(priv->drag_start_x - ranges[0]),
-                                       -(priv->drag_start_y));
+                                       -(priv->drag_start_x - ranges[0]) * sx,
+                                       -(priv->drag_start_y) * sy);
       g_free (ranges);
 
       gtk_drag_set_icon_surface (context, surface);
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 00084b4998..735695ef2c 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -6485,6 +6485,7 @@ gtk_icon_view_drag_begin (GtkWidget      *widget,
   cairo_surface_t *icon;
   gint x, y;
   GtkTreePath *path;
+  double sx, sy;
 
   icon_view = GTK_ICON_VIEW (widget);
 
@@ -6507,7 +6508,8 @@ gtk_icon_view_drag_begin (GtkWidget      *widget,
   icon = gtk_icon_view_create_drag_icon (icon_view, path);
   gtk_tree_path_free (path);
 
-  cairo_surface_set_device_offset (icon, -x, -y);
+  cairo_surface_get_device_scale (icon, &sx, &sy);
+  cairo_surface_set_device_offset (icon, -x * sx, -y * sy);
 
   gtk_drag_set_icon_surface (context, icon);
 
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 6364ca8aca..1407a8e96a 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -7944,6 +7944,7 @@ gtk_tree_view_drag_begin (GtkWidget      *widget,
   gint cell_x, cell_y;
   cairo_surface_t *row_pix;
   TreeViewDragInfo *di;
+  double sx, sy;
 
   tree_view = GTK_TREE_VIEW (widget);
 
@@ -7972,10 +7973,11 @@ gtk_tree_view_drag_begin (GtkWidget      *widget,
 
   row_pix = gtk_tree_view_create_row_drag_icon (tree_view,
                                                 path);
+  cairo_surface_get_device_scale (row_pix, &sx, &sy);
   cairo_surface_set_device_offset (row_pix,
                                    /* the + 1 is for the black border in the icon */
-                                   - (tree_view->priv->press_start_x + 1),
-                                   - (cell_y + 1));
+                                   - (tree_view->priv->press_start_x + 1) * sx,
+                                   - (cell_y + 1) * sy);
 
   gtk_drag_set_icon_surface (context, row_pix);
 
diff --git a/tests/testlist3.c b/tests/testlist3.c
index ddd194c489..9a8d1c6603 100644
--- a/tests/testlist3.c
+++ b/tests/testlist3.c
@@ -14,6 +14,7 @@ drag_begin (GtkWidget      *widget,
   cairo_surface_t *surface;
   cairo_t *cr;
   int x, y;
+  double sx, sy;
 
   row = gtk_widget_get_ancestor (widget, GTK_TYPE_LIST_BOX_ROW);
   gtk_widget_get_allocation (row, &alloc);
@@ -25,7 +26,8 @@ drag_begin (GtkWidget      *widget,
   gtk_style_context_remove_class (gtk_widget_get_style_context (row), "drag-icon");
 
   gtk_widget_translate_coordinates (widget, row, 0, 0, &x, &y);
-  cairo_surface_set_device_offset (surface, -x, -y);
+  cairo_surface_get_device_scale (surface, &sx, &sy);
+  cairo_surface_set_device_offset (surface, -x * sy, -y * sy);
   gtk_drag_set_icon_surface (context, surface);
 
   cairo_destroy (cr);


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