X-Git-Url: https://jasonwoof.com/gitweb/?p=st.git;a=blobdiff_plain;f=st.c;h=64366afb3e9393613db1460faed9c5bd9090c05c;hp=f4b419eb1a6f70a8d11def687a197e12ae7d48eb;hb=f4a6c20f464df79a9b15b4a2a11daaa7a06c60a0;hpb=95033753be32e93915ddce14ea41b8765b665771 diff --git a/st.c b/st.c index f4b419e..64366af 100644 --- a/st.c +++ b/st.c @@ -61,6 +61,7 @@ #define DRAW_BUF_SIZ 20*1024 #define XK_ANY_MOD UINT_MAX #define XK_NO_MOD 0 +#define XK_SWITCH_MOD (1<<13) #define REDRAW_TIMEOUT (80*1000) /* 80 ms */ @@ -3008,6 +3009,8 @@ focus(XEvent *ev) { inline bool match(uint mask, uint state) { + state &= ~(ignoremod); + if(mask == XK_NO_MOD && state) return false; if(mask != XK_ANY_MOD && mask != XK_NO_MOD && !state) @@ -3166,12 +3169,12 @@ void run(void) { XEvent ev; fd_set rfd; - int xfd = XConnectionNumber(xw.dpy); + int xfd = XConnectionNumber(xw.dpy), xev; struct timeval drawtimeout, *tv = NULL, now, last; gettimeofday(&last, NULL); - for(;;) { + for(xev = actionfps;;) { FD_ZERO(&rfd); FD_SET(cmdfd, &rfd); FD_SET(xfd, &rfd); @@ -3182,24 +3185,18 @@ run(void) { } gettimeofday(&now, NULL); - /* usecs until (next) frame */ drawtimeout.tv_sec = 0; - drawtimeout.tv_usec = \ - ((1000/framespersecond) - TIMEDIFF(now, last)) * 1000; - - /* Let us draw a frame. */ - if(drawtimeout.tv_usec <= 0) { - draw(); - XFlush(xw.dpy); - - last = now; - tv = NULL; - } + drawtimeout.tv_usec = (1000/xfps) * 1000; + tv = &drawtimeout; if(FD_ISSET(cmdfd, &rfd)) ttyread(); - if(FD_ISSET(xfd, &rfd)) { + if(FD_ISSET(xfd, &rfd)) + xev = actionfps; + + if(TIMEDIFF(now, last) > \ + (xev ? (1000/xfps) : (1000/actionfps))) { while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev); if(XFilterEvent(&ev, None)) @@ -3208,16 +3205,14 @@ run(void) { (handler[ev.type])(&ev); } - if(drawtimeout.tv_usec <= 0) { - draw(); - XFlush(xw.dpy); - } - } + draw(); + XFlush(xw.dpy); + last = now; - /* There is still some time to wait until next frame. */ - if(drawtimeout.tv_usec > 0) { - tv = &drawtimeout; - continue; + if(xev && !FD_ISSET(xfd, &rfd)) + xev--; + if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) + tv = NULL; } } }