diff options
Diffstat (limited to 'src/xterm.c')
| -rw-r--r-- | src/xterm.c | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/src/xterm.c b/src/xterm.c index 7989cecec7f..6340700cb89 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -2376,8 +2376,6 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor) | |||
| 2376 | x_query_colors (f, bgcolor, 1); | 2376 | x_query_colors (f, bgcolor, 1); |
| 2377 | } | 2377 | } |
| 2378 | 2378 | ||
| 2379 | #define HEX_COLOR_NAME_LENGTH 32 | ||
| 2380 | |||
| 2381 | /* On frame F, translate the color name to RGB values. Use cached | 2379 | /* On frame F, translate the color name to RGB values. Use cached |
| 2382 | information, if possible. | 2380 | information, if possible. |
| 2383 | 2381 | ||
| @@ -2389,44 +2387,23 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor) | |||
| 2389 | Status x_parse_color (struct frame *f, const char *color_name, | 2387 | Status x_parse_color (struct frame *f, const char *color_name, |
| 2390 | XColor *color) | 2388 | XColor *color) |
| 2391 | { | 2389 | { |
| 2390 | /* Don't pass #RGB strings directly to XParseColor, because that | ||
| 2391 | follows the X convention of zero-extending each channel | ||
| 2392 | value: #f00 means #f00000. We want the convention of scaling | ||
| 2393 | channel values, so #f00 means #ff0000, just as it does for | ||
| 2394 | HTML, SVG, and CSS. */ | ||
| 2395 | unsigned short r, g, b; | ||
| 2396 | if (parse_color_spec (color_name, &r, &g, &b)) | ||
| 2397 | { | ||
| 2398 | color->red = r; | ||
| 2399 | color->green = g; | ||
| 2400 | color->blue = b; | ||
| 2401 | return 1; | ||
| 2402 | } | ||
| 2403 | |||
| 2392 | Display *dpy = FRAME_X_DISPLAY (f); | 2404 | Display *dpy = FRAME_X_DISPLAY (f); |
| 2393 | Colormap cmap = FRAME_X_COLORMAP (f); | 2405 | Colormap cmap = FRAME_X_COLORMAP (f); |
| 2394 | struct color_name_cache_entry *cache_entry; | 2406 | struct color_name_cache_entry *cache_entry; |
| 2395 | |||
| 2396 | if (color_name[0] == '#') | ||
| 2397 | { | ||
| 2398 | /* Don't pass #RGB strings directly to XParseColor, because that | ||
| 2399 | follows the X convention of zero-extending each channel | ||
| 2400 | value: #f00 means #f00000. We want the convention of scaling | ||
| 2401 | channel values, so #f00 means #ff0000, just as it does for | ||
| 2402 | HTML, SVG, and CSS. | ||
| 2403 | |||
| 2404 | So we translate #f00 to rgb:f/0/0, which X handles | ||
| 2405 | differently. */ | ||
| 2406 | char rgb_color_name[HEX_COLOR_NAME_LENGTH]; | ||
| 2407 | int len = strlen (color_name); | ||
| 2408 | int digits_per_channel; | ||
| 2409 | if (len == 4) | ||
| 2410 | digits_per_channel = 1; | ||
| 2411 | else if (len == 7) | ||
| 2412 | digits_per_channel = 2; | ||
| 2413 | else if (len == 10) | ||
| 2414 | digits_per_channel = 3; | ||
| 2415 | else if (len == 13) | ||
| 2416 | digits_per_channel = 4; | ||
| 2417 | else | ||
| 2418 | return 0; | ||
| 2419 | |||
| 2420 | snprintf (rgb_color_name, sizeof rgb_color_name, "rgb:%.*s/%.*s/%.*s", | ||
| 2421 | digits_per_channel, color_name + 1, | ||
| 2422 | digits_per_channel, color_name + digits_per_channel + 1, | ||
| 2423 | digits_per_channel, color_name + 2 * digits_per_channel + 1); | ||
| 2424 | |||
| 2425 | /* The rgb form is parsed directly by XParseColor without | ||
| 2426 | talking to the X server. No need for caching. */ | ||
| 2427 | return XParseColor (dpy, cmap, rgb_color_name, color); | ||
| 2428 | } | ||
| 2429 | |||
| 2430 | for (cache_entry = FRAME_DISPLAY_INFO (f)->color_names; cache_entry; | 2407 | for (cache_entry = FRAME_DISPLAY_INFO (f)->color_names; cache_entry; |
| 2431 | cache_entry = cache_entry->next) | 2408 | cache_entry = cache_entry->next) |
| 2432 | { | 2409 | { |