dwm-dwmc-6.2.diff (5837B)
1 From d94cb6f1a553d19127f44dbdc96e8bb5041956c2 Mon Sep 17 00:00:00 2001 2 From: Nihal Jere <noocsharp@gmail.com> 3 Date: Sat, 21 Mar 2020 15:16:49 -0500 4 Subject: [PATCH] dwm-client 5 6 --- 7 Makefile | 2 +- 8 config.def.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 dwm.c | 55 +++++++++++++++++++++++++++++++++++++++-- 10 dwmc | 40 ++++++++++++++++++++++++++++++ 11 4 files changed, 164 insertions(+), 3 deletions(-) 12 create mode 100755 dwmc 13 14 diff --git a/Makefile b/Makefile 15 index 77bcbc0..f837f5c 100644 16 --- a/Makefile 17 +++ b/Makefile 18 @@ -38,7 +38,7 @@ dist: clean 19 20 install: all 21 mkdir -p ${DESTDIR}${PREFIX}/bin 22 - cp -f dwm ${DESTDIR}${PREFIX}/bin 23 + cp -f dwm dwmc ${DESTDIR}${PREFIX}/bin 24 chmod 755 ${DESTDIR}${PREFIX}/bin/dwm 25 mkdir -p ${DESTDIR}${MANPREFIX}/man1 26 sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 27 diff --git a/config.def.h b/config.def.h 28 index 1c0b587..efbae79 100644 29 --- a/config.def.h 30 +++ b/config.def.h 31 @@ -113,3 +113,73 @@ static Button buttons[] = { 32 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 33 }; 34 35 +void 36 +setlayoutex(const Arg *arg) 37 +{ 38 + setlayout(&((Arg) { .v = &layouts[arg->i] })); 39 +} 40 + 41 +void 42 +viewex(const Arg *arg) 43 +{ 44 + view(&((Arg) { .ui = 1 << arg->ui })); 45 +} 46 + 47 +void 48 +viewall(const Arg *arg) 49 +{ 50 + view(&((Arg){.ui = ~0})); 51 +} 52 + 53 +void 54 +toggleviewex(const Arg *arg) 55 +{ 56 + toggleview(&((Arg) { .ui = 1 << arg->ui })); 57 +} 58 + 59 +void 60 +tagex(const Arg *arg) 61 +{ 62 + tag(&((Arg) { .ui = 1 << arg->ui })); 63 +} 64 + 65 +void 66 +toggletagex(const Arg *arg) 67 +{ 68 + toggletag(&((Arg) { .ui = 1 << arg->ui })); 69 +} 70 + 71 +void 72 +tagall(const Arg *arg) 73 +{ 74 + tag(&((Arg){.ui = ~0})); 75 +} 76 + 77 +/* signal definitions */ 78 +/* signum must be greater than 0 */ 79 +/* trigger signals using `xsetroot -name "fsignal:<signame> [<type> <value>]"` */ 80 +static Signal signals[] = { 81 + /* signum function */ 82 + { "focusstack", focusstack }, 83 + { "setmfact", setmfact }, 84 + { "togglebar", togglebar }, 85 + { "incnmaster", incnmaster }, 86 + { "togglefloating", togglefloating }, 87 + { "focusmon", focusmon }, 88 + { "tagmon", tagmon }, 89 + { "zoom", zoom }, 90 + { "view", view }, 91 + { "viewall", viewall }, 92 + { "viewex", viewex }, 93 + { "toggleview", view }, 94 + { "toggleviewex", toggleviewex }, 95 + { "tag", tag }, 96 + { "tagall", tagall }, 97 + { "tagex", tagex }, 98 + { "toggletag", tag }, 99 + { "toggletagex", toggletagex }, 100 + { "killclient", killclient }, 101 + { "quit", quit }, 102 + { "setlayout", setlayout }, 103 + { "setlayoutex", setlayoutex }, 104 +}; 105 diff --git a/dwm.c b/dwm.c 106 index 4465af1..aa53706 100644 107 --- a/dwm.c 108 +++ b/dwm.c 109 @@ -106,6 +106,11 @@ typedef struct { 110 const Arg arg; 111 } Key; 112 113 +typedef struct { 114 + const char * sig; 115 + void (*func)(const Arg *); 116 +} Signal; 117 + 118 typedef struct { 119 const char *symbol; 120 void (*arrange)(Monitor *); 121 @@ -148,6 +153,7 @@ static void arrange(Monitor *m); 122 static void arrangemon(Monitor *m); 123 static void attach(Client *c); 124 static void attachstack(Client *c); 125 +static int fake_signal(void); 126 static void buttonpress(XEvent *e); 127 static void checkotherwm(void); 128 static void cleanup(void); 129 @@ -998,6 +1004,49 @@ keypress(XEvent *e) 130 keys[i].func(&(keys[i].arg)); 131 } 132 133 +int 134 +fake_signal(void) 135 +{ 136 + char fsignal[256]; 137 + char indicator[9] = "fsignal:"; 138 + char str_sig[50]; 139 + char param[16]; 140 + int i, len_str_sig, n, paramn; 141 + size_t len_fsignal, len_indicator = strlen(indicator); 142 + Arg arg; 143 + 144 + // Get root name property 145 + if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) { 146 + len_fsignal = strlen(fsignal); 147 + 148 + // Check if this is indeed a fake signal 149 + if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) { 150 + paramn = sscanf(fsignal+len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n); 151 + 152 + if (paramn == 1) arg = (Arg) {0}; 153 + else if (paramn > 2) return 1; 154 + else if (strncmp(param, "i", n - len_str_sig) == 0) 155 + sscanf(fsignal + len_indicator + n, "%i", &(arg.i)); 156 + else if (strncmp(param, "ui", n - len_str_sig) == 0) 157 + sscanf(fsignal + len_indicator + n, "%u", &(arg.ui)); 158 + else if (strncmp(param, "f", n - len_str_sig) == 0) 159 + sscanf(fsignal + len_indicator + n, "%f", &(arg.f)); 160 + else return 1; 161 + 162 + // Check if a signal was found, and if so handle it 163 + for (i = 0; i < LENGTH(signals); i++) 164 + if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func) 165 + signals[i].func(&(arg)); 166 + 167 + // A fake signal was sent 168 + return 1; 169 + } 170 + } 171 + 172 + // No fake signal was sent, so proceed with update 173 + return 0; 174 +} 175 + 176 void 177 killclient(const Arg *arg) 178 { 179 @@ -1215,8 +1264,10 @@ propertynotify(XEvent *e) 180 Window trans; 181 XPropertyEvent *ev = &e->xproperty; 182 183 - if ((ev->window == root) && (ev->atom == XA_WM_NAME)) 184 - updatestatus(); 185 + if ((ev->window == root) && (ev->atom == XA_WM_NAME)) { 186 + if (!fake_signal()) 187 + updatestatus(); 188 + } 189 else if (ev->state == PropertyDelete) 190 return; /* ignore */ 191 else if ((c = wintoclient(ev->window))) { 192 diff --git a/dwmc b/dwmc 193 new file mode 100755 194 index 0000000..5ff8dbc 195 --- /dev/null 196 +++ b/dwmc 197 @@ -0,0 +1,40 @@ 198 +#!/usr/bin/env sh 199 + 200 +signal() { 201 + xsetroot -name "fsignal:$*" 202 +} 203 + 204 +case $# in 205 +1) 206 + case $1 in 207 + setlayout | view | viewall | togglebar | togglefloating | zoom | killclient | quit) 208 + signal $1 209 + ;; 210 + *) 211 + echo "Unknown command or missing one argument." 212 + exit 1 213 + ;; 214 + esac 215 + ;; 216 +2) 217 + case $1 in 218 + view) 219 + signal $1 ui $2 220 + ;; 221 + viewex | toggleviewex | tagex | toggletagex | setlayoutex | focusstack | incnmaster | focusmon | tagmon) 222 + signal $1 i $2 223 + ;; 224 + setmfact) 225 + signal $1 f $2 226 + ;; 227 + *) 228 + echo "Unknown command or one too many arguments." 229 + exit 1 230 + ;; 231 + esac 232 + ;; 233 +*) 234 + echo "Too many arguments." 235 + exit 1 236 + ;; 237 +esac 238 -- 239 2.25.1 240