From: Christian Hergert Date: Tue, 15 Feb 2022 20:11:36 +0000 (-0800) Subject: macos: improve monitor detection at display coordinates X-Git-Tag: archive/raspbian/4.6.5+ds-1+rpi1~1^2~19^2~3^2~94^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=056e9012d2d01c04899dcb8cd4c14b1933a0b2c8;p=gtk4.git macos: improve monitor detection at display coordinates This needs to handle the boundary case where the value is exactly equal to the edge of a rectangle (which gdk_rectangle_contains_point() does not consider to be containing). However, if there is a monitor in the list that is a better match, we still want to prefer it. --- diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c index 8d3aa0224e..a76cc1e111 100644 --- a/gdk/macos/gdkmacosdisplay.c +++ b/gdk/macos/gdkmacosdisplay.c @@ -815,6 +815,7 @@ _gdk_macos_display_get_monitor_at_coords (GdkMacosDisplay *self, int x, int y) { + GdkMacosMonitor *best_match = NULL; guint n_monitors; g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), NULL); @@ -824,12 +825,25 @@ _gdk_macos_display_get_monitor_at_coords (GdkMacosDisplay *self, for (guint i = 0; i < n_monitors; i++) { GdkMacosMonitor *monitor = get_monitor (self, i); + const GdkRectangle *geom = &GDK_MONITOR (monitor)->geometry; - if (gdk_rectangle_contains_point (&GDK_MONITOR (monitor)->geometry, x, y)) - return GDK_MONITOR (monitor); + if (x >= geom->x && + y >= geom->y && + x <= (geom->x + geom->width) && + y <= (geom->y + geom->height)) + { + if (x <= geom->x + geom->width && y < geom->y + geom->height) + return GDK_MONITOR (monitor); + + /* Not an exact match as we're on a boundary, but there is + * a good chance another monitor doesn't exist there so we + * would want to still treat this as the best monitor. + */ + best_match = monitor; + } } - return NULL; + return GDK_MONITOR (best_match); } GdkMonitor *