X-Git-Url: https://jasonwoof.com/gitweb/?p=st.git;a=blobdiff_plain;f=st.c;h=64366afb3e9393613db1460faed9c5bd9090c05c;hp=08cda34c2b55585c7471ab59b78c1f247b950a53;hb=f4a6c20f464df79a9b15b4a2a11daaa7a06c60a0;hpb=8a9475a0dd9b8751b9b0ed4c7da4db09232e318e diff --git a/st.c b/st.c index 08cda34..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 */ @@ -1557,9 +1558,11 @@ tsetmode(bool priv, bool set, int *args, int narg) { break; case 1000: /* 1000,1002: enable xterm mouse report */ MODBIT(term.mode, set, MODE_MOUSEBTN); + MODBIT(term.mode, 0, MODE_MOUSEMOTION); break; case 1002: MODBIT(term.mode, set, MODE_MOUSEMOTION); + MODBIT(term.mode, 0, MODE_MOUSEBTN); break; case 1006: MODBIT(term.mode, set, MODE_MOUSESGR); @@ -2440,7 +2443,9 @@ xloadfonts(char *fontstr, int fontsize) { xw.cw = dc.font.width; xw.ch = dc.font.height; + FcPatternDel(pattern, FC_SLANT); FcPatternDel(pattern, FC_WEIGHT); + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN); FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); if(xloadfont(&dc.bfont, pattern)) die("st: can't open font %s\n", fontstr); @@ -2451,6 +2456,7 @@ xloadfonts(char *fontstr, int fontsize) { die("st: can't open font %s\n", fontstr); FcPatternDel(pattern, FC_WEIGHT); + FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM); if(xloadfont(&dc.ifont, pattern)) die("st: can't open font %s\n", fontstr); @@ -2986,6 +2992,11 @@ xseturgency(int add) { void focus(XEvent *ev) { + XFocusChangeEvent *e = &ev->xfocus; + + if(e->mode == NotifyGrab) + return; + if(ev->type == FocusIn) { XSetICFocus(xw.xic); xw.state |= WIN_FOCUSED; @@ -2998,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) @@ -3156,10 +3169,12 @@ void run(void) { XEvent ev; fd_set rfd; - int xfd = XConnectionNumber(xw.dpy), i; - struct timeval drawtimeout, *tv = NULL; + int xfd = XConnectionNumber(xw.dpy), xev; + struct timeval drawtimeout, *tv = NULL, now, last; - for(i = 0;; i++) { + gettimeofday(&last, NULL); + + for(xev = actionfps;;) { FD_ZERO(&rfd); FD_SET(cmdfd, &rfd); FD_SET(xfd, &rfd); @@ -3169,35 +3184,36 @@ run(void) { die("select failed: %s\n", SERRNO); } - /* - * Stop after a certain number of reads so the user does not - * feel like the system is stuttering. - */ - if(i < 1000 && FD_ISSET(cmdfd, &rfd)) { + gettimeofday(&now, NULL); + drawtimeout.tv_sec = 0; + drawtimeout.tv_usec = (1000/xfps) * 1000; + tv = &drawtimeout; + + if(FD_ISSET(cmdfd, &rfd)) ttyread(); - /* - * Just wait a bit so it isn't disturbing the - * user and the system is able to write something. - */ - drawtimeout.tv_sec = 0; - drawtimeout.tv_usec = 5; - tv = &drawtimeout; - continue; - } - i = 0; - tv = NULL; + if(FD_ISSET(xfd, &rfd)) + xev = actionfps; - while(XPending(xw.dpy)) { - XNextEvent(xw.dpy, &ev); - if(XFilterEvent(&ev, None)) - continue; - if(handler[ev.type]) - (handler[ev.type])(&ev); - } + if(TIMEDIFF(now, last) > \ + (xev ? (1000/xfps) : (1000/actionfps))) { + while(XPending(xw.dpy)) { + XNextEvent(xw.dpy, &ev); + if(XFilterEvent(&ev, None)) + continue; + if(handler[ev.type]) + (handler[ev.type])(&ev); + } - draw(); - XFlush(xw.dpy); + draw(); + XFlush(xw.dpy); + last = now; + + if(xev && !FD_ISSET(xfd, &rfd)) + xev--; + if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) + tv = NULL; + } } }