URI: 
       st-color_schemes-0.8.1.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       st-color_schemes-0.8.1.diff (4920B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index 82b1b09..fe1680b 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -82,44 +82,29 @@ char *termname = "st-256color";
            6   */
            7  unsigned int tabspaces = 8;
            8  
            9 -/* Terminal colors (16 first used in escape sequence) */
           10 -static const char *colorname[] = {
           11 -        /* 8 normal colors */
           12 -        "black",
           13 -        "red3",
           14 -        "green3",
           15 -        "yellow3",
           16 -        "blue2",
           17 -        "magenta3",
           18 -        "cyan3",
           19 -        "gray90",
           20 -
           21 -        /* 8 bright colors */
           22 -        "gray50",
           23 -        "red",
           24 -        "green",
           25 -        "yellow",
           26 -        "#5c5cff",
           27 -        "magenta",
           28 -        "cyan",
           29 -        "white",
           30 -
           31 -        [255] = 0,
           32 -
           33 -        /* more colors can be added after 255 to use with DefaultXX */
           34 -        "#cccccc",
           35 -        "#555555",
           36 +/* Terminal colors (16 used in escape sequence) */
           37 +static const char *palettes[][16] = {
           38 +    {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90",
           39 +    "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"},
           40 +    {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa",
           41 +    "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"},
           42 +    {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777",
           43 +    "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"},
           44 +    {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3",
           45 +    "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"},
           46  };
           47  
           48 +static const char **colorname;
           49 +
           50  
           51  /*
           52   * Default colors (colorname index)
           53   * foreground, background, cursor, reverse cursor
           54   */
           55 -unsigned int defaultfg = 7;
           56 +unsigned int defaultfg = 5;
           57  unsigned int defaultbg = 0;
           58 -static unsigned int defaultcs = 256;
           59 -static unsigned int defaultrcs = 257;
           60 +static unsigned int defaultcs = 5;
           61 +static unsigned int defaultrcs = 5;
           62  
           63  /*
           64   * Default shape of cursor
           65 @@ -178,8 +163,18 @@ static Shortcut shortcuts[] = {
           66          { TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
           67          { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
           68          { TERMMOD,              XK_I,           iso14755,       {.i =  0} },
           69 +        { MODKEY|ShiftMask,     XK_F1,          setpalette,     {.i =  0} },
           70 +        { MODKEY|ShiftMask,     XK_F2,          setpalette,     {.i =  1} },
           71 +        { MODKEY|ShiftMask,     XK_F3,          setpalette,     {.i =  2} },
           72 +        { MODKEY|ShiftMask,     XK_F4,          setpalette,     {.i =  3} },
           73 +        { MODKEY|ShiftMask,     XK_F5,          setpalette,     {.i =  4} },
           74 +        { MODKEY|ShiftMask,     XK_F6,          setpalette,     {.i =  5} },
           75 +        { MODKEY|ShiftMask,     XK_F7,          setpalette,     {.i =  6} },
           76 +        { MODKEY|ShiftMask,     XK_F8,          setpalette,     {.i =  7} },
           77 +        { MODKEY|ShiftMask,     XK_F9,          setpalette,     {.i =  8} },
           78  };
           79  
           80 +
           81  /*
           82   * Special keys (change & recompile st.info accordingly)
           83   *
           84 @@ -460,3 +455,4 @@ static char ascii_printable[] =
           85          " !\"#$%&'()*+,-./0123456789:;<=>?"
           86          "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
           87          "`abcdefghijklmnopqrstuvwxyz{|}~";
           88 +
           89 diff --git a/x.c b/x.c
           90 index c343ba2..4b2fc7b 100644
           91 --- a/x.c
           92 +++ b/x.c
           93 @@ -56,6 +56,7 @@ static void selpaste(const Arg *);
           94  static void zoom(const Arg *);
           95  static void zoomabs(const Arg *);
           96  static void zoomreset(const Arg *);
           97 +static void setpalette(const Arg *);
           98  
           99  /* config.h for applying patches and the configuration. */
          100  #include "config.h"
          101 @@ -703,24 +704,7 @@ sixd_to_16bit(int x)
          102  int
          103  xloadcolor(int i, const char *name, Color *ncolor)
          104  {
          105 -        XRenderColor color = { .alpha = 0xffff };
          106 -
          107 -        if (!name) {
          108 -                if (BETWEEN(i, 16, 255)) { /* 256 color */
          109 -                        if (i < 6*6*6+16) { /* same colors as xterm */
          110 -                                color.red   = sixd_to_16bit( ((i-16)/36)%6 );
          111 -                                color.green = sixd_to_16bit( ((i-16)/6) %6 );
          112 -                                color.blue  = sixd_to_16bit( ((i-16)/1) %6 );
          113 -                        } else { /* greyscale */
          114 -                                color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
          115 -                                color.green = color.blue = color.red;
          116 -                        }
          117 -                        return XftColorAllocValue(xw.dpy, xw.vis,
          118 -                                                  xw.cmap, &color, ncolor);
          119 -                } else
          120 -                        name = colorname[i];
          121 -        }
          122 -
          123 +        if (!name)  name = colorname[i];
          124          return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
          125  }
          126  
          127 @@ -731,7 +715,7 @@ xloadcols(void)
          128          static int loaded;
          129          Color *cp;
          130  
          131 -        dc.collen = MAX(LEN(colorname), 256);
          132 +        dc.collen = 16;
          133          dc.col = xmalloc(dc.collen * sizeof(Color));
          134  
          135          if (loaded) {
          136 @@ -1725,6 +1709,7 @@ kpress(XEvent *ev)
          137                          len = 2;
          138                  }
          139          }
          140 +        
          141          ttywrite(buf, len, 1);
          142  }
          143  
          144 @@ -1880,6 +1865,15 @@ usage(void)
          145              " [stty_args ...]\n", argv0, argv0);
          146  }
          147  
          148 +void setpalette(const Arg *arg) {
          149 +
          150 +    if ( arg->i < LEN(palettes) )   {
          151 +        colorname = palettes[arg->i];
          152 +        xloadcols();
          153 +        cresize(win.w, win.h);
          154 +    }
          155 +}
          156 +
          157  int
          158  main(int argc, char *argv[])
          159  {
          160 @@ -1932,6 +1926,8 @@ main(int argc, char *argv[])
          161          } ARGEND;
          162  
          163  run:
          164 +    colorname = palettes[0];
          165 +
          166          if (argc > 0) /* eat all remaining arguments */
          167                  opt_cmd = argv;
          168  
          169 @@ -1950,3 +1946,4 @@ run:
          170  
          171          return 0;
          172  }
          173 +