MODE_APPCURSOR = 2048,
MODE_MOUSESGR = 4096,
MODE_8BIT = 8192,
+ MODE_BLINK = 16384,
+ MODE_FBLINK = 32768,
+ MODE_FOCUS = 65536,
};
enum escape_state {
char state; /* focus, redraw, visible */
} XWindow;
+typedef struct {
+ int b;
+ uint mask;
+ char s[ESC_BUF_SIZ];
+} Mousekey;
+
typedef struct {
KeySym k;
uint mask;
int mode;
int type;
int snap;
- int bx, by;
- int ex, ey;
+ /*
+ * Selection variables:
+ * nb – normalized coordinates of the beginning of the selection
+ * ne – normalized coordinates of the end of the selection
+ * ob – original coordinates of the beginning of the selection
+ * oe – original coordinates of the end of the selection
+ */
struct {
int x, y;
- } b, e;
+ } nb, ne, ob, oe;
+
char *clip;
Atom xtarget;
bool alt;
static void strparse(void);
static void strreset(void);
+static int tattrset(int);
static void tclearregion(int, int, int, int);
static void tcursor(int);
static void tdeletechar(int);
static void tsetscroll(int, int);
static void tswapscreen(void);
static void tsetdirt(int, int);
+static void tsetdirtattr(int);
static void tsetmode(bool, bool, int *, int);
static void tfulldirt(void);
static void techo(char *, int);
static int xsetcolorname(int, const char *);
static int xloadfont(Font *, FcPattern *);
static void xloadfonts(char *, int);
+static int xloadfontset(Font *);
static void xsettitle(char *);
static void xresettitle(void);
static void xseturgency(int);
static void xsetsel(char*);
static void xtermclear(int, int, int, int);
+static void xunloadfont(Font *f);
static void xunloadfonts(void);
static void xresize(int, int);
static void selrequest(XEvent *);
static void selinit(void);
+static void selsort(void);
static inline bool selected(int, int);
static void selcopy(void);
static void selscroll(int, int);
}
}
-void
+static void
selinit(void) {
memset(&sel.tclick1, 0, sizeof(sel.tclick1));
memset(&sel.tclick2, 0, sizeof(sel.tclick2));
sel.mode = 0;
- sel.bx = -1;
+ sel.ob.x = -1;
sel.clip = NULL;
sel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
if(sel.xtarget == None)
return LIMIT(y, 0, term.row-1);
}
+static void
+selsort(void) {
+ if(sel.ob.y == sel.oe.y) {
+ sel.nb.x = MIN(sel.ob.x, sel.oe.x);
+ sel.ne.x = MAX(sel.ob.x, sel.oe.x);
+ } else {
+ sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x;
+ sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x;
+ }
+ sel.nb.y = MIN(sel.ob.y, sel.oe.y);
+ sel.ne.y = MAX(sel.ob.y, sel.oe.y);
+}
+
static inline bool
selected(int x, int y) {
- int bx, ex;
-
- if(sel.ey == y && sel.by == y) {
- bx = MIN(sel.bx, sel.ex);
- ex = MAX(sel.bx, sel.ex);
-
- return BETWEEN(x, bx, ex);
- }
+ if(sel.ne.y == y && sel.nb.y == y)
+ return BETWEEN(x, sel.nb.x, sel.ne.x);
if(sel.type == SEL_RECTANGULAR) {
- return ((sel.b.y <= y && y <= sel.e.y)
- && (sel.b.x <= x && x <= sel.e.x));
+ return ((sel.nb.y <= y && y <= sel.ne.y)
+ && (sel.nb.x <= x && x <= sel.ne.x));
}
- return ((sel.b.y < y && y < sel.e.y)
- || (y == sel.e.y && x <= sel.e.x))
- || (y == sel.b.y && x >= sel.b.x
- && (x <= sel.e.x || sel.b.y != sel.e.y));
+
+ return ((sel.nb.y < y && y < sel.ne.y)
+ || (y == sel.ne.y && x <= sel.ne.x))
+ || (y == sel.nb.y && x >= sel.nb.x
+ && (x <= sel.ne.x || sel.nb.y != sel.ne.y));
}
void
selsnap(int mode, int *x, int *y, int direction) {
+ int i;
+
switch(mode) {
case SNAP_WORD:
- while(*x > 0 && *x < term.col-1
- && term.line[*y][*x + direction].c[0] != ' ') {
+ /*
+ * Snap around if the word wraps around at the end or
+ * beginning of a line.
+ */
+ for(;;) {
+ if(direction < 0 && *x <= 0) {
+ if(*y > 0 && term.line[*y - 1][term.col-1].mode
+ & ATTR_WRAP) {
+ *y -= 1;
+ *x = term.col-1;
+ } else {
+ break;
+ }
+ }
+ if(direction > 0 && *x >= term.col-1) {
+ if(*y < term.row-1 && term.line[*y][*x].mode
+ & ATTR_WRAP) {
+ *y += 1;
+ *x = 0;
+ } else {
+ break;
+ }
+ }
+
+ if(strchr(worddelimiters,
+ term.line[*y][*x + direction].c[0])) {
+ break;
+ }
+
*x += direction;
}
break;
case SNAP_LINE:
+ /*
+ * Snap around if the the previous line or the current one
+ * has set ATTR_WRAP at its end. Then the whole next or
+ * previous line will be selected.
+ */
*x = (direction < 0) ? 0 : term.col - 1;
+ if(direction < 0 && *y > 0) {
+ for(; *y > 0; *y += direction) {
+ if(!(term.line[*y-1][term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+ }
+ } else if(direction > 0 && *y < term.row-1) {
+ for(; *y < term.row; *y += direction) {
+ if(!(term.line[*y][term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+ }
+ }
break;
default:
+ /*
+ * Select the whole line when the end of line is reached.
+ */
+ if(direction > 0) {
+ i = term.col;
+ while(--i > 0 && term.line[*y][i].c[0] == ' ')
+ /* nothing */;
+ if(i > 0 && i < *x)
+ *x = term.col - 1;
+ }
break;
}
}
sel.alt = IS_SET(MODE_ALTSCREEN);
- sel.ex = x2col(e->xbutton.x);
- sel.ey = y2row(e->xbutton.y);
+ sel.oe.x = x2col(e->xbutton.x);
+ sel.oe.y = y2row(e->xbutton.y);
- if (sel.by < sel.ey
- || (sel.by == sel.ey && sel.bx < sel.ex)) {
- selsnap(sel.snap, &sel.bx, &sel.by, -1);
- selsnap(sel.snap, &sel.ex, &sel.ey, +1);
+ if(sel.ob.y < sel.oe.y
+ || (sel.ob.y == sel.oe.y && sel.ob.x < sel.oe.x)) {
+ selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
+ selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
} else {
- selsnap(sel.snap, &sel.ex, &sel.ey, -1);
- selsnap(sel.snap, &sel.bx, &sel.by, +1);
+ selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
+ selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
}
-
- sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex;
- sel.b.y = MIN(sel.by, sel.ey);
- sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx;
- sel.e.y = MAX(sel.by, sel.ey);
+ selsort();
sel.type = SEL_REGULAR;
for(type = 1; type < LEN(selmasks); ++type) {
if(!IS_SET(MODE_MOUSEMOTION) || (x == ox && y == oy))
return;
button = ob + 32;
- ox = x, oy = y;
+ ox = x;
+ oy = y;
} else if(!IS_SET(MODE_MOUSESGR)
&& (e->xbutton.type == ButtonRelease
|| button == AnyButton)) {
button += 64 - 3;
if(e->xbutton.type == ButtonPress) {
ob = button;
- ox = x, oy = y;
+ ox = x;
+ oy = y;
}
}
void
bpress(XEvent *e) {
struct timeval now;
+ Mousekey *mk;
if(IS_SET(MODE_MOUSE)) {
mousereport(e);
- } else if(e->xbutton.button == Button1) {
+ return;
+ }
+
+ for(mk = mshortcuts; mk < mshortcuts + LEN(mshortcuts); mk++) {
+ if(e->xbutton.button == mk->b
+ && match(mk->mask, e->xbutton.state)) {
+ ttywrite(mk->s, strlen(mk->s));
+ if(IS_SET(MODE_ECHO))
+ techo(mk->s, strlen(mk->s));
+ return;
+ }
+ }
+
+ if(e->xbutton.button == Button1) {
gettimeofday(&now, NULL);
/* Clear previous selection, logically and visually. */
- if(sel.bx != -1) {
- sel.bx = -1;
- tsetdirt(sel.b.y, sel.e.y);
+ if(sel.ob.x != -1) {
+ sel.ob.x = -1;
+ tsetdirt(sel.nb.y, sel.ne.y);
draw();
}
sel.mode = 1;
sel.type = SEL_REGULAR;
- sel.ex = sel.bx = x2col(e->xbutton.x);
- sel.ey = sel.by = y2row(e->xbutton.y);
+ sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
+ sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
/*
- * Snap handling.
- * If user clicks are fasst enough (e.g. below timeouts),
- * we ignore if his hand slipped left or down and accidentally
- * selected more; we are just snapping to whatever we're
- * snapping.
+ * If the user clicks below predefined timeouts specific
+ * snapping behaviour is exposed.
*/
if(TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) {
sel.snap = SNAP_LINE;
} else {
sel.snap = 0;
}
- selsnap(sel.snap, &sel.bx, &sel.by, -1);
- selsnap(sel.snap, &sel.ex, &sel.ey, 1);
- sel.b.x = sel.bx;
- sel.b.y = sel.by;
- sel.e.x = sel.ex;
- sel.e.y = sel.ey;
+ selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
+ selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
+ selsort();
/*
* Draw selection, unless it's regular and we don't want to
* make clicks visible
*/
- if (sel.snap != 0) {
- tsetdirt(sel.b.y, sel.e.y);
+ if(sel.snap != 0) {
+ sel.mode++;
+ tsetdirt(sel.nb.y, sel.ne.y);
draw();
}
sel.tclick2 = sel.tclick1;
sel.tclick1 = now;
- } else if(e->xbutton.button == Button4) {
- ttywrite("\031", 1);
- } else if(e->xbutton.button == Button5) {
- ttywrite("\005", 1);
}
}
void
selcopy(void) {
char *str, *ptr;
- int x, y, bufsize, size;
+ int x, y, bufsize, size, i, ex;
Glyph *gp, *last;
- if(sel.bx == -1) {
+ if(sel.ob.x == -1) {
str = NULL;
} else {
- bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
+ bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ;
ptr = str = xmalloc(bufsize);
/* append every set & selected glyph to the selection */
- for(y = sel.b.y; y < sel.e.y + 1; y++) {
+ for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
gp = &term.line[y][0];
last = gp + term.col;
* st.
* FIXME: Fix the computer world.
*/
- if(y < sel.e.y && !((gp-1)->mode & ATTR_WRAP))
+ if(y < sel.ne.y && !((gp-1)->mode & ATTR_WRAP))
*ptr++ = '\n';
+
+ /*
+ * If the last selected line expands in the selection
+ * after the visible text '\n' is appended.
+ */
+ if(y == sel.ne.y) {
+ i = term.col;
+ while(--i > 0 && term.line[y][i].c[0] == ' ')
+ /* nothing */;
+ ex = sel.ne.x;
+ if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
+ ex = sel.nb.x;
+ if(i < ex)
+ *ptr++ = '\n';
+ }
}
*ptr = 0;
}
void
selclear(XEvent *e) {
- if(sel.bx == -1)
+ if(sel.ob.x == -1)
return;
- sel.bx = -1;
- tsetdirt(sel.b.y, sel.e.y);
+ sel.ob.x = -1;
+ tsetdirt(sel.nb.y, sel.ne.y);
}
void
if(e->xbutton.button == Button2) {
selpaste(NULL);
} else if(e->xbutton.button == Button1) {
- sel.mode = 0;
- getbuttoninfo(e);
- term.dirty[sel.ey] = 1;
- if(sel.bx == sel.ex && sel.by == sel.ey) {
- sel.bx = -1;
+ if(sel.mode < 2) {
+ sel.ob.x = -1;
} else {
+ getbuttoninfo(e);
selcopy();
}
+ sel.mode = 0;
+ tsetdirt(sel.nb.y, sel.ne.y);
}
}
if(!sel.mode)
return;
- oldey = sel.ey;
- oldex = sel.ex;
- oldsby = sel.b.y;
- oldsey = sel.e.y;
+ sel.mode++;
+ oldey = sel.oe.y;
+ oldex = sel.oe.x;
+ oldsby = sel.nb.y;
+ oldsey = sel.ne.y;
getbuttoninfo(e);
- if(oldey != sel.ey || oldex != sel.ex) {
- tsetdirt(MIN(sel.b.y, oldsby), MAX(sel.e.y, oldsey));
- }
+ if(oldey != sel.oe.y || oldex != sel.oe.x)
+ tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
}
void
fprintf(stderr, "Couldn't set window size: %s\n", SERRNO);
}
+int
+tattrset(int attr) {
+ int i, j;
+
+ for(i = 0; i < term.row-1; i++) {
+ for(j = 0; j < term.col-1; j++) {
+ if(term.line[i][j].mode & attr)
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
void
tsetdirt(int top, int bot) {
int i;
term.dirty[i] = 1;
}
+void
+tsetdirtattr(int attr) {
+ int i, j;
+
+ for(i = 0; i < term.row-1; i++) {
+ for(j = 0; j < term.col-1; j++) {
+ if(term.line[i][j].mode & attr) {
+ tsetdirt(i, i);
+ break;
+ }
+ }
+ }
+}
+
void
tfulldirt(void) {
tsetdirt(0, term.row-1);
void
selscroll(int orig, int n) {
- if(sel.bx == -1)
+ if(sel.ob.x == -1)
return;
- if(BETWEEN(sel.by, orig, term.bot) || BETWEEN(sel.ey, orig, term.bot)) {
- if((sel.by += n) > term.bot || (sel.ey += n) < term.top) {
- sel.bx = -1;
+ if(BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
+ if((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
+ sel.ob.x = -1;
return;
}
if(sel.type == SEL_RECTANGULAR) {
- if(sel.by < term.top)
- sel.by = term.top;
- if(sel.ey > term.bot)
- sel.ey = term.bot;
+ if(sel.ob.y < term.top)
+ sel.ob.y = term.top;
+ if(sel.oe.y > term.bot)
+ sel.oe.y = term.bot;
} else {
- if(sel.by < term.top) {
- sel.by = term.top;
- sel.bx = 0;
+ if(sel.ob.y < term.top) {
+ sel.ob.y = term.top;
+ sel.ob.x = 0;
}
- if(sel.ey > term.bot) {
- sel.ey = term.bot;
- sel.ex = term.col;
+ if(sel.oe.y > term.bot) {
+ sel.oe.y = term.bot;
+ sel.oe.x = term.col;
}
}
- sel.b.y = sel.by, sel.b.x = sel.bx;
- sel.e.y = sel.ey, sel.e.x = sel.ex;
+ selsort();
}
}
for(y = y1; y <= y2; y++) {
term.dirty[y] = 1;
for(x = x1; x <= x2; x++) {
+ if(selected(x, y))
+ selclear(NULL);
term.line[y][x] = term.c.attr;
memcpy(term.line[y][x].c, " ", 2);
}
MODBIT(term.mode, set, MODE_MOUSEMOTION);
MODBIT(term.mode, 0, MODE_MOUSEBTN);
break;
+ case 1003: /* 1003: enable all mouse reports */
+ MODBIT(term.mode, set, MODE_MOUSEMOTION);
+ MODBIT(term.mode, set, MODE_MOUSEBTN);
+ break;
+ case 1004:
+ MODBIT(term.mode, set, MODE_FOCUS);
+ break;
case 1006:
MODBIT(term.mode, set, MODE_MOUSESGR);
break;
case 1048:
tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
break;
+ /* Not implemented mouse modes. See comments there. */
+ case 9: /* X10 compatibility mode */
+ case 1001: /* mouse highlight mode; can hang the
+ terminal by design when implemented. */
+ case 1005: /* UTF-8 mouse mode; will confuse
+ applications not supporting UTF-8
+ and luit. */
+ case 1015: /* urxvt mangled mouse mode; incompatible
+ and can be mistaken for other control
+ codes. */
default:
fprintf(stderr,
"erresc: unknown private set/reset mode %d\n",
tputtab(1);
break;
case 'J': /* ED -- Clear screen */
- sel.bx = -1;
+ sel.ob.x = -1;
switch(csiescseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
*/
if(control && !(term.c.attr.mode & ATTR_GFX))
return;
- if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey))
- sel.bx = -1;
+ if(sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
+ sel.ob.x = -1;
if(IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
term.line[term.c.y][term.c.x].mode |= ATTR_WRAP;
tnewline(1);
if(!match)
return 1;
- if(!(f->set = FcFontSort(0, match, FcTrue, 0, &result))) {
- FcPatternDestroy(match);
- return 1;
- }
-
if(!(f->match = XftFontOpenPattern(xw.dpy, match))) {
FcPatternDestroy(match);
return 1;
}
+ f->set = NULL;
f->pattern = FcPatternDuplicate(pattern);
f->ascent = f->match->ascent;
FcPatternDestroy(pattern);
}
+int
+xloadfontset(Font *f) {
+ FcResult result;
+
+ if(!(f->set = FcFontSort(0, f->pattern, FcTrue, 0, &result)))
+ return 1;
+ return 0;
+}
+
+void
+xunloadfont(Font *f) {
+ XftFontClose(xw.dpy, f->match);
+ FcPatternDestroy(f->pattern);
+ if(f->set)
+ FcFontSetDestroy(f->set);
+}
+
void
xunloadfonts(void) {
int i, ip;
frccur = -1;
frclen = 0;
- XftFontClose(xw.dpy, dc.font.match);
- FcPatternDestroy(dc.font.pattern);
- FcFontSetDestroy(dc.font.set);
- XftFontClose(xw.dpy, dc.bfont.match);
- FcPatternDestroy(dc.bfont.pattern);
- FcFontSetDestroy(dc.bfont.set);
- XftFontClose(xw.dpy, dc.ifont.match);
- FcPatternDestroy(dc.ifont.pattern);
- FcFontSetDestroy(dc.ifont.set);
- XftFontClose(xw.dpy, dc.ibfont.match);
- FcPatternDestroy(dc.ibfont.pattern);
- FcFontSetDestroy(dc.ibfont.set);
+ xunloadfont(&dc.font);
+ xunloadfont(&dc.bfont);
+ xunloadfont(&dc.ifont);
+ xunloadfont(&dc.ibfont);
}
void
bg = temp;
}
+ if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
+ fg = bg;
+
/* Intelligent cleaning up of the borders. */
if(x == 0) {
xclear(0, (y == 0)? 0 : winy, borderpx,
/* Clean up the region we want to draw to. */
XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
+
+ /* Set the clip region because Xft is sometimes dirty. */
r.x = 0;
r.y = 0;
r.height = xw.ch;
r.width = width;
XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
- fcsets[0] = font->set;
for(xp = winx; bytelen > 0;) {
/*
* Search for the range in the to be printed string of glyphs
/* Nothing was found. */
if(i >= frclen) {
+ if(!font->set)
+ xloadfontset(font);
+ fcsets[0] = font->set;
+
/*
* Nothing was found in the cache. Now use
* some dozen of Fontconfig calls to get the
int ic, ib, x, y, ox, sl;
Glyph base, new;
char buf[DRAW_BUF_SIZ];
- bool ena_sel = sel.bx != -1;
+ bool ena_sel = sel.ob.x != -1;
if(sel.alt ^ IS_SET(MODE_ALTSCREEN))
ena_sel = 0;
ic = ib = ox = 0;
for(x = x1; x < x2; x++) {
new = term.line[y][x];
- if(ena_sel && *(new.c) && selected(x, y))
+ if(ena_sel && selected(x, y))
new.mode ^= ATTR_REVERSE;
if(ib > 0 && (ATTRCMP(base, new)
|| ib >= DRAW_BUF_SIZ-UTF_SIZ)) {
XSetICFocus(xw.xic);
xw.state |= WIN_FOCUSED;
xseturgency(0);
+ if(IS_SET(MODE_FOCUS))
+ ttywrite("\033[I", 3);
} else {
XUnsetICFocus(xw.xic);
xw.state &= ~WIN_FOCUSED;
+ if(IS_SET(MODE_FOCUS))
+ ttywrite("\033[O", 3);
}
}
run(void) {
XEvent ev;
fd_set rfd;
- int xfd = XConnectionNumber(xw.dpy), xev;
- struct timeval drawtimeout, *tv = NULL, now, last;
+ int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
+ struct timeval drawtimeout, *tv = NULL, now, last, lastblink;
+ gettimeofday(&lastblink, NULL);
gettimeofday(&last, NULL);
for(xev = actionfps;;) {
FD_ZERO(&rfd);
FD_SET(cmdfd, &rfd);
FD_SET(xfd, &rfd);
+
if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv) < 0) {
if(errno == EINTR)
continue;
die("select failed: %s\n", SERRNO);
}
+ if(FD_ISSET(cmdfd, &rfd)) {
+ ttyread();
+ if(blinktimeout) {
+ blinkset = tattrset(ATTR_BLINK);
+ if(!blinkset && term.mode & ATTR_BLINK)
+ term.mode &= ~(MODE_BLINK);
+ }
+ }
+
+ if(FD_ISSET(xfd, &rfd))
+ xev = actionfps;
gettimeofday(&now, NULL);
drawtimeout.tv_sec = 0;
drawtimeout.tv_usec = (1000/xfps) * 1000;
tv = &drawtimeout;
- if(FD_ISSET(cmdfd, &rfd))
- ttyread();
-
- if(FD_ISSET(xfd, &rfd))
- xev = actionfps;
+ dodraw = 0;
+ if(blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
+ tsetdirtattr(ATTR_BLINK);
+ term.mode ^= MODE_BLINK;
+ gettimeofday(&lastblink, NULL);
+ dodraw = 1;
+ }
+ if(TIMEDIFF(now, last) \
+ > (xev? (1000/xfps) : (1000/actionfps))) {
+ dodraw = 1;
+ last = now;
+ }
- if(TIMEDIFF(now, last) > \
- (xev ? (1000/xfps) : (1000/actionfps))) {
+ if(dodraw) {
while(XPending(xw.dpy)) {
XNextEvent(xw.dpy, &ev);
if(XFilterEvent(&ev, None))
draw();
XFlush(xw.dpy);
- last = now;
if(xev && !FD_ISSET(xfd, &rfd))
xev--;
- if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd))
- tv = NULL;
+ if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+ if(blinkset) {
+ if(TIMEDIFF(now, lastblink) \
+ > blinktimeout) {
+ drawtimeout.tv_usec = 1;
+ } else {
+ drawtimeout.tv_usec = (1000 * \
+ (blinktimeout - \
+ TIMEDIFF(now,
+ lastblink)));
+ }
+ } else {
+ tv = NULL;
+ }
+ }
}
}
}