From 78801c6e211b966d4730759e56ae65f94ef8bc8a Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sun, 3 Jan 2021 16:22:34 +0900 Subject: [PATCH] Make display-mm-width/height consider multi-monitor. * src/pgtkfns.c (Fx_display_mm_height): (Fx_display_mm_width): Calculate width/height mm assuming monitor other than origin does not overlap. --- src/pgtkfns.c | 58 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/pgtkfns.c b/src/pgtkfns.c index f52dab6dbe8..3e55b83872b 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -2047,9 +2047,32 @@ for each physical monitor, use `display-monitor-attributes-list'. */) (Lisp_Object terminal) { struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); - GdkDisplay *gdpy = dpyinfo->gdpy; - GdkMonitor *gmon = gdk_display_get_monitor_at_point (gdpy, 0, 0); - return make_fixnum (gdk_monitor_get_height_mm (gmon)); + GdkDisplay *gdpy; + gint n_monitors, i; + int height_mm_at_0 = 0, height_mm_at_other = 0; + + block_input (); + gdpy = dpyinfo->gdpy; + n_monitors = gdk_display_get_n_monitors (gdpy); + + for (i = 0; i < n_monitors; ++i) + { + GdkRectangle rec; + + GdkMonitor *monitor = gdk_display_get_monitor (gdpy, i); + gdk_monitor_get_geometry (monitor, &rec); + + int mm = gdk_monitor_get_height_mm (monitor); + + if (rec.y == 0) + height_mm_at_0 = max(height_mm_at_0, mm); + else + height_mm_at_other += mm; + } + + unblock_input (); + + return make_fixnum (height_mm_at_0 + height_mm_at_other); } @@ -2065,9 +2088,32 @@ for each physical monitor, use `display-monitor-attributes-list'. */) (Lisp_Object terminal) { struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); - GdkDisplay *gdpy = dpyinfo->gdpy; - GdkMonitor *gmon = gdk_display_get_monitor_at_point (gdpy, 0, 0); - return make_fixnum (gdk_monitor_get_width_mm (gmon)); + GdkDisplay *gdpy; + gint n_monitors, i; + int width_mm_at_0 = 0, width_mm_at_other = 0; + + block_input (); + gdpy = dpyinfo->gdpy; + n_monitors = gdk_display_get_n_monitors (gdpy); + + for (i = 0; i < n_monitors; ++i) + { + GdkRectangle rec; + + GdkMonitor *monitor = gdk_display_get_monitor (gdpy, i); + gdk_monitor_get_geometry (monitor, &rec); + + int mm = gdk_monitor_get_width_mm (monitor); + + if (rec.x == 0) + width_mm_at_0 = max(width_mm_at_0, mm); + else + width_mm_at_other += mm; + } + + unblock_input (); + + return make_fixnum (width_mm_at_0 + width_mm_at_other); } -- 2.39.5