sites

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

st-color_schemes-20220615-baa9357.diff (5074B)


      1 From 285c1c63f22bc00771428088c1938b8a0161bd7b Mon Sep 17 00:00:00 2001
      2 From: Max Schillinger <maxschillinger@web.de>
      3 Date: Wed, 15 Jun 2022 21:06:42 +0200
      4 Subject: [PATCH] color_schemes patch for st commit baa9357
      5 
      6 ---
      7  config.def.h | 57 ++++++++++++++++++++++------------------------------
      8  x.c          | 35 +++++++++++++++-----------------
      9  2 files changed, 40 insertions(+), 52 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 91ab8ca..22bdb3c 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -93,46 +93,28 @@ char *termname = "st-256color";
     16   */
     17  unsigned int tabspaces = 8;
     18  
     19 -/* Terminal colors (16 first used in escape sequence) */
     20 -static const char *colorname[] = {
     21 -	/* 8 normal colors */
     22 -	"black",
     23 -	"red3",
     24 -	"green3",
     25 -	"yellow3",
     26 -	"blue2",
     27 -	"magenta3",
     28 -	"cyan3",
     29 -	"gray90",
     30 -
     31 -	/* 8 bright colors */
     32 -	"gray50",
     33 -	"red",
     34 -	"green",
     35 -	"yellow",
     36 -	"#5c5cff",
     37 -	"magenta",
     38 -	"cyan",
     39 -	"white",
     40 -
     41 -	[255] = 0,
     42 -
     43 -	/* more colors can be added after 255 to use with DefaultXX */
     44 -	"#cccccc",
     45 -	"#555555",
     46 -	"gray90", /* default foreground colour */
     47 -	"black", /* default background colour */
     48 +/* Terminal colors (16 used in escape sequence) */
     49 +static const char *palettes[][16] = {
     50 +	{"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90",
     51 +	 "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"},
     52 +	{"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa",
     53 +	 "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"},
     54 +	{"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777",
     55 +	 "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"},
     56 +	{"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3",
     57 +	 "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"},
     58  };
     59  
     60 +static const char **colorname;
     61  
     62  /*
     63   * Default colors (colorname index)
     64   * foreground, background, cursor, reverse cursor
     65   */
     66 -unsigned int defaultfg = 258;
     67 -unsigned int defaultbg = 259;
     68 -unsigned int defaultcs = 256;
     69 -static unsigned int defaultrcs = 257;
     70 +unsigned int defaultfg = 5;
     71 +unsigned int defaultbg = 0;
     72 +unsigned int defaultcs = 5;
     73 +static unsigned int defaultrcs = 5;
     74  
     75  /*
     76   * Default shape of cursor
     77 @@ -201,6 +183,15 @@ static Shortcut shortcuts[] = {
     78  	{ TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
     79  	{ ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
     80  	{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
     81 +	{ MODKEY|ShiftMask,     XK_F1,          setpalette,     {.i =  0} },
     82 +	{ MODKEY|ShiftMask,     XK_F2,          setpalette,     {.i =  1} },
     83 +	{ MODKEY|ShiftMask,     XK_F3,          setpalette,     {.i =  2} },
     84 +	{ MODKEY|ShiftMask,     XK_F4,          setpalette,     {.i =  3} },
     85 +	{ MODKEY|ShiftMask,     XK_F5,          setpalette,     {.i =  4} },
     86 +	{ MODKEY|ShiftMask,     XK_F6,          setpalette,     {.i =  5} },
     87 +	{ MODKEY|ShiftMask,     XK_F7,          setpalette,     {.i =  6} },
     88 +	{ MODKEY|ShiftMask,     XK_F8,          setpalette,     {.i =  7} },
     89 +	{ MODKEY|ShiftMask,     XK_F9,          setpalette,     {.i =  8} },
     90  };
     91  
     92  /*
     93 diff --git a/x.c b/x.c
     94 index 2a3bd38..0d77d2a 100644
     95 --- a/x.c
     96 +++ b/x.c
     97 @@ -59,6 +59,7 @@ static void zoom(const Arg *);
     98  static void zoomabs(const Arg *);
     99  static void zoomreset(const Arg *);
    100  static void ttysend(const Arg *);
    101 +static void setpalette(const Arg *);
    102  
    103  /* config.h for applying patches and the configuration. */
    104  #include "config.h"
    105 @@ -769,24 +770,8 @@ sixd_to_16bit(int x)
    106  int
    107  xloadcolor(int i, const char *name, Color *ncolor)
    108  {
    109 -	XRenderColor color = { .alpha = 0xffff };
    110 -
    111 -	if (!name) {
    112 -		if (BETWEEN(i, 16, 255)) { /* 256 color */
    113 -			if (i < 6*6*6+16) { /* same colors as xterm */
    114 -				color.red   = sixd_to_16bit( ((i-16)/36)%6 );
    115 -				color.green = sixd_to_16bit( ((i-16)/6) %6 );
    116 -				color.blue  = sixd_to_16bit( ((i-16)/1) %6 );
    117 -			} else { /* greyscale */
    118 -				color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
    119 -				color.green = color.blue = color.red;
    120 -			}
    121 -			return XftColorAllocValue(xw.dpy, xw.vis,
    122 -			                          xw.cmap, &color, ncolor);
    123 -		} else
    124 -			name = colorname[i];
    125 -	}
    126 -
    127 +	if (!name)
    128 +		name = colorname[i];
    129  	return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
    130  }
    131  
    132 @@ -801,7 +786,7 @@ xloadcols(void)
    133  		for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
    134  			XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
    135  	} else {
    136 -		dc.collen = MAX(LEN(colorname), 256);
    137 +		dc.collen = 16;
    138  		dc.col = xmalloc(dc.collen * sizeof(Color));
    139  	}
    140  
    141 @@ -2024,6 +2009,16 @@ usage(void)
    142  	    " [stty_args ...]\n", argv0, argv0);
    143  }
    144  
    145 +void
    146 +setpalette(const Arg *arg)
    147 +{
    148 +	if (arg->i < LEN(palettes)) {
    149 +		colorname = palettes[arg->i];
    150 +		xloadcols();
    151 +		cresize(win.w, win.h);
    152 +	}
    153 +}
    154 +
    155  int
    156  main(int argc, char *argv[])
    157  {
    158 @@ -2076,6 +2071,8 @@ main(int argc, char *argv[])
    159  	} ARGEND;
    160  
    161  run:
    162 +	colorname = palettes[0];
    163 +
    164  	if (argc > 0) /* eat all remaining arguments */
    165  		opt_cmd = argv;
    166  
    167 -- 
    168 2.36.1
    169