SWOv git · main
SWOv - window overview for sway
C 97.3% Markdown 2.4%git clone https://git.christianimmanuel.de/sway/SWOv.gitwget https://git.christianimmanuel.de/sway/SWOv/archive/SWOv.tar.gzFix bad performance caused by raster
README.md | 22 +- commit_message.txt | 53 ++--- sw_draw.h | 619 +++++++++++++++++++++++++++++++++++++++++------------ swov.c | 51 ++--- 4 files changed, 534 insertions(+), 211 deletions(-) diff --git a/README.md b/README.md index 9730d01..2edef7c 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,13 @@ Needs a running sway session (`$SWAYSOCK`) and any TTF font. ``` bindsym $mod+Tab exec swov -for_window [app_id="swov"] floating enable, border none ``` -Without that `for_window` line swov opens as an ordinary tile, which rearranges -the layout it is meant to be showing you. It also asks sway for the keyboard -itself once it is up (`focus_self=1`), since an overlay that is not focused -does nothing at all — every key goes to whatever is underneath it. +That is the whole config. swov is a layer-shell overlay, not a window, so +sway neither tiles it nor touches the layout underneath, and it takes the +keyboard by asking for it on the surface. The old +`for_window [app_id="swov"] floating enable` rule does nothing now and can +be deleted. | key | action | | --- | --- | @@ -219,15 +219,9 @@ to read the workspace you are aiming at. It costs three scaled blits of a frame that is already drawn, and swov only repaints on change, so an idle backdrop costs nothing at all. -It uses its own app id, so give it a rule or it steals the keyboard: - -``` -no_focus [app_id="swov-backdrop"] -for_window [app_id="swov-backdrop"] floating enable, border none -``` - -`no_focus` takes the criteria itself. `for_window [...] no_focus` is not the -same thing and does nothing at all. +The backdrop takes no keyboard at all and sits on the layer below the +program in front of it, so it needs no sway rule. The old +`no_focus [app_id="swov-backdrop"]` line does nothing now and can be deleted. `--backdrop-debug` is the same mode with the conversation echoed to stderr. diff --git a/commit_message.txt b/commit_message.txt index fcf6eea..4e5b3b7 100644 --- a/commit_message.txt +++ b/commit_message.txt @@ -1,30 +1,35 @@ -shared: bold faces, offscreen canvases and a PNG writer +shared: a rasteriser fast enough for a full-screen overlay -What swov needed from the layer that swas and swbr already use, added -without changing anything the two of them do. +sw_draw.h was written for swbr, which draws a bar. Asked to draw a whole +screen it cost 77 ms a frame at 1600x900 and most of a second at 4K, because +every shape walked its bounding box and blended each pixel in floating +point. What changed: -sw_draw.h - - sw_fonts_bold() / sw_font_bold(): a second face for headings. Without - one the regular face is emboldened by drawing each glyph twice, a - third of a pixel apart, so bold still reads as bold on a desktop that - ships only one weight. The cache is keyed on size and weight together. - - sw_canvas_new/free/clear and sw_blit_canvas(): an offscreen canvas - that can be scaled, tinted and faded onto another. Shrinking box- - filters; a 1:1 aligned blit is a straight premultiplied-over copy. - This is what swov's backdrop fade and its full -> half -> small blur - chain are made of. - - sw_write_png(): one canvas to a PNG, stored (uncompressed) deflate, - for swov --shot. No zlib, a big file, which is fine for one frame. - - sw_text_width_n() and sw_font_descent(), for measuring part of a - string and centring a line in a box. + - Blending is 8-bit integer throughout. A run of one colour composites two + channels at a time out of a packed word, so the inner loop is one + multiply per half and an add. + - Every shape fills its solid middle with plain spans and keeps the + distance field for the edge: a rounded rectangle evaluates it only in + the four corners, a circle only at the ends of each span, an annular + wedge only inside its own bounding box rather than the whole disc. + - Triangles are a distance field too, stepped along the row, instead of + four samples a pixel. + - sw_canvas_bg() replaces the clip rectangle instead of blending into it, + for the one fill that is always the first thing drawn. -sw_wl.h - - SwEvent.code carries the raw evdev keycode, so a program can read a - key by its place on the board rather than by what it types. swov's - number row needs that on a layout where the digits take shift. - - sw_win_create() accepts a NULL SwApp: a program that drives its own - frames with sw_win_begin/end has no callbacks to give, and passing - NULL used to dereference it. +Measured, same frames: a swov-like frame 77 -> 1.2 ms at 1600x900 and +473 -> 6.6 ms at 4K; a swas-like frame 278 -> 7.4 ms and 1741 -> 40 ms; a +single wedge 24 -> 0.24 ms. Output is unchanged to the eye — the distance +fields antialias at least as well as the sampling did. + +Earlier in this release: bold faces (sw_fonts_bold / sw_font_bold, with a +synthesised bold when the desktop ships one weight), offscreen canvases +(sw_canvas_new / sw_blit_canvas) for the backdrop's fade and blur, +sw_write_png for swov --shot, sw_text_width_n and sw_font_descent. + +sw_wl.h: SwEvent.code carries the raw evdev keycode, so a program can read a +key by its place on the board; and sw_win_create accepts a NULL SwApp, which +a program driving its own frames has no use for and which used to crash. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SuAfijAAYjLpcVwhCq3AF4 diff --git a/sw_draw.h b/sw_draw.h index f9e133e..cca1c2c 100644 --- a/sw_draw.h +++ b/sw_draw.h @@ -1,12 +1,20 @@ /* sw_draw.h — a software canvas. ARGB8888, premultiplied, which is what - * wl_shm wants. Rounded rectangles come out of a signed distance field, text - * out of stb_truetype with a per-size glyph cache, images out of a box filter. + * wl_shm wants. Rounded rectangles, circles, wedges and triangles come out of + * signed distance fields, text out of stb_truetype with a per-size glyph + * cache, images out of a box filter. * * No GPU and no windowing system: a Canvas is a pixel buffer and a clip * rectangle, so a whole frame can be drawn and then inspected in a test with * no compositor anywhere near it. That is the point of doing it this way, as * much as the short link line. * + * It is written to be fast enough for a full-screen overlay. Blending is in + * 8-bit integers, a run of one colour composites two channels at a time, and + * every shape fills its solid middle with plain spans and keeps the distance + * field for the edge — a rounded rectangle only evaluates it in the four + * corners, a wedge only inside its own bounding box. Doing this per pixel in + * floating point, as the first version did, cost a 4K frame most of a second. + * * Lifted out of swbr, which has drawn itself like this all along. * * Define SW_DRAW_IMPL in exactly one translation unit before including this. @@ -93,6 +101,11 @@ float sw_text_width(Font *f, const char *s); void sw_canvas_clip(Canvas *cv, int x0, int y0, int x1, int y1); void sw_canvas_clip_all(Canvas *cv); void sw_canvas_fill(Canvas *cv, Col c); /* the whole clip rectangle */ +/* The frame's background: the clip rectangle is *replaced* by c rather than + blended with it. On a buffer that was just cleared the result is the same, + and it is a plain store instead of a read-modify-write — worth having on a + full-screen overlay, where this is the single biggest thing drawn. */ +void sw_canvas_bg(Canvas *cv, Col c); void sw_fill_rect(Canvas *cv, float x, float y, float w, float h, Col c); void sw_fill_round(Canvas *cv, float x, float y, float w, float h, @@ -473,101 +486,251 @@ void sw_canvas_clip(Canvas *cv, int x0, int y0, int x1, int y1) void sw_canvas_clip_all(Canvas *cv) { sw_canvas_clip(cv, 0, 0, cv->w, cv->h); } -static inline void sw_blend(Canvas *cv, int x, int y, Col c, float cov) +/* ------------------------------------------------------------- blending + * The canvas is premultiplied ARGB8888. Everything below works in 8-bit + * integers: a float blend per pixel is what made a full-screen frame cost + * tens of milliseconds. SW_MUL is the usual x*y/255 without a divide. + */ + +#define SW_MUL(x, y) ((unsigned)((((unsigned)(x) * (unsigned)(y) + 128u) * 257u) >> 16)) + +/* Two 8-bit channels packed in 0x00ff00ff, each already multiplied by a + 0..255 factor: divide both by 255, rounded, without a divide. */ +static inline uint32_t sw_div255x2(uint32_t x) +{ + uint32_t t = x + 0x00800080u; + return ((t + ((t >> 8) & 0x00ff00ffu)) >> 8) & 0x00ff00ffu; +} + +/* One pixel, no bounds check: callers clip their spans first. `a` is the + coverage and the colour's own alpha already multiplied together. */ +static inline void sw_put(uint32_t *p, Col c, unsigned a) +{ + unsigned ia, d, da, dr, dg, db; + if (!a) return; + if (a == 255) { + *p = 0xff000000u | ((uint32_t)c.r << 16) | ((uint32_t)c.g << 8) | c.b; + return; + } + ia = 255u - a; + d = *p; + da = (d >> 24) & 0xffu; dr = (d >> 16) & 0xffu; + dg = (d >> 8) & 0xffu; db = d & 0xffu; + *p = ((SW_MUL(da, ia) + a) << 24) + | ((SW_MUL(c.r, a) + SW_MUL(dr, ia)) << 16) + | ((SW_MUL(c.g, a) + SW_MUL(dg, ia)) << 8) + | (SW_MUL(c.b, a) + SW_MUL(db, ia)); +} + +static inline void sw_blend8(Canvas *cv, int x, int y, Col c, unsigned a) { if (x < cv->cx0 || x >= cv->cx1 || y < cv->cy0 || y >= cv->cy1) return; - float a = (float)c.a / 255.0f * cov; - if (a <= 0.0f) return; - uint32_t d = cv->px[y * cv->w + x]; - float da = (float)((d >> 24) & 0xff) / 255.0f; - float dr = (float)((d >> 16) & 0xff) / 255.0f; - float dg = (float)((d >> 8) & 0xff) / 255.0f; - float db = (float)(d & 0xff) / 255.0f; - float sr = (float)c.r / 255.0f * a; - float sg = (float)c.g / 255.0f * a; - float sb = (float)c.b / 255.0f * a; - float ia = 1.0f - a; - float orr = sr + dr * ia, og = sg + dg * ia, ob = sb + db * ia, oa = a + da * ia; - cv->px[y * cv->w + x] = - ((uint32_t)(orr * 255.0f + 0.5f) << 16) | - ((uint32_t)(og * 255.0f + 0.5f) << 8) | - ((uint32_t)(ob * 255.0f + 0.5f)) | - ((uint32_t)(oa * 255.0f + 0.5f) << 24); + sw_put(&cv->px[(size_t)y * (size_t)cv->w + x], c, a); +} + +/* Kept for callers that think in coverage. */ +static inline void sw_blend(Canvas *cv, int x, int y, Col c, float cov) +{ + int a; + if (cov <= 0.0f) return; + if (cov > 1.0f) cov = 1.0f; + a = (int)((float)c.a * cov + 0.5f); + if (a <= 0) return; + sw_blend8(cv, x, y, c, (unsigned)a); +} + +/* A run of pixels on one row at a constant alpha. This is where the time + goes, so the clip is applied once and the inner loop is bare. */ +static void sw_span(Canvas *cv, int x0, int x1, int y, Col c, unsigned a) +{ + uint32_t *p, *e; + if (!a || y < cv->cy0 || y >= cv->cy1) return; + if (x0 < cv->cx0) x0 = cv->cx0; + if (x1 > cv->cx1) x1 = cv->cx1; + if (x0 >= x1) return; + p = &cv->px[(size_t)y * (size_t)cv->w + x0]; + e = p + (x1 - x0); + if (a == 255) { + uint32_t v = 0xff000000u | ((uint32_t)c.r << 16) | ((uint32_t)c.g << 8) | c.b; + while (p < e) *p++ = v; + return; + } + { /* two channels at a time: the colour is constant along the run, so + the only work per pixel is one multiply per half and an add */ + unsigned ia = 255u - a; + uint32_t srb = (SW_MUL(c.r, a) << 16) | SW_MUL(c.b, a); + uint32_t sag = ((unsigned)a << 16) | SW_MUL(c.g, a); + while (p < e) { + uint32_t d = *p; + uint32_t rb = sw_div255x2((d & 0x00ff00ffu) * ia); + uint32_t ag = sw_div255x2(((d >> 8) & 0x00ff00ffu) * ia); + *p++ = ((srb + rb) & 0x00ff00ffu) | (((sag + ag) & 0x00ff00ffu) << 8); + } + } +} + +/* how much of [a0,a1) the unit cell [i,i+1) covers */ +static inline float sw_cov1(float a0, float a1, int i) +{ + float lo = (float)i, hi = lo + 1.0f; + float l = a0 > lo ? a0 : lo, r = a1 < hi ? a1 : hi; + return r > l ? r - l : 0.0f; } void sw_fill_rect(Canvas *cv, float x, float y, float w, float h, Col c) { + int ix0, ix1, iy0, iy1, yy, fx0, fx1; + float x1f = x + w, y1f = y + h; if (w <= 0 || h <= 0 || !c.a) return; - int x0 = (int)floorf(x), y0 = (int)floorf(y); - int x1 = (int)ceilf(x + w), y1 = (int)ceilf(y + h); - for (int yy = y0; yy < y1; ++yy) - for (int xx = x0; xx < x1; ++xx) { - float cxs = sw_clampf(x + w, (float)xx, (float)xx + 1) - sw_clampf(x, (float)xx, (float)xx + 1); - float cys = sw_clampf(y + h, (float)yy, (float)yy + 1) - sw_clampf(y, (float)yy, (float)yy + 1); - sw_blend(cv, xx, yy, c, cxs * cys); + + ix0 = (int)floorf(x); ix1 = (int)ceilf(x1f); + iy0 = (int)floorf(y); iy1 = (int)ceilf(y1f); + if (ix0 < cv->cx0) ix0 = cv->cx0; + if (ix1 > cv->cx1) ix1 = cv->cx1; + if (iy0 < cv->cy0) iy0 = cv->cy0; + if (iy1 > cv->cy1) iy1 = cv->cy1; + if (ix0 >= ix1 || iy0 >= iy1) return; + + fx0 = (int)ceilf(x); if (fx0 < ix0) fx0 = ix0; /* first full column */ + fx1 = (int)floorf(x1f); if (fx1 > ix1) fx1 = ix1; /* past the last one */ + + for (yy = iy0; yy < iy1; ++yy) { + float yc = sw_cov1(y, y1f, yy); + unsigned af; + if (yc <= 0.0f) continue; + af = (unsigned)((float)c.a * yc + 0.5f); + if (fx0 > ix0) sw_blend8(cv, ix0, yy, + c, (unsigned)((float)c.a * yc * sw_cov1(x, x1f, ix0) + 0.5f)); + if (fx1 > fx0) sw_span(cv, fx0, fx1, yy, c, af); + if (fx1 < ix1) sw_blend8(cv, ix1 - 1, yy, + c, (unsigned)((float)c.a * yc * sw_cov1(x, x1f, ix1 - 1) + 0.5f)); + } +} + +/* One rounded corner: inside its own box the distance to the shape is just + the distance to the circle's centre, so this is a quarter disc. */ +static void sw_corner(Canvas *cv, float cx, float cy, float r, + int sx, int sy, Col c) +{ + int x0, y0, x1, y1, xx, yy; + if (r <= 0.0f) return; + x0 = (int)floorf(sx < 0 ? cx - r - 1.0f : cx); + x1 = (int)ceilf (sx < 0 ? cx : cx + r + 1.0f); + y0 = (int)floorf(sy < 0 ? cy - r - 1.0f : cy); + y1 = (int)ceilf (sy < 0 ? cy : cy + r + 1.0f); + if (x0 < cv->cx0) x0 = cv->cx0; + if (x1 > cv->cx1) x1 = cv->cx1; + if (y0 < cv->cy0) y0 = cv->cy0; + if (y1 > cv->cy1) y1 = cv->cy1; + for (yy = y0; yy < y1; ++yy) { + float dy = (float)yy + 0.5f - cy; + uint32_t *row = &cv->px[(size_t)yy * (size_t)cv->w]; + for (xx = x0; xx < x1; ++xx) { + float dx = (float)xx + 0.5f - cx; + float d = sqrtf(dx * dx + dy * dy) - r; + float cov = 0.5f - d; + if (cov <= 0.0f) continue; + if (cov > 1.0f) cov = 1.0f; + sw_put(&row[xx], c, (unsigned)((float)c.a * cov + 0.5f)); } + } } -/* Rounded box with a radius per corner (tl, tr, br, bl), anti-aliased through - * the usual signed distance trick. A corner radius of 0 is a square corner — - * that is how the bar stays flush with the screen edge. */ +/* Rounded box with a radius per corner (tl, tr, br, bl). The straight parts + * are plain rectangles and only the four corners go through a distance + * field, which is what keeps a full-screen fill cheap. A corner radius of 0 + * is a square corner — that is how the bar stays flush with the screen edge. */ void sw_fill_round(Canvas *cv, float x, float y, float w, float h, float rtl, float rtr, float rbr, float rbl, Col c) { + float cap, rt, rb, mid; if (w <= 0 || h <= 0 || !c.a) return; - float hw = w * 0.5f, hh = h * 0.5f; - float ccx = x + hw, ccy = y + hh; - float cap = fminf(hw, hh); + cap = fminf(w * 0.5f, h * 0.5f); rtl = sw_clampf(rtl, 0, cap); rtr = sw_clampf(rtr, 0, cap); rbr = sw_clampf(rbr, 0, cap); rbl = sw_clampf(rbl, 0, cap); + if (rtl <= 0.0f && rtr <= 0.0f && rbr <= 0.0f && rbl <= 0.0f) { + sw_fill_rect(cv, x, y, w, h, c); + return; + } + + rt = fmaxf(rtl, rtr); + rb = fmaxf(rbr, rbl); + mid = h - rt - rb; + + if (mid > 0.0f) sw_fill_rect(cv, x, y + rt, w, mid, c); + + /* top band */ + if (rt > 0.0f) { + sw_fill_rect(cv, x + rtl, y, w - rtl - rtr, rt, c); + if (rtl < rt) sw_fill_rect(cv, x, y + rtl, rtl, rt - rtl, c); + if (rtr < rt) sw_fill_rect(cv, x + w - rtr, y + rtr, rtr, rt - rtr, c); + sw_corner(cv, x + rtl, y + rtl, rtl, -1, -1, c); + sw_corner(cv, x + w - rtr, y + rtr, rtr, +1, -1, c); + } + /* bottom band */ + if (rb > 0.0f) { + sw_fill_rect(cv, x + rbl, y + h - rb, w - rbl - rbr, rb, c); + if (rbl < rb) sw_fill_rect(cv, x, y + h - rb, rbl, rb - rbl, c); + if (rbr < rb) sw_fill_rect(cv, x + w - rbr, y + h - rb, rbr, rb - rbr, c); + sw_corner(cv, x + rbl, y + h - rbl, rbl, -1, +1, c); + sw_corner(cv, x + w - rbr, y + h - rbr, rbr, +1, +1, c); + } +} - int x0 = (int)floorf(x) - 1, y0 = (int)floorf(y) - 1; - int x1 = (int)ceilf(x + w) + 1, y1 = (int)ceilf(y + h) + 1; - for (int yy = y0; yy < y1; ++yy) { - if (yy < cv->cy0 || yy >= cv->cy1) continue; - for (int xx = x0; xx < x1; ++xx) { - if (xx < cv->cx0 || xx >= cv->cx1) continue; - float px = (float)xx + 0.5f - ccx, py = (float)yy + 0.5f - ccy; - float r = px < 0 ? (py < 0 ? rtl : rbl) : (py < 0 ? rtr : rbr); - float qx = fabsf(px) - (hw - r), qy = fabsf(py) - (hh - r); - float mx = fmaxf(qx, 0.0f), my = fmaxf(qy, 0.0f); - float d = sqrtf(mx * mx + my * my) + fminf(fmaxf(qx, qy), 0.0f) - r; - float cov = sw_clampf(0.5f - d, 0.0f, 1.0f); - if (cov > 0) sw_blend(cv, xx, yy, c, cov); +/* One corner of an outline: the same quarter disc kept to a ring. */ +static void sw_corner_ring(Canvas *cv, float cx, float cy, float r, float t, + int sx, int sy, Col c) +{ + int x0, y0, x1, y1, xx, yy; + if (r <= 0.0f || t <= 0.0f) return; + x0 = (int)floorf(sx < 0 ? cx - r - 1.0f : cx); + x1 = (int)ceilf (sx < 0 ? cx : cx + r + 1.0f); + y0 = (int)floorf(sy < 0 ? cy - r - 1.0f : cy); + y1 = (int)ceilf (sy < 0 ? cy : cy + r + 1.0f); + if (x0 < cv->cx0) x0 = cv->cx0; + if (x1 > cv->cx1) x1 = cv->cx1; + if (y0 < cv->cy0) y0 = cv->cy0; + if (y1 > cv->cy1) y1 = cv->cy1; + for (yy = y0; yy < y1; ++yy) { + float dy = (float)yy + 0.5f - cy; + uint32_t *row = &cv->px[(size_t)yy * (size_t)cv->w]; + for (xx = x0; xx < x1; ++xx) { + float dx = (float)xx + 0.5f - cx; + float d = sqrtf(dx * dx + dy * dy) - r; + float cov = 0.5f - fabsf(d + t * 0.5f) + t * 0.5f; + if (cov <= 0.0f) continue; + if (cov > 1.0f) cov = 1.0f; + sw_put(&row[xx], c, (unsigned)((float)c.a * cov + 0.5f)); } } } -/* The same distance field kept to a ring: an outline that follows the corner - * radius and stays inside the box, so a button with no fill still has an edge. */ +/* An outline that follows the corner radius and stays inside the box, so a + * button with no fill still has an edge. Four straight bars and four arcs. */ void sw_stroke_round(Canvas *cv, float x, float y, float w, float h, float rtl, float rtr, float rbr, float rbl, float t, Col c) { + float cap; if (w <= 0 || h <= 0 || t <= 0 || !c.a) return; - float hw = w * 0.5f, hh = h * 0.5f; - float ccx = x + hw, ccy = y + hh; - float cap = fminf(hw, hh); + cap = fminf(w * 0.5f, h * 0.5f); rtl = sw_clampf(rtl, 0, cap); rtr = sw_clampf(rtr, 0, cap); rbr = sw_clampf(rbr, 0, cap); rbl = sw_clampf(rbl, 0, cap); - - int x0 = (int)floorf(x) - 1, y0 = (int)floorf(y) - 1; - int x1 = (int)ceilf(x + w) + 1, y1 = (int)ceilf(y + h) + 1; - for (int yy = y0; yy < y1; ++yy) { - if (yy < cv->cy0 || yy >= cv->cy1) continue; - for (int xx = x0; xx < x1; ++xx) { - if (xx < cv->cx0 || xx >= cv->cx1) continue; - float px = (float)xx + 0.5f - ccx, py = (float)yy + 0.5f - ccy; - float r = px < 0 ? (py < 0 ? rtl : rbl) : (py < 0 ? rtr : rbr); - float qx = fabsf(px) - (hw - r), qy = fabsf(py) - (hh - r); - float mx = fmaxf(qx, 0.0f), my = fmaxf(qy, 0.0f); - float d = sqrtf(mx * mx + my * my) + fminf(fmaxf(qx, qy), 0.0f) - r; - float cov = sw_clampf(0.5f - fabsf(d + t * 0.5f) + t * 0.5f, 0.0f, 1.0f); - if (cov > 0) sw_blend(cv, xx, yy, c, cov); - } - } + if (t > cap) t = cap; + + /* the straight runs, between the corners */ + if (w - rtl - rtr > 0.0f) sw_fill_rect(cv, x + rtl, y, w - rtl - rtr, t, c); + if (w - rbl - rbr > 0.0f) sw_fill_rect(cv, x + rbl, y + h - t, w - rbl - rbr, t, c); + if (h - rtl - rbl > 0.0f) sw_fill_rect(cv, x, y + rtl, t, h - rtl - rbl, c); + if (h - rtr - rbr > 0.0f) sw_fill_rect(cv, x + w - t, y + rtr, t, h - rtr - rbr, c); + + sw_corner_ring(cv, x + rtl, y + rtl, rtl, t, -1, -1, c); + sw_corner_ring(cv, x + w - rtr, y + rtr, rtr, t, +1, -1, c); + sw_corner_ring(cv, x + w - rbr, y + h - rbr, rbr, t, +1, +1, c); + sw_corner_ring(cv, x + rbl, y + h - rbl, rbl, t, -1, +1, c); } + void sw_text(Canvas *cv, Font *f, float x, float baseline, Col c, const char *s) { const char *p = s; @@ -581,13 +744,19 @@ void sw_text(Canvas *cv, Font *f, float x, float baseline, Col c, const char *s) int gy = (int)lroundf(baseline) + g->y0; int pass, passes = f->synth ? 2 : 1; for (pass = 0; pass < passes; ++pass) { + int bx = gx + pass; + int x0 = bx < cv->cx0 ? cv->cx0 - bx : 0; + int x1 = bx + g->w > cv->cx1 ? cv->cx1 - bx : g->w; for (int yy = 0; yy < g->h; ++yy) { int ty = gy + yy; + const unsigned char *row; + uint32_t *dst; if (ty < cv->cy0 || ty >= cv->cy1) continue; - const unsigned char *row = g->bmp + (size_t)yy * (size_t)g->w; - for (int xx = 0; xx < g->w; ++xx) { - unsigned char a = row[xx]; - if (a) sw_blend(cv, gx + pass + xx, ty, c, (float)a / 255.0f); + row = g->bmp + (size_t)yy * (size_t)g->w; + dst = &cv->px[(size_t)ty * (size_t)cv->w + bx]; + for (int xx = x0; xx < x1; ++xx) { + unsigned a = row[xx]; + if (a) sw_put(&dst[xx], c, SW_MUL(c.a, a)); } } } @@ -599,85 +768,231 @@ void sw_text(Canvas *cv, Font *f, float x, float baseline, Col c, const char *s) void sw_canvas_fill(Canvas *cv, Col c) { - sw_fill_rect(cv, (float)cv->cx0, (float)cv->cy0, - (float)(cv->cx1 - cv->cx0), (float)(cv->cy1 - cv->cy0), c); + int y; + if (!c.a) return; + for (y = cv->cy0; y < cv->cy1; ++y) sw_span(cv, cv->cx0, cv->cx1, y, c, c.a); +} + +void sw_canvas_bg(Canvas *cv, Col c) +{ + uint32_t v = ((uint32_t)c.a << 24) | (SW_MUL(c.r, c.a) << 16) + | (SW_MUL(c.g, c.a) << 8) | SW_MUL(c.b, c.a); + int y; + for (y = cv->cy0; y < cv->cy1; ++y) { + uint32_t *p = &cv->px[(size_t)y * (size_t)cv->w + cv->cx0]; + uint32_t *e = p + (cv->cx1 - cv->cx0); + while (p < e) *p++ = v; + } } /* A filled triangle, by half-plane tests on a 2x2 grid per pixel. swbr never * needed one; swas draws its wheel slices and its chevrons out of them. */ +/* A filled triangle as a distance field: the signed distance to each of the + * three edges, normalised so it is in pixels, and the smallest of them is the + * coverage. One pass, no supersampling, and the span is stepped rather than + * recomputed from scratch. */ void sw_fill_tri(Canvas *cv, float x0, float y0, float x1, float y1, float x2, float y2, Col c) { + float minx, maxx, miny, maxy, d; + float nx[3], ny[3], off[3]; + int ix0, iy0, ix1, iy1, y, e; + if (!c.a) return; - float minx = fminf(x0, fminf(x1, x2)), maxx = fmaxf(x0, fmaxf(x1, x2)); - float miny = fminf(y0, fminf(y1, y2)), maxy = fmaxf(y0, fmaxf(y1, y2)); - int ix0 = sw_clampi((int)floorf(minx), cv->cx0, cv->cx1); - int iy0 = sw_clampi((int)floorf(miny), cv->cy0, cv->cy1); - int ix1 = sw_clampi((int)ceilf(maxx) + 1, cv->cx0, cv->cx1); - int iy1 = sw_clampi((int)ceilf(maxy) + 1, cv->cy0, cv->cy1); - - float d = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0); + d = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0); if (fabsf(d) < 1e-6f) return; /* degenerate */ - float inv = 1.0f / d; - - for (int y = iy0; y < iy1; ++y) { - for (int x = ix0; x < ix1; ++x) { - int hits = 0; - for (int sy = 0; sy < 2; ++sy) { - for (int sx = 0; sx < 2; ++sx) { - float px = (float)x + 0.25f + 0.5f * (float)sx; - float py = (float)y + 0.25f + 0.5f * (float)sy; - float l0 = ((x1 - px) * (y2 - py) - (x2 - px) * (y1 - py)) * inv; - float l1 = ((x2 - px) * (y0 - py) - (x0 - px) * (y2 - py)) * inv; - float l2 = 1.0f - l0 - l1; - if (l0 >= 0.0f && l1 >= 0.0f && l2 >= 0.0f) hits++; - } + if (d < 0.0f) { /* make it counter-clockwise */ + float tx = x1, ty = y1; + x1 = x2; y1 = y2; x2 = tx; y2 = ty; + } + + minx = fminf(x0, fminf(x1, x2)); maxx = fmaxf(x0, fmaxf(x1, x2)); + miny = fminf(y0, fminf(y1, y2)); maxy = fmaxf(y0, fmaxf(y1, y2)); + ix0 = (int)floorf(minx) - 1; ix1 = (int)ceilf(maxx) + 1; + iy0 = (int)floorf(miny) - 1; iy1 = (int)ceilf(maxy) + 1; + if (ix0 < cv->cx0) ix0 = cv->cx0; + if (ix1 > cv->cx1) ix1 = cv->cx1; + if (iy0 < cv->cy0) iy0 = cv->cy0; + if (iy1 > cv->cy1) iy1 = cv->cy1; + if (ix0 >= ix1 || iy0 >= iy1) return; + + { /* inward unit normals, one per edge */ + float ex[3], ey[3], ax[3], ay[3]; + ax[0] = x0; ay[0] = y0; ex[0] = x1 - x0; ey[0] = y1 - y0; + ax[1] = x1; ay[1] = y1; ex[1] = x2 - x1; ey[1] = y2 - y1; + ax[2] = x2; ay[2] = y2; ex[2] = x0 - x2; ey[2] = y0 - y2; + for (e = 0; e < 3; ++e) { + float len = sqrtf(ex[e] * ex[e] + ey[e] * ey[e]); + if (len < 1e-6f) return; + nx[e] = -ey[e] / len; + ny[e] = ex[e] / len; + off[e] = -(nx[e] * ax[e] + ny[e] * ay[e]); + } + } + + for (y = iy0; y < iy1; ++y) { + float py = (float)y + 0.5f; + float base[3]; + uint32_t *row = &cv->px[(size_t)y * (size_t)cv->w]; + int x; + for (e = 0; e < 3; ++e) base[e] = ny[e] * py + off[e] + nx[e] * ((float)ix0 + 0.5f); + for (x = ix0; x < ix1; ++x) { + float dmin = base[0], cov; + if (base[1] < dmin) dmin = base[1]; + if (base[2] < dmin) dmin = base[2]; + cov = 0.5f + dmin; + if (cov > 0.0f) { + if (cov > 1.0f) cov = 1.0f; + sw_put(&row[x], c, (unsigned)((float)c.a * cov + 0.5f)); } - if (hits) sw_blend(cv, x, y, c, (float)hits * 0.25f); + base[0] += nx[0]; base[1] += nx[1]; base[2] += nx[2]; } } } void sw_fill_circle(Canvas *cv, float cx, float cy, float rad, Col c) { - sw_fill_round(cv, cx - rad, cy - rad, rad * 2.0f, rad * 2.0f, - rad, rad, rad, rad, c); + int y0, y1, y; + if (!c.a || rad <= 0.0f) return; + y0 = (int)floorf(cy - rad) - 1; y1 = (int)ceilf(cy + rad) + 1; + if (y0 < cv->cy0) y0 = cv->cy0; + if (y1 > cv->cy1) y1 = cv->cy1; + for (y = y0; y < y1; ++y) { + float dy = (float)y + 0.5f - cy; + float q = rad * rad - dy * dy; + float hw = q > 0.0f ? sqrtf(q) : 0.0f; + int x0 = (int)floorf(cx - hw) - 1, x1 = (int)ceilf(cx + hw) + 1, x; + uint32_t *row = &cv->px[(size_t)y * (size_t)cv->w]; + int fx0, fx1; + if (x0 < cv->cx0) x0 = cv->cx0; + if (x1 > cv->cx1) x1 = cv->cx1; + /* the middle of the span is solid; only its ends need a distance */ + fx0 = (int)ceilf(cx - hw + 0.5f); if (fx0 < x0) fx0 = x0; + fx1 = (int)floorf(cx + hw - 0.5f); if (fx1 > x1) fx1 = x1; + for (x = x0; x < x1; ++x) { + float dx, d, cov; + if (x == fx0 && fx1 > fx0) { /* jump the solid middle */ + sw_span(cv, fx0, fx1, y, c, c.a); + x = fx1 - 1; + continue; + } + dx = (float)x + 0.5f - cx; + d = sqrtf(dx * dx + dy * dy) - rad; + cov = 0.5f - d; + if (cov <= 0.0f) continue; + if (cov > 1.0f) cov = 1.0f; + sw_put(&row[x], c, (unsigned)((float)c.a * cov + 0.5f)); + } + } } -/* A wedge of an annulus: the slice shape a radial menu is made of. Tested - * per pixel against the two radii and the two angles, four samples a pixel so - * the long curved edges do not stair-step. A0 may exceed a1 going the other - * way round; the wedge is always drawn the short way from a0 to a1. */ +/* A wedge of an annulus: the slice shape a radial menu is made of. + * + * Written as a distance field rather than by sampling. Both radial edges are + * circles and both angular edges are rays through the centre, and the signed + * distance to a ray through the origin is just the cross product with its + * unit vector — so one sqrt a pixel covers all four edges, with no atan2 and + * no supersampling. Rows outside the outer circle are skipped and the hole in + * the middle is jumped over, which is most of a thick wheel. + * + * a0 may exceed a1 going the other way round; the wedge is always drawn the + * short way from a0 to a1. */ void sw_fill_sector(Canvas *cv, float cx, float cy, float r0, float r1, float a0, float a1, Col c) { + const float TAU = 6.283185307f; + float span, u0x, u0y, u1x, u1y, sx0, sy0, sx1, sy1; + int wide, y0, y1, y; + if (!c.a || r1 <= 0.0f || r1 <= r0) return; - int ix0 = sw_clampi((int)floorf(cx - r1) - 1, cv->cx0, cv->cx1); - int iy0 = sw_clampi((int)floorf(cy - r1) - 1, cv->cy0, cv->cy1); - int ix1 = sw_clampi((int)ceilf(cx + r1) + 1, cv->cx0, cv->cx1); - int iy1 = sw_clampi((int)ceilf(cy + r1) + 1, cv->cy0, cv->cy1); - - float span = a1 - a0; - while (span < 0.0f) span += 6.283185307f; - while (span > 6.283185307f) span -= 6.283185307f; - float r0s = r0 > 0.0f ? r0 * r0 : -1.0f, r1s = r1 * r1; - - for (int y = iy0; y < iy1; ++y) { - for (int x = ix0; x < ix1; ++x) { - int hits = 0; - for (int sy = 0; sy < 2; ++sy) { - for (int sx = 0; sx < 2; ++sx) { - float dx = (float)x + 0.25f + 0.5f * (float)sx - cx; - float dy = (float)y + 0.25f + 0.5f * (float)sy - cy; - float d2 = dx * dx + dy * dy; - if (d2 < r0s || d2 > r1s) continue; - float da = atan2f(dy, dx) - a0; - while (da < 0.0f) da += 6.283185307f; - while (da > 6.283185307f) da -= 6.283185307f; - if (da <= span) hits++; - } + if (r0 < 0.0f) r0 = 0.0f; + + span = a1 - a0; + while (span < 0.0f) span += TAU; + while (span >= TAU) span -= TAU; + if (span >= TAU - 1e-4f) { /* a full ring: no angular edges */ + span = TAU; + } + wide = span > 3.14159265f; + u0x = cosf(a0); u0y = sinf(a0); + u1x = cosf(a0 + span); u1y = sinf(a0 + span); + + /* The wedge's own box, not the whole circle's: a slice of a eleven-slot + wheel touches about a tenth of the disc, and walking the rest of it is + what made a frame cost tens of milliseconds. */ + { + float bx0 = 0.0f, by0 = 0.0f, bx1 = 0.0f, by1 = 0.0f; + float pts[8], k; + int i, nq; + pts[0] = r0 * u0x; pts[1] = r0 * u0y; + pts[2] = r1 * u0x; pts[3] = r1 * u0y; + pts[4] = r0 * u1x; pts[5] = r0 * u1y; + pts[6] = r1 * u1x; pts[7] = r1 * u1y; + bx0 = bx1 = pts[0]; by0 = by1 = pts[1]; + for (i = 1; i < 4; ++i) { + if (pts[i * 2] < bx0) bx0 = pts[i * 2]; + if (pts[i * 2] > bx1) bx1 = pts[i * 2]; + if (pts[i * 2 + 1] < by0) by0 = pts[i * 2 + 1]; + if (pts[i * 2 + 1] > by1) by1 = pts[i * 2 + 1]; + } + /* and wherever the arc crosses an axis inside the wedge */ + for (nq = 0; nq < 4; ++nq) { + float ang = (float)nq * 1.570796327f; + float rel = ang - a0; + while (rel < 0.0f) rel += TAU; + while (rel >= TAU) rel -= TAU; + if (rel > span) continue; + k = r1; + if (nq == 0 && k > bx1) bx1 = k; + if (nq == 1 && k > by1) by1 = k; + if (nq == 2 && -k < bx0) bx0 = -k; + if (nq == 3 && -k < by0) by0 = -k; + } + sy0 = cy + by0; sy1 = cy + by1; + sx0 = cx + bx0; sx1 = cx + bx1; + } + + y0 = (int)floorf(sy0) - 1; y1 = (int)ceilf(sy1) + 1; + if (y0 < cv->cy0) y0 = cv->cy0; + if (y1 > cv->cy1) y1 = cv->cy1; + + for (y = y0; y < y1; ++y) { + float dy = (float)y + 0.5f - cy; + float q = r1 * r1 - dy * dy; + float ow = q > 0.0f ? sqrtf(q) : 0.0f; + float qi = r0 * r0 - dy * dy; + float iw = (r0 > 0.0f && qi > 0.0f) ? sqrtf(qi) : -1.0f; + int x0, x1, x; + int hole0 = 0, hole1 = 0; + uint32_t *row = &cv->px[(size_t)y * (size_t)cv->w]; + float lo = cx - ow, hi = cx + ow; + if (lo < sx0) lo = sx0; + if (hi > sx1) hi = sx1; + x0 = (int)floorf(lo) - 1; x1 = (int)ceilf(hi) + 1; + if (x0 < cv->cx0) x0 = cv->cx0; + if (x1 > cv->cx1) x1 = cv->cx1; + if (iw > 1.0f) { /* the untouched middle */ + hole0 = (int)ceilf(cx - iw + 1.0f); + hole1 = (int)floorf(cx + iw - 1.0f); + } + for (x = x0; x < x1; ++x) { + float dx, len, d, da, cov; + if (hole1 > hole0 && x >= hole0 && x < hole1) { x = hole1 - 1; continue; } + dx = (float)x + 0.5f - cx; + len = sqrtf(dx * dx + dy * dy); + d = r1 - len; /* inside the outer circle */ + if (r0 > 0.0f) { float di = len - r0; if (di < d) d = di; } + if (d <= -1.0f) continue; + if (span < TAU) { + float e0 = u0x * dy - u0y * dx; /* left of the first ray */ + float e1 = dx * u1y - dy * u1x; /* right of the second */ + da = wide ? (e0 > e1 ? e0 : e1) : (e0 < e1 ? e0 : e1); + if (da < d) d = da; } - if (hits) sw_blend(cv, x, y, c, (float)hits * 0.25f); + cov = 0.5f + d; + if (cov <= 0.0f) continue; + if (cov > 1.0f) cov = 1.0f; + sw_put(&row[x], c, (unsigned)((float)c.a * cov + 0.5f)); } } } @@ -692,6 +1007,7 @@ void sw_blit(Canvas *cv, Image img, float x, float y, float w, float h, if (!img.rgba || img.w <= 0 || img.h <= 0 || w <= 0.0f || h <= 0.0f) return; if (alpha <= 0.0f) return; int stride = img.stride > 0 ? img.stride : img.w * 4; + unsigned ga = alpha >= 1.0f ? 255u : (unsigned)(alpha * 255.0f + 0.5f); int ix0 = sw_clampi((int)floorf(x), cv->cx0, cv->cx1); int iy0 = sw_clampi((int)floorf(y), cv->cy0, cv->cy1); @@ -724,8 +1040,13 @@ void sw_blit(Canvas *cv, Image img, float x, float y, float w, float h, } } if (!n || !as) continue; - Col c = { (uint8_t)(rs / n), (uint8_t)(gs / n), (uint8_t)(bs / n), 255 }; - sw_blend(cv, dx, dy, c, (float)(as / n) / 255.0f * alpha); + { + Col c; + unsigned av = as / n; + c.r = (uint8_t)(rs / n); c.g = (uint8_t)(gs / n); + c.b = (uint8_t)(bs / n); c.a = 255; + sw_blend8(cv, dx, dy, c, SW_MUL(av, ga)); + } } } } @@ -779,37 +1100,51 @@ void sw_blit_canvas(Canvas *dst, const Canvas *src, float x, float y, { int ix0, iy0, ix1, iy1, dx, dy, bx, by; float sx, sy; + unsigned ga; if (!dst || !src || !src->px || w <= 0.0f || h <= 0.0f || alpha <= 0.0f) return; + ga = alpha >= 1.0f ? 255u : (unsigned)(alpha * 255.0f + 0.5f); + if (!ga) return; ix0 = sw_clampi((int)floorf(x), dst->cx0, dst->cx1); iy0 = sw_clampi((int)floorf(y), dst->cy0, dst->cy1); ix1 = sw_clampi((int)ceilf(x + w), dst->cx0, dst->cx1); iy1 = sw_clampi((int)ceilf(y + h), dst->cy0, dst->cy1); - /* 1:1 and aligned: a straight premultiplied-over copy, no resampling */ + /* 1:1 and aligned: compose premultiplied over premultiplied, which needs + no un-premultiply and no resampling. This is the backdrop's own path, + so it runs on every frame of a fade. */ if (tint.r == 255 && tint.g == 255 && tint.b == 255 && (int)w == src->w && (int)h == src->h && x == floorf(x) && y == floorf(y)) { int ox = (int)x, oy = (int)y; for (dy = iy0; dy < iy1; ++dy) { const uint32_t *srow; + uint32_t *drow; int sy1 = dy - oy; if (sy1 < 0 || sy1 >= src->h) continue; srow = src->px + (size_t)sy1 * (size_t)src->w; + drow = dst->px + (size_t)dy * (size_t)dst->w; for (dx = ix0; dx < ix1; ++dx) { - uint32_t p; - unsigned av; - Col c; + uint32_t sp, dp; + unsigned sa, sr, sg, sb, ia; int sx1 = dx - ox; if (sx1 < 0 || sx1 >= src->w) continue; - p = srow[sx1]; - av = (p >> 24) & 0xff; - if (!av) continue; - c.r = (uint8_t)sw_clampi((int)((p >> 16 & 0xff) * 255 / av), 0, 255); - c.g = (uint8_t)sw_clampi((int)((p >> 8 & 0xff) * 255 / av), 0, 255); - c.b = (uint8_t)sw_clampi((int)((p & 0xff) * 255 / av), 0, 255); - c.a = 255; - sw_blend(dst, dx, dy, c, (float)av / 255.0f * alpha); + sp = srow[sx1]; + sa = (sp >> 24) & 0xffu; + if (!sa) continue; + sr = (sp >> 16) & 0xffu; sg = (sp >> 8) & 0xffu; sb = sp & 0xffu; + if (ga != 255u) { + sa = SW_MUL(sa, ga); sr = SW_MUL(sr, ga); + sg = SW_MUL(sg, ga); sb = SW_MUL(sb, ga); + if (!sa) continue; + } + if (sa == 255u) { drow[dx] = 0xff000000u | (sr << 16) | (sg << 8) | sb; continue; } + dp = drow[dx]; + ia = 255u - sa; + drow[dx] = ((sa + SW_MUL((dp >> 24) & 0xffu, ia)) << 24) + | ((sr + SW_MUL((dp >> 16) & 0xffu, ia)) << 16) + | ((sg + SW_MUL((dp >> 8) & 0xffu, ia)) << 8) + | (sb + SW_MUL(dp & 0xffu, ia)); } } return; @@ -858,7 +1193,7 @@ void sw_blit_canvas(Canvas *dst, const Canvas *src, float x, float y, c.g = (uint8_t)(c.g * tint.g / 255); c.b = (uint8_t)(c.b * tint.b / 255); } - sw_blend(dst, dx, dy, c, a * alpha); + sw_blend8(dst, dx, dy, c, SW_MUL((unsigned)(as / n), ga)); } } } diff --git a/swov.c b/swov.c index 9586d98..c2d838a 100644 --- a/swov.c +++ b/swov.c @@ -121,7 +121,7 @@ static uint64_t now_ms_(void) } #define APP_ID "swov" -#define SWOV_VERSION "1.3" +#define SWOV_VERSION "1.3.1" #ifndef SWOV_BUILD /* set by the Makefile: md5 of this file */ #define SWOV_BUILD "unknown" #endif @@ -5504,8 +5504,7 @@ static void draw_pencil(Rect r, FCol c) static void render(void) { sw_canvas_clip_all(REN); - sw_canvas_clear(REN); - sw_canvas_fill(REN, fcol(C.bg)); + sw_canvas_bg(REN, fcol(C.bg)); if (NWS == 0) { Tex t = text_make(F_LABEL, "no windows found on this output"); @@ -7009,18 +7008,10 @@ static bool backdrop_command(char *line) return true; } if (!strncmp(line, "raise ", 6) && line[6]) { - str_set(RAISE_APP, sizeof(RAISE_APP), line + 6); - RAISE_LEFT = 3; /* now, and twice more */ - RAISE_AT = 0.0; - /* Our window mapped on top of the one that asked for us, and on - * Wayland that one cannot lift itself back. sway can. - * - * Focusing it directly is not enough: it usually still *is* the - * focused window, thanks to `no_focus`, so sway has nothing to do and - * the stacking never changes. Focusing us first and it second makes - * the second a real change, which restacks. That is also why this - * waits for our own window to exist in the tree — asking before sway - * knows about it is the other half of the race. */ + /* Nothing to do any more. Both programs are layer surfaces now, and + the one that asked for us sits on the layer above the backdrop, so + it is already in front and already has the keyboard. Accepted and + ignored, so an older swas still talks to this one. */ return true; } if (!strcmp(line, "fade in")) { BACKDROP_WANT = 1.0f; return true; } @@ -7064,12 +7055,10 @@ static void backdrop_poll(void) * raises it, so one command does the job — but only once sway knows our window * exists. Rather than guess when that is, say it three times over half a * second. Repeating is harmless: the wheel is already the focused window. */ +/* The overlay asks the compositor for the keyboard on the surface itself, so + there is nothing to ask sway for. `focus_self` is accepted and ignored. */ static void focus_self_soon(void) { - if (BACKDROP || SERVING || !C.focus_self || RAISE_APP[0]) return; - str_set(RAISE_APP, sizeof(RAISE_APP), APP_ID); - RAISE_LEFT = 3; - RAISE_AT = 0.0; } static void backdrop_raise_tick(void) @@ -7135,11 +7124,8 @@ static void map_dwell_tick(void) set_ghosts(C.drop_ghosts ? 0 : -1, C.drop_ghosts ? 10 : -1); backdrop_reply("target none"); - /* The app on the pointer is drawn by the launcher, on its own - * surface. Redrawing everything here is enough for sway to put this - * window in front of it, and then the icon is behind the overview - * for the rest of the drag. Ask for it back. */ - if (RAISE_APP[0]) { RAISE_LEFT = 3; RAISE_AT = 0.0; } + /* The app on the pointer is drawn by the launcher, on the layer + * above this one, so redrawing here never covers it. */ } dirty = true; } @@ -7202,13 +7188,15 @@ static void backdrop_blur(Canvas *dst, float alpha) sw_blit_canvas(dst, BLUR_SMALL, 0, 0, (float)RW, (float)RH, SW_WHITE, alpha); } -static void present(void) +/* false when the compositor still holds both buffers: the caller keeps the + frame pending rather than dropping it, which is what made the overview + feel like it was ignoring the keyboard. */ +static bool present(void) { Canvas *win = sw_win_begin(WIN); - if (!win) return; /* both buffers still on screen */ + if (!win) return false; /* both buffers still on screen */ - sw_canvas_clip_all(win); - sw_canvas_clear(win); + sw_canvas_clip_all(win); /* sw_win_begin already cleared it */ REN = TARGET ? TARGET : win; if (TARGET) sw_canvas_clear(TARGET); @@ -7233,6 +7221,7 @@ static void present(void) } sw_win_end(WIN); shown_once = true; + return true; } /* Which output the overlay goes on. sway names its outputs by connector @@ -7616,7 +7605,7 @@ int main(int argc, char **argv) bool pending_reload = false; if (BACKDROP && SHOT_PATH) BACKDROP_A = 1.0f; /* a still has nothing to fade */ - present(); + if (!present()) dirty = true; sw_flush(); if (BACKDROP) { @@ -7649,7 +7638,7 @@ int main(int argc, char **argv) if (!running) break; } - sw_dispatch((BACKDROP || SERVING) ? 8 + sw_dispatch((BACKDROP || SERVING || dirty) ? 8 : (anim_running() || pending_reload) ? 8 : 60); while (running && sw_poll(&e)) handle_event(&e); @@ -7669,7 +7658,7 @@ int main(int argc, char **argv) dirty = true; } } - if (running && dirty) { present(); dirty = false; } + if (running && dirty && present()) dirty = false; } /* cleanup */