From: Po Lu Date: Tue, 24 May 2022 02:09:59 +0000 (+0000) Subject: Minor fixes to cursor color handling on Haiku X-Git-Tag: emacs-29.0.90~1910^2~473 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cd355038d9451c37cc2081ad35ac13383d993351;p=emacs.git Minor fixes to cursor color handling on Haiku * src/haikufns.c (haiku_decode_color): New function. (haiku_set_foreground_color, haiku_set_background_color) (haiku_set_cursor_color, haiku_set_mouse_color): Use that function to decode colors instead. Also set cursor GC foreground when setting background color. * src/haikuterm.c (haiku_merge_cursor_foreground): Fix color equality test. --- diff --git a/src/haikufns.c b/src/haikufns.c index 7b1abb5cdc7..a08b43879e3 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -613,28 +613,33 @@ unwind_create_tip_frame (Lisp_Object frame) tip_frame = Qnil; } -static void -haiku_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +static unsigned long +haiku_decode_color (struct frame *f, Lisp_Object color_name) { - struct haiku_output *output = FRAME_OUTPUT_DATA (f); - unsigned long old_fg; + Emacs_Color cdef; - Emacs_Color color; + CHECK_STRING (color_name); - if (haiku_get_color (SSDATA (arg), &color)) - { - store_frame_param (f, Qforeground_color, oldval); - unblock_input (); - error ("Bad color"); - } + if (!haiku_get_color (SSDATA (color_name), &cdef)) + return cdef.pixel; + signal_error ("Undefined color", color_name); +} + +static void +haiku_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +{ + struct haiku_output *output; + unsigned long fg, old_fg; + + fg = haiku_decode_color (f, arg); old_fg = FRAME_FOREGROUND_PIXEL (f); - FRAME_FOREGROUND_PIXEL (f) = color.pixel; + FRAME_FOREGROUND_PIXEL (f) = fg; + output = FRAME_OUTPUT_DATA (f); if (FRAME_HAIKU_WINDOW (f)) { - block_input (); if (output->cursor_color.pixel == old_fg) { output->cursor_color.pixel = old_fg; @@ -643,8 +648,6 @@ haiku_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval output->cursor_color.blue = BLUE_FROM_ULONG (old_fg); } - unblock_input (); - update_face_from_frame_parameter (f, Qforeground_color, arg); if (FRAME_VISIBLE_P (f)) @@ -1487,76 +1490,51 @@ frame_geometry (Lisp_Object frame, Lisp_Object attribute) void haiku_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - Emacs_Color color; - struct face *defface; + unsigned long background; - CHECK_STRING (arg); + background = haiku_decode_color (f, arg); - block_input (); - if (haiku_get_color (SSDATA (arg), &color)) - { - store_frame_param (f, Qbackground_color, oldval); - unblock_input (); - error ("Bad color"); - } - - FRAME_OUTPUT_DATA (f)->cursor_fg = color.pixel; - FRAME_BACKGROUND_PIXEL (f) = color.pixel; + FRAME_OUTPUT_DATA (f)->cursor_fg = background; + FRAME_BACKGROUND_PIXEL (f) = background; if (FRAME_HAIKU_VIEW (f)) { BView_draw_lock (FRAME_HAIKU_VIEW (f), false, 0, 0, 0, 0); - BView_SetViewColor (FRAME_HAIKU_VIEW (f), color.pixel); + BView_SetViewColor (FRAME_HAIKU_VIEW (f), background); BView_draw_unlock (FRAME_HAIKU_VIEW (f)); - defface = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID); - if (defface) - { - defface->background = color.pixel; - update_face_from_frame_parameter (f, Qbackground_color, arg); - clear_frame (f); - } - } + FRAME_OUTPUT_DATA (f)->cursor_fg = background; + update_face_from_frame_parameter (f, Qbackground_color, arg); - if (FRAME_VISIBLE_P (f)) - SET_FRAME_GARBAGED (f); - unblock_input (); + if (FRAME_VISIBLE_P (f)) + redraw_frame (f); + } } void haiku_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - Emacs_Color color, fore_pixel; + unsigned long fore_pixel, pixel; - CHECK_STRING (arg); - block_input (); - - if (haiku_get_color (SSDATA (arg), &color)) - { - store_frame_param (f, Qcursor_color, oldval); - unblock_input (); - error ("Bad color"); - } - - FRAME_CURSOR_COLOR (f) = color; + pixel = haiku_decode_color (f, arg); - if (STRINGP (Vx_cursor_fore_pixel)) + if (!NILP (Vx_cursor_fore_pixel)) { - if (haiku_get_color (SSDATA (Vx_cursor_fore_pixel), - &fore_pixel)) - error ("Bad color %s", SSDATA (Vx_cursor_fore_pixel)); - FRAME_OUTPUT_DATA (f)->cursor_fg = fore_pixel.pixel; + fore_pixel = haiku_decode_color (f, Vx_cursor_fore_pixel); + FRAME_OUTPUT_DATA (f)->cursor_fg = fore_pixel; } else FRAME_OUTPUT_DATA (f)->cursor_fg = FRAME_BACKGROUND_PIXEL (f); + haiku_query_color (pixel, &FRAME_CURSOR_COLOR (f)); + if (FRAME_VISIBLE_P (f)) { - gui_update_cursor (f, 0); - gui_update_cursor (f, 1); + gui_update_cursor (f, false); + gui_update_cursor (f, true); } + update_face_from_frame_parameter (f, Qcursor_color, arg); - unblock_input (); } void @@ -2066,7 +2044,7 @@ haiku_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) rc = haiku_get_color (SSDATA (arg), &color); if (color_specified_p && rc) - signal_error ("Invalid color", arg); + signal_error ("Undefined color", arg); output = FRAME_OUTPUT_DATA (f); diff --git a/src/haikuterm.c b/src/haikuterm.c index 59fbb9ad82f..a4875562185 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -4476,7 +4476,7 @@ haiku_merge_cursor_foreground (struct glyph_string *s, foreground = s->face->foreground; if (background == s->face->background - || foreground == s->face->foreground) + && foreground == s->face->foreground) { background = s->face->foreground; foreground = s->face->background;