[gtk/gtk-3-24: 1/2] macos: correctly handle retina cursors
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-3-24: 1/2] macos: correctly handle retina cursors
- Date: Thu, 27 Jan 2022 05:43:51 +0000 (UTC)
commit 021cdf382d6f12adcfc2ed1259fda8245c120347
Author: Lukas Oberhuber <lukaso gmail com>
Date: Fri Jan 14 00:01:38 2022 +0000
macos: correctly handle retina cursors
This change correctly sizes HiDPI curors on macOS.
Before this, the cursors would appear double the size of normal cursors
on non HiDPI screens.
Based in part on this comment:
https://gitlab.gnome.org/GNOME/gtk/-/issues/613#note_687914
gdk/quartz/gdkcursor-quartz.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gdk/quartz/gdkcursor-quartz.c b/gdk/quartz/gdkcursor-quartz.c
index ad9228f90c..0a938e093d 100644
--- a/gdk/quartz/gdkcursor-quartz.c
+++ b/gdk/quartz/gdkcursor-quartz.c
@@ -261,14 +261,21 @@ _gdk_quartz_display_get_cursor_for_surface (GdkDisplay *display,
NSCursor *nscursor;
GdkCursor *cursor;
GdkPixbuf *pixbuf;
+ double x_scale;
+ double y_scale;
GDK_QUARTZ_ALLOC_POOL;
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
+ cairo_surface_get_device_scale (surface,
+ &x_scale,
+ &y_scale);
image = gdk_quartz_pixbuf_to_ns_image_libgtk_only (pixbuf);
- nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x, y)];
+ NSImageRep *rep = [[image representations] objectAtIndex:0];
+ [image setSize:NSMakeSize(rep.pixelsWide / x_scale, rep.pixelsHigh / y_scale)];
+ nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x / x_scale, y / y_scale)];
cursor = gdk_quartz_cursor_new_from_nscursor (nscursor, GDK_CURSOR_IS_PIXMAP);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]