In Xlib, How can I animate until an event occurs?

狂风中的少年 提交于 2019-12-06 07:14:39

Use the file descriptor returned by ConnectionNumber(display) with select() and use the timeout argument. If select() returns 0, then draw some more frames. Remember to call XSync() before you select() so that the X server gets your update.

int fd,r;
struct timeval tv;
FD_SET rfds;

fd=ConnectionNumber(display);
FD_ZERO(&rfds);
FD_SET(fd,&rfds);
memset(&tv,0,sizeof(tv));
tv.tv_usec = 100000; /* delay in microseconds */
r=select(fd+1,&rfds,0,0,&tv);
if(r == 0) { /* draw frame */ }
else if (r < 0) { /* error; try again if errno=EINTR */ }
else { /* pull events out */ }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!