aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-06 05:15:26 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-06 05:15:26 -0400
commit261fc5698fb494b466ce35b0150a2f52c964d8a4 (patch)
treedb03fa0bb99f02606bbb33b5894ce126ad718443
parent626525986b0a55c2ed1d72e8f76a49b31efabd52 (diff)
downloadrunes-261fc5698fb494b466ce35b0150a2f52c964d8a4.tar.gz
runes-261fc5698fb494b466ce35b0150a2f52c964d8a4.zip
rate limit redraws
-rw-r--r--src/window-xlib.c42
-rw-r--r--src/window-xlib.h3
2 files changed, 45 insertions, 0 deletions
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 <cairo-xlib.h>
#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xlib.h>
@@ -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 <cairo.h>
+#include <time.h>
#include <X11/Xlib.h>
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[]);