summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2014-08-27 22:21:36 -0400
committerQuentin Carbonneaux2014-08-27 22:21:36 -0400
commit7db6832e6ef836d0443c5dd8719e6a4dc8bdece8 (patch)
tree65c2a967a3983fa03a665efcbb2b4db44bdc7bac
parent54511cf924d9631ebc700fc0c8b5abe2cfe941d2 (diff)
mitigate race with XFlush
-rw-r--r--main.c48
-rw-r--r--x11.c1
2 files changed, 25 insertions, 24 deletions
diff --git a/main.c b/main.c
index 0789ec5..3ed8cac 100644
--- a/main.c
+++ b/main.c
@@ -12,41 +12,27 @@
#include "gui.h"
#include "win.h"
-enum { RedrawDelay = 15 /* in milliseconds */ };
-
W *curwin;
int scrolling;
-int needsredraw;
-static struct gui *g;
+static void redraw(void);
-void
-die(char *m)
-{
- fprintf(stderr, "dying, %s\n", m);
- abort();
-}
+static struct gui *g;
+static int needsredraw;
-static void
-redraw()
-{
- assert(needsredraw);
- win_redraw_frame();
- needsredraw = 0;
-}
static int
gev(int fd, int flag, void *unused)
{
+ enum { RedrawDelay = 16 /* in milliseconds */ };
static unsigned selbeg;
static W *mousewin;
static int resizing;
- unsigned pos;
+ unsigned pos, ne;
GEvent e;
- (void) fd;
- assert(flag == ERead && unused == 0);
- while (g->nextevent(&e) != 0) {
+ (void)fd; (void)flag; (void)unused;
+ for (ne = 0; g->nextevent(&e) != 0; ne |= 1) {
switch (e.type) {
case GResize:
win_resize_frame(e.resize.width, e.resize.height);
@@ -112,13 +98,22 @@ gev(int fd, int flag, void *unused)
curwin->cu = pos;
curwin->rev = 0;
}
- if (!needsredraw) {
+ if (ne && !needsredraw) {
ev_alarm(RedrawDelay, redraw);
needsredraw = 1;
}
return 0;
}
+static void
+redraw()
+{
+ assert(needsredraw);
+ win_redraw_frame();
+ needsredraw = 0;
+ gev(0, 0, 0);
+}
+
int
main(int ac, char *av[])
{
@@ -133,6 +128,13 @@ main(int ac, char *av[])
if (ac > 1)
ex_get(eb, av[1]);
curwin = win_new(eb);
- gev(0, ERead, 0);
+ gev(0, 0, 0);
ev_loop();
}
+
+void
+die(char *m)
+{
+ fprintf(stderr, "dying, %s\n", m);
+ abort();
+}
diff --git a/x11.c b/x11.c
index 0ac120d..11dd437 100644
--- a/x11.c
+++ b/x11.c
@@ -196,7 +196,6 @@ static void
sync()
{
XCopyArea(d, pbuf, win, gc, 0, 0, w, h, 0, 0);
- XFlush(d);
}
static int