diff options
| author | Quentin Carbonneaux | 2014-08-27 22:21:36 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-08-27 22:21:36 -0400 |
| commit | 7db6832e6ef836d0443c5dd8719e6a4dc8bdece8 (patch) | |
| tree | 65c2a967a3983fa03a665efcbb2b4db44bdc7bac | |
| parent | 54511cf924d9631ebc700fc0c8b5abe2cfe941d2 (diff) | |
mitigate race with XFlush
| -rw-r--r-- | main.c | 48 | ||||
| -rw-r--r-- | x11.c | 1 |
2 files changed, 25 insertions, 24 deletions
@@ -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(); +} @@ -196,7 +196,6 @@ static void sync() { XCopyArea(d, pbuf, win, gc, 0, 0, w, h, 0, 0); - XFlush(d); } static int |
