aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/xterm.c b/src/xterm.c
index c96aa74a7a6..75568a82a18 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -2381,6 +2381,8 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor)
2381 x_query_colors (f, bgcolor, 1); 2381 x_query_colors (f, bgcolor, 1);
2382} 2382}
2383 2383
2384#define HEX_COLOR_NAME_LENGTH 32
2385
2384/* On frame F, translate the color name to RGB values. Use cached 2386/* On frame F, translate the color name to RGB values. Use cached
2385 information, if possible. 2387 information, if possible.
2386 2388
@@ -2398,9 +2400,36 @@ Status x_parse_color (struct frame *f, const char *color_name,
2398 2400
2399 if (color_name[0] == '#') 2401 if (color_name[0] == '#')
2400 { 2402 {
2401 /* The hex form is parsed directly by XParseColor without 2403 /* Don't pass #RGB strings directly to XParseColor, because that
2404 follows the X convention of zero-extending each channel
2405 value: #f00 means #f00000. We want the convention of scaling
2406 channel values, so #f00 means #ff0000, just as it does for
2407 HTML, SVG, and CSS.
2408
2409 So we translate #f00 to rgb:f/0/0, which X handles
2410 differently. */
2411 char rgb_color_name[HEX_COLOR_NAME_LENGTH];
2412 int len = strlen (color_name);
2413 int digits_per_channel;
2414 if (len == 4)
2415 digits_per_channel = 1;
2416 else if (len == 7)
2417 digits_per_channel = 2;
2418 else if (len == 10)
2419 digits_per_channel = 3;
2420 else if (len == 13)
2421 digits_per_channel = 4;
2422 else
2423 return 0;
2424
2425 snprintf (rgb_color_name, sizeof rgb_color_name, "rgb:%.*s/%.*s/%.*s",
2426 digits_per_channel, color_name + 1,
2427 digits_per_channel, color_name + digits_per_channel + 1,
2428 digits_per_channel, color_name + 2 * digits_per_channel + 1);
2429
2430 /* The rgb form is parsed directly by XParseColor without
2402 talking to the X server. No need for caching. */ 2431 talking to the X server. No need for caching. */
2403 return XParseColor (dpy, cmap, color_name, color); 2432 return XParseColor (dpy, cmap, rgb_color_name, color);
2404 } 2433 }
2405 2434
2406 for (cache_entry = FRAME_DISPLAY_INFO (f)->color_names; cache_entry; 2435 for (cache_entry = FRAME_DISPLAY_INFO (f)->color_names; cache_entry;