aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShay Elkin2026-02-11 15:28:11 -0800
committerAlan Third2026-02-21 17:37:56 +0000
commita7dbf2427aed70e9c44caa82e1e9d47085ff6d9c (patch)
treef1a22c7ad8df49d371e0ef96f96211561c738c5c /src
parentc6cedfbb2f29992c911a9a730d1567bf6a9adbad (diff)
downloademacs-a7dbf2427aed70e9c44caa82e1e9d47085ff6d9c.tar.gz
emacs-a7dbf2427aed70e9c44caa82e1e9d47085ff6d9c.zip
Use real display geometry on NS (bug#80331)
In nsfns.m, `x-display-mm-height' and `x-display-mm-weight' computes the display size by dividing its (logical) pixel dimensions by 92 dpi. This would often give wrong results: by default, logical pixels on in macOS are computed to 72 dpi, but that can be changed by the user. As macOS multi-screen geometry is all computed based on the main screen's cooridnate system, use its dpi to compute the physical size of the bounding box containing all the screens. * src/nsfns.m (Fx_display_mm_height): (Fx_display_mm_width): Calculate the total physical display size using the main-screen's geometry. Copyright-paperwork-exempt: yes
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index dddceb8d17b..cdd293b8c41 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1995,9 +1995,20 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1,
1995 doc: /* SKIP: real doc in xfns.c. */) 1995 doc: /* SKIP: real doc in xfns.c. */)
1996 (Lisp_Object terminal) 1996 (Lisp_Object terminal)
1997{ 1997{
1998 double px_to_mm;
1998 struct ns_display_info *dpyinfo = check_ns_display_info (terminal); 1999 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
1999 2000
2000 return make_fixnum (ns_display_pixel_height (dpyinfo) / (92.0/25.4)); 2001#ifdef NS_IMPL_COCOA
2002 CGDirectDisplayID did = CGMainDisplayID ();
2003 CGSize size_mm = CGDisplayScreenSize (did);
2004 CGRect bounds = CGDisplayBounds (did);
2005
2006 px_to_mm = size_mm.height / bounds.size.height;
2007#else
2008 dpi = 25.4 / dpyinfo->resx;
2009#endif
2010
2011 return make_fixnum (ns_display_pixel_height (dpyinfo) * px_to_mm);
2001} 2012}
2002 2013
2003 2014
@@ -2005,9 +2016,20 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
2005 doc: /* SKIP: real doc in xfns.c. */) 2016 doc: /* SKIP: real doc in xfns.c. */)
2006 (Lisp_Object terminal) 2017 (Lisp_Object terminal)
2007{ 2018{
2019 double px_to_mm;
2008 struct ns_display_info *dpyinfo = check_ns_display_info (terminal); 2020 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
2009 2021
2010 return make_fixnum (ns_display_pixel_width (dpyinfo) / (92.0/25.4)); 2022#ifdef NS_IMPL_COCOA
2023 CGDirectDisplayID did = CGMainDisplayID ();
2024 CGSize size_mm = CGDisplayScreenSize (did);
2025 CGRect bounds = CGDisplayBounds (did);
2026
2027 px_to_mm = size_mm.width / bounds.size.width;
2028#else
2029 px_to_mm = 25.4 / dpyinfo->resy;
2030#endif
2031
2032 return make_fixnum (ns_display_pixel_width (dpyinfo) * px_to_mm);
2011} 2033}
2012 2034
2013 2035