From 0f714bccda28cd2faa5095fa1ace5d8a113beaec Mon Sep 17 00:00:00 2001 From: Bert Date: Sat, 22 Jan 2011 23:27:29 +0100 Subject: Handle window resize events properly --- main.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 497cc38..5c29e8e 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -45,14 +46,34 @@ const char **filenames; unsigned int filecnt; unsigned int fileidx; +unsigned char timeout; + #define TITLE_LEN 256 char win_title[TITLE_LEN]; void run() { + int xfd; + fd_set fds; + struct timeval t; XEvent ev; - while (!XNextEvent(win.env.dpy, &ev)) { - if (handler[ev.type]) + timeout = 0; + + while (1) { + if (timeout) { + t.tv_sec = 0; + t.tv_usec = 250; + xfd = ConnectionNumber(win.env.dpy); + FD_ZERO(&fds); + FD_SET(xfd, &fds); + + if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) { + img_render(&img, &win); + timeout = 0; + } + } + + if (!XNextEvent(win.env.dpy, &ev) && handler[ev.type]) handler[ev.type](&ev); } } @@ -175,14 +196,18 @@ void on_keypress(XEvent *ev) { if (changed) { img_render(&img, &win); update_title(); + timeout = 0; } } void on_configurenotify(XEvent *ev) { if (!ev) return; - - win_configure(&win, &ev->xconfigure); + + if (win_configure(&win, &ev->xconfigure)) { + img.checkpan = 1; + timeout = 1; + } } void update_title() { -- cgit v1.2.3-54-g00ecf