sites

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

dwm-bartoggle-keybinds-6.4.diff (7497B)


      1 This patch adds keybinds to toggle each part of the dwm bar. This include the title, tags, layout indicator, status and floating indicator.
      2 It also allows you to show/hide parts by default, similar to showbar.
      3 
      4 There is also a version without keybinds if you don't want keybinds, see the dwm-bartoggle-6.4.diff patch.
      5 
      6 diff -up a/config.def.h b/config.def.h
      7 --- a/config.def.h	2022-10-04 19:38:18.000000000 +0200
      8 +++ b/config.def.h	2022-10-22 14:40:36.113933644 +0200
      9 @@ -4,6 +4,11 @@
     10  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     11  static const unsigned int snap      = 32;       /* snap pixel */
     12  static const int showbar            = 1;        /* 0 means no bar */
     13 +static const int showtitle          = 1;        /* 0 means no title */
     14 +static const int showtags           = 1;        /* 0 means no tags */
     15 +static const int showlayout         = 1;        /* 0 means no layout indicator */
     16 +static const int showstatus         = 1;        /* 0 means no status bar */
     17 +static const int showfloating       = 1;        /* 0 means no floating indicator */
     18  static const int topbar             = 1;        /* 0 means bottom bar */
     19  static const char *fonts[]          = { "monospace:size=10" };
     20  static const char dmenufont[]       = "monospace:size=10";
     21 @@ -78,6 +83,11 @@ static const Key keys[] = {
     22  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     23  	{ MODKEY,                       XK_space,  setlayout,      {0} },
     24  	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
     25 +	{ MODKEY,					    XK_t,      togglebartitle, {0} },
     26 +	{ MODKEY,                       XK_s,      togglebarstatus,{0} },
     27 +	{ MODKEY|ShiftMask,             XK_t,      togglebartags,  {0} },
     28 +	{ MODKEY|ShiftMask,				XK_s,      togglebarlt,    {0} },
     29 +	{ MODKEY|ShiftMask,				XK_f,      togglebarfloat, {0} },
     30  	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     31  	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     32  	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
     33 diff -up a/dwm.c b/dwm.c
     34 --- a/dwm.c	2022-10-04 19:38:18.000000000 +0200
     35 +++ b/dwm.c	2022-10-22 14:41:29.903932288 +0200
     36 @@ -123,6 +123,11 @@ struct Monitor {
     37  	unsigned int sellt;
     38  	unsigned int tagset[2];
     39  	int showbar;
     40 +	int showtitle;
     41 +	int showtags;
     42 +	int showlayout;
     43 +	int showstatus;
     44 +	int showfloating;
     45  	int topbar;
     46  	Client *clients;
     47  	Client *sel;
     48 @@ -211,6 +216,11 @@ static void tag(const Arg *arg);
     49  static void tagmon(const Arg *arg);
     50  static void tile(Monitor *m);
     51  static void togglebar(const Arg *arg);
     52 +static void togglebartags(const Arg *arg);
     53 +static void togglebartitle(const Arg *arg);
     54 +static void togglebarlt(const Arg *arg);
     55 +static void togglebarstatus(const Arg *arg);
     56 +static void togglebarfloat(const Arg *arg);
     57  static void togglefloating(const Arg *arg);
     58  static void toggletag(const Arg *arg);
     59  static void toggleview(const Arg *arg);
     60 @@ -435,16 +445,17 @@ buttonpress(XEvent *e)
     61  	if (ev->window == selmon->barwin) {
     62  		i = x = 0;
     63  		do
     64 -			x += TEXTW(tags[i]);
     65 +		    if (selmon->showtags)
     66 +				x += TEXTW(tags[i]);
     67  		while (ev->x >= x && ++i < LENGTH(tags));
     68 -		if (i < LENGTH(tags)) {
     69 +		if (i < LENGTH(tags) && selmon->showtags) {
     70  			click = ClkTagBar;
     71  			arg.ui = 1 << i;
     72 -		} else if (ev->x < x + TEXTW(selmon->ltsymbol))
     73 +		} else if (ev->x < x + TEXTW(selmon->ltsymbol) && selmon->showlayout)
     74  			click = ClkLtSymbol;
     75 -		else if (ev->x > selmon->ww - (int)TEXTW(stext))
     76 +		else if (ev->x > selmon->ww - (int)TEXTW(stext) && selmon->showstatus)
     77  			click = ClkStatusText;
     78 -		else
     79 +		else if (selmon->showtitle)
     80  			click = ClkWinTitle;
     81  	} else if ((c = wintoclient(ev->window))) {
     82  		focus(c);
     83 @@ -641,6 +652,11 @@ createmon(void)
     84  	m->mfact = mfact;
     85  	m->nmaster = nmaster;
     86  	m->showbar = showbar;
     87 +	m->showtitle = showtitle;
     88 +	m->showtags = showtags;
     89 +	m->showlayout = showlayout;
     90 +	m->showstatus = showstatus;
     91 +	m->showfloating = showfloating;
     92  	m->topbar = topbar;
     93  	m->lt[0] = &layouts[0];
     94  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
     95 @@ -709,7 +725,7 @@ drawbar(Monitor *m)
     96  		return;
     97  
     98  	/* draw status first so it can be overdrawn by tags later */
     99 -	if (m == selmon) { /* status is only drawn on selected monitor */
    100 +	if (m == selmon && selmon->showstatus) { /* status is only drawn on selected monitor */
    101  		drw_setscheme(drw, scheme[SchemeNorm]);
    102  		tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
    103  		drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
    104 @@ -717,29 +733,35 @@ drawbar(Monitor *m)
    105  
    106  	for (c = m->clients; c; c = c->next) {
    107  		occ |= c->tags;
    108 -		if (c->isurgent)
    109 +		if (c->isurgent && selmon->showtags)
    110  			urg |= c->tags;
    111  	}
    112  	x = 0;
    113  	for (i = 0; i < LENGTH(tags); i++) {
    114 -		w = TEXTW(tags[i]);
    115 -		drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
    116 -		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
    117 -		if (occ & 1 << i)
    118 -			drw_rect(drw, x + boxs, boxs, boxw, boxw,
    119 -				m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
    120 -				urg & 1 << i);
    121 -		x += w;
    122 -	}
    123 -	w = TEXTW(m->ltsymbol);
    124 -	drw_setscheme(drw, scheme[SchemeNorm]);
    125 -	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
    126 +		if (selmon->showtags) {
    127 +				w = TEXTW(tags[i]);
    128 +				drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
    129 +				drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
    130 +				if (occ & 1 << i && selmon->showfloating)
    131 +				drw_rect(drw, x + boxs, boxs, boxw, boxw,
    132 +						m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
    133 +						urg & 1 << i);
    134 +				x += w;
    135 +		}
    136 +    }
    137 +	
    138 +	/* draw layout indicator if selmon->showlayout */
    139 +	if (selmon->showlayout) {
    140 +		w = TEXTW(m->ltsymbol);
    141 +		drw_setscheme(drw, scheme[SchemeNorm]);
    142 +		x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
    143 +	}
    144  
    145  	if ((w = m->ww - tw - x) > bh) {
    146 -		if (m->sel) {
    147 +		if (m->sel && selmon->showtitle) {
    148  			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
    149  			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
    150 -			if (m->sel->isfloating)
    151 +			if (m->sel->isfloating && selmon->showfloating)
    152  				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
    153  		} else {
    154  			drw_setscheme(drw, scheme[SchemeNorm]);
    155 @@ -1238,7 +1260,7 @@ propertynotify(XEvent *e)
    156  		}
    157  		if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
    158  			updatetitle(c);
    159 -			if (c == c->mon->sel)
    160 +			if (c == c->mon->sel && selmon->showtitle)
    161  				drawbar(c->mon);
    162  		}
    163  		if (ev->atom == netatom[NetWMWindowType])
    164 @@ -1704,6 +1726,41 @@ togglebar(const Arg *arg)
    165  }
    166  
    167  void
    168 +togglebartags(const Arg *arg)
    169 +{
    170 +    selmon->showtags = !selmon->showtags;
    171 +	arrange(selmon);
    172 +}
    173 +
    174 +void
    175 +togglebartitle(const Arg *arg)
    176 +{
    177 +    selmon->showtitle = !selmon->showtitle;
    178 +	arrange(selmon);
    179 +}
    180 +
    181 +void
    182 +togglebarlt(const Arg *arg)
    183 +{
    184 +    selmon->showlayout = !selmon->showlayout;
    185 +	arrange(selmon);
    186 +}
    187 +
    188 +void
    189 +togglebarstatus(const Arg *arg)
    190 +{
    191 +    selmon->showstatus = !selmon->showstatus;
    192 +	arrange(selmon);
    193 +}
    194 +
    195 +void
    196 +togglebarfloat(const Arg *arg)
    197 +{
    198 +    selmon->showfloating = !selmon->showfloating;
    199 +	arrange(selmon);
    200 +}
    201 +
    202 +void
    203  togglefloating(const Arg *arg)
    204  {
    205  	if (!selmon->sel)
    206 @@ -1987,7 +2044,7 @@ updatesizehints(Client *c)
    207  void
    208  updatestatus(void)
    209  {
    210 -	if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
    211 +	if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)) && selmon->showstatus)
    212  		strcpy(stext, "dwm-"VERSION);
    213  	drawbar(selmon);
    214  }