From: Po Lu Date: Sun, 24 Apr 2022 05:37:22 +0000 (+0000) Subject: Allow looking up window system colors on Haiku X-Git-Tag: emacs-29.0.90~1931^2~336 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e2d870016cb3981baef128cabe849fdb63127541;p=emacs.git Allow looking up window system colors on Haiku * lisp/help-fns.el (help-fns--editable-variable): Fix describing variables which don't have symbol values. * lisp/term/haiku-win.el (haiku-allowed-ui-colors): Set list of allowed UI colors. * src/haiku_support.cc (be_get_ui_color): New function. * src/haiku_support.h: Update prototypes. * src/haikufns.c (haiku_get_color): Look for defined UI color. (syms_of_haikufns): New defvar `haiku-allowed-ui-colors'. * src/haikuterm.c (haiku_term_init): Fix coding style. --- diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 0e46ca1c559..12a4ecf2f3a 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1303,8 +1303,8 @@ it is displayed along with the global value." (defun help-fns--editable-variable (start end variable value buffer) (when (and (readablep value) - (not (boundp value)) - (not (fboundp value)) + (not (and (symbolp value) (boundp value))) + (not (and (symbolp value) (fboundp value))) help-enable-variable-value-editing) (add-text-properties start end diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el index 955947fe6a2..dddad544fa3 100644 --- a/lisp/term/haiku-win.el +++ b/lisp/term/haiku-win.el @@ -46,6 +46,7 @@ (defvar haiku-initialized) (defvar haiku-signal-invalid-refs) (defvar haiku-drag-track-function) +(defvar haiku-allowed-ui-colors) (defvar haiku-dnd-selection-value nil "The local value of the special `XdndSelection' selection.") @@ -74,6 +75,29 @@ content that is being put into the selection by `gui-set-selection'. See the doc string of `haiku-drag-message' for more details on the structure of the associations.") +;; This list has to be set correctly, otherwise Emacs will crash upon +;; encountering an invalid color. +(setq haiku-allowed-ui-colors + ["B_PANEL_BACKGROUND_COLOR" "B_MENU_BACKGROUND_COLOR" + "B_WINDOW_TAB_COLOR" "B_KEYBOARD_NAVIGATION_COLOR" + "B_DESKTOP_COLOR" "B_MENU_SELECTED_BACKGROUND_COLOR" + "B_MENU_ITEM_TEXT_COLOR" "B_MENU_SELECTED_ITEM_TEXT_COLOR" + "B_MENU_SELECTED_BORDER_COLOR" "B_PANEL_TEXT_COLOR" + "B_DOCUMENT_BACKGROUND_COLOR" "B_DOCUMENT_TEXT_COLOR" + "B_CONTROL_BACKGROUND_COLOR" "B_CONTROL_TEXT_COLOR" + "B_CONTROL_BORDER_COLOR" "B_CONTROL_HIGHLIGHT_COLOR" + "B_NAVIGATION_PULSE_COLOR" "B_SHINE_COLOR" + "B_SHADOW_COLOR" "B_TOOLTIP_BACKGROUND_COLOR" + "B_TOOLTIP_TEXT_COLOR" "B_WINDOW_TEXT_COLOR" + "B_WINDOW_INACTIVE_TAB_COLOR" "B_WINDOW_INACTIVE_TEXT_COLOR" + "B_WINDOW_BORDER_COLOR" "B_WINDOW_INACTIVE_BORDER_COLOR" + "B_CONTROL_MARK_COLOR" "B_LIST_BACKGROUND_COLOR" + "B_LIST_SELECTED_BACKGROUND_COLOR" "B_LIST_ITEM_TEXT_COLOR" + "B_LIST_SELECTED_ITEM_TEXT_COLOR" "B_SCROLL_BAR_THUMB_COLOR" + "B_LINK_TEXT_COLOR" "B_LINK_HOVER_COLOR" + "B_LINK_VISITED_COLOR" "B_LINK_ACTIVE_COLOR" + "B_STATUS_BAR_COLOR" "B_SUCCESS_COLOR" "B_FAILURE_COLOR"]) + (defun haiku-selection-bounds (value) "Return bounds of selection value VALUE. The return value is a list (BEG END BUF) if VALUE is a cons of diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 2ec536729f6..eb9379f17d7 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -4323,3 +4323,21 @@ BWindow_set_z_group (void *window, enum haiku_z_group z_group) w->UnlockLooper (); } } + +int +be_get_ui_color (const char *name, uint32_t *color) +{ + color_which which; + rgb_color rgb; + + which = which_ui_color (name); + + if (which == B_NO_COLOR) + return 1; + + rgb = ui_color (which); + *color = (rgb.blue | rgb.green << 8 + | rgb.red << 16 | 255 << 24); + + return 0; +} diff --git a/src/haiku_support.h b/src/haiku_support.h index 3f071f2b09e..3337df55515 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -639,6 +639,7 @@ extern int be_get_display_screens (void); extern bool be_use_subpixel_antialiasing (void); extern const char *be_find_setting (const char *); extern haiku_font_family_or_style *be_list_font_families (size_t *); +extern int be_get_ui_color (const char *, uint32 *); extern void BMessage_delete (void *); @@ -648,7 +649,6 @@ extern bool be_drag_message (void *, void *, bool, void (*) (void), extern bool be_drag_and_drop_in_progress (void); extern bool be_replay_menu_bar_event (void *, struct haiku_menu_bar_click_event *); - #ifdef __cplusplus } diff --git a/src/haikufns.c b/src/haikufns.c index 979a47d7668..4f4979fe094 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -253,7 +253,10 @@ haiku_get_color (const char *name, Emacs_Color *color) { unsigned short r16, g16, b16; Lisp_Object tem, col; - int32 clr; + int32 clr, rc; + uint32_t ui_color; + ptrdiff_t size, i; + Lisp_Object string; if (parse_color_spec (name, &r16, &g16, &b16)) { @@ -283,11 +286,34 @@ haiku_get_color (const char *name, Emacs_Color *color) return 0; } } - unblock_input (); } - return 1; + rc = 1; + if (VECTORP (Vhaiku_allowed_ui_colors)) + { + size = ASIZE (Vhaiku_allowed_ui_colors); + + for (i = 0; i < size; ++i) + { + string = AREF (Vhaiku_allowed_ui_colors, i); + + block_input (); + if (STRINGP (string) && !strcmp (SSDATA (string), name)) + rc = be_get_ui_color (name, &ui_color); + unblock_input (); + } + } + + if (!rc) + { + color->pixel = ui_color; + color->red = RED_FROM_ULONG (ui_color) * 257; + color->green = GREEN_FROM_ULONG (ui_color) * 257; + color->blue = BLUE_FROM_ULONG (ui_color) * 257; + } + + return rc; } static struct haiku_display_info * @@ -2742,6 +2768,12 @@ syms_of_haikufns (void) doc: /* SKIP: real doc in xfns.c. */); Vx_cursor_fore_pixel = Qnil; + DEFVAR_LISP ("haiku-allowed-ui-colors", Vhaiku_allowed_ui_colors, + doc: /* Vector of UI colors that Emacs can look up from the system. +If this is set up incorrectly, Emacs can crash when encoutering an +invalid color. */); + Vhaiku_allowed_ui_colors = Qnil; + #ifdef USE_BE_CAIRO DEFVAR_LISP ("cairo-version-string", Vcairo_version_string, doc: /* Version info for cairo. */); diff --git a/src/haikuterm.c b/src/haikuterm.c index 12db1a6f4f4..f81efbdcbb7 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -3964,21 +3964,19 @@ haiku_term_init (void) color_file = Fexpand_file_name (build_string ("rgb.txt"), Fsymbol_value (intern ("data-directory"))); - color_map = Fx_load_color_file (color_file); + if (NILP (color_map)) fatal ("Could not read %s.\n", SDATA (color_file)); dpyinfo->color_map = color_map; - dpyinfo->display = BApplication_setup (); - - BScreen_res (&dpyinfo->resx, &dpyinfo->resy); - dpyinfo->next = x_display_list; dpyinfo->n_planes = be_get_display_planes (); x_display_list = dpyinfo; + BScreen_res (&dpyinfo->resx, &dpyinfo->resy); + terminal = haiku_create_terminal (dpyinfo); if (current_kboard == initial_kboard) current_kboard = terminal->kboard;