Based on patch for version 0.8.1
https://st.suckless.org/patches/palettes/
This commit is contained in:
pgrondek 2020-05-31 23:44:52 +02:00
parent 80e7848d57
commit 46040e8e04
4 changed files with 76 additions and 95 deletions

View File

@ -87,45 +87,30 @@ unsigned int tabspaces = 8;
/* bg opacity */ /* bg opacity */
float alpha = 0.8; float alpha = 0.8;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 used in escape sequence) */
static const char *colorname[] = { static const char *palettes[][16] = {
/* 8 normal colors */ {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90",
"black", "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"},
"red3", {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa",
"green3", "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"},
"yellow3", {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777",
"blue2", "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"},
"magenta3", {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3",
"cyan3", "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"},
"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",
"black", "black",
}; };
static const char **colorname;
/* /*
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 7; unsigned int defaultfg = 5;
unsigned int defaultbg = 258; unsigned int defaultbg = 258;
static unsigned int defaultcs = 256; static unsigned int defaultcs = 5;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 5;
/* /*
* Default shape of cursor * Default shape of cursor
@ -194,6 +179,15 @@ static Shortcut shortcuts[] = {
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.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} },
}; };
/* /*

View File

@ -87,44 +87,28 @@ unsigned int tabspaces = 8;
/* bg opacity */ /* bg opacity */
float alpha = 0.7; float alpha = 0.7;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 used in escape sequence) */
static const char *colorname[] = { static const char *palettes[][16] = {
/* 8 normal colors */ {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90",
"black", "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"},
"red3", {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa",
"green3", "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"},
"yellow3", {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777",
"blue2", "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"},
"magenta3", {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3",
"cyan3", "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"},
"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",
}; };
static const char **colorname;
/* /*
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 7; unsigned int defaultfg = 1;
unsigned int defaultbg = 0; unsigned int defaultbg = 0;
static unsigned int defaultcs = 256; static unsigned int defaultcs = 1;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 1;
/* /*
* Default shape of cursor * Default shape of cursor
@ -181,20 +165,29 @@ static MouseShortcut mshortcuts[] = {
static Shortcut shortcuts[] = { static Shortcut shortcuts[] = {
/* mask keysym function argument */ /* mask keysym function argument */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, {XK_ANY_MOD, XK_Break, sendbreak, {.i = 0}},
{ ControlMask, XK_Print, toggleprinter, {.i = 0} }, {ControlMask, XK_Print, toggleprinter, {.i = 0}},
{ ShiftMask, XK_Print, printscreen, {.i = 0} }, {ShiftMask, XK_Print, printscreen, {.i = 0}},
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, {XK_ANY_MOD, XK_Print, printsel, {.i = 0}},
{ TERMMOD, XK_Prior, zoom, {.f = +1} }, {TERMMOD, XK_Prior, zoom, {.f = +1}},
{ TERMMOD, XK_Next, zoom, {.f = -1} }, {TERMMOD, XK_Next, zoom, {.f = -1}},
{ TERMMOD, XK_Home, zoomreset, {.f = 0} }, {TERMMOD, XK_Home, zoomreset, {.f = 0}},
{ TERMMOD, XK_C, clipcopy, {.i = 0} }, {TERMMOD, XK_C, clipcopy, {.i = 0}},
{ TERMMOD, XK_V, clippaste, {.i = 0} }, {TERMMOD, XK_V, clippaste, {.i = 0}},
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, {TERMMOD, XK_Y, selpaste, {.i = 0}},
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, {ShiftMask, XK_Page_Up, kscrollup, {.i = -1}},
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, {ShiftMask, XK_Page_Down, kscrolldown, {.i = -1}},
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, {ShiftMask, XK_Insert, selpaste, {.i = 0}},
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, {TERMMOD, XK_Num_Lock, numlock, {.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}},
}; };
/* /*

View File

@ -22,7 +22,7 @@ LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
# flags # flags
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) -ggdb
STLDFLAGS = $(LIBS) $(LDFLAGS) STLDFLAGS = $(LIBS) $(LDFLAGS)
# OpenBSD: # OpenBSD:

32
x.c
View File

@ -58,6 +58,7 @@ static void selpaste(const Arg *);
static void zoom(const Arg *); static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void setpalette(const Arg *);
static void ttysend(const Arg *); static void ttysend(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
@ -753,24 +754,7 @@ sixd_to_16bit(int x)
int int
xloadcolor(int i, const char *name, Color *ncolor) xloadcolor(int i, const char *name, Color *ncolor)
{ {
XRenderColor color = { .alpha = 0xffff }; if (!name) name = colorname[i];
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];
}
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
} }
@ -781,11 +765,11 @@ xloadcols(void)
static int loaded; static int loaded;
Color *cp; Color *cp;
dc.collen = 16;
if (loaded) { if (loaded) {
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
} else { } else {
dc.collen = MAX(LEN(colorname), 256);
dc.col = xmalloc(dc.collen * sizeof(Color)); dc.col = xmalloc(dc.collen * sizeof(Color));
} }
@ -2000,6 +1984,14 @@ usage(void)
" [stty_args ...]\n", argv0, argv0); " [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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -2055,6 +2047,8 @@ main(int argc, char *argv[])
} ARGEND; } ARGEND;
run: run:
colorname = palettes[0];
if (argc > 0) /* eat all remaining arguments */ if (argc > 0) /* eat all remaining arguments */
opt_cmd = argv; opt_cmd = argv;