|
|
|
|
@ -48,7 +48,7 @@ typedef struct {
|
|
|
|
|
/* X modifiers */
|
|
|
|
|
#define XK_ANY_MOD UINT_MAX
|
|
|
|
|
#define XK_NO_MOD 0
|
|
|
|
|
#define XK_SWITCH_MOD (1<<13|1<<14)
|
|
|
|
|
#define XK_SWITCH_MOD (1<<13)
|
|
|
|
|
|
|
|
|
|
/* function definitions used in config.h */
|
|
|
|
|
static void clipcopy(const Arg *);
|
|
|
|
|
@ -81,7 +81,6 @@ typedef XftGlyphFontSpec GlyphFontSpec;
|
|
|
|
|
typedef struct {
|
|
|
|
|
int tw, th; /* tty width and height */
|
|
|
|
|
int w, h; /* window width and height */
|
|
|
|
|
int hborderpx, vborderpx;
|
|
|
|
|
int ch; /* char height */
|
|
|
|
|
int cw; /* char width */
|
|
|
|
|
int mode; /* window state/mode flags */
|
|
|
|
|
@ -94,7 +93,7 @@ typedef struct {
|
|
|
|
|
Window win;
|
|
|
|
|
Drawable buf;
|
|
|
|
|
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
|
|
|
|
|
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
|
|
|
|
|
Atom xembed, wmdeletewin, netwmname, netwmpid;
|
|
|
|
|
struct {
|
|
|
|
|
XIM xim;
|
|
|
|
|
XIC xic;
|
|
|
|
|
@ -104,11 +103,6 @@ typedef struct {
|
|
|
|
|
Draw draw;
|
|
|
|
|
Visual *vis;
|
|
|
|
|
XSetWindowAttributes attrs;
|
|
|
|
|
/* Here, we use the term *pointer* to differentiate the cursor
|
|
|
|
|
* one sees when hovering the mouse over the terminal from, e.g.,
|
|
|
|
|
* a green rectangle where text would be entered. */
|
|
|
|
|
Cursor vpointer, bpointer; /* visible and hidden pointers */
|
|
|
|
|
int pointerisvisible;
|
|
|
|
|
int scr;
|
|
|
|
|
int isfixed; /* is fixed geometry? */
|
|
|
|
|
int l, t; /* left and top offset */
|
|
|
|
|
@ -162,7 +156,7 @@ static void xresize(int, int);
|
|
|
|
|
static void xhints(void);
|
|
|
|
|
static int xloadcolor(int, const char *, Color *);
|
|
|
|
|
static int xloadfont(Font *, FcPattern *);
|
|
|
|
|
static void xloadfonts(const char *, double);
|
|
|
|
|
static void xloadfonts(char *, double);
|
|
|
|
|
static void xunloadfont(Font *);
|
|
|
|
|
static void xunloadfonts(void);
|
|
|
|
|
static void xsetenv(void);
|
|
|
|
|
@ -337,7 +331,7 @@ ttysend(const Arg *arg)
|
|
|
|
|
int
|
|
|
|
|
evcol(XEvent *e)
|
|
|
|
|
{
|
|
|
|
|
int x = e->xbutton.x - win.hborderpx;
|
|
|
|
|
int x = e->xbutton.x - borderpx;
|
|
|
|
|
LIMIT(x, 0, win.tw - 1);
|
|
|
|
|
return x / win.cw;
|
|
|
|
|
}
|
|
|
|
|
@ -345,7 +339,7 @@ evcol(XEvent *e)
|
|
|
|
|
int
|
|
|
|
|
evrow(XEvent *e)
|
|
|
|
|
{
|
|
|
|
|
int y = e->xbutton.y - win.vborderpx;
|
|
|
|
|
int y = e->xbutton.y - borderpx;
|
|
|
|
|
LIMIT(y, 0, win.th - 1);
|
|
|
|
|
return y / win.ch;
|
|
|
|
|
}
|
|
|
|
|
@ -393,9 +387,7 @@ mousereport(XEvent *e)
|
|
|
|
|
button = 3;
|
|
|
|
|
} else {
|
|
|
|
|
button -= Button1;
|
|
|
|
|
if (button >= 7)
|
|
|
|
|
button += 128 - 7;
|
|
|
|
|
else if (button >= 3)
|
|
|
|
|
if (button >= 3)
|
|
|
|
|
button += 64 - 3;
|
|
|
|
|
}
|
|
|
|
|
if (e->xbutton.type == ButtonPress) {
|
|
|
|
|
@ -706,13 +698,6 @@ brelease(XEvent *e)
|
|
|
|
|
void
|
|
|
|
|
bmotion(XEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (!xw.pointerisvisible) {
|
|
|
|
|
XDefineCursor(xw.dpy, xw.win, xw.vpointer);
|
|
|
|
|
xw.pointerisvisible = 1;
|
|
|
|
|
if (!IS_SET(MODE_MOUSEMANY))
|
|
|
|
|
xsetpointermotion(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
|
|
|
|
|
mousereport(e);
|
|
|
|
|
return;
|
|
|
|
|
@ -736,9 +721,6 @@ cresize(int width, int height)
|
|
|
|
|
col = MAX(1, col);
|
|
|
|
|
row = MAX(1, row);
|
|
|
|
|
|
|
|
|
|
win.hborderpx = (win.w - col * win.cw) / 2;
|
|
|
|
|
win.vborderpx = (win.h - row * win.ch) / 2;
|
|
|
|
|
|
|
|
|
|
tresize(col, row);
|
|
|
|
|
xresize(col, row);
|
|
|
|
|
ttyresize(win.tw, win.th);
|
|
|
|
|
@ -856,8 +838,8 @@ xhints(void)
|
|
|
|
|
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
|
|
|
|
|
sizeh->height = win.h;
|
|
|
|
|
sizeh->width = win.w;
|
|
|
|
|
sizeh->height_inc = 1;
|
|
|
|
|
sizeh->width_inc = 1;
|
|
|
|
|
sizeh->height_inc = win.ch;
|
|
|
|
|
sizeh->width_inc = win.cw;
|
|
|
|
|
sizeh->base_height = 2 * borderpx;
|
|
|
|
|
sizeh->base_width = 2 * borderpx;
|
|
|
|
|
sizeh->min_height = win.ch + 2 * borderpx;
|
|
|
|
|
@ -968,7 +950,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
xloadfonts(const char *fontstr, double fontsize)
|
|
|
|
|
xloadfonts(char *fontstr, double fontsize)
|
|
|
|
|
{
|
|
|
|
|
FcPattern *pattern;
|
|
|
|
|
double fontval;
|
|
|
|
|
@ -976,7 +958,7 @@ xloadfonts(const char *fontstr, double fontsize)
|
|
|
|
|
if (fontstr[0] == '-')
|
|
|
|
|
pattern = XftXlfdParse(fontstr, False, False);
|
|
|
|
|
else
|
|
|
|
|
pattern = FcNameParse((const FcChar8 *)fontstr);
|
|
|
|
|
pattern = FcNameParse((FcChar8 *)fontstr);
|
|
|
|
|
|
|
|
|
|
if (!pattern)
|
|
|
|
|
die("can't open font %s\n", fontstr);
|
|
|
|
|
@ -1117,10 +1099,10 @@ void
|
|
|
|
|
xinit(int cols, int rows)
|
|
|
|
|
{
|
|
|
|
|
XGCValues gcvalues;
|
|
|
|
|
Cursor cursor;
|
|
|
|
|
Window parent;
|
|
|
|
|
pid_t thispid = getpid();
|
|
|
|
|
XColor xmousefg, xmousebg;
|
|
|
|
|
Pixmap blankpm;
|
|
|
|
|
|
|
|
|
|
if (!(xw.dpy = XOpenDisplay(NULL)))
|
|
|
|
|
die("can't open display\n");
|
|
|
|
|
@ -1139,8 +1121,8 @@ xinit(int cols, int rows)
|
|
|
|
|
xloadcols();
|
|
|
|
|
|
|
|
|
|
/* adjust fixed window geometry */
|
|
|
|
|
win.w = 2 * win.hborderpx + cols * win.cw;
|
|
|
|
|
win.h = 2 * win.vborderpx + rows * win.ch;
|
|
|
|
|
win.w = 2 * borderpx + cols * win.cw;
|
|
|
|
|
win.h = 2 * borderpx + rows * win.ch;
|
|
|
|
|
if (xw.gm & XNegative)
|
|
|
|
|
xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
|
|
|
|
|
if (xw.gm & YNegative)
|
|
|
|
|
@ -1184,9 +1166,8 @@ xinit(int cols, int rows)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* white cursor, black outline */
|
|
|
|
|
xw.pointerisvisible = 1;
|
|
|
|
|
xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
|
|
|
|
|
XDefineCursor(xw.dpy, xw.win, xw.vpointer);
|
|
|
|
|
cursor = XCreateFontCursor(xw.dpy, mouseshape);
|
|
|
|
|
XDefineCursor(xw.dpy, xw.win, cursor);
|
|
|
|
|
|
|
|
|
|
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
|
|
|
|
|
xmousefg.red = 0xffff;
|
|
|
|
|
@ -1200,15 +1181,11 @@ xinit(int cols, int rows)
|
|
|
|
|
xmousebg.blue = 0x0000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
|
|
|
|
|
blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
|
|
|
|
|
xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
|
|
|
|
|
&xmousefg, &xmousebg, 0, 0);
|
|
|
|
|
XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
|
|
|
|
|
|
|
|
|
|
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
|
|
|
|
|
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
|
xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
|
|
|
|
|
xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False);
|
|
|
|
|
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
|
|
|
|
|
|
|
|
|
|
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
|
|
|
|
|
@ -1233,7 +1210,7 @@ xinit(int cols, int rows)
|
|
|
|
|
int
|
|
|
|
|
xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
float winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, xp, yp;
|
|
|
|
|
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
|
|
|
|
|
ushort mode, prevmode = USHRT_MAX;
|
|
|
|
|
Font *font = &dc.font;
|
|
|
|
|
int frcflags = FRC_NORMAL;
|
|
|
|
|
@ -1366,7 +1343,7 @@ void
|
|
|
|
|
xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
|
|
|
|
|
int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch,
|
|
|
|
|
int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
|
|
|
|
|
width = charlen * win.cw;
|
|
|
|
|
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
|
|
|
|
|
XRenderColor colfg, colbg;
|
|
|
|
|
@ -1456,17 +1433,17 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
|
|
|
|
|
|
|
|
|
|
/* Intelligent cleaning up of the borders. */
|
|
|
|
|
if (x == 0) {
|
|
|
|
|
xclear(0, (y == 0)? 0 : winy, win.vborderpx,
|
|
|
|
|
xclear(0, (y == 0)? 0 : winy, borderpx,
|
|
|
|
|
winy + win.ch +
|
|
|
|
|
((winy + win.ch >= win.vborderpx + win.th)? win.h : 0));
|
|
|
|
|
((winy + win.ch >= borderpx + win.th)? win.h : 0));
|
|
|
|
|
}
|
|
|
|
|
if (winx + width >= win.hborderpx + win.tw) {
|
|
|
|
|
if (winx + width >= borderpx + win.tw) {
|
|
|
|
|
xclear(winx + width, (y == 0)? 0 : winy, win.w,
|
|
|
|
|
((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch)));
|
|
|
|
|
((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
|
|
|
|
|
}
|
|
|
|
|
if (y == 0)
|
|
|
|
|
xclear(winx, 0, winx + width, win.hborderpx);
|
|
|
|
|
if (winy + win.ch >= win.vborderpx + win.th)
|
|
|
|
|
xclear(winx, 0, winx + width, borderpx);
|
|
|
|
|
if (winy + win.ch >= borderpx + win.th)
|
|
|
|
|
xclear(winx, winy + win.ch, winx + width, win.h);
|
|
|
|
|
|
|
|
|
|
/* Clean up the region we want to draw to. */
|
|
|
|
|
@ -1549,9 +1526,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
|
|
|
|
/* draw the new one */
|
|
|
|
|
if (IS_SET(MODE_FOCUSED)) {
|
|
|
|
|
switch (win.cursor) {
|
|
|
|
|
case 7: /* st extension */
|
|
|
|
|
g.u = 0x2603; /* snowman (U+2603) */
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
case 7: /* st extension: snowman (U+2603) */
|
|
|
|
|
g.u = 0x2603;
|
|
|
|
|
case 0: /* Blinking Block */
|
|
|
|
|
case 1: /* Blinking Block (Default) */
|
|
|
|
|
case 2: /* Steady Block */
|
|
|
|
|
@ -1560,35 +1536,35 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
|
|
|
|
case 3: /* Blinking Underline */
|
|
|
|
|
case 4: /* Steady Underline */
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + cx * win.cw,
|
|
|
|
|
win.vborderpx + (cy + 1) * win.ch - \
|
|
|
|
|
borderpx + cx * win.cw,
|
|
|
|
|
borderpx + (cy + 1) * win.ch - \
|
|
|
|
|
cursorthickness,
|
|
|
|
|
win.cw, cursorthickness);
|
|
|
|
|
break;
|
|
|
|
|
case 5: /* Blinking bar */
|
|
|
|
|
case 6: /* Steady bar */
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + cx * win.cw,
|
|
|
|
|
win.vborderpx + cy * win.ch,
|
|
|
|
|
borderpx + cx * win.cw,
|
|
|
|
|
borderpx + cy * win.ch,
|
|
|
|
|
cursorthickness, win.ch);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + cx * win.cw,
|
|
|
|
|
win.vborderpx + cy * win.ch,
|
|
|
|
|
borderpx + cx * win.cw,
|
|
|
|
|
borderpx + cy * win.ch,
|
|
|
|
|
win.cw - 1, 1);
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + cx * win.cw,
|
|
|
|
|
win.vborderpx + cy * win.ch,
|
|
|
|
|
borderpx + cx * win.cw,
|
|
|
|
|
borderpx + cy * win.ch,
|
|
|
|
|
1, win.ch - 1);
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + (cx + 1) * win.cw - 1,
|
|
|
|
|
win.vborderpx + cy * win.ch,
|
|
|
|
|
borderpx + (cx + 1) * win.cw - 1,
|
|
|
|
|
borderpx + cy * win.ch,
|
|
|
|
|
1, win.ch - 1);
|
|
|
|
|
XftDrawRect(xw.draw, &drawcol,
|
|
|
|
|
win.hborderpx + cx * win.cw,
|
|
|
|
|
win.vborderpx + (cy + 1) * win.ch - 1,
|
|
|
|
|
borderpx + cx * win.cw,
|
|
|
|
|
borderpx + (cy + 1) * win.ch - 1,
|
|
|
|
|
win.cw, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1602,29 +1578,14 @@ xsetenv(void)
|
|
|
|
|
setenv("WINDOWID", buf, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
xseticontitle(char *p)
|
|
|
|
|
{
|
|
|
|
|
XTextProperty prop;
|
|
|
|
|
DEFAULT(p, opt_title);
|
|
|
|
|
|
|
|
|
|
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
|
|
|
|
&prop) != Success)
|
|
|
|
|
return;
|
|
|
|
|
XSetWMIconName(xw.dpy, xw.win, &prop);
|
|
|
|
|
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
|
|
|
|
|
XFree(prop.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
xsettitle(char *p)
|
|
|
|
|
{
|
|
|
|
|
XTextProperty prop;
|
|
|
|
|
DEFAULT(p, opt_title);
|
|
|
|
|
|
|
|
|
|
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
|
|
|
|
&prop) != Success)
|
|
|
|
|
return;
|
|
|
|
|
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
|
|
|
|
&prop);
|
|
|
|
|
XSetWMName(xw.dpy, xw.win, &prop);
|
|
|
|
|
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
|
|
|
|
|
XFree(prop.value);
|
|
|
|
|
@ -1712,8 +1673,6 @@ unmap(XEvent *ev)
|
|
|
|
|
void
|
|
|
|
|
xsetpointermotion(int set)
|
|
|
|
|
{
|
|
|
|
|
if (!set && !xw.pointerisvisible)
|
|
|
|
|
return;
|
|
|
|
|
MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
|
|
|
|
|
XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
|
|
|
|
|
}
|
|
|
|
|
@ -1730,7 +1689,8 @@ xsetmode(int set, unsigned int flags)
|
|
|
|
|
int
|
|
|
|
|
xsetcursor(int cursor)
|
|
|
|
|
{
|
|
|
|
|
if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
|
|
|
|
|
DEFAULT(cursor, 1);
|
|
|
|
|
if (!BETWEEN(cursor, 0, 6))
|
|
|
|
|
return 1;
|
|
|
|
|
win.cursor = cursor;
|
|
|
|
|
return 0;
|
|
|
|
|
@ -1833,12 +1793,6 @@ kpress(XEvent *ev)
|
|
|
|
|
Status status;
|
|
|
|
|
Shortcut *bp;
|
|
|
|
|
|
|
|
|
|
if (xw.pointerisvisible) {
|
|
|
|
|
XDefineCursor(xw.dpy, xw.win, xw.bpointer);
|
|
|
|
|
xsetpointermotion(1);
|
|
|
|
|
xw.pointerisvisible = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IS_SET(MODE_KBDLOCK))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
@ -1913,9 +1867,10 @@ run(void)
|
|
|
|
|
XEvent ev;
|
|
|
|
|
int w = win.w, h = win.h;
|
|
|
|
|
fd_set rfd;
|
|
|
|
|
int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
|
|
|
|
|
struct timespec seltv, *tv, now, lastblink, trigger;
|
|
|
|
|
double timeout;
|
|
|
|
|
int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
|
|
|
|
|
int ttyfd;
|
|
|
|
|
struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
|
|
|
|
|
long deltatime;
|
|
|
|
|
|
|
|
|
|
/* Waiting for window mapping */
|
|
|
|
|
do {
|
|
|
|
|
@ -1936,31 +1891,51 @@ run(void)
|
|
|
|
|
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
|
|
|
|
|
cresize(w, h);
|
|
|
|
|
|
|
|
|
|
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &last);
|
|
|
|
|
lastblink = last;
|
|
|
|
|
|
|
|
|
|
for (xev = actionfps;;) {
|
|
|
|
|
FD_ZERO(&rfd);
|
|
|
|
|
FD_SET(ttyfd, &rfd);
|
|
|
|
|
FD_SET(xfd, &rfd);
|
|
|
|
|
|
|
|
|
|
if (XPending(xw.dpy))
|
|
|
|
|
timeout = 0; /* existing events might not set xfd */
|
|
|
|
|
|
|
|
|
|
seltv.tv_sec = timeout / 1E3;
|
|
|
|
|
seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec);
|
|
|
|
|
tv = timeout >= 0 ? &seltv : NULL;
|
|
|
|
|
|
|
|
|
|
if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
die("select failed: %s\n", strerror(errno));
|
|
|
|
|
}
|
|
|
|
|
if (FD_ISSET(ttyfd, &rfd)) {
|
|
|
|
|
ttyread();
|
|
|
|
|
if (blinktimeout) {
|
|
|
|
|
blinkset = tattrset(ATTR_BLINK);
|
|
|
|
|
if (!blinkset)
|
|
|
|
|
MODBIT(win.mode, 0, MODE_BLINK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FD_ISSET(xfd, &rfd))
|
|
|
|
|
xev = actionfps;
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
|
drawtimeout.tv_sec = 0;
|
|
|
|
|
drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
|
|
|
|
|
tv = &drawtimeout;
|
|
|
|
|
|
|
|
|
|
if (FD_ISSET(ttyfd, &rfd))
|
|
|
|
|
ttyread();
|
|
|
|
|
dodraw = 0;
|
|
|
|
|
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
|
|
|
|
|
tsetdirtattr(ATTR_BLINK);
|
|
|
|
|
win.mode ^= MODE_BLINK;
|
|
|
|
|
lastblink = now;
|
|
|
|
|
dodraw = 1;
|
|
|
|
|
}
|
|
|
|
|
deltatime = TIMEDIFF(now, last);
|
|
|
|
|
if (deltatime > 1000 / (xev ? xfps : actionfps)) {
|
|
|
|
|
dodraw = 1;
|
|
|
|
|
last = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xev = 0;
|
|
|
|
|
if (dodraw) {
|
|
|
|
|
while (XPending(xw.dpy)) {
|
|
|
|
|
xev = 1;
|
|
|
|
|
XNextEvent(xw.dpy, &ev);
|
|
|
|
|
if (XFilterEvent(&ev, None))
|
|
|
|
|
continue;
|
|
|
|
|
@ -1968,45 +1943,30 @@ run(void)
|
|
|
|
|
(handler[ev.type])(&ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* To reduce flicker and tearing, when new content or event
|
|
|
|
|
* triggers drawing, we first wait a bit to ensure we got
|
|
|
|
|
* everything, and if nothing new arrives - we draw.
|
|
|
|
|
* We start with trying to wait minlatency ms. If more content
|
|
|
|
|
* arrives sooner, we retry with shorter and shorter periods,
|
|
|
|
|
* and eventually draw even without idle after maxlatency ms.
|
|
|
|
|
* Typically this results in low latency while interacting,
|
|
|
|
|
* maximum latency intervals during `cat huge.txt`, and perfect
|
|
|
|
|
* sync with periodic updates from animations/key-repeats/etc.
|
|
|
|
|
*/
|
|
|
|
|
if (FD_ISSET(ttyfd, &rfd) || xev) {
|
|
|
|
|
if (!drawing) {
|
|
|
|
|
trigger = now;
|
|
|
|
|
drawing = 1;
|
|
|
|
|
}
|
|
|
|
|
timeout = (maxlatency - TIMEDIFF(now, trigger)) \
|
|
|
|
|
/ maxlatency * minlatency;
|
|
|
|
|
if (timeout > 0)
|
|
|
|
|
continue; /* we have time, try to find idle */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* idle detected or maxlatency exhausted -> draw */
|
|
|
|
|
timeout = -1;
|
|
|
|
|
if (blinktimeout && tattrset(ATTR_BLINK)) {
|
|
|
|
|
timeout = blinktimeout - TIMEDIFF(now, lastblink);
|
|
|
|
|
if (timeout <= 0) {
|
|
|
|
|
if (-timeout > blinktimeout) /* start visible */
|
|
|
|
|
win.mode |= MODE_BLINK;
|
|
|
|
|
win.mode ^= MODE_BLINK;
|
|
|
|
|
tsetdirtattr(ATTR_BLINK);
|
|
|
|
|
lastblink = now;
|
|
|
|
|
timeout = blinktimeout;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draw();
|
|
|
|
|
XFlush(xw.dpy);
|
|
|
|
|
drawing = 0;
|
|
|
|
|
|
|
|
|
|
if (xev && !FD_ISSET(xfd, &rfd))
|
|
|
|
|
xev--;
|
|
|
|
|
if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
|
|
|
|
|
if (blinkset) {
|
|
|
|
|
if (TIMEDIFF(now, lastblink) \
|
|
|
|
|
> blinktimeout) {
|
|
|
|
|
drawtimeout.tv_nsec = 1000;
|
|
|
|
|
} else {
|
|
|
|
|
drawtimeout.tv_nsec = (1E6 * \
|
|
|
|
|
(blinktimeout - \
|
|
|
|
|
TIMEDIFF(now,
|
|
|
|
|
lastblink)));
|
|
|
|
|
}
|
|
|
|
|
drawtimeout.tv_sec = \
|
|
|
|
|
drawtimeout.tv_nsec / 1E9;
|
|
|
|
|
drawtimeout.tv_nsec %= (long)1E9;
|
|
|
|
|
} else {
|
|
|
|
|
tv = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -2028,7 +1988,7 @@ main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
xw.l = xw.t = 0;
|
|
|
|
|
xw.isfixed = False;
|
|
|
|
|
xsetcursor(cursorshape);
|
|
|
|
|
win.cursor = cursorshape;
|
|
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
|
case 'a':
|
|
|
|
|
|