diff options
author | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2015-04-23 17:59:39 +0200 |
---|---|---|
committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2015-04-23 17:59:39 +0200 |
commit | f36dd277a2e71e99624fe26365757242d56259c0 (patch) | |
tree | 1d5dfdbf6c0425f2573a7f88e3581ac44f45203d /st.c | |
parent | 0d7448dabc981716d277a5afac22fabc127bacca (diff) | |
parent | 89807ed453e27893dea5ac73ee2c6b4f8dd15afb (diff) | |
download | st-f36dd277a2e71e99624fe26365757242d56259c0.tar.gz st-f36dd277a2e71e99624fe26365757242d56259c0.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 84 |
1 files changed, 30 insertions, 54 deletions
@@ -2897,10 +2897,31 @@ sixd_to_16bit(int x) { | |||
2897 | return x == 0 ? 0 : 0x3737 + 0x2828 * x; | 2897 | return x == 0 ? 0 : 0x3737 + 0x2828 * x; |
2898 | } | 2898 | } |
2899 | 2899 | ||
2900 | bool | ||
2901 | xloadcolor(int i, const char *name, Color *ncolor) { | ||
2902 | XRenderColor color = { .alpha = 0xffff }; | ||
2903 | |||
2904 | if(!name) { | ||
2905 | if(BETWEEN(i, 16, 255)) { /* 256 color */ | ||
2906 | if(i < 6*6*6+16) { /* same colors as xterm */ | ||
2907 | color.red = sixd_to_16bit( ((i-16)/36)%6 ); | ||
2908 | color.green = sixd_to_16bit( ((i-16)/6) %6 ); | ||
2909 | color.blue = sixd_to_16bit( ((i-16)/1) %6 ); | ||
2910 | } else { /* greyscale */ | ||
2911 | color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16)); | ||
2912 | color.green = color.blue = color.red; | ||
2913 | } | ||
2914 | return XftColorAllocValue(xw.dpy, xw.vis, | ||
2915 | xw.cmap, &color, ncolor); | ||
2916 | } else | ||
2917 | name = colorname[i]; | ||
2918 | } | ||
2919 | return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); | ||
2920 | } | ||
2921 | |||
2900 | void | 2922 | void |
2901 | xloadcols(void) { | 2923 | xloadcols(void) { |
2902 | int i; | 2924 | int i; |
2903 | XRenderColor color = { .alpha = 0xffff }; | ||
2904 | static bool loaded; | 2925 | static bool loaded; |
2905 | Color *cp; | 2926 | Color *cp; |
2906 | 2927 | ||
@@ -2909,70 +2930,25 @@ xloadcols(void) { | |||
2909 | XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); | 2930 | XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); |
2910 | } | 2931 | } |
2911 | 2932 | ||
2912 | /* load colors [0-15] and [256-LEN(colorname)] (config.h) */ | 2933 | for(i = 0; i < LEN(dc.col); i++) |
2913 | for(i = 0; i < LEN(colorname); i++) { | 2934 | if(!xloadcolor(i, NULL, &dc.col[i])) { |
2914 | if(!colorname[i]) | 2935 | if(colorname[i]) |
2915 | continue; | 2936 | die("Could not allocate color '%s'\n", colorname[i]); |
2916 | if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.col[i])) { | 2937 | else |
2917 | die("Could not allocate color '%s'\n", colorname[i]); | 2938 | die("Could not allocate color %d\n", i); |
2918 | } | 2939 | } |
2919 | } | ||
2920 | |||
2921 | /* load colors [16-231] ; same colors as xterm */ | ||
2922 | for(i = 16; i < 6*6*6+16; i++) { | ||
2923 | color.red = sixd_to_16bit( ((i-16)/36)%6 ); | ||
2924 | color.green = sixd_to_16bit( ((i-16)/6) %6 ); | ||
2925 | color.blue = sixd_to_16bit( ((i-16)/1) %6 ); | ||
2926 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) | ||
2927 | die("Could not allocate color %d\n", i); | ||
2928 | } | ||
2929 | |||
2930 | /* load colors [232-255] ; grayscale */ | ||
2931 | for(; i < 256; i++) { | ||
2932 | color.red = color.green = color.blue = 0x0808 + 0x0a0a * (i-(6*6*6+16)); | ||
2933 | if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) | ||
2934 | die("Could not allocate color %d\n", i); | ||
2935 | } | ||
2936 | loaded = true; | 2940 | loaded = true; |
2937 | } | 2941 | } |
2938 | 2942 | ||
2939 | int | 2943 | int |
2940 | xsetcolorname(int x, const char *name) { | 2944 | xsetcolorname(int x, const char *name) { |
2941 | XRenderColor color = { .alpha = 0xffff }; | ||
2942 | Color ncolor; | 2945 | Color ncolor; |
2943 | 2946 | ||
2944 | if(!BETWEEN(x, 0, LEN(colorname))) | 2947 | if(!BETWEEN(x, 0, LEN(dc.col))) |
2945 | return 1; | 2948 | return 1; |
2946 | 2949 | ||
2947 | if(!name) { | ||
2948 | if(BETWEEN(x, 16, 16 + 215)) { /* 256 color */ | ||
2949 | color.red = sixd_to_16bit( ((x-16)/36)%6 ); | ||
2950 | color.green = sixd_to_16bit( ((x-16)/6) %6 ); | ||
2951 | color.blue = sixd_to_16bit( ((x-16)/1) %6 ); | ||
2952 | if(!XftColorAllocValue(xw.dpy, xw.vis, | ||
2953 | xw.cmap, &color, &ncolor)) { | ||
2954 | return 1; | ||
2955 | } | ||
2956 | |||
2957 | XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); | ||
2958 | dc.col[x] = ncolor; | ||
2959 | return 0; | ||
2960 | } else if(BETWEEN(x, 16 + 216, 255)) { /* greyscale */ | ||
2961 | color.red = color.green = color.blue = \ | ||
2962 | 0x0808 + 0x0a0a * (x - (16 + 216)); | ||
2963 | if(!XftColorAllocValue(xw.dpy, xw.vis, | ||
2964 | xw.cmap, &color, &ncolor)) { | ||
2965 | return 1; | ||
2966 | } | ||
2967 | 2950 | ||
2968 | XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); | 2951 | if(!xloadcolor(x, name, &ncolor)) |
2969 | dc.col[x] = ncolor; | ||
2970 | return 0; | ||
2971 | } else { /* system colors */ | ||
2972 | name = colorname[x]; | ||
2973 | } | ||
2974 | } | ||
2975 | if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &ncolor)) | ||
2976 | return 1; | 2952 | return 1; |
2977 | 2953 | ||
2978 | XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); | 2954 | XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); |