sites

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

dwm-colorschemes-6.5.diff (4329B)


      1 From 3f7b5b2ebdbd43f562229085802a16e1b1a4ee22 Mon Sep 17 00:00:00 2001
      2 From: Listeria monocytogenes <listeria@disroot.org>
      3 Date: Mon, 22 Apr 2024 14:28:01 -0300
      4 Subject: [PATCH] add setscheme() to cycle between colorschemes
      5 
      6 ---
      7  config.def.h | 15 +++++++++++----
      8  dwm.c        | 33 ++++++++++++++++++++++++---------
      9  2 files changed, 35 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..53b1eaf 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,21 @@ setmfact(const Arg *arg)
     88  	arrange(selmon);
     89  }
     90  
     91 +void
     92 +setscheme(const Arg *arg)
     93 +{
     94 +	scheme += arg->i * SchemeN;
     95 +	if (scheme < schemes)
     96 +		scheme = schemes + (LENGTH(colors) - 1) * SchemeN;
     97 +	else if (scheme >= schemes + LENGTH(colors) * SchemeN)
     98 +		scheme = schemes;
     99 +	drawbars();
    100 +}
    101 +
    102  void
    103  setup(void)
    104  {
    105 -	int i;
    106 +	int i, j;
    107  	XSetWindowAttributes wa;
    108  	Atom utf8string;
    109  	struct sigaction sa;
    110 @@ -1584,9 +1596,12 @@ setup(void)
    111  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    112  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    113  	/* init appearance */
    114 -	scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
    115 -	for (i = 0; i < LENGTH(colors); i++)
    116 -		scheme[i] = drw_scm_create(drw, colors[i], 3);
    117 +	schemes = ecalloc(LENGTH(colors), SchemeN * sizeof(Clr **));
    118 +	for (j = LENGTH(colors) - 1; j >= 0; j--) {
    119 +		scheme = &schemes[j * SchemeN];
    120 +		for (i = 0; i < SchemeN; i++)
    121 +			scheme[i] = drw_scm_create(drw, colors[j][i], 3);
    122 +	}
    123  	/* init bars */
    124  	updatebars();
    125  	updatestatus();
    126 -- 
    127 2.44.0
    128