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.
This commit is contained in:
Po Lu 2022-05-06 07:28:23 +00:00
parent 7609c6cadb
commit ded4413acc
4 changed files with 37 additions and 23 deletions

View file

@ -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

View file

@ -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);

View file

@ -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));
}

View file

@ -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)