URI: 
       dwm-colorschemes-6.5.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       dwm-colorschemes-6.5.diff (4731B)
       ---
            1 From d067cd3815e35c8c5b804893a551d24fa7505e4b Mon Sep 17 00:00:00 2001
            2 From: Listeria monocytogenes <listeria@disroot.org>
            3 Date: Wed, 26 Jun 2024 11:49:20 -0300
            4 Subject: [PATCH] add setscheme() to cycle between colorschemes
            5 
            6 ---
            7  config.def.h | 15 +++++++++++----
            8  dwm.c        | 49 ++++++++++++++++++++++++++++++++++++++++---------
            9  2 files changed, 51 insertions(+), 13 deletions(-)
           10 
           11 diff --git a/config.def.h b/config.def.h
           12 index 9efa774..f87f707 100644
           13 --- a/config.def.h
           14 +++ b/config.def.h
           15 @@ -12,10 +12,16 @@ static const char col_gray2[]       = "#444444";
           16  static const char col_gray3[]       = "#bbbbbb";
           17  static const char col_gray4[]       = "#eeeeee";
           18  static const char col_cyan[]        = "#005577";
           19 -static const char *colors[][3]      = {
           20 -        /*               fg         bg         border   */
           21 -        [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
           22 -        [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
           23 +static const char *colors[][SchemeN][3] = {
           24 +                /*               fg         bg         border   */
           25 +        { /* dark */
           26 +                [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
           27 +                [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
           28 +        },
           29 +        { /* light */
           30 +                [SchemeNorm] = { col_gray2, col_gray4, col_gray3 },
           31 +                [SchemeSel]  = { col_gray1, col_cyan,  col_cyan  },
           32 +        },
           33  };
           34  
           35  /* tagging */
           36 @@ -85,6 +91,7 @@ static const Key keys[] = {
           37          { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
           38          { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
           39          { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
           40 +        { MODKEY,                       XK_s,      setscheme,      {.i = +1 } },
           41          TAGKEYS(                        XK_1,                      0)
           42          TAGKEYS(                        XK_2,                      1)
           43          TAGKEYS(                        XK_3,                      2)
           44 diff --git a/dwm.c b/dwm.c
           45 index f1d86b2..9c00a09 100644
           46 --- a/dwm.c
           47 +++ b/dwm.c
           48 @@ -59,7 +59,7 @@
           49  
           50  /* enums */
           51  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
           52 -enum { SchemeNorm, SchemeSel }; /* color schemes */
           53 +enum { SchemeNorm, SchemeSel, SchemeN /* keeplast */ }; /* color schemes */
           54  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
           55         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
           56         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
           57 @@ -202,6 +202,7 @@ static void setfocus(Client *c);
           58  static void setfullscreen(Client *c, int fullscreen);
           59  static void setlayout(const Arg *arg);
           60  static void setmfact(const Arg *arg);
           61 +static void setscheme(const Arg *arg);
           62  static void setup(void);
           63  static void seturgent(Client *c, int urg);
           64  static void showhide(Client *c);
           65 @@ -262,7 +263,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
           66  static Atom wmatom[WMLast], netatom[NetLast];
           67  static int running = 1;
           68  static Cur *cursor[CurLast];
           69 -static Clr **scheme;
           70 +static Clr **schemes, **scheme;
           71  static Display *dpy;
           72  static Drw *drw;
           73  static Monitor *mons, *selmon;
           74 @@ -486,9 +487,9 @@ cleanup(void)
           75                  cleanupmon(mons);
           76          for (i = 0; i < CurLast; i++)
           77                  drw_cur_free(drw, cursor[i]);
           78 -        for (i = 0; i < LENGTH(colors); i++)
           79 -                free(scheme[i]);
           80 -        free(scheme);
           81 +        for (i = 0; i < LENGTH(colors) * SchemeN; i++)
           82 +                free(schemes[i]);
           83 +        free(schemes);
           84          XDestroyWindow(dpy, wmcheckwin);
           85          drw_free(drw);
           86          XSync(dpy, False);
           87 @@ -1536,10 +1537,37 @@ setmfact(const Arg *arg)
           88          arrange(selmon);
           89  }
           90  
           91 +void
           92 +setscheme(const Arg *arg)
           93 +{
           94 +        ptrdiff_t si;
           95 +        Monitor *m;
           96 +        Client *c;
           97 +
           98 +        /* select default color scheme */
           99 +        if (!arg || arg->i == 0)
          100 +                si = 0;
          101 +        else
          102 +                si = (scheme - schemes) + arg->i * SchemeN;
          103 +
          104 +        /* wrap around, won't work if (abs(arg->i) > LENGTH(colors)) */
          105 +        if (si < 0)
          106 +                si += LENGTH(colors) * SchemeN;
          107 +        else if (si >= LENGTH(colors) * SchemeN)
          108 +                si -= LENGTH(colors) * SchemeN;
          109 +
          110 +        scheme = &schemes[si];
          111 +
          112 +        drawbars();
          113 +        for (m = mons; m; m = m->next)
          114 +                for (c = m->clients; c; c = c->next)
          115 +                        XSetWindowBorder(dpy, c->win, scheme[c == selmon->sel ? SchemeSel : SchemeNorm][ColBorder].pixel);
          116 +}
          117 +
          118  void
          119  setup(void)
          120  {
          121 -        int i;
          122 +        int i, j;
          123          XSetWindowAttributes wa;
          124          Atom utf8string;
          125          struct sigaction sa;
          126 @@ -1584,9 +1612,12 @@ setup(void)
          127          cursor[CurResize] = drw_cur_create(drw, XC_sizing);
          128          cursor[CurMove] = drw_cur_create(drw, XC_fleur);
          129          /* init appearance */
          130 -        scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
          131 -        for (i = 0; i < LENGTH(colors); i++)
          132 -                scheme[i] = drw_scm_create(drw, colors[i], 3);
          133 +        schemes = ecalloc(LENGTH(colors), SchemeN * sizeof(Clr *));
          134 +        for (j = LENGTH(colors) - 1; j >= 0; j--) {
          135 +                scheme = &schemes[j * SchemeN];
          136 +                for (i = 0; i < SchemeN; i++)
          137 +                        scheme[i] = drw_scm_create(drw, colors[j][i], 3);
          138 +        }
          139          /* init bars */
          140          updatebars();
          141          updatestatus();
          142 -- 
          143 2.47.1
          144