From ded4413acc6a894bd47736672cceb960bf0fad7d Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 6 May 2022 07:28:23 +0000 Subject: [PATCH] Fix calculation of display resolution on Haiku * src/haiku_support.cc (BScreen_px_dim): Rename to `be_get_screen_dimensions'. (BScreen_res): Rename to `be_get_display_resolution' and fix resolution computation. * src/haiku_support.h: Update prototypes. * src/haikufns.c (compute_tip_xy, Fx_display_pixel_width) (Fx_display_pixel_height, Fx_display_mm_height) (Fx_display_mm_width): Update accordingly. * src/haikuterm.c (haiku_term_init): Likewise. --- src/haiku_support.cc | 38 ++++++++++++++++++++++++-------------- src/haiku_support.h | 4 ++-- src/haikufns.c | 14 +++++++++----- src/haikuterm.c | 4 ++-- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 0ab31bc98dc..b8fa963c627 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -3265,15 +3265,18 @@ BWindow_activate (void *window) /* Return the pixel dimensions of the main screen in WIDTH and HEIGHT. */ void -BScreen_px_dim (int *width, int *height) +be_get_screen_dimensions (int *width, int *height) { BScreen screen; + BRect frame; + if (!screen.IsValid ()) gui_abort ("Invalid screen"); - BRect frame = screen.Frame (); - *width = frame.right - frame.left; - *height = frame.bottom - frame.top; + frame = screen.Frame (); + + *width = 1 + frame.right - frame.left; + *height = 1 + frame.bottom - frame.top; } /* Resize VIEW to WIDTH, HEIGHT. */ @@ -4129,25 +4132,32 @@ BAlert_delete (void *alert) delete (BAlert *) alert; } -/* Place the resolution of the monitor in DPI in RSSX and RSSY. */ +/* Place the resolution of the monitor in DPI in X_OUT and Y_OUT. */ void -BScreen_res (double *rrsx, double *rrsy) +be_get_display_resolution (double *x_out, double *y_out) { BScreen s (B_MAIN_SCREEN_ID); + monitor_info i; + double x_inches, y_inches; + BRect frame; + if (!s.IsValid ()) gui_abort ("Invalid screen for resolution checks"); - monitor_info i; if (s.GetMonitorInfo (&i) == B_OK) { - *rrsx = (double) i.width / (double) 2.54; - *rrsy = (double) i.height / (double) 2.54; - } - else - { - *rrsx = 72.27; - *rrsy = 72.27; + frame = s.Frame (); + + x_inches = (double) i.width * 25.4; + y_inches = (double) i.height * 25.4; + + *x_out = (double) BE_RECT_WIDTH (frame) / x_inches; + *y_out = (double) BE_RECT_HEIGHT (frame) / y_inches; + return; } + + *x_out = 72.0; + *y_out = 72.0; } /* Add WINDOW to OTHER_WINDOW's subset and parent it to diff --git a/src/haiku_support.h b/src/haiku_support.h index 0fe2af3329a..1433783c9fb 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -549,8 +549,8 @@ extern void BView_scroll_bar_update (void *, int, int, int, int, bool); extern void *BBitmap_transform_bitmap (void *, void *, uint32_t, double, int, int); -extern void BScreen_px_dim (int *, int *); -extern void BScreen_res (double *, double *); +extern void be_get_display_resolution (double *, double *); +extern void be_get_screen_dimensions (int *, int *); /* Functions for creating and freeing cursors. */ extern void *BCursor_create_default (void); diff --git a/src/haikufns.c b/src/haikufns.c index e88ded23ffe..2f26623fa5c 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -1203,7 +1203,11 @@ compute_tip_xy (struct frame *f, /* Default min and max values. */ min_x = 0; min_y = 0; - BScreen_px_dim (&max_x, &max_y); + + be_get_screen_dimensions (&max_x, &max_y); + + max_x = max_x - 1; + max_y = max_y - 1; block_input (); BView_get_mouse (FRAME_HAIKU_VIEW (f), &x, &y); @@ -1917,7 +1921,7 @@ DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, int width, height; check_haiku_display_info (terminal); - BScreen_px_dim (&width, &height); + be_get_screen_dimensions (&width, &height); return make_fixnum (width); } @@ -1930,7 +1934,7 @@ DEFUN ("x-display-pixel-height", Fx_display_pixel_height, Sx_display_pixel_heigh int width, height; check_haiku_display_info (terminal); - BScreen_px_dim (&width, &height); + be_get_screen_dimensions (&width, &height); return make_fixnum (width); } @@ -1941,7 +1945,7 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, struct haiku_display_info *dpyinfo = check_haiku_display_info (terminal); int width, height; - BScreen_px_dim (&width, &height); + be_get_screen_dimensions (&width, &height); return make_fixnum (height / (dpyinfo->resy / 25.4)); } @@ -1953,7 +1957,7 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, struct haiku_display_info *dpyinfo = check_haiku_display_info (terminal); int width, height; - BScreen_px_dim (&width, &height); + be_get_screen_dimensions (&width, &height); return make_fixnum (width / (dpyinfo->resx / 25.4)); } diff --git a/src/haikuterm.c b/src/haikuterm.c index b903e017e40..ced16d9f09b 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -3939,9 +3939,9 @@ haiku_term_init (void) dpyinfo->display = BApplication_setup (); dpyinfo->next = x_display_list; dpyinfo->n_planes = be_get_display_planes (); - x_display_list = dpyinfo; + be_get_display_resolution (&dpyinfo->resx, &dpyinfo->resy); - BScreen_res (&dpyinfo->resx, &dpyinfo->resy); + x_display_list = dpyinfo; terminal = haiku_create_terminal (dpyinfo); if (current_kboard == initial_kboard) -- 2.39.2