X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=d7ca87516155edc8977cf5fafadc2fc9ed3de13a;hb=85849ce72aa4e9cee307a031b97777e9eba2d453;hp=2e1ac670b04498445534194f9f38a7cb5f3c55bb;hpb=a62789788c87425fd90209bad15b324f8dee84da;p=st.git diff --git a/st.c b/st.c index 2e1ac67..d7ca875 100644 --- a/st.c +++ b/st.c @@ -53,8 +53,6 @@ #define XK_NO_MOD UINT_MAX #define XK_ANY_MOD 0 -#define SELECT_TIMEOUT (20*1000) /* 20 ms */ -#define DRAW_TIMEOUT (20*1000) /* 20 ms */ #define REDRAW_TIMEOUT (80*1000) /* 80 ms */ #define SERRNO strerror(errno) @@ -205,7 +203,6 @@ typedef struct { int ch; /* char height */ int cw; /* char width */ char state; /* focus, redraw, visible */ - struct timeval lastdraw; } XWindow; typedef struct { @@ -250,7 +247,6 @@ static void drawregion(int, int, int, int); static void execsh(void); static void sigchld(int); static void run(void); -static bool last_draw_too_old(void); static void csidump(void); static void csihandle(void); @@ -1970,7 +1966,7 @@ xinit(void) { XSetWindowAttributes attrs; Cursor cursor; Window parent; - int sw, sh; + int sw, sh, major, minor; if(!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); @@ -2021,9 +2017,10 @@ xinit(void) { CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask | CWColormap, &attrs); + if(!XdbeQueryExtension(xw.dpy, &major, &minor)) + die("Xdbe extension is not present\n"); xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied); - /* input methods */ xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL); xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing @@ -2149,6 +2146,7 @@ redraw(void) { struct timespec tv = {0, REDRAW_TIMEOUT * 1000}; tfulldirt(); draw(); + XSync(xw.dpy, False); /* necessary for a good tput flash */ nanosleep(&tv, NULL); } @@ -2156,7 +2154,6 @@ void draw() { drawregion(0, 0, term.col, term.row); xcopy(); - gettimeofday(&xw.lastdraw, NULL); } void @@ -2343,41 +2340,25 @@ resize(XEvent *e) { ttyresize(col, row); } -bool -last_draw_too_old(void) { - struct timeval now; - gettimeofday(&now, NULL); - return TIMEDIFF(now, xw.lastdraw) >= DRAW_TIMEOUT/1000; -} - void run(void) { XEvent ev; fd_set rfd; int xfd = XConnectionNumber(xw.dpy); - struct timeval timeout = {0}; - bool stuff_to_print = 0; for(;;) { FD_ZERO(&rfd); FD_SET(cmdfd, &rfd); FD_SET(xfd, &rfd); - timeout.tv_sec = 0; - timeout.tv_usec = SELECT_TIMEOUT; - if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, &timeout) < 0) { + if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) < 0) { if(errno == EINTR) continue; die("select failed: %s\n", SERRNO); } - if(FD_ISSET(cmdfd, &rfd)) { + if(FD_ISSET(cmdfd, &rfd)) ttyread(); - stuff_to_print = 1; - } - if(stuff_to_print && last_draw_too_old()) { - stuff_to_print = 0; - draw(); - } + draw(); while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev);