+#ifdef __unix__
+ dpy = glXGetCurrentDisplay();
+ xfd = ConnectionNumber(dpy);
+ maxfd = xfd > pfd[0] ? xfd : pfd[0];
+
+ while(!quit) {
+ struct timeval tv = {0, 0};
+ fd_set rdset;
+
+ FD_ZERO(&rdset);
+ FD_SET(xfd, &rdset);
+ FD_SET(pfd[0], &rdset);
+
+ if(select(maxfd + 1, &rdset, 0, 0, redisp_pending ? &tv : 0) == -1) {
+ if(errno == EINTR) continue;
+ fprintf(stderr, "select failed: %s\n", strerror(errno));
+ break;
+ }
+
+ redisp_pending = 0;
+ glutMainLoopEvent();
+
+ if(FD_ISSET(pfd[0], &rdset)) {
+ struct erb_rect rect;
+ read(pfd[0], &rect, sizeof rect);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x, rect.y, rect.w, rect.h,
+ GL_RGBA, GL_FLOAT, erb_getframe(erb) + (rect.y * win_width + rect.x) * 4);
+ post_redisplay();
+ printf("update (%d %d %dx%d)!\n", rect.x, rect.y, rect.w, rect.h);
+ }
+ }
+#endif /* __unix__ */
+