diff options
| author | Quentin Carbonneaux | 2018-02-28 16:22:02 -0500 |
|---|---|---|
| committer | Quentin Carbonneaux | 2018-02-28 16:22:02 -0500 |
| commit | 77d96145b163d79186c722a7ffccfff57601157c (patch) | |
| tree | 674fb2cd69b7731051675ed73fd5d23548e55615 | |
| parent | ee62f95569841f016025198dabf379eaa816c1dc (diff) | |
fix unlikely race
XFlush() can in fact fetch events and add them to Xlib's
internal queue. It happens very rarely with the current
implementation, but when it does, we are missing a UI
update.
| -rw-r--r-- | gui.h | 2 | ||||
| -rw-r--r-- | main.c | 33 | ||||
| -rw-r--r-- | win.c | 1 | ||||
| -rw-r--r-- | x11.c | 4 |
4 files changed, 22 insertions, 18 deletions
@@ -94,7 +94,6 @@ enum { struct gui { int (*init)(void); void (*fini)(void); - void (*sync)(void); void (*getfont)(GFont *fret); void (*decorate)(GRect *clip, int dirty, GColor color); void (*drawtext)(GRect *clip, Rune *str, int len, @@ -102,6 +101,7 @@ struct gui { void (*drawrect)(GRect *clip, int x, int y, int w, int h, GColor c); void (*drawcursor)(GRect *clip, int insert, int x, int y, int w); void (*setpointer)(GPointer pt); + int (*sync)(void); int (*textwidth)(Rune *str, int len); int (*nextevent)(GEvent *eret); int hmargin; @@ -18,14 +18,17 @@ W *curwin; int scrolling; -int needsredraw; enum { RedrawDelay = 16, /* in milliseconds */ DoubleClick = 600, }; + +static void redraw(); + static struct gui *g; static int clicks; +static int needsredraw; void @@ -47,19 +50,6 @@ resetclicks() clicks = 0; } -static void -redraw() -{ - static W *old; - - assert(needsredraw); - if (old != curwin && old) - old->dirty = 1; - win_redraw_frame(curwin, mode == 'i'); - old = curwin; - needsredraw = 0; -} - void repaint() { @@ -157,6 +147,21 @@ gev(int fd, int flag, void *unused) } } +static void +redraw() +{ + static W *old; + + assert(needsredraw); + if (old != curwin && old) + old->dirty = 1; + old = curwin; + needsredraw = 0; + win_redraw_frame(curwin, mode == 'i'); + if (g->sync()) + gev(0, 0, 0); +} + int main(int ac, char *av[]) { @@ -294,7 +294,6 @@ win_redraw_frame(W *focus, int insert) g->drawrect(&b, 0, 0, b.w, g->border, GGray); draw(&tag.win, GPaleGreen, focus, insert); } - g->sync(); } /* win_scroll - Scroll the window by [n] lines. @@ -208,11 +208,11 @@ textwidth(Rune *str, int len) return gi.xOff; } -static void +static int sync() { XCopyArea(d, pbuf, win, gc, 0, 0, w, h, 0, 0); - XFlush(d); + return XPending(d); // calls XFlush() } static int |
