Pull term references out of xdrawcursor
Gradually reducing x.c dependency on Term object. Old and new cursor glyph/position are passed to xdrawcursor. (There may be an opportunity to refactor further if we can unify "clear old cursor" and "draw new cursor" functionality.) Signed-off-by: Devin J. Pohly <djpohly@gmail.com>dev
parent
88d8293fb4
commit
a5dc1b4697
15
st.c
15
st.c
|
@ -2544,10 +2544,23 @@ drawregion(int x1, int y1, int x2, int y2)
|
||||||
void
|
void
|
||||||
draw(void)
|
draw(void)
|
||||||
{
|
{
|
||||||
|
int cx = term.c.x;
|
||||||
|
|
||||||
if (!xstartdraw())
|
if (!xstartdraw())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* adjust cursor position */
|
||||||
|
LIMIT(term.ocx, 0, term.col-1);
|
||||||
|
LIMIT(term.ocy, 0, term.row-1);
|
||||||
|
if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY)
|
||||||
|
term.ocx--;
|
||||||
|
if (term.line[term.c.y][cx].mode & ATTR_WDUMMY)
|
||||||
|
cx--;
|
||||||
|
|
||||||
drawregion(0, 0, term.col, term.row);
|
drawregion(0, 0, term.col, term.row);
|
||||||
xdrawcursor();
|
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
||||||
|
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
|
term.ocx = cx, term.ocy = term.c.y;
|
||||||
xfinishdraw();
|
xfinishdraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
st.h
2
st.h
|
@ -84,6 +84,8 @@ typedef struct {
|
||||||
Line *alt; /* alternate screen */
|
Line *alt; /* alternate screen */
|
||||||
int *dirty; /* dirtyness of lines */
|
int *dirty; /* dirtyness of lines */
|
||||||
TCursor c; /* cursor */
|
TCursor c; /* cursor */
|
||||||
|
int ocx; /* old cursor col */
|
||||||
|
int ocy; /* old cursor row */
|
||||||
int top; /* top scroll limit */
|
int top; /* top scroll limit */
|
||||||
int bot; /* bottom scroll limit */
|
int bot; /* bottom scroll limit */
|
||||||
int mode; /* terminal mode flags */
|
int mode; /* terminal mode flags */
|
||||||
|
|
2
win.h
2
win.h
|
@ -25,7 +25,7 @@ enum win_mode {
|
||||||
|
|
||||||
void xbell(void);
|
void xbell(void);
|
||||||
void xclipcopy(void);
|
void xclipcopy(void);
|
||||||
void xdrawcursor(void);
|
void xdrawcursor(int, int, Glyph, int, int, Glyph);
|
||||||
void xdrawline(Line, int, int, int);
|
void xdrawline(Line, int, int, int);
|
||||||
void xhints(void);
|
void xhints(void);
|
||||||
void xfinishdraw(void);
|
void xfinishdraw(void);
|
||||||
|
|
61
x.c
61
x.c
|
@ -1387,41 +1387,26 @@ xdrawglyph(Glyph g, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xdrawcursor(void)
|
xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
||||||
{
|
{
|
||||||
static int oldx = 0, oldy = 0;
|
|
||||||
int curx;
|
|
||||||
Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}, og;
|
|
||||||
Color drawcol;
|
Color drawcol;
|
||||||
|
|
||||||
LIMIT(oldx, 0, term.col-1);
|
|
||||||
LIMIT(oldy, 0, term.row-1);
|
|
||||||
|
|
||||||
curx = term.c.x;
|
|
||||||
|
|
||||||
/* adjust position if in dummy */
|
|
||||||
if (term.line[oldy][oldx].mode & ATTR_WDUMMY)
|
|
||||||
oldx--;
|
|
||||||
if (term.line[term.c.y][curx].mode & ATTR_WDUMMY)
|
|
||||||
curx--;
|
|
||||||
|
|
||||||
/* remove the old cursor */
|
/* remove the old cursor */
|
||||||
og = term.line[oldy][oldx];
|
if (selected(ox, oy))
|
||||||
if (selected(oldx, oldy))
|
|
||||||
og.mode ^= ATTR_REVERSE;
|
og.mode ^= ATTR_REVERSE;
|
||||||
xdrawglyph(og, oldx, oldy);
|
xdrawglyph(og, ox, oy);
|
||||||
|
|
||||||
g.u = term.line[term.c.y][term.c.x].u;
|
|
||||||
g.mode |= term.line[term.c.y][term.c.x].mode &
|
|
||||||
(ATTR_BOLD | ATTR_ITALIC | ATTR_UNDERLINE | ATTR_STRUCK);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select the right color for the right mode.
|
* Select the right color for the right mode.
|
||||||
*/
|
*/
|
||||||
|
g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
|
||||||
|
g.fg = defaultbg;
|
||||||
|
g.bg = defaultcs;
|
||||||
|
|
||||||
if (IS_SET(MODE_REVERSE)) {
|
if (IS_SET(MODE_REVERSE)) {
|
||||||
g.mode |= ATTR_REVERSE;
|
g.mode |= ATTR_REVERSE;
|
||||||
g.bg = defaultfg;
|
g.bg = defaultfg;
|
||||||
if (selected(term.c.x, term.c.y)) {
|
if (selected(cx, cy)) {
|
||||||
drawcol = dc.col[defaultcs];
|
drawcol = dc.col[defaultcs];
|
||||||
g.fg = defaultrcs;
|
g.fg = defaultrcs;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1429,7 +1414,7 @@ xdrawcursor(void)
|
||||||
g.fg = defaultcs;
|
g.fg = defaultcs;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (selected(term.c.x, term.c.y)) {
|
if (selected(cx, cy)) {
|
||||||
drawcol = dc.col[defaultrcs];
|
drawcol = dc.col[defaultrcs];
|
||||||
g.fg = defaultfg;
|
g.fg = defaultfg;
|
||||||
g.bg = defaultrcs;
|
g.bg = defaultrcs;
|
||||||
|
@ -1449,44 +1434,42 @@ xdrawcursor(void)
|
||||||
case 0: /* Blinking Block */
|
case 0: /* Blinking Block */
|
||||||
case 1: /* Blinking Block (Default) */
|
case 1: /* Blinking Block (Default) */
|
||||||
case 2: /* Steady Block */
|
case 2: /* Steady Block */
|
||||||
g.mode |= term.line[term.c.y][curx].mode & ATTR_WIDE;
|
xdrawglyph(g, cx, cy);
|
||||||
xdrawglyph(g, term.c.x, term.c.y);
|
|
||||||
break;
|
break;
|
||||||
case 3: /* Blinking Underline */
|
case 3: /* Blinking Underline */
|
||||||
case 4: /* Steady Underline */
|
case 4: /* Steady Underline */
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + curx * win.cw,
|
borderpx + cx * win.cw,
|
||||||
borderpx + (term.c.y + 1) * win.ch - \
|
borderpx + (cy + 1) * win.ch - \
|
||||||
cursorthickness,
|
cursorthickness,
|
||||||
win.cw, cursorthickness);
|
win.cw, cursorthickness);
|
||||||
break;
|
break;
|
||||||
case 5: /* Blinking bar */
|
case 5: /* Blinking bar */
|
||||||
case 6: /* Steady bar */
|
case 6: /* Steady bar */
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + curx * win.cw,
|
borderpx + cx * win.cw,
|
||||||
borderpx + term.c.y * win.ch,
|
borderpx + cy * win.ch,
|
||||||
cursorthickness, win.ch);
|
cursorthickness, win.ch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + curx * win.cw,
|
borderpx + cx * win.cw,
|
||||||
borderpx + term.c.y * win.ch,
|
borderpx + cy * win.ch,
|
||||||
win.cw - 1, 1);
|
win.cw - 1, 1);
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + curx * win.cw,
|
borderpx + cx * win.cw,
|
||||||
borderpx + term.c.y * win.ch,
|
borderpx + cy * win.ch,
|
||||||
1, win.ch - 1);
|
1, win.ch - 1);
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + (curx + 1) * win.cw - 1,
|
borderpx + (cx + 1) * win.cw - 1,
|
||||||
borderpx + term.c.y * win.ch,
|
borderpx + cy * win.ch,
|
||||||
1, win.ch - 1);
|
1, win.ch - 1);
|
||||||
XftDrawRect(xw.draw, &drawcol,
|
XftDrawRect(xw.draw, &drawcol,
|
||||||
borderpx + curx * win.cw,
|
borderpx + cx * win.cw,
|
||||||
borderpx + (term.c.y + 1) * win.ch - 1,
|
borderpx + (cy + 1) * win.ch - 1,
|
||||||
win.cw, 1);
|
win.cw, 1);
|
||||||
}
|
}
|
||||||
oldx = curx, oldy = term.c.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue