i3lock-color

The world's most popular non-default computer lockscreen.
Index Commits Files Refs README LICENSE
commit e69147d8604c508e3b83f2a18ad236a071aa255b
parent d623b5b9043ae51c56fa9cdfa3268977c2820cb3
Author: Pandora <Pandora@techfo.xyz>
Date:   Fri,  8 Dec 2017 00:38:55 -0500

fix that annoying refresh bug

Diffstat:
Mconfigure.ac | 1+
Mi3lock.c | 19+++++++++++++++----
Munlock_indicator.c | 23++++++-----------------
Munlock_indicator.h | 2+-
4 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -103,6 +103,7 @@ AM_PROG_AR
 AX_FLAGS_WARN_ALL
 AX_APPEND_FLAG([-O2], [AM_CFLAGS])
 AX_APPEND_FLAG([-funroll-loops], [AM_CFLAGS])
+AX_APPEND_FLAG([-pthread], [AM_CFLAGS])
 AX_CHECK_COMPILE_FLAG([-Wunused-value], [AX_APPEND_FLAG([-Wunused-value], [AM_CFLAGS])])
 AC_SUBST(AM_CFLAGS)
 
diff --git a/i3lock.c b/i3lock.c
@@ -8,6 +8,9 @@
  */
 #include <config.h>
 
+#include <pthread.h>
+#include <math.h>
+
 #include <stdio.h>
 #include <locale.h>
 #include <stdlib.h>
@@ -481,10 +484,9 @@ static void input_done(void) {
         return;
     }
 #endif
-
     if (debug_mode)
         fprintf(stderr, "Authentication failure\n");
-
+    
     /* Get state of Caps and Num lock modifiers, to be displayed in
      * STATE_AUTH_WRONG state */
     xkb_mod_index_t idx, num_mods;
@@ -1560,7 +1562,7 @@ int main(int argc, char *argv[]) {
                         errx(1, "bar-color is invalid, color must be given in 4-byte format: rrggbbaa\n");
                 
                 }
-                else if (strcmp(longopts[longoptind].name, "bar-perioidic-step") == 0) {
+                else if (strcmp(longopts[longoptind].name, "bar-periodic-step") == 0) {
                     int tmp = atoi(optarg);
                     if (tmp > 0)
                         bar_periodic_step = tmp;
@@ -1811,8 +1813,17 @@ int main(int argc, char *argv[]) {
      * received up until now. ev will only pick up new events (when the X11
      * file descriptor becomes readable). */
     ev_invoke(main_loop, xcb_check, 0);
+
+// boy i sure hope this doesnt change in the future
+#define NANOSECONDS_IN_SECOND 1000000000
     if (show_clock || bar_enabled) {
-        start_time_redraw_tick(main_loop);
+        pthread_t draw_thread;
+        struct timespec ts;
+        double s;
+        double ns = modf(refresh_rate, &s);
+        ts.tv_sec = (time_t) s;
+        ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
+        (void) pthread_create(&draw_thread, NULL, start_time_redraw_tick, (void*) &ts);
     }
     ev_loop(main_loop, 0);
 
diff --git a/unlock_indicator.c b/unlock_indicator.c
@@ -133,9 +133,6 @@ extern xcb_screen_t *screen;
  * Local variables.
  ******************************************************************************/
 
-/* time stuff */
-static struct ev_periodic *time_redraw_tick;
-
 /* Cache the screen’s visual, necessary for creating a Cairo context. */
 static xcb_visualtype_t *vistype;
 
@@ -940,19 +937,11 @@ void clear_indicator(void) {
     redraw_screen();
 }
 
-static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) {
-    redraw_screen();
-}
-
-void start_time_redraw_tick(struct ev_loop* main_loop) {
-    if (time_redraw_tick) {
-        ev_periodic_set(time_redraw_tick, 0., refresh_rate, 0);
-        ev_periodic_again(main_loop, time_redraw_tick);
-    } else {
-        if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) {
-           return;
-        }
-        ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., refresh_rate, 0);
-        ev_periodic_start(main_loop, time_redraw_tick);
+void* start_time_redraw_tick(void* arg) {
+    struct timespec *ts = (struct timespec *) arg;
+    while(1) {
+        nanosleep(ts, NULL);
+        redraw_screen();
     }
+    return NULL;
 }
diff --git a/unlock_indicator.h b/unlock_indicator.h
@@ -51,5 +51,5 @@ void init_colors_once(void);
 void redraw_screen(void);
 void clear_indicator(void);
 void start_time_redraw_timeout(void);
-void start_time_redraw_tick(struct ev_loop*);
+void* start_time_redraw_tick(void* arg);
 #endif