aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-24 14:53:23 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:56:26 -0600
commit88d8293fb4ba150a5f19d58d133b5db93d9dcfa5 (patch)
treef9e3cce2feda5565049c5d99012e8bd84144b8a2
parent05c66cb37d9ff278a3e0c45682c4b5e7945deb42 (diff)
downloadst-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.c25
-rw-r--r--st.h1
-rw-r--r--win.h7
-rw-r--r--x.c79
4 files changed, 65 insertions, 47 deletions
diff --git a/st.c b/st.c
index 01791a5..504239e 100644
--- a/st.c
+++ b/st.c
@@ -166,6 +166,8 @@ static int32_t tdefcolor(int *, int *, int);
166static void tdeftran(char); 166static void tdeftran(char);
167static void tstrsequence(uchar); 167static void tstrsequence(uchar);
168 168
169static void drawregion(int, int, int, int);
170
169static void selscroll(int, int); 171static void selscroll(int, int);
170static void selsnap(int *, int *, int); 172static void selsnap(int *, int *, int);
171 173
@@ -2527,6 +2529,29 @@ resettitle(void)
2527} 2529}
2528 2530
2529void 2531void
2532drawregion(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
2544void
2545draw(void)
2546{
2547 if (!xstartdraw())
2548 return;
2549 drawregion(0, 0, term.col, term.row);
2550 xdrawcursor();
2551 xfinishdraw();
2552}
2553
2554void
2530redraw(void) 2555redraw(void)
2531{ 2556{
2532 tfulldirt(); 2557 tfulldirt();
diff --git a/st.h b/st.h
index 3382d61..7026de8 100644
--- a/st.h
+++ b/st.h
@@ -131,6 +131,7 @@ typedef union {
131 131
132void die(const char *, ...); 132void die(const char *, ...);
133void redraw(void); 133void redraw(void);
134void draw(void);
134 135
135void iso14755(const Arg *); 136void iso14755(const Arg *);
136void printscreen(const Arg *); 137void printscreen(const Arg *);
diff --git a/win.h b/win.h
index 1e08b16..6e662af 100644
--- a/win.h
+++ b/win.h
@@ -23,12 +23,12 @@ enum win_mode {
23 |MODE_MOUSEMANY, 23 |MODE_MOUSEMANY,
24}; 24};
25 25
26void draw(void);
27void drawregion(int, int, int, int);
28
29void xbell(void); 26void xbell(void);
30void xclipcopy(void); 27void xclipcopy(void);
28void xdrawcursor(void);
29void xdrawline(Line, int, int, int);
31void xhints(void); 30void xhints(void);
31void xfinishdraw(void);
32void xloadcols(void); 32void xloadcols(void);
33int xsetcolorname(int, const char *); 33int xsetcolorname(int, const char *);
34void xsettitle(char *); 34void xsettitle(char *);
@@ -36,3 +36,4 @@ int xsetcursor(int);
36void xsetmode(int, unsigned int); 36void xsetmode(int, unsigned int);
37void xsetpointermotion(int); 37void xsetpointermotion(int);
38void xsetsel(char *); 38void xsetsel(char *);
39int xstartdraw(void);
diff --git a/x.c b/x.c
index c5826cf..96944ee 100644
--- a/x.c
+++ b/x.c
@@ -129,7 +129,6 @@ static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int)
129static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int); 129static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
130static void xdrawglyph(Glyph, int, int); 130static void xdrawglyph(Glyph, int, int);
131static void xclear(int, int, int, int); 131static void xclear(int, int, int, int);
132static void xdrawcursor(void);
133static int xgeommasktogravity(int); 132static int xgeommasktogravity(int);
134static void xinit(void); 133static void xinit(void);
135static void cresize(int, int); 134static void cresize(int, int);
@@ -1512,59 +1511,51 @@ xsettitle(char *p)
1512 XFree(prop.value); 1511 XFree(prop.value);
1513} 1512}
1514 1513
1515void 1514int
1516draw(void) 1515xstartdraw(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
1526void 1520void
1527drawregion(int x1, int y1, int x2, int y2) 1521xdrawline(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
1551void
1552xfinishdraw(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
1570void 1561void