fix that annoying refresh bug

This commit is contained in:
Pandora 2017-12-08 00:38:55 -05:00
parent d623b5b904
commit e69147d860
4 changed files with 23 additions and 22 deletions

View File

@ -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)

View File

@ -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);

View File

@ -133,9 +133,6 @@ extern xcb_screen_t *screen;
* Local variables.
******************************************************************************/
/* time stuff */
static struct ev_periodic *time_redraw_tick;
/* Cache the screens 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;
}

View File

@ -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