sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 183568620ad0e40010c25f03d2fec2d60d2f949f
parent 9397ab5c4b38ce7a104253799db461267c94ed8d
Author: Tonton Couillon <la.luge@free.fr>
Date:   Sat,  1 Sep 2018 13:00:11 +0200

[st] This patch allows you to work with 16 color palettes and change them on the fly.

Diffstat:
Ast.suckless.org/patches/palettes/index.md | 42++++++++++++++++++++++++++++++++++++++++++
Ast.suckless.org/patches/palettes/st-color_schemes-0.8.1.diff | 173+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ast.suckless.org/patches/palettes/st-color_schemes-20180901-4f4bccd.diff | 173+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 388 insertions(+), 0 deletions(-)

diff --git a/st.suckless.org/patches/palettes/index.md b/st.suckless.org/patches/palettes/index.md @@ -0,0 +1,42 @@ +color_schemes +============= + +Description +----------- + +This patch allows you to work with 16 color palettes and change them on the +fly. + + +Instructions +------------ +The patch changes the &ldquo;config.def.h&rdquo;. +Delete your &ldquo;config.h&rdquo; or change it manually if you use a custom one. + + +Notes +----- +It uses the following shortcuts : + + Shortcut shortcuts[] = { + ... + { TERMMOD, XK_F1, setpalette, {.i = 0} }, + { TERMMOD, XK_F2, setpalette, {.i = 1} }, + { TERMMOD, XK_F3, setpalette, {.i = 2} }, + { TERMMOD, XK_F4, setpalette, {.i = 3} }, + { TERMMOD, XK_F5, setpalette, {.i = 4} }, + { TERMMOD, XK_F6, setpalette, {.i = 5} }, + { TERMMOD, XK_F7, setpalette, {.i = 6} }, + { TERMMOD, XK_F8, setpalette, {.i = 7} }, + { TERMMOD, XK_F9, setpalette, {.i = 8} }, + }; + +Download +-------- + + * [st-color_schemes-0.8.1.diff](st-color_schemes-0.8.1.diff) + + +Authors +------- + * Tonton Couillon - &lt;la dot luge at free dot fr> diff --git a/st.suckless.org/patches/palettes/st-color_schemes-0.8.1.diff b/st.suckless.org/patches/palettes/st-color_schemes-0.8.1.diff @@ -0,0 +1,173 @@ +diff --git a/config.def.h b/config.def.h +index 82b1b09..fe1680b 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -82,44 +82,29 @@ char *termname = "st-256color"; + */ + unsigned int tabspaces = 8; + +-/* Terminal colors (16 first used in escape sequence) */ +-static const char *colorname[] = { +- /* 8 normal colors */ +- "black", +- "red3", +- "green3", +- "yellow3", +- "blue2", +- "magenta3", +- "cyan3", +- "gray90", +- +- /* 8 bright colors */ +- "gray50", +- "red", +- "green", +- "yellow", +- "#5c5cff", +- "magenta", +- "cyan", +- "white", +- +- [255] = 0, +- +- /* more colors can be added after 255 to use with DefaultXX */ +- "#cccccc", +- "#555555", ++/* Terminal colors (16 used in escape sequence) */ ++static const char *palettes[][16] = { ++ {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90", ++ "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"}, ++ {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa", ++ "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"}, ++ {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777", ++ "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"}, ++ {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3", ++ "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"}, + }; + ++static const char **colorname; ++ + + /* + * Default colors (colorname index) + * foreground, background, cursor, reverse cursor + */ +-unsigned int defaultfg = 7; ++unsigned int defaultfg = 5; + unsigned int defaultbg = 0; +-static unsigned int defaultcs = 256; +-static unsigned int defaultrcs = 257; ++static unsigned int defaultcs = 5; ++static unsigned int defaultrcs = 5; + + /* + * Default shape of cursor +@@ -178,8 +163,18 @@ static Shortcut shortcuts[] = { + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, + { TERMMOD, XK_I, iso14755, {.i = 0} }, ++ { MODKEY|ShiftMask, XK_F1, setpalette, {.i = 0} }, ++ { MODKEY|ShiftMask, XK_F2, setpalette, {.i = 1} }, ++ { MODKEY|ShiftMask, XK_F3, setpalette, {.i = 2} }, ++ { MODKEY|ShiftMask, XK_F4, setpalette, {.i = 3} }, ++ { MODKEY|ShiftMask, XK_F5, setpalette, {.i = 4} }, ++ { MODKEY|ShiftMask, XK_F6, setpalette, {.i = 5} }, ++ { MODKEY|ShiftMask, XK_F7, setpalette, {.i = 6} }, ++ { MODKEY|ShiftMask, XK_F8, setpalette, {.i = 7} }, ++ { MODKEY|ShiftMask, XK_F9, setpalette, {.i = 8} }, + }; + ++ + /* + * Special keys (change & recompile st.info accordingly) + * +@@ -460,3 +455,4 @@ static char ascii_printable[] = + " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "`abcdefghijklmnopqrstuvwxyz{|}~"; ++ +diff --git a/x.c b/x.c +index c343ba2..4b2fc7b 100644 +--- a/x.c ++++ b/x.c +@@ -56,6 +56,7 @@ static void selpaste(const Arg *); + static void zoom(const Arg *); + static void zoomabs(const Arg *); + static void zoomreset(const Arg *); ++static void setpalette(const Arg *); + + /* config.h for applying patches and the configuration. */ + #include "config.h" +@@ -703,24 +704,7 @@ sixd_to_16bit(int x) + int + xloadcolor(int i, const char *name, Color *ncolor) + { +- XRenderColor color = { .alpha = 0xffff }; +- +- if (!name) { +- if (BETWEEN(i, 16, 255)) { /* 256 color */ +- if (i < 6*6*6+16) { /* same colors as xterm */ +- color.red = sixd_to_16bit( ((i-16)/36)%6 ); +- color.green = sixd_to_16bit( ((i-16)/6) %6 ); +- color.blue = sixd_to_16bit( ((i-16)/1) %6 ); +- } else { /* greyscale */ +- color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16)); +- color.green = color.blue = color.red; +- } +- return XftColorAllocValue(xw.dpy, xw.vis, +- xw.cmap, &color, ncolor); +- } else +- name = colorname[i]; +- } +- ++ if (!name) name = colorname[i]; + return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); + } + +@@ -731,7 +715,7 @@ xloadcols(void) + static int loaded; + Color *cp; + +- dc.collen = MAX(LEN(colorname), 256); ++ dc.collen = 16; + dc.col = xmalloc(dc.collen * sizeof(Color)); + + if (loaded) { +@@ -1725,6 +1709,7 @@ kpress(XEvent *ev) + len = 2; + } + } ++ + ttywrite(buf, len, 1); + } + +@@ -1880,6 +1865,15 @@ usage(void) + " [stty_args ...]\n", argv0, argv0); + } + ++void setpalette(const Arg *arg) { ++ ++ if ( arg->i < LEN(palettes) ) { ++ colorname = palettes[arg->i]; ++ xloadcols(); ++ cresize(win.w, win.h); ++ } ++} ++ + int + main(int argc, char *argv[]) + { +@@ -1932,6 +1926,8 @@ main(int argc, char *argv[]) + } ARGEND; + + run: ++ colorname = palettes[0]; ++ + if (argc > 0) /* eat all remaining arguments */ + opt_cmd = argv; + +@@ -1950,3 +1946,4 @@ run: + + return 0; + } ++ diff --git a/st.suckless.org/patches/palettes/st-color_schemes-20180901-4f4bccd.diff b/st.suckless.org/patches/palettes/st-color_schemes-20180901-4f4bccd.diff @@ -0,0 +1,173 @@ +diff --git a/config.def.h b/config.def.h +index 82b1b09..fe1680b 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -82,44 +82,29 @@ char *termname = "st-256color"; + */ + unsigned int tabspaces = 8; + +-/* Terminal colors (16 first used in escape sequence) */ +-static const char *colorname[] = { +- /* 8 normal colors */ +- "black", +- "red3", +- "green3", +- "yellow3", +- "blue2", +- "magenta3", +- "cyan3", +- "gray90", +- +- /* 8 bright colors */ +- "gray50", +- "red", +- "green", +- "yellow", +- "#5c5cff", +- "magenta", +- "cyan", +- "white", +- +- [255] = 0, +- +- /* more colors can be added after 255 to use with DefaultXX */ +- "#cccccc", +- "#555555", ++/* Terminal colors (16 used in escape sequence) */ ++static const char *palettes[][16] = { ++ {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90", ++ "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"}, ++ {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa", ++ "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"}, ++ {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777", ++ "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"}, ++ {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3", ++ "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"}, + }; + ++static const char **colorname; ++ + + /* + * Default colors (colorname index) + * foreground, background, cursor, reverse cursor + */ +-unsigned int defaultfg = 7; ++unsigned int defaultfg = 5; + unsigned int defaultbg = 0; +-static unsigned int defaultcs = 256; +-static unsigned int defaultrcs = 257; ++static unsigned int defaultcs = 5; ++static unsigned int defaultrcs = 5; + + /* + * Default shape of cursor +@@ -178,8 +163,18 @@ static Shortcut shortcuts[] = { + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, + { TERMMOD, XK_I, iso14755, {.i = 0} }, ++ { MODKEY|ShiftMask, XK_F1, setpalette, {.i = 0} }, ++ { MODKEY|ShiftMask, XK_F2, setpalette, {.i = 1} }, ++ { MODKEY|ShiftMask, XK_F3, setpalette, {.i = 2} }, ++ { MODKEY|ShiftMask, XK_F4, setpalette, {.i = 3} }, ++ { MODKEY|ShiftMask, XK_F5, setpalette, {.i = 4} }, ++ { MODKEY|ShiftMask, XK_F6, setpalette, {.i = 5} }, ++ { MODKEY|ShiftMask, XK_F7, setpalette, {.i = 6} }, ++ { MODKEY|ShiftMask, XK_F8, setpalette, {.i = 7} }, ++ { MODKEY|ShiftMask, XK_F9, setpalette, {.i = 8} }, + }; + ++ + /* + * Special keys (change & recompile st.info accordingly) + * +@@ -460,3 +455,4 @@ static char ascii_printable[] = + " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "`abcdefghijklmnopqrstuvwxyz{|}~"; ++ +diff --git a/x.c b/x.c +index 00cb6b1..7871c80 100644 +--- a/x.c ++++ b/x.c +@@ -56,6 +56,7 @@ static void selpaste(const Arg *); + static void zoom(const Arg *); + static void zoomabs(const Arg *); + static void zoomreset(const Arg *); ++static void setpalette(const Arg *); + + /* config.h for applying patches and the configuration. */ + #include "config.h" +@@ -705,24 +706,7 @@ sixd_to_16bit(int x) + int + xloadcolor(int i, const char *name, Color *ncolor) + { +- XRenderColor color = { .alpha = 0xffff }; +- +- if (!name) { +- if (BETWEEN(i, 16, 255)) { /* 256 color */ +- if (i < 6*6*6+16) { /* same colors as xterm */ +- color.red = sixd_to_16bit( ((i-16)/36)%6 ); +- color.green = sixd_to_16bit( ((i-16)/6) %6 ); +- color.blue = sixd_to_16bit( ((i-16)/1) %6 ); +- } else { /* greyscale */ +- color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16)); +- color.green = color.blue = color.red; +- } +- return XftColorAllocValue(xw.dpy, xw.vis, +- xw.cmap, &color, ncolor); +- } else +- name = colorname[i]; +- } +- ++ if (!name) name = colorname[i]; + return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); + } + +@@ -733,7 +717,7 @@ xloadcols(void) + static int loaded; + Color *cp; + +- dc.collen = MAX(LEN(colorname), 256); ++ dc.collen = 16; + dc.col = xmalloc(dc.collen * sizeof(Color)); + + if (loaded) { +@@ -1728,6 +1712,7 @@ kpress(XEvent *ev) + len = 2; + } + } ++ + ttywrite(buf, len, 1); + } + +@@ -1883,6 +1868,15 @@ usage(void) + " [stty_args ...]\n", argv0, argv0); + } + ++void setpalette(const Arg *arg) { ++ ++ if ( arg->i < LEN(palettes) ) { ++ colorname = palettes[arg->i]; ++ xloadcols(); ++ cresize(win.w, win.h); ++ } ++} ++ + int + main(int argc, char *argv[]) + { +@@ -1935,6 +1929,8 @@ main(int argc, char *argv[]) + } ARGEND; + + run: ++ colorname = palettes[0]; ++ + if (argc > 0) /* eat all remaining arguments */ + opt_cmd = argv; + +@@ -1953,3 +1949,4 @@ run: + + return 0; + } ++