]> git.sur5r.net Git - i3/i3status/blobdiff - i3status.c
README: refer to cr.i3wm.org for patches
[i3/i3status] / i3status.c
index 503f76382b9103ecea50ff9663e0bdb80385f6fb..af62a7ce74c46fbb1c80d76b0a83fa5c4591e88e 100644 (file)
@@ -57,6 +57,14 @@ void sigpipe(int signum) {
         exit(1);
 }
 
+/*
+ * Do nothing upon SIGUSR1. Running this signal handler will nevertheless
+ * interrupt nanosleep() so that i3status immediately generates new output.
+ *
+ */
+void sigusr1(int signum) {
+}
+
 /*
  * Checks if the given path exists by calling stat().
  *
@@ -305,6 +313,10 @@ int main(int argc, char *argv[]) {
         action.sa_handler = sigpipe;
         sigaction(SIGPIPE, &action, NULL);
 
+        memset(&action, 0, sizeof(struct sigaction));
+        action.sa_handler = sigusr1;
+        sigaction(SIGUSR1, &action, NULL);
+
         if (setlocale(LC_ALL, "") == NULL)
                 die("Could not set locale. Please make sure all your LC_* / LANG settings are correct.");
 
@@ -503,10 +515,11 @@ int main(int argc, char *argv[]) {
                 /* To provide updates on every full second (as good as possible)
                  * we don’t use sleep(interval) but we sleep until the next
                  * second (with microsecond precision) plus (interval-1)
-                 * seconds. */
+                 * seconds. We also align to 60 seconds modulo interval such
+                 * that we start with :00 on every new minute. */
                 struct timeval current_timeval;
                 gettimeofday(&current_timeval, NULL);
-                struct timespec ts = {interval - 1, (10e5 - current_timeval.tv_usec) * 1000};
+                struct timespec ts = {interval - 1 - (current_timeval.tv_sec % interval), (10e5 - current_timeval.tv_usec) * 1000};
                 nanosleep(&ts, NULL);
         }
 }