[gtk/wip/chergert/for-macos-1: 1/3] macos: improve monitor detection at display coordinates
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/for-macos-1: 1/3] macos: improve monitor detection at display coordinates
- Date: Wed, 16 Feb 2022 10:52:25 +0000 (UTC)
commit 056e9012d2d01c04899dcb8cd4c14b1933a0b2c8
Author: Christian Hergert <christian hergert me>
Date: Tue Feb 15 12:11:36 2022 -0800
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.
gdk/macos/gdkmacosdisplay.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
---
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 *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]