From: Yuuki Harano Date: Tue, 12 May 2020 13:39:15 +0000 (+0900) Subject: * src/pgtkterm.c (pgtk_defined_color): support gtk special colors X-Git-Tag: emacs-29.0.90~3804 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d68633bfa1124e32f6aa6a288a9c7b2098a39bd8;p=emacs.git * src/pgtkterm.c (pgtk_defined_color): support gtk special colors Color functions take the frame * src/gtkutil.c (xg_check_special_colors): pass frame as argument. * src/pgtkfns.c (x_set_foreground_color, x_set_background_color, x_set_cursor_color, pgtk_set_scroll_bar_foreground, pgtk_set_scroll_bar_background, Fxw_color_defined_p, Fxw_color_values): pass frame as argument. * src/pgtkterm.c (pgtk_parse_color): take frame as argument. (pgtk_lisp_to_color): take frame as argument, and pass it. Remove pgtk_lisp_to_color * src/pgtkfns.c (x_set_foreground_color, x_set_background_color, x_set_cursor_color): use x_decode_color instead of pgtk_lisp_to_color. (Fxw_color_defined_p, Fxw_color_values): use pgtk_defined_color instead of pgtk_lisp_to_color. * src/pgtkterm.c (pgtk_lisp_to_color): remove. * src/gtkutil.c (xg_check_special_colors): change color format * src/pgtkterm.h: remove pgtk_lisp_to_color declaration --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 16fac6cc08d..ce08ffec375 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -710,11 +710,12 @@ xg_check_special_colors (struct frame *f, r = col.red * 65535, g = col.green * 65535, b = col.blue * 65535; - sprintf (buf, "rgb:%04x/%04x/%04x", r, g, b); #ifndef HAVE_PGTK + sprintf (buf, "rgb:%04x/%04x/%04x", r, g, b); success_p = x_parse_color (f, buf, color) != 0; #else - success_p = pgtk_parse_color (buf, color) != 0; + sprintf (buf, "#%04x%04x%04x", r, g, b); + success_p = pgtk_parse_color (f, buf, color) != 0; #endif #else GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 79c9aab1a22..feda0933848 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -133,22 +133,11 @@ pgtk_display_info_for_name (Lisp_Object name) static void x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - Emacs_Color col; - - /* Must block_input, because pgtk_lisp_to_color does block/unblock_input - which means that col may be deallocated in its unblock_input if there - is user input, unless we also block_input. */ - block_input (); - if (pgtk_lisp_to_color (arg, &col)) - { - store_frame_param (f, Qforeground_color, oldval); - unblock_input (); - error ("Unknown color"); - } + unsigned long fg; - FRAME_X_OUTPUT(f)->foreground_color = col.pixel; - - FRAME_FOREGROUND_PIXEL (f) = col.pixel; + fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); + FRAME_FOREGROUND_PIXEL (f) = fg; + FRAME_X_OUTPUT(f)->foreground_color = fg; if (FRAME_GTK_WIDGET (f)) { @@ -157,40 +146,30 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) if (FRAME_VISIBLE_P (f)) SET_FRAME_GARBAGED (f); } - unblock_input (); } static void x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - Emacs_Color col; + unsigned long bg; - block_input (); - if (pgtk_lisp_to_color (arg, &col)) - { - store_frame_param (f, Qbackground_color, oldval); - unblock_input (); - error ("Unknown color"); - } + bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); + FRAME_BACKGROUND_PIXEL (f) = bg; /* clear the frame */ if (FRAME_VISIBLE_P (f)) pgtk_clear_frame (f); - PGTK_TRACE("x_set_background_color: col.pixel=%08lx.", col.pixel); - FRAME_X_OUTPUT(f)->background_color = col.pixel; - FRAME_BACKGROUND_PIXEL (f) = - ARGB_TO_ULONG ((unsigned int)(0xff), (unsigned int)(col.red>>8), (unsigned int)(col.green>>8), (unsigned int)(col.blue>>8)); + PGTK_TRACE("x_set_background_color: col.pixel=%08lx.", bg); + FRAME_X_OUTPUT(f)->background_color = bg; - xg_set_background_color(f, col.pixel); + xg_set_background_color(f, bg); update_face_from_frame_parameter (f, Qbackground_color, arg); PGTK_TRACE("visible_p=%d.", FRAME_VISIBLE_P(f)); if (FRAME_VISIBLE_P (f)) SET_FRAME_GARBAGED (f); - - unblock_input (); } static void @@ -209,20 +188,16 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { unsigned long fore_pixel, pixel; struct pgtk_output *x = f->output_data.pgtk; - Emacs_Color col; if (!NILP (Vx_cursor_fore_pixel)) { - if (pgtk_lisp_to_color(Vx_cursor_fore_pixel, &col)) - signal_error ("Undefined color", Vx_cursor_fore_pixel); - fore_pixel = col.pixel; + fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, + WHITE_PIX_DEFAULT (f)); } else fore_pixel = FRAME_BACKGROUND_PIXEL (f); - if (pgtk_lisp_to_color(arg, &col)) - signal_error ("Undefined color", arg); - pixel = col.pixel; + pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); /* Make sure that the cursor color differs from the background color. */ if (pixel == FRAME_BACKGROUND_PIXEL (f)) @@ -817,7 +792,7 @@ pgtk_set_scroll_bar_foreground (struct frame *f, Lisp_Object new_value, Lisp_Obj } else if (STRINGP (new_value)) { Emacs_Color rgb; - if (!pgtk_parse_color (SSDATA (new_value), &rgb)) + if (!pgtk_parse_color (f, SSDATA (new_value), &rgb)) error ("Unknown color."); char css[64]; @@ -838,7 +813,7 @@ pgtk_set_scroll_bar_background (struct frame *f, Lisp_Object new_value, Lisp_Obj } else if (STRINGP (new_value)) { Emacs_Color rgb; - if (!pgtk_parse_color (SSDATA (new_value), &rgb)) + if (!pgtk_parse_color (f, SSDATA (new_value), &rgb)) error ("Unknown color."); char css[64]; @@ -2149,7 +2124,14 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, (Lisp_Object color, Lisp_Object frame) { Emacs_Color col; - return pgtk_lisp_to_color (color, &col) ? Qnil : Qt; + struct frame *f = decode_window_system_frame (frame); + + CHECK_STRING (color); + + if (pgtk_defined_color (f, SSDATA (color), &col, false, false)) + return Qt; + else + return Qnil; } @@ -2158,20 +2140,14 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, (Lisp_Object color, Lisp_Object frame) { Emacs_Color col; + struct frame *f = decode_window_system_frame (frame); CHECK_STRING (color); - block_input (); - - if (pgtk_lisp_to_color (color, &col)) - { - unblock_input (); - return Qnil; - } - - unblock_input (); - - return list3i (col.red, col.green, col.blue); + if (pgtk_defined_color (f, SSDATA (color), &col, false, false)) + return list3i (col.red, col.green, col.blue); + else + return Qnil; } diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 2d1a990483f..ef8daba720a 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -6436,7 +6436,9 @@ pgtk_defined_color (struct frame *f, int r; block_input (); - r = pgtk_parse_color (name, color_def); + r = xg_check_special_colors(f, name, color_def); + if (!r) + r = pgtk_parse_color (f, name, color_def); unblock_input (); return r; } @@ -6449,7 +6451,7 @@ pgtk_defined_color (struct frame *f, and names we've actually looked up; list-colors-display is probably the most color-intensive case we're likely to hit. */ -int pgtk_parse_color (const char *color_name, Emacs_Color *color) +int pgtk_parse_color (struct frame *f, const char *color_name, Emacs_Color *color) { PGTK_TRACE("pgtk_parse_color: %s", color_name); @@ -6468,20 +6470,6 @@ int pgtk_parse_color (const char *color_name, Emacs_Color *color) return 0; } -int -pgtk_lisp_to_color (Lisp_Object color, Emacs_Color *col) -/* -------------------------------------------------------------------------- - Convert a Lisp string object to a NS color - -------------------------------------------------------------------------- */ -{ - PGTK_TRACE("pgtk_lisp_to_color"); - if (STRINGP (color)) - return !pgtk_parse_color (SSDATA (color), col); - else if (SYMBOLP (color)) - return !pgtk_parse_color (SSDATA (SYMBOL_NAME (color)), col); - return 1; -} - /* On frame F, translate pixel colors to RGB values for the NCOLORS colors in COLORS. On W32, we no longer try to map colors to a palette. */ diff --git a/src/pgtkterm.h b/src/pgtkterm.h index 706198aa8a4..b92a2cd1d19 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -534,8 +534,7 @@ extern bool pgtk_defined_color (struct frame *f, bool makeIndex); extern void pgtk_query_color (struct frame *f, Emacs_Color *color); extern void pgtk_query_colors (struct frame *f, Emacs_Color *colors, int ncolors); -extern int pgtk_parse_color (const char *color_name, Emacs_Color *color); -extern int pgtk_lisp_to_color (Lisp_Object color, Emacs_Color *col); +extern int pgtk_parse_color (struct frame *f, const char *color_name, Emacs_Color *color); /* Implemented in pgtkterm.c */ extern void pgtk_clear_area (struct frame *f, int x, int y, int width, int height);