From 20d3d62ec9a6048cacf1297622a8f7e48d6d5a4b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 29 Apr 2022 11:06:52 +0000 Subject: [PATCH] Fix colorspace calculations on Haiku * src/haiku_support.cc (be_get_display_planes) (be_get_display_color_cells): Handle grayscale basic colorspaces correctly. (be_is_display_grayscale): New function. * src/haiku_support.h: Update prototypes. * src/haikufns.c (haiku_set_no_accept_focus, haiku_iconify_frame) (Fxw_display_color_p, Fxw_color_values, Fx_display_grayscale_p): Actually handle grayscale colorspaces. (Fx_display_pixel_width, Fx_display_pixel_height) (Fx_display_mm_height, Fx_display_mm_width): Clean up coding style. (Fx_display_visual_class): Handle grayscale colorspaces. (syms_of_haikufns): New defsyms. --- src/haiku_support.cc | 81 +++++++++++++++++++++++++++++++++----------- src/haiku_support.h | 1 + src/haikufns.c | 59 ++++++++++++++++++-------------- 3 files changed, 95 insertions(+), 46 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 6dea2d36206..8ad3c58a17e 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -3587,24 +3587,35 @@ int be_get_display_planes (void) { color_space space = dpy_color_space; + BScreen screen; + if (space == B_NO_COLOR_SPACE) { - BScreen screen; /* This is actually a very slow operation. */ if (!screen.IsValid ()) gui_abort ("Invalid screen"); + space = dpy_color_space = screen.ColorSpace (); } - if (space == B_RGB32 || space == B_RGB24) - return 24; - if (space == B_RGB16) - return 16; - if (space == B_RGB15) - return 15; - if (space == B_CMAP8) - return 8; + switch (space) + { + case B_RGB32: + case B_RGB24: + return 24; + case B_RGB16: + return 16; + case B_RGB15: + return 15; + case B_CMAP8: + case B_GRAY8: + return 8; + case B_GRAY1: + return 1; + + default: + gui_abort ("Bad colorspace for screen"); + } - gui_abort ("Bad colorspace for screen"); /* https://www.haiku-os.org/docs/api/classBScreen.html says a valid screen can't be anything else. */ return -1; @@ -3614,28 +3625,58 @@ be_get_display_planes (void) int be_get_display_color_cells (void) { + BScreen screen; color_space space = dpy_color_space; + if (space == B_NO_COLOR_SPACE) { - BScreen screen; if (!screen.IsValid ()) gui_abort ("Invalid screen"); + space = dpy_color_space = screen.ColorSpace (); } - if (space == B_RGB32 || space == B_RGB24) - return 1677216; - if (space == B_RGB16) - return 65536; - if (space == B_RGB15) - return 32768; - if (space == B_CMAP8) - return 256; + switch (space) + { + case B_RGB32: + case B_RGB24: + return 16777216; + case B_RGB16: + return 65536; + case B_RGB15: + return 32768; + case B_CMAP8: + case B_GRAY8: + return 256; + case B_GRAY1: + return 2; + + default: + gui_abort ("Bad colorspace for screen"); + } - gui_abort ("Bad colorspace for screen"); return -1; } +/* Return whether or not the current display is only capable of + producing grayscale colors. */ +bool +be_is_display_grayscale (void) +{ + BScreen screen; + color_space space = dpy_color_space; + + if (space == B_NO_COLOR_SPACE) + { + if (!screen.IsValid ()) + gui_abort ("Invalid screen"); + + space = dpy_color_space = screen.ColorSpace (); + } + + return space == B_GRAY8 || space == B_GRAY1; +} + /* Warp the pointer to X by Y. */ void be_warp_pointer (int x, int y) diff --git a/src/haiku_support.h b/src/haiku_support.h index d442635476d..88edc1ae149 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -605,6 +605,7 @@ extern void EmacsWindow_unzoom (void *); extern void be_get_version_string (char *, int); extern int be_get_display_planes (void); extern int be_get_display_color_cells (void); +extern bool be_is_display_grayscale (void); extern void be_warp_pointer (int, int); extern void EmacsView_set_up_double_buffering (void *); diff --git a/src/haikufns.c b/src/haikufns.c index 7ec6f576cfe..fb79066b77f 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -511,15 +511,13 @@ haiku_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) static void haiku_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { - block_input (); if (!EQ (new_value, old_value)) FRAME_NO_ACCEPT_FOCUS (f) = !NILP (new_value); + block_input (); if (FRAME_HAIKU_WINDOW (f)) - { - BWindow_set_avoid_focus (FRAME_HAIKU_WINDOW (f), - FRAME_NO_ACCEPT_FOCUS (f)); - } + BWindow_set_avoid_focus (FRAME_HAIKU_WINDOW (f), + FRAME_NO_ACCEPT_FOCUS (f)); unblock_input (); } @@ -1626,13 +1624,11 @@ haiku_iconify_frame (struct frame *frame) if (FRAME_ICONIFIED_P (frame)) return; - block_input (); - SET_FRAME_VISIBLE (frame, false); SET_FRAME_ICONIFIED (frame, true); + block_input (); BWindow_iconify (FRAME_HAIKU_WINDOW (frame)); - unblock_input (); } @@ -1841,7 +1837,9 @@ DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, doc: /* SKIP: real doc in xfns.c. */) (Lisp_Object terminal) { - return Qt; + check_haiku_display_info (terminal); + + return be_is_display_grayscale () ? Qnil : Qt; } DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, @@ -1861,20 +1859,19 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, (Lisp_Object color, Lisp_Object frame) { Emacs_Color col; + int rc; CHECK_STRING (color); decode_window_system_frame (frame); block_input (); - if (haiku_get_color (SSDATA (color), &col)) - { - unblock_input (); - return Qnil; - } + rc = haiku_get_color (SSDATA (color), &col); unblock_input (); - return list3i (lrint (col.red), lrint (col.green), - lrint (col.blue)); + if (rc) + return Qnil; + + return list3i (col.red, col.green, col.blue); } DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, @@ -1882,7 +1879,9 @@ DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, doc: /* SKIP: real doc in xfns.c. */) (Lisp_Object terminal) { - return Qnil; + check_haiku_display_info (terminal); + + return be_is_display_grayscale () ? Qt : Qnil; } DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, @@ -1923,9 +1922,9 @@ DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, (Lisp_Object terminal) { + int width, height; check_haiku_display_info (terminal); - int width, height; BScreen_px_dim (&width, &height); return make_fixnum (width); } @@ -1936,9 +1935,9 @@ DEFUN ("x-display-pixel-height", Fx_display_pixel_height, Sx_display_pixel_heigh (Lisp_Object terminal) { + int width, height; check_haiku_display_info (terminal); - int width, height; BScreen_px_dim (&width, &height); return make_fixnum (width); } @@ -1948,10 +1947,9 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, (Lisp_Object terminal) { struct haiku_display_info *dpyinfo = check_haiku_display_info (terminal); - int width, height; - BScreen_px_dim (&width, &height); + BScreen_px_dim (&width, &height); return make_fixnum (height / (dpyinfo->resy / 25.4)); } @@ -1961,10 +1959,9 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, (Lisp_Object terminal) { struct haiku_display_info *dpyinfo = check_haiku_display_info (terminal); - int width, height; - BScreen_px_dim (&width, &height); + BScreen_px_dim (&width, &height); return make_fixnum (width / (dpyinfo->resx / 25.4)); } @@ -1981,14 +1978,20 @@ DEFUN ("x-display-visual-class", Fx_display_visual_class, doc: /* SKIP: real doc in xfns.c. */) (Lisp_Object terminal) { + int planes; + bool grayscale_p; + check_haiku_display_info (terminal); - int planes = be_get_display_planes (); + grayscale_p = be_is_display_grayscale (); + if (grayscale_p) + return Qstatic_gray; + planes = be_get_display_planes (); if (planes == 8) - return intern ("static-color"); + return Qstatic_color; - return intern ("true-color"); + return Qtrue_color; } DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, @@ -2742,6 +2745,10 @@ syms_of_haikufns (void) DEFSYM (Qwhen_mapped, "when-mapped"); DEFSYM (Qtooltip_reuse_hidden_frame, "tooltip-reuse-hidden-frame"); + DEFSYM (Qstatic_color, "static-color"); + DEFSYM (Qstatic_gray, "static-gray"); + DEFSYM (Qtrue_color, "true-color"); + defsubr (&Sx_hide_tip); defsubr (&Sxw_display_color_p); defsubr (&Sx_display_grayscale_p); -- 2.39.2