[wiki] [sites] [slstatus][patch][signals] overhaul logic || sewn

From: <git_AT_suckless.org>
Date: Sat, 12 Oct 2024 19:48:24 +0200

commit 1e8125f674f7f90ccdf922832395af2bfe4f6f62
Author: sewn <sewn_AT_disroot.org>
Date: Sat Oct 12 20:48:10 2024 +0300

    [slstatus][patch][signals] overhaul logic
    
    allows thread-safety and wait-time for signal catch.

diff --git a/tools.suckless.org/slstatus/patches/signals/index.md b/tools.suckless.org/slstatus/patches/signals/index.md
index 88f0555c..350ae88d 100644
--- a/tools.suckless.org/slstatus/patches/signals/index.md
+++ b/tools.suckless.org/slstatus/patches/signals/index.md
_AT_@ -3,9 +3,13 @@ signals
 
 Description
 -----------
-This patch lets slstatus handle signals and use intervals
+This patch lets slstatus handle signals and uses 'turns'
 to update modules in the status text.
 
+After each interval loop, that iteration is what is used to
+give a module its 'turn'. If the interval is simply 1000ms (default),
+the 'turn' will effectively function as a interval for that module.
+
 This behavior is similar to that of [dwmblocks](https://github.com/torrinfail/dwmblocks).
 
 Download
diff --git a/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch b/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch
index 946ff120..64523419 100644
--- a/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch
+++ b/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch
_AT_@ -1,15 +1,15 @@
-From 7ec52e9f292fa50fae646d89302a3aa0c326b83e Mon Sep 17 00:00:00 2001
+From 8eaf9e1d101d93c784b12902eb71d5b2985a6985 Mon Sep 17 00:00:00 2001
 From: sewn <sewn_AT_disroot.org>
-Date: Fri, 13 Sep 2024 11:51:02 +0300
-Subject: [PATCH] implement signals & intervals
+Date: Sat, 12 Oct 2024 20:45:16 +0300
+Subject: [PATCH] implement signals & turns
 
 ---
  config.def.h | 11 ++++--
- slstatus.c | 109 +++++++++++++++++++++++++++++++++------------------
- 2 files changed, 77 insertions(+), 43 deletions(-)
+ slstatus.c | 108 ++++++++++++++++++++++++++++++++-------------------
+ 2 files changed, 75 insertions(+), 44 deletions(-)
 
 diff --git a/config.def.h b/config.def.h
-index d805331..7fbd164 100644
+index d805331..a89127b 100644
 --- a/config.def.h
 +++ b/config.def.h
 _AT_@ -6,8 +6,8 @@ const unsigned int interval = 1000;
_AT_@ -29,27 +29,28 @@ index d805331..7fbd164 100644
  static const struct arg args[] = {
 - /* function format argument */
 - { datetime, "%s", "%F %T" },
-+ /* function format argument interval signal */
-+ { datetime, "%s", "%F %T", 1, -1 },
++ /* function format argument turn signal */
++ { datetime, "%s", "%F %T", 1, -1 },
  };
 +
 +/* maximum output string length */
 +#define MAXLEN CMDLEN * LEN(args)
 diff --git a/slstatus.c b/slstatus.c
-index fd31313..41ef7a9 100644
+index fd31313..d5efd35 100644
 --- a/slstatus.c
 +++ b/slstatus.c
 _AT_@ -15,20 +15,19 @@ struct arg {
          const char *(*func)(const char *);
          const char *fmt;
          const char *args;
-+ unsigned int interval;
++ unsigned int turn;
 + int signal;
  };
  
  char buf[1024];
+-static volatile sig_atomic_t done;
 +static int sflag = 0;
- static volatile sig_atomic_t done;
++static volatile sig_atomic_t done, upsigno;
  static Display *dpy;
  
  #include "config.h"
_AT_@ -65,26 +66,23 @@ index fd31313..41ef7a9 100644
  
  static void
  difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
-_AT_@ -44,17 +43,68 @@ usage(void)
+_AT_@ -44,17 +43,61 @@ usage(void)
          die("usage: %s [-v] [-s] [-1]", argv0);
  }
  
 +static void
-+printstatus(int it, int upsig)
++printstatus(unsigned int iter)
 +{
 + size_t i;
-+ int update = 0;
 + char status[MAXLEN];
 + const char *res;
 +
 + for (i = 0; i < LEN(args); i++) {
-+ if (!((args[i].interval > 0 && !(it % args[i].interval)) ||
-+ (!it || (args[i].signal > -1 && upsig == args[i].signal)) ||
-+ (it < 0 && upsig < 0)))
++ if (!((!iter && !upsigno) || upsigno == SIGUSR1 ||
++ (!upsigno && args[i].turn > 0 && !(iter % args[i].turn)) ||
++ (args[i].signal >= 0 && upsigno - SIGRTMIN == args[i].signal)))
 + continue;
 +
-+ update = 1;
-+
 + if (!(res = args[i].func(args[i].args)))
 + res = unknown_str;
 +
_AT_@ -92,9 +90,6 @@ index fd31313..41ef7a9 100644
 + break;
 + }
 +
-+ if (!update)
-+ return;
-+
 + status[0] = ' + for (i = 0; i < LEN(args); i++)
 + strcat(status, statuses[i]);
_AT_@ -116,10 +111,8 @@ index fd31313..41ef7a9 100644
 +static void
 +sighandler(const int signo)
 +{
-+ if (signo <= SIGRTMAX && signo >= SIGRTMIN)
-+ printstatus(-1, signo - SIGRTMIN);
-+ else if (signo == SIGUSR1)
-+ printstatus(-1, -1);
++ if ((signo <= SIGRTMAX && signo >= SIGRTMIN) || signo == SIGUSR1)
++ upsigno = signo;
 + else
 + done = 1;
 +}
_AT_@ -133,13 +126,14 @@ index fd31313..41ef7a9 100644
 - int sflag, ret;
 - char status[MAXLEN];
 - const char *res;
-+ int i, ret, time = 0;
++ unsigned int iter = 0;
++ int i, ret;
  
 - sflag = 0;
          ARGBEGIN {
          case 'v':
                  die("slstatus-"VERSION);
-_AT_@ -72,11 +122,12 @@ main(int argc, char *argv[])
+_AT_@ -72,11 +115,12 @@ main(int argc, char *argv[])
                  usage();
  
          memset(&act, 0, sizeof(act));
_AT_@ -154,7 +148,7 @@ index fd31313..41ef7a9 100644
  
          if (!sflag && !(dpy = XOpenDisplay(NULL)))
                  die("XOpenDisplay: Failed to open display");
-_AT_@ -85,28 +136,7 @@ main(int argc, char *argv[])
+_AT_@ -85,28 +129,7 @@ main(int argc, char *argv[])
                  if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
                          die("clock_gettime:");
  
_AT_@ -180,11 +174,11 @@ index fd31313..41ef7a9 100644
 - die("XStoreName: Allocation failed");
 - XFlush(dpy);
 - }
-+ printstatus(time++, -1);
++ printstatus(iter++);
  
                  if (!done) {
                          if (clock_gettime(CLOCK_MONOTONIC, &current) < 0)
-_AT_@ -117,10 +147,11 @@ main(int argc, char *argv[])
+_AT_@ -117,10 +140,15 @@ main(int argc, char *argv[])
                          intspec.tv_nsec = (interval % 1000) * 1E6;
                          difftimespec(&wait, &intspec, &diff);
  
_AT_@ -192,14 +186,18 @@ index fd31313..41ef7a9 100644
 - nanosleep(&wait, NULL) < 0 &&
 - errno != EINTR)
 - die("nanosleep:");
-+ do
-+ ret = nanosleep(&wait, &wait);
-+ while (wait.tv_sec >= 0 && ret < 0 && errno != EINTR && !done);
++ do {
++ if (errno == EINTR) {
++ printstatus(0);
++ errno = upsigno = 0;
++ }
++ ret = nanosleep(&wait, &wait);
++ } while (wait.tv_sec >= 0 && ret < 0 && !done);
 + if (ret < 0 && errno != EINTR)
 + die("nanosleep:");
                  }
          } while (!done);
  
 --
-2.46.0
+2.46.2
 
Received on Sat Oct 12 2024 - 19:48:24 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 12 2024 - 19:48:54 CEST