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.
This commit is contained in:
parent
5d23819c69
commit
77e0d83000
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user