dwm-multimon-1-monitor_marker-6.4.patch (6902B)
1 From c13f9b5a379422525ec7f714d83a1cbb0e3251c2 Mon Sep 17 00:00:00 2001 2 From: "Gary B. Genett" <me@garybgenett.net> 3 Date: Sun, 19 Feb 2023 08:56:42 -0800 4 Subject: added monitor marker to bar 5 MIME-Version: 1.0 6 Content-Type: multipart/mixed; boundary="------------2.37.4" 7 8 This is a multi-part message in MIME format. 9 --------------2.37.4 10 Content-Type: text/plain; charset=UTF-8; format=fixed 11 Content-Transfer-Encoding: 8bit 12 13 --- 14 config.def.h | 2 ++ 15 dwm.c | 12 +++++++++++- 16 2 files changed, 13 insertions(+), 1 deletion(-) 17 18 19 --------------2.37.4 20 Content-Type: text/x-patch; name="0001-added-monitor-marker-to-bar.patch" 21 Content-Transfer-Encoding: 8bit 22 Content-Disposition: attachment; filename="0001-added-monitor-marker-to-bar.patch" 23 24 diff --git a/config.def.h b/config.def.h 25 index 9efa7744b39c8b0ff0cf09a504a2539910c2881c..9d549ce8628e1a7769ee2a3d5c0a4c6d56ce6931 100644 26 --- a/config.def.h 27 +++ b/config.def.h 28 @@ -96,20 +96,22 @@ static const Key keys[] = { 29 TAGKEYS( XK_9, 8) 30 { MODKEY|ShiftMask, XK_q, quit, {0} }, 31 }; 32 33 /* button definitions */ 34 /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ 35 static const Button buttons[] = { 36 /* click event mask button function argument */ 37 { ClkLtSymbol, 0, Button1, setlayout, {0} }, 38 { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, 39 + { ClkMonNum, 0, Button1, focusmon, {.i = +1} }, 40 + { ClkMonNum, 0, Button3, focusmon, {.i = -1} }, 41 { ClkWinTitle, 0, Button2, zoom, {0} }, 42 { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, 43 { ClkClientWin, MODKEY, Button1, movemouse, {0} }, 44 { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, 45 { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, 46 { ClkTagBar, 0, Button1, view, {0} }, 47 { ClkTagBar, 0, Button3, toggleview, {0} }, 48 { ClkTagBar, MODKEY, Button1, tag, {0} }, 49 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 50 }; 51 diff --git a/dwm.c b/dwm.c 52 index c2bd8710544eb4b4e7eaa4a1307e1f1dfd8d16ba..bc5160a7d46ab07da82f0595abb7700debb2b891 100644 53 --- a/dwm.c 54 +++ b/dwm.c 55 @@ -57,21 +57,21 @@ 56 #define TAGMASK ((1 << LENGTH(tags)) - 1) 57 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 58 59 /* enums */ 60 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 61 enum { SchemeNorm, SchemeSel }; /* color schemes */ 62 enum { NetSupported, NetWMName, NetWMState, NetWMCheck, 63 NetWMFullscreen, NetActiveWindow, NetWMWindowType, 64 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ 65 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ 66 -enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 67 +enum { ClkTagBar, ClkLtSymbol, ClkMonNum, ClkStatusText, ClkWinTitle, 68 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 69 70 typedef union { 71 int i; 72 unsigned int ui; 73 float f; 74 const void *v; 75 } Arg; 76 77 typedef struct { 78 @@ -106,20 +106,21 @@ typedef struct { 79 const Arg arg; 80 } Key; 81 82 typedef struct { 83 const char *symbol; 84 void (*arrange)(Monitor *); 85 } Layout; 86 87 struct Monitor { 88 char ltsymbol[16]; 89 + char monmark[16]; 90 float mfact; 91 int nmaster; 92 int num; 93 int by; /* bar geometry */ 94 int mx, my, mw, mh; /* screen size */ 95 int wx, wy, ww, wh; /* window area */ 96 unsigned int seltags; 97 unsigned int sellt; 98 unsigned int tagset[2]; 99 int showbar; 100 @@ -434,20 +435,22 @@ buttonpress(XEvent *e) 101 if (ev->window == selmon->barwin) { 102 i = x = 0; 103 do 104 x += TEXTW(tags[i]); 105 while (ev->x >= x && ++i < LENGTH(tags)); 106 if (i < LENGTH(tags)) { 107 click = ClkTagBar; 108 arg.ui = 1 << i; 109 } else if (ev->x < x + TEXTW(selmon->ltsymbol)) 110 click = ClkLtSymbol; 111 + else if (ev->x < x + TEXTW(selmon->ltsymbol) + TEXTW(selmon->monmark)) 112 + click = ClkMonNum; 113 else if (ev->x > selmon->ww - (int)TEXTW(stext)) 114 click = ClkStatusText; 115 else 116 click = ClkWinTitle; 117 } else if ((c = wintoclient(ev->window))) { 118 focus(c); 119 restack(selmon); 120 XAllowEvents(dpy, ReplayPointer, CurrentTime); 121 click = ClkClientWin; 122 } 123 @@ -637,20 +640,22 @@ createmon(void) 124 125 m = ecalloc(1, sizeof(Monitor)); 126 m->tagset[0] = m->tagset[1] = 1; 127 m->mfact = mfact; 128 m->nmaster = nmaster; 129 m->showbar = showbar; 130 m->topbar = topbar; 131 m->lt[0] = &layouts[0]; 132 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 133 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 134 + /* this is actually set in updategeom, to avoid a race condition */ 135 +// snprintf(m->monmark, sizeof(m->monmark), "(%d)", m->num); 136 return m; 137 } 138 139 void 140 destroynotify(XEvent *e) 141 { 142 Client *c; 143 XDestroyWindowEvent *ev = &e->xdestroywindow; 144 145 if ((c = wintoclient(ev->window))) 146 @@ -726,20 +731,23 @@ drawbar(Monitor *m) 147 drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 148 if (occ & 1 << i) 149 drw_rect(drw, x + boxs, boxs, boxw, boxw, 150 m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 151 urg & 1 << i); 152 x += w; 153 } 154 w = TEXTW(m->ltsymbol); 155 drw_setscheme(drw, scheme[SchemeNorm]); 156 x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 157 + w = TEXTW(m->monmark); 158 + drw_setscheme(drw, scheme[SchemeNorm]); 159 + x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->monmark, 0); 160 161 if ((w = m->ww - tw - x) > bh) { 162 if (m->sel) { 163 drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); 164 drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); 165 if (m->sel->isfloating) 166 drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); 167 } else { 168 drw_setscheme(drw, scheme[SchemeNorm]); 169 drw_rect(drw, x, 0, w, bh, 1, 1); 170 @@ -1886,20 +1894,22 @@ updategeom(void) 171 else 172 mons = createmon(); 173 } 174 for (i = 0, m = mons; i < nn && m; m = m->next, i++) 175 if (i >= n 176 || unique[i].x_org != m->mx || unique[i].y_org != m->my 177 || unique[i].width != m->mw || unique[i].height != m->mh) 178 { 179 dirty = 1; 180 m->num = i; 181 + /* this is ugly, but it is a race condition otherwise */ 182 + snprintf(m->monmark, sizeof(m->monmark), "(%d)", m->num); 183 m->mx = m->wx = unique[i].x_org; 184 m->my = m->wy = unique[i].y_org; 185 m->mw = m->ww = unique[i].width; 186 m->mh = m->wh = unique[i].height; 187 updatebarpos(m); 188 } 189 /* removed monitors if n > nn */ 190 for (i = nn; i < n; i++) { 191 for (m = mons; m && m->next; m = m->next); 192 while ((c = m->clients)) { 193 194 --------------2.37.4-- 195 196