aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-22 23:27:29 +0100
committerBert <ber.t@gmx.com>2011-01-22 23:27:29 +0100
commit0f714bccda28cd2faa5095fa1ace5d8a113beaec (patch)
tree3cb8987a175e0267b062137be553ee515c4fe88f /main.c
parent60a9ed756778478b19ce9d44cfa3ac963aeec175 (diff)
Handle window resize events properly
Diffstat (limited to 'main.c')
-rw-r--r--main.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/main.c b/main.c
index 497cc38..5c29e8e 100644
--- a/main.c
+++ b/main.c
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <sys/select.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -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() {