dwm-statusbutton-20180524-c8e9479.diff (3377B)
1 From 63515eaf23d3f32f12d159c5e84af09f3a2d3323 Mon Sep 17 00:00:00 2001 2 From: Christopher Drelich <cd@cdrakka.com> 3 Date: Thu, 24 May 2018 20:26:42 -0400 4 Subject: [PATCH] Added left-hand side statusbar button. 5 6 --- 7 config.def.h | 2 ++ 8 dwm.c | 34 +++++++++++++++++++++------------- 9 2 files changed, 23 insertions(+), 13 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index a9ac303..63ff917 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ 16 static const unsigned int snap = 32; /* snap pixel */ 17 static const int showbar = 1; /* 0 means no bar */ 18 static const int topbar = 1; /* 0 means bottom bar */ 19 +static const char buttonbar[] = "<O>"; 20 static const char *fonts[] = { "monospace:size=10" }; 21 static const char dmenufont[] = "monospace:size=10"; 22 static const char col_gray1[] = "#222222"; 23 @@ -100,6 +101,7 @@ static Key keys[] = { 24 /* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ 25 static Button buttons[] = { 26 /* click event mask button function argument */ 27 + { ClkButton, 0, Button1, spawn, {.v = dmenucmd } }, 28 { ClkLtSymbol, 0, Button1, setlayout, {0} }, 29 { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, 30 { ClkWinTitle, 0, Button2, zoom, {0} }, 31 diff --git a/dwm.c b/dwm.c 32 index bb95e26..689cb01 100644 33 --- a/dwm.c 34 +++ b/dwm.c 35 @@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, 36 NetWMFullscreen, NetActiveWindow, NetWMWindowType, 37 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ 38 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ 39 -enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 40 +enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkButton, ClkWinTitle, 41 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 42 43 typedef union { 44 @@ -431,18 +431,23 @@ buttonpress(XEvent *e) 45 } 46 if (ev->window == selmon->barwin) { 47 i = x = 0; 48 - do 49 - x += TEXTW(tags[i]); 50 - while (ev->x >= x && ++i < LENGTH(tags)); 51 - if (i < LENGTH(tags)) { 52 - click = ClkTagBar; 53 - arg.ui = 1 << i; 54 - } else if (ev->x < x + blw) 55 - click = ClkLtSymbol; 56 - else if (ev->x > selmon->ww - TEXTW(stext)) 57 - click = ClkStatusText; 58 - else 59 - click = ClkWinTitle; 60 + x += TEXTW(buttonbar); 61 + if(ev->x < x) { 62 + click = ClkButton; 63 + } else { 64 + do 65 + x += TEXTW(tags[i]); 66 + while (ev->x >= x && ++i < LENGTH(tags)); 67 + if (i < LENGTH(tags)) { 68 + click = ClkTagBar; 69 + arg.ui = 1 << i; 70 + } else if (ev->x < x + blw) 71 + click = ClkLtSymbol; 72 + else if (ev->x > selmon->ww - TEXTW(stext)) 73 + click = ClkStatusText; 74 + else 75 + click = ClkWinTitle; 76 + } 77 } else if ((c = wintoclient(ev->window))) { 78 focus(c); 79 restack(selmon); 80 @@ -714,6 +719,9 @@ drawbar(Monitor *m) 81 urg |= c->tags; 82 } 83 x = 0; 84 + w = blw = TEXTW(buttonbar); 85 + drw_setscheme(drw, scheme[SchemeNorm]); 86 + x = drw_text(drw, x, 0, w, bh, lrpad / 2, buttonbar, 0); 87 for (i = 0; i < LENGTH(tags); i++) { 88 w = TEXTW(tags[i]); 89 drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 90 -- 91 2.7.4 92