From b41e015f1b70fa614cac5e847c808a39f319b389 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Mon, 26 May 2025 20:27:39 +0100 Subject: [PATCH] Fix NS port screen geometry report (bug#76051) * src/nsfns.m (Fns_display_monitor_attributes_list): Fix the arithmetic to calculate the origin of the visible frame. (cherry picked from commit 50e3bce315eb499917c1d208f87f84315f1a8b4e) --- src/nsfns.m | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/nsfns.m b/src/nsfns.m index b219064cdd1..41400e8883f 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -2692,41 +2692,28 @@ Internal use only, use `display-monitor-attributes-list' instead. */) struct MonitorInfo *m = &monitors[i]; NSRect fr = [s frame]; NSRect vfr = [s visibleFrame]; - short y, vy; #ifdef NS_IMPL_COCOA NSDictionary *dict = [s deviceDescription]; NSNumber *nid = [dict objectForKey:@"NSScreenNumber"]; CGDirectDisplayID did = [nid unsignedIntValue]; #endif + + /* The primary display is always the first in the array. */ if (i == 0) - { - primary_display_height = fr.size.height; - y = (short) fr.origin.y; - vy = (short) vfr.origin.y; - } - else - { - /* Flip y coordinate as NS screen coordinates originate from - the bottom. */ - y = (short) (primary_display_height - fr.size.height - fr.origin.y); - vy = (short) (primary_display_height - - vfr.size.height - vfr.origin.y); - } + primary_display_height = fr.size.height; + + /* Flip y coordinate as NS screen coordinates originate from + the bottom. */ m->geom.x = (short) fr.origin.x; - m->geom.y = y; + m->geom.y = (short) (primary_display_height - NSMaxY(fr)); m->geom.width = (unsigned short) fr.size.width; m->geom.height = (unsigned short) fr.size.height; + /* The work area excludes the menu bar and the dock. */ m->work.x = (short) vfr.origin.x; - /* y is flipped on NS, so vy - y are pixels missing at the - bottom, and fr.size.height - vfr.size.height are pixels - missing in total. - - Pixels missing at top are fr.size.height - vfr.size.height - - vy + y. work.y is then pixels missing at top + y. */ - m->work.y = (short) (fr.size.height - vfr.size.height) - vy + y + y; + m->work.y = (short) (primary_display_height - NSMaxY(vfr)); m->work.width = (unsigned short) vfr.size.width; m->work.height = (unsigned short) vfr.size.height; -- 2.39.5