From 0af4e7587e1b5ac9066e17b875952cb5a16e63c0 Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sun, 3 Jan 2021 16:26:25 +0900 Subject: [PATCH] Fix display-pixel-width/height to return physical pixel size. * src/pgtkfns.c (Fx_display_pixel_width): (Fx_display_pixel_height): Return bottom/right-most of all the monitors. --- src/pgtkfns.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 3e55b83872b..7d2183d2a0a 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -2408,8 +2408,35 @@ each physical monitor, use `display-monitor-attributes-list'. */) (Lisp_Object terminal) { struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); + GdkDisplay *gdpy; + gint n_monitors, i; + int width = 0; + + block_input (); + gdpy = dpyinfo->gdpy; + n_monitors = gdk_display_get_n_monitors (gdpy); + + for (i = 0; i < n_monitors; ++i) + { + GdkRectangle rec; + int scale = 1; + + GdkMonitor *monitor = gdk_display_get_monitor (gdpy, i); + gdk_monitor_get_geometry (monitor, &rec); + + /* GTK returns scaled sizes for the workareas. */ + scale = gdk_monitor_get_scale_factor (monitor); + rec.x *= scale; + rec.y *= scale; + rec.width *= scale; + rec.height *= scale; + + width = max(width, rec.x + rec.width); + } + + unblock_input (); - return make_fixnum (x_display_pixel_width (dpyinfo)); + return make_fixnum (width); } @@ -2425,8 +2452,35 @@ each physical monitor, use `display-monitor-attributes-list'. */) (Lisp_Object terminal) { struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal); + GdkDisplay *gdpy; + gint n_monitors, i; + int height = 0; + + block_input (); + gdpy = dpyinfo->gdpy; + n_monitors = gdk_display_get_n_monitors (gdpy); + + for (i = 0; i < n_monitors; ++i) + { + GdkRectangle rec; + int scale = 1; + + GdkMonitor *monitor = gdk_display_get_monitor (gdpy, i); + gdk_monitor_get_geometry (monitor, &rec); + + /* GTK returns scaled sizes for the workareas. */ + scale = gdk_monitor_get_scale_factor (monitor); + rec.x *= scale; + rec.y *= scale; + rec.width *= scale; + rec.height *= scale; + + height = max(height, rec.y + rec.height); + } + + unblock_input (); - return make_fixnum (x_display_pixel_height (dpyinfo)); + return make_fixnum (height); } DEFUN ("pgtk-display-monitor-attributes-list", Fpgtk_display_monitor_attributes_list, -- 2.39.5