dwm-fsignal-6.2.diff (3145B)
1 From e7f523c898983c84ba3102675662dc33cbb5573e Mon Sep 17 00:00:00 2001 2 From: Nihal Jere <noocsharp@gmail.com> 3 Date: Sat, 21 Mar 2020 15:50:00 -0500 4 Subject: [PATCH] fsignal 5 6 --- 7 config.def.h | 7 +++++++ 8 dwm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 9 2 files changed, 59 insertions(+), 2 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index 1c0b587..8d2e6e9 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -113,3 +113,10 @@ static Button buttons[] = { 16 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 17 }; 18 19 +/* signal definitions */ 20 +/* signum must be greater than 0 */ 21 +/* trigger signals using `xsetroot -name "fsignal:<signum>"` */ 22 +static Signal signals[] = { 23 + /* signum function argument */ 24 + { 1, setlayout, {.v = 0} }, 25 +}; 26 diff --git a/dwm.c b/dwm.c 27 index 4465af1..db2ee08 100644 28 --- a/dwm.c 29 +++ b/dwm.c 30 @@ -106,6 +106,12 @@ typedef struct { 31 const Arg arg; 32 } Key; 33 34 +typedef struct { 35 + unsigned int signum; 36 + void (*func)(const Arg *); 37 + const Arg arg; 38 +} Signal; 39 + 40 typedef struct { 41 const char *symbol; 42 void (*arrange)(Monitor *); 43 @@ -176,6 +182,7 @@ static void grabbuttons(Client *c, int focused); 44 static void grabkeys(void); 45 static void incnmaster(const Arg *arg); 46 static void keypress(XEvent *e); 47 +static int fake_signal(void); 48 static void killclient(const Arg *arg); 49 static void manage(Window w, XWindowAttributes *wa); 50 static void mappingnotify(XEvent *e); 51 @@ -998,6 +1005,47 @@ keypress(XEvent *e) 52 keys[i].func(&(keys[i].arg)); 53 } 54 55 +int 56 +fake_signal(void) 57 +{ 58 + char fsignal[256]; 59 + char indicator[9] = "fsignal:"; 60 + char str_signum[16]; 61 + int i, v, signum; 62 + size_t len_fsignal, len_indicator = strlen(indicator); 63 + 64 + // Get root name property 65 + if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) { 66 + len_fsignal = strlen(fsignal); 67 + 68 + // Check if this is indeed a fake signal 69 + if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) { 70 + memcpy(str_signum, &fsignal[len_indicator], len_fsignal - len_indicator); 71 + str_signum[len_fsignal - len_indicator] = '\0'; 72 + 73 + // Convert string value into managable integer 74 + for (i = signum = 0; i < strlen(str_signum); i++) { 75 + v = str_signum[i] - '0'; 76 + if (v >= 0 && v <= 9) { 77 + signum = signum * 10 + v; 78 + } 79 + } 80 + 81 + // Check if a signal was found, and if so handle it 82 + if (signum) 83 + for (i = 0; i < LENGTH(signals); i++) 84 + if (signum == signals[i].signum && signals[i].func) 85 + signals[i].func(&(signals[i].arg)); 86 + 87 + // A fake signal was sent 88 + return 1; 89 + } 90 + } 91 + 92 + // No fake signal was sent, so proceed with update 93 + return 0; 94 +} 95 + 96 void 97 killclient(const Arg *arg) 98 { 99 @@ -1215,8 +1263,10 @@ propertynotify(XEvent *e) 100 Window trans; 101 XPropertyEvent *ev = &e->xproperty; 102 103 - if ((ev->window == root) && (ev->atom == XA_WM_NAME)) 104 - updatestatus(); 105 + if ((ev->window == root) && (ev->atom == XA_WM_NAME)) { 106 + if (!fake_signal()) 107 + updatestatus(); 108 + } 109 else if (ev->state == PropertyDelete) 110 return; /* ignore */ 111 else if ((c = wintoclient(ev->window))) { 112 -- 113 2.25.1 114