sites

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

dwm-colorschemes-6.5.diff (4424B)


      1 From a9dc99543fe07801587ed1b412cd97b5da01474f 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        | 37 ++++++++++++++++++++++++++++---------
      9  2 files changed, 39 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..1ac8e05 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,25 @@ setmfact(const Arg *arg)
     88  	arrange(selmon);
     89  }
     90  
     91 +void
     92 +setscheme(const Arg *arg)
     93 +{
     94 +	ptrdiff_t si = (scheme - schemes) + arg->i * SchemeN;
     95 +
     96 +	/* wrap around, won't work if (abs(arg->i) > LENGTH(colors)) */
     97 +	if (si < 0)
     98 +		si += LENGTH(colors) * SchemeN;
     99 +	else if (si >= LENGTH(colors) * SchemeN)
    100 +		si -= LENGTH(colors) * SchemeN;
    101 +
    102 +	scheme = &schemes[si];
    103 +	drawbars();
    104 +}
    105 +
    106  void
    107  setup(void)
    108  {
    109 -	int i;
    110 +	int i, j;
    111  	XSetWindowAttributes wa;
    112  	Atom utf8string;
    113  	struct sigaction sa;
    114 @@ -1584,9 +1600,12 @@ setup(void)
    115  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    116  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    117  	/* init appearance */
    118 -	scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
    119 -	for (i = 0; i < LENGTH(colors); i++)
    120 -		scheme[i] = drw_scm_create(drw, colors[i], 3);
    121 +	schemes = ecalloc(LENGTH(colors), SchemeN * sizeof(Clr *));
    122 +	for (j = LENGTH(colors) - 1; j >= 0; j--) {
    123 +		scheme = &schemes[j * SchemeN];
    124 +		for (i = 0; i < SchemeN; i++)
    125 +			scheme[i] = drw_scm_create(drw, colors[j][i], 3);
    126 +	}
    127  	/* init bars */
    128  	updatebars();
    129  	updatestatus();
    130 -- 
    131 2.45.2
    132