Merge branch 'dnd-coordinates2' into 'gtk-3-24'

gtk: Properly calculate device offset for DnD

See merge request GNOME/gtk!1104
This commit is contained in:
Jonas Ådahl 2019-09-27 15:56:01 +00:00
commit c05f25d968
5 changed files with 17 additions and 7 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);