aboutsummaryrefslogtreecommitdiff
path: root/x.c
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 /x.c
parent05c66cb37d9ff278a3e0c45682c4b5e7945deb42 (diff)
downloadst-88d8293fb4ba150a5f19d58d133b5db93d9dcfa5.tar.gz
st-88d8293fb4ba150a5f19d58d133b5db93d9dcfa5.tar.bz2
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>
Diffstat (limited to 'x.c')
-rw-r--r--x.c79
1 files changed, 35 insertions, 44 deletions
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)
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int);
-static void xdrawcursor(void);
static int xgeommasktogravity(int);
static void xinit(void);
static void cresize(int, int);
@@ -1512,59 +1511,51 @@ xsettitle(char *p)
XFree(prop.value);
}
-void
-draw(void)
+int
+xstartdraw(void)
{
- drawregion(0, 0, term.col, term.row);
- XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
- win.h, 0, 0);
- XSetForeground(xw.dpy, dc.gc,
- dc.col[IS_SET(MODE_REVERSE)?
- defaultfg : defaultbg].pixel);
+ return IS_SET(MODE_VISIBLE);
}
void
-drawregion(int x1, int y1, int x2, int y2)
+xdrawline(Line line, int x1, int y1, int x2)
{
- int i, x, y, ox, numspecs;
+ int i, x, ox, numspecs;
Glyph base, new;
- XftGlyphFontSpec *specs;
+ XftGlyphFontSpec *specs = xw.specbuf;
- if (!(IS_SET(MODE_VISIBLE)))
- return;
-
- for (y = y1; y < y2; y++) {
- if (!term.dirty[y])
+ numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
+ i = ox = 0;
+ for (x = x1; x < x2 && i < numspecs; x++) {
+ new = line[x];
+ if (new.mode == ATTR_WDUMMY)
continue;
-
- term.dirty[y] = 0;
-
- specs = xw.specbuf;
- numspecs = xmakeglyphfontspecs(specs, &term.line[y][x1], x2 - x1, x1, y);
-
- i = ox = 0;
- for (x = x1; x < x2 && i < numspecs; x++) {
- new = term.line[y][x];
- if (new.mode == ATTR_WDUMMY)
- continue;
- if (selected(x, y))
- new.mode ^= ATTR_REVERSE;
- if (i > 0 && ATTRCMP(base, new)) {
- xdrawglyphfontspecs(specs, base, i, ox, y);
- specs += i;
- numspecs -= i;
- i = 0;
- }
- if (i == 0) {
- ox = x;
- base = new;
- }
- i++;
+ if (selected(x, y1))
+ new.mode ^= ATTR_REVERSE;
+ if (i > 0 && ATTRCMP(base, new)) {
+ xdrawglyphfontspecs(specs, base, i, ox, y1);
+ specs += i;
+ numspecs -= i;
+ i = 0;
+ }
+ if (i == 0) {
+ ox = x;
+ base = new;
}
- if (i > 0)
- xdrawglyphfontspecs(specs, base, i, ox, y);
+ i++;
}
- xdrawcursor();
+ if (i > 0)
+ xdrawglyphfontspecs(specs, base, i, ox, y1);
+}
+
+void
+xfinishdraw(void)
+{
+ XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
+ win.h, 0, 0);
+ XSetForeground(xw.dpy, dc.gc,
+ dc.col[IS_SET(MODE_REVERSE)?
+ defaultfg : defaultbg].pixel);
}
void