diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2018-02-24 14:58:54 -0600 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:56:26 -0600 |
commit | a5dc1b46976b2252f9d7bb68f126c4b0f351dd1a (patch) | |
tree | a9ce0c1a4dd254ccb71a61a08dc3df54dc4f2814 | |
parent | 88d8293fb4ba150a5f19d58d133b5db93d9dcfa5 (diff) | |
download | st-patched-a5dc1b46976b2252f9d7bb68f126c4b0f351dd1a.tar.bz2 st-patched-a5dc1b46976b2252f9d7bb68f126c4b0f351dd1a.tar.xz st-patched-a5dc1b46976b2252f9d7bb68f126c4b0f351dd1a.zip |
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>
-rw-r--r-- | st.c | 15 | ||||
-rw-r--r-- | st.h | 4 | ||||
-rw-r--r-- | win.h | 2 | ||||
-rw-r--r-- | x.c | 61 |
4 files changed, 40 insertions, 42 deletions
@@ -2544,10 +2544,23 @@ drawregion(int x1, int y1, int x2, int y2) | |||
2544 | void | 2544 | void |
2545 | draw(void) | 2545 | draw(void) |
2546 | { | 2546 | { |
2547 | int cx = term.c.x; | ||
2548 | |||
2547 | if (!xstartdraw()) | 2549 | if (!xstartdraw()) |
2548 | return; | 2550 | return; |
2551 | |||
2552 | /* adjust cursor position */ | ||
2553 | LIMIT(term.ocx, 0, term.col-1); | ||
2554 | LIMIT(term.ocy, 0, term.row-1); | ||
2555 | if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY) | ||
2556 | term.ocx--; | ||
2557 | if (term.line[term.c.y][cx].mode & ATTR_WDUMMY) | ||
2558 | cx--; | ||
2559 | |||
2549 | drawregion(0, 0, term.col, term.row); | 2560 | drawregion(0, 0, term.col, term.row); |
2550 | xdrawcursor(); | 2561 | xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], |
2562 | term.ocx, term.ocy, term.line[term.ocy][term.ocx]); | ||
2563 | term.ocx = cx, term.ocy = term.c.y; | ||
2551 | xfinishdraw(); | 2564 | xfinishdraw(); |
2552 | } | 2565 | } |
2553 | 2566 | ||
@@ -82,8 +82,10 @@ typedef struct { | |||
82 | int col; /* nb col */ | 82 | int col; /* nb col */ |
83 | Line *line; /* screen */ | 83 | Line *line; /* screen */ |
84 | Line *alt; /* alternate screen */ | 84 | Line *alt; /* alternate screen */ |
85 | int *dirty; /* dirtyness of lines */ | 85 | int *dirty; /* dirtyness of lines */ |
86 | TCursor c; /* cursor */ | 86 | TCursor c; /* cursor */ |
87 | int ocx; /* old cursor col */ | ||
88 | int ocy; /* old cursor row */ | ||
87 | int top; /* top scroll limit */ | 89 | int top; /* top scroll limit */ |
88 | int bot; /* bottom scroll limit */ | 90 | int bot; /* bottom scroll limit */ |
89 | int mode; /* terminal mode flags */ | 91 | int mode; /* terminal mode flags */ |
@@ -25,7 +25,7 @@ enum win_mode { | |||
25 | 25 | ||
26 | void xbell(void); | 26 | void xbell(void); |
27 | void xclipcopy(void); | 27 | void xclipcopy(void); |
28 | void xdrawcursor(void); | 28 | void xdrawcursor(int, int, Glyph, int, int, Glyph); |
29 | void xdrawline(Line, int, int, int); | 29 | void xdrawline(Line, int, int, int); |
30 | void xhints(void); | 30 | void xhints(void); |
31 | void xfinishdraw(void); | 31 | void xfinishdraw(void); |
@@ -1387,41 +1387,26 @@ xdrawglyph(Glyph g, int x, int y) | |||
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | void | 1389 | void |
1390 | xdrawcursor(void) | 1390 | xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) |
1391 | { | 1391 | { |
1392 | static int oldx = 0, oldy = 0; | ||
1393 | int curx; | ||
1394 | Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}, og; | ||
1395 | Color drawcol; | 1392 | Color drawcol; |
1396 | 1393 | ||
1397 | LIMIT(oldx, 0, term.col-1); | ||
1398 | LIMIT(oldy, 0, term.row-1); | ||
1399 | |||
1400 | curx = term.c.x; | ||
1401 | |||
1402 | /* adjust position if in dummy */ | ||
1403 | if (term.line[oldy][oldx].mode & ATTR_WDUMMY) | ||
1404 | oldx--; | ||
1405 | if (term.line[term.c.y][curx].mode & ATTR_WDUMMY) | ||
1406 | curx--; | ||
1407 | |||
1408 | /* remove the old cursor */ | 1394 | /* remove the old cursor */ |
1409 | og = term.line[oldy][oldx]; | 1395 | if (selected(ox, oy)) |
1410 | if (selected(oldx, oldy)) | ||
1411 | og.mode ^= ATTR_REVERSE; | 1396 | og.mode ^= ATTR_REVERSE; |
1412 | xdrawglyph(og, oldx, oldy); | 1397 | xdrawglyph(og, ox, oy); |
1413 | |||
1414 | g.u = term.line[term.c.y][term.c.x].u; | ||
1415 | g.mode |= term.line[term.c.y][term.c.x].mode & | ||
1416 | (ATTR_BOLD | ATTR_ITALIC | ATTR_UNDERLINE | ATTR_STRUCK); | ||
1417 | 1398 | ||
1418 | /* | 1399 | /* |
1419 | * Select the right color for the right mode. | 1400 | * Select the right color for the right mode. |
1420 | */ | 1401 | */ |
1402 | g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE; | ||
1403 | g.fg = defaultbg; | ||
1404 | g.bg = defaultcs; | ||
1405 | |||
1421 | if (IS_SET(MODE_REVERSE)) { | 1406 | if (IS_SET(MODE_REVERSE)) { |
1422 | g.mode |= ATTR_REVERSE; | 1407 | g.mode |= ATTR_REVERSE; |
1423 | g.bg = defaultfg; | 1408 | g.bg = defaultfg; |
1424 | if (selected(term.c.x, term.c.y)) { | 1409 | if (selected(cx, cy)) { |
1425 | drawcol = dc.col[defaultcs]; | 1410 | drawcol = dc.col[defaultcs]; |
1426 | g.fg = defaultrcs; | 1411 | g.fg = defaultrcs; |
1427 | } else { | 1412 | } else { |
@@ -1429,7 +1414,7 @@ xdrawcursor(void) | |||
1429 | g.fg = defaultcs; | 1414 | g.fg = defaultcs; |
1430 | } | 1415 | } |
1431 | } else { | 1416 | } else { |
1432 | if (selected(term.c.x, term.c.y)) { | 1417 | if (selected(cx, cy)) { |
1433 | drawcol = dc.col[defaultrcs]; | 1418 | drawcol = dc.col[defaultrcs]; |
1434 | g.fg = defaultfg; | 1419 | g.fg = defaultfg; |
1435 | g.bg = defaultrcs; | 1420 | g.bg = defaultrcs; |
@@ -1449,44 +1434,42 @@ xdrawcursor(void) | |||
1449 | case 0: /* Blinking Block */ | 1434 | case 0: /* Blinking Block */ |
1450 | case 1: /* Blinking Block (Default) */ | 1435 | case 1: /* Blinking Block (Default) */ |
1451 | case 2: /* Steady Block */ | 1436 | case 2: /* Steady Block */ |
1452 | g.mode |= term.line[term.c.y][curx].mode & ATTR_WIDE; | 1437 | xdrawglyph(g, cx, cy); |
1453 | xdrawglyph(g, term.c.x, term.c.y); | ||
1454 | break; | 1438 | break; |
1455 | case 3: /* Blinking Underline */ | 1439 | case 3: /* Blinking Underline */ |
1456 | case 4: /* Steady Underline */ | 1440 | case 4: /* Steady Underline */ |
1457 | XftDrawRect(xw.draw, &drawcol, | 1441 | XftDrawRect(xw.draw, &drawcol, |
1458 | borderpx + curx * win.cw, | 1442 | borderpx + cx * win.cw, |
1459 | borderpx + (term.c.y + 1) * win.ch - \ | 1443 | borderpx + (cy + 1) * win.ch - \ |
1460 | cursorthickness, | 1444 | cursorthickness, |
1461 | win.cw, cursorthickness); | 1445 | win.cw, cursorthickness); |
1462 | break; | 1446 | break; |
1463 | case 5: /* Blinking bar */ | 1447 | case 5: /* Blinking bar */ |
1464 | case 6: /* Steady bar */ | 1448 | case 6: /* Steady bar */ |
1465 | XftDrawRect(xw.draw, &drawcol, | 1449 | XftDrawRect(xw.draw, &drawcol, |
1466 | borderpx + curx * win.cw, | 1450 | borderpx + cx * win.cw, |
1467 | borderpx + term.c.y * win.ch, | 1451 | borderpx + cy * win.ch, |
1468 | cursorthickness, win.ch); | 1452 | cursorthickness, win.ch); |
1469 | break; | 1453 | break; |
1470 | } | 1454 | } |
1471 | } else { | 1455 | } else { |
1472 | XftDrawRect(xw.draw, &drawcol, | 1456 | XftDrawRect(xw.draw, &drawcol, |
1473 | borderpx + curx * win.cw, | 1457 | borderpx + cx * win.cw, |
1474 | borderpx + term.c.y * win.ch, | 1458 | borderpx + cy * win.ch, |
1475 | win.cw - 1, 1); | 1459 | win.cw - 1, 1); |
1476 | XftDrawRect(xw.draw, &drawcol, | 1460 | XftDrawRect(xw.draw, &drawcol, |
1477 | borderpx + curx * win.cw, | 1461 | borderpx + cx * win.cw, |
1478 | borderpx + term.c.y * win.ch, | 1462 | borderpx + cy * win.ch, |
1479 | 1, win.ch - 1); | 1463 | 1, win.ch - 1); |
1480 | XftDrawRect(xw.draw, &drawcol, | 1464 | XftDrawRect(xw.draw, &drawcol, |
1481 | borderpx + (curx + 1) * win.cw - 1, | 1465 | borderpx + (cx + 1) * win.cw - 1, |
1482 | borderpx + term.c.y * win.ch, | 1466 | borderpx + cy * win.ch, |
1483 | 1, win.ch - 1); | 1467 | 1, win.ch - 1); |
1484 | XftDrawRect(xw.draw, &drawcol, | 1468 | XftDrawRect(xw.draw, &drawcol, |
1485 | borderpx + curx * win.cw, | 1469 | borderpx + cx * win.cw, |
1486 | borderpx + (term.c.y + 1) * win.ch - 1, | 1470 | borderpx + (cy + 1) * win.ch - 1, |
1487 | win.cw, 1); | 1471 | win.cw, 1); |
1488 | } | 1472 | } |
1489 | oldx = curx, oldy = term.c.y; | ||
1490 | } | 1473 | } |
1491 | 1474 | ||
1492 | void | 1475 | void |