From 261fc5698fb494b466ce35b0150a2f52c964d8a4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 May 2016 05:15:26 -0400 Subject: rate limit redraws --- src/window-xlib.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/window-xlib.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/window-xlib.c b/src/window-xlib.c index 48d8654..64abafc 100644 --- a/src/window-xlib.c +++ b/src/window-xlib.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -83,6 +84,8 @@ static Bool runes_window_backend_find_flush_events( static void runes_window_backend_resize_window( RunesTerm *t, int width, int height); static void runes_window_backend_flush(RunesTerm *t); +static int runes_window_backend_check_recent(RunesTerm *t); +static void runes_window_backend_delay_cb(RunesTerm *t); static void runes_window_backend_visible_scroll(RunesTerm *t, int count); static void runes_window_backend_visual_bell(RunesTerm *t); static void runes_window_backend_reset_visual_bell(RunesTerm *t); @@ -470,6 +473,10 @@ static void runes_window_backend_flush(RunesTerm *t) { RunesWindowBackend *w = &t->w; + if (runes_window_backend_check_recent(t)) { + return; + } + if (t->scr.audible_bell) { runes_window_backend_audible_bell(t); t->scr.audible_bell = 0; @@ -503,6 +510,41 @@ static void runes_window_backend_flush(RunesTerm *t) cairo_paint(w->backend_cr); runes_display_draw_cursor(t, w->backend_cr); cairo_surface_flush(cairo_get_target(w->backend_cr)); + + clock_gettime(CLOCK_REALTIME, &w->last_redraw); +} + +static int runes_window_backend_check_recent(RunesTerm *t) +{ + RunesWindowBackend *w = &t->w; + struct timespec now; + + clock_gettime(CLOCK_REALTIME, &now); + now.tv_nsec -= 10000000; + if (now.tv_nsec < 0) { + now.tv_sec -= 1; + now.tv_nsec += 1000000000; + } + if (now.tv_sec < w->last_redraw.tv_sec || (now.tv_sec == w->last_redraw.tv_sec && now.tv_nsec < w->last_redraw.tv_nsec)) { + if (!w->delaying) { + runes_loop_timer_set( + t->loop, 10, 0, t, runes_window_backend_delay_cb); + w->delaying = 1; + } + return 1; + } + else { + return 0; + } + +} + +static void runes_window_backend_delay_cb(RunesTerm *t) +{ + RunesWindowBackend *w = &t->w; + + w->delaying = 0; + runes_window_backend_request_flush(t); } static void runes_window_backend_visible_scroll(RunesTerm *t, int count) diff --git a/src/window-xlib.h b/src/window-xlib.h index 4a49340..d8e04f2 100644 --- a/src/window-xlib.h +++ b/src/window-xlib.h @@ -2,6 +2,7 @@ #define _RUNES_XLIB_H #include +#include #include enum runes_atoms { @@ -27,12 +28,14 @@ struct runes_window { XEvent event; char *selection_contents; size_t selection_len; + struct timespec last_redraw; cairo_t *backend_cr; Atom atoms[RUNES_NUM_ATOMS]; char visual_bell_is_ringing: 1; + char delaying: 1; }; void runes_window_backend_create_window(RunesTerm *t, int argc, char *argv[]); -- cgit v1.2.3-54-g00ecf