X-Git-Url: https://jasonwoof.com/gitweb/?p=st.git;a=blobdiff_plain;f=st.c;h=64366afb3e9393613db1460faed9c5bd9090c05c;hp=a1932dd4e69de6b0b8a9bf62981f9dbee33073e5;hb=f4a6c20f464df79a9b15b4a2a11daaa7a06c60a0;hpb=efd04ccad6d3c4e981b3efdb0423d8f5ca40f984 diff --git a/st.c b/st.c index a1932dd..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 */ @@ -807,7 +808,6 @@ void selclear(XEvent *e) { void selrequest(XEvent *e) { - fprintf(stderr, "selrequest\n"); XSelectionRequestEvent *xsre; XSelectionEvent xev; Atom xa_targets, string; @@ -843,7 +843,6 @@ selrequest(XEvent *e) { void xsetsel(char *str) { - fprintf(stderr, "xsetsel: %s\n", str); /* register the selection for both the clipboard and the primary */ Atom clipboard; @@ -1559,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); @@ -2277,7 +2278,7 @@ xresize(int col, int row) { XFreePixmap(xw.dpy, xw.buf); xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, DefaultDepth(xw.dpy, xw.scr)); - XSetForeground(xw.dpy, dc.gc, 0); + XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel); XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); } @@ -2442,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); @@ -2453,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); @@ -2572,7 +2576,7 @@ xinit(void) { &gcvalues); xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, DefaultDepth(xw.dpy, xw.scr)); - XSetForeground(xw.dpy, dc.gc, 0); + XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); //xw.buf = xw.win; /* @@ -2896,7 +2900,7 @@ draw(void) { } else { XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, 0, 0); - XSetForeground(xw.dpy, dc.gc, 0); + XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel); } } @@ -2988,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; @@ -3000,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) @@ -3158,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); @@ -3171,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; + } } }