diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2018-02-24 14:53:23 -0600 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:56:26 -0600 |
commit | 88d8293fb4ba150a5f19d58d133b5db93d9dcfa5 (patch) | |
tree | f9e3cce2feda5565049c5d99012e8bd84144b8a2 | |
parent | 05c66cb37d9ff278a3e0c45682c4b5e7945deb42 (diff) | |
download | st-patched-88d8293fb4ba150a5f19d58d133b5db93d9dcfa5.tar.bz2 st-patched-88d8293fb4ba150a5f19d58d133b5db93d9dcfa5.tar.xz st-patched-88d8293fb4ba150a5f19d58d133b5db93d9dcfa5.zip |
Move win-agnostic parts of draw/drawregion to st.c
Introduces three functions to encapsulate X-specific behavior:
* xdrawline: draws a portion of a single line (used by drawregion)
* xbegindraw: called to prepare for drawing (will be useful for e.g.
Wayland) and returns true if drawing should happen
* xfinishdraw: called to finish drawing (used by draw)
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
-rw-r--r-- | st.c | 25 | ||||
-rw-r--r-- | st.h | 1 | ||||
-rw-r--r-- | win.h | 7 | ||||
-rw-r--r-- | x.c | 79 |
4 files changed, 65 insertions, 47 deletions
@@ -166,6 +166,8 @@ static int32_t tdefcolor(int *, int *, int); | |||
166 | static void tdeftran(char); | 166 | static void tdeftran(char); |
167 | static void tstrsequence(uchar); | 167 | static void tstrsequence(uchar); |
168 | 168 | ||
169 | static void drawregion(int, int, int, int); | ||
170 | |||
169 | static void selscroll(int, int); | 171 | static void selscroll(int, int); |
170 | static void selsnap(int *, int *, int); | 172 | static void selsnap(int *, int *, int); |
171 | 173 | ||
@@ -2527,6 +2529,29 @@ resettitle(void) | |||
2527 | } | 2529 | } |
2528 | 2530 | ||
2529 | void | 2531 | void |
2532 | drawregion(int x1, int y1, int x2, int y2) | ||
2533 | { | ||
2534 | int y; | ||
2535 | for (y = y1; y < y2; y++) { | ||
2536 | if (!term.dirty[y]) | ||
2537 | continue; | ||
2538 | |||
2539 | term.dirty[y] = 0; | ||
2540 | xdrawline(term.line[y], x1, y, x2); | ||
2541 | } | ||
2542 | } | ||
2543 | |||
2544 | void | ||
2545 | draw(void) | ||
2546 | { | ||
2547 | if (!xstartdraw()) | ||
2548 | return; | ||
2549 | drawregion(0, 0, term.col, term.row); | ||
2550 | xdrawcursor(); | ||
2551 | xfinishdraw(); | ||
2552 | } | ||
2553 | |||
2554 | void | ||
2530 | redraw(void) | 2555 | redraw(void) |
2531 | { | 2556 | { |
2532 | tfulldirt(); | 2557 | tfulldirt(); |
@@ -131,6 +131,7 @@ typedef union { | |||
131 | 131 | ||
132 | void die(const char *, ...); | 132 | void die(const char *, ...); |
133 | void redraw(void); | 133 | void redraw(void); |
134 | void draw(void); | ||
134 | 135 | ||
135 | void iso14755(const Arg *); | 136 | void iso14755(const Arg *); |
136 | void printscreen(const Arg *); | 137 | void printscreen(const Arg *); |
@@ -23,12 +23,12 @@ enum win_mode { | |||
23 | |MODE_MOUSEMANY, | 23 | |MODE_MOUSEMANY, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | void draw(void); | ||
27 | void drawregion(int, int, int, int); | ||
28 | |||
29 | void xbell(void); | 26 | void xbell(void); |
30 | void xclipcopy(void); | 27 | void xclipcopy(void); |
28 | void xdrawcursor(void); | ||
29 | void xdrawline(Line, int, int, int); | ||
31 | void xhints(void); | 30 | void xhints(void); |
31 | void xfinishdraw(void); | ||
32 | void xloadcols(void); | 32 | void xloadcols(void); |
33 | int xsetcolorname(int, const char *); | 33 | int xsetcolorname(int, const char *); |
34 | void xsettitle(char *); | 34 | void xsettitle(char *); |
@@ -36,3 +36,4 @@ int xsetcursor(int); | |||
36 | void xsetmode(int, unsigned int); | 36 | void xsetmode(int, unsigned int); |
37 | void xsetpointermotion(int); | 37 | void xsetpointermotion(int); |
38 | void xsetsel(char *); | 38 | void xsetsel(char *); |
39 | int xstartdraw(void); | ||
@@ -129,7 +129,6 @@ static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int) | |||
129 | static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int); | 129 | static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int); |
130 | static void xdrawglyph(Glyph, int, int); | 130 | static void xdrawglyph(Glyph, int, int); |
131 | static void xclear(int, int, int, int); | 131 | static void xclear(int, int, int, int); |
132 | static void xdrawcursor(void); | ||
133 | static int xgeommasktogravity(int); | 132 | static int xgeommasktogravity(int); |
134 | static void xinit(void); | 133 | static void xinit(void); |
135 | static void cresize(int, int); | 134 | static void cresize(int, int); |
@@ -1512,59 +1511,51 @@ xsettitle(char *p) | |||
1512 | XFree(prop.value); | 1511 | XFree(prop.value); |
1513 | } | 1512 | } |
1514 | 1513 | ||
1515 | void | 1514 | int |
1516 | draw(void) | 1515 | xstartdraw(void) |
1517 | { | 1516 | { |
1518 | drawregion(0, 0, term.col, term.row); | 1517 | return IS_SET(MODE_VISIBLE); |
1519 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, | ||
1520 | win.h, 0, 0); | ||
1521 | XSetForeground(xw.dpy, dc.gc, | ||
1522 | dc.col[IS_SET(MODE_REVERSE)? | ||
1523 | defaultfg : defaultbg].pixel); | ||
1524 | } | 1518 | } |
1525 | 1519 | ||
1526 | void | 1520 | void |
1527 | drawregion(int x1, int y1, int x2, int y2) | 1521 | xdrawline(Line line, int x1, int y1, int x2) |
1528 | { | 1522 | { |
1529 | int i, x, y, ox, numspecs; | 1523 | int i, x, ox, numspecs; |
1530 | Glyph base, new; | 1524 | Glyph base, new; |
1531 | XftGlyphFontSpec *specs; | 1525 | XftGlyphFontSpec *specs = xw.specbuf; |
1532 | 1526 | ||
1533 | if (!(IS_SET(MODE_VISIBLE))) | 1527 | numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1); |
1534 | return; | 1528 | i = ox = 0; |
1535 | 1529 | for (x = x1; x < x2 && i < numspecs; x++) { | |
1536 | for (y = y1; y < y2; y++) { | 1530 | new = line[x]; |
1537 | if (!term.dirty[y]) | 1531 | if (new.mode == ATTR_WDUMMY) |
1538 | continue; | 1532 | continue; |
1539 | 1533 | if (selected(x, y1)) | |
1540 | term.dirty[y] = 0; | 1534 | new.mode ^= ATTR_REVERSE; |
1541 | 1535 | if (i > 0 && ATTRCMP(base, new)) { | |
1542 | specs = xw.specbuf; | 1536 | xdrawglyphfontspecs(specs, base, i, ox, y1); |
1543 | numspecs = xmakeglyphfontspecs(specs, &term.line[y][x1], x2 - x1, x1, y); | 1537 | specs += i; |
1544 | 1538 | numspecs -= i; | |
1545 | i = ox = 0; | 1539 | i = 0; |
1546 | for (x = x1; x < x2 && i < numspecs; x++) { | 1540 | } |
1547 | new = term.line[y][x]; | 1541 | if (i == 0) { |
1548 | if (new.mode == ATTR_WDUMMY) | 1542 | ox = x; |
1549 | continue; | 1543 | base = new; |
1550 | if (selected(x, y)) | ||
1551 | new.mode ^= ATTR_REVERSE; | ||
1552 | if (i > 0 && ATTRCMP(base, new)) { | ||
1553 | xdrawglyphfontspecs(specs, base, i, ox, y); | ||
1554 | specs += i; | ||
1555 | numspecs -= i; | ||
1556 | i = 0; | ||
1557 | } | ||
1558 | if (i == 0) { | ||
1559 | ox = x; | ||
1560 | base = new; | ||
1561 | } | ||
1562 | i++; | ||
1563 | } | 1544 | } |
1564 | if (i > 0) | 1545 | i++; |
1565 | xdrawglyphfontspecs(specs, base, i, ox, y); | ||
1566 | } | 1546 | } |
1567 | xdrawcursor(); | 1547 | if (i > 0) |
1548 | xdrawglyphfontspecs(specs, base, i, ox, y1); | ||
1549 | } | ||
1550 | |||
1551 | void | ||
1552 | xfinishdraw(void) | ||
1553 | { | ||
1554 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, | ||
1555 | win.h, 0, 0); | ||
1556 | XSetForeground(xw.dpy, dc.gc, | ||
1557 | dc.col[IS_SET(MODE_REVERSE)? | ||
1558 | defaultfg : defaultbg].pixel); | ||
1568 | } | 1559 | } |
1569 | 1560 | ||
1570 | void | 1561 | void |