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 font sizing and so
build.sh | 12 ++++++++++++ commit_message.txt | 53 ++++++++++++----------------------------------------- sw_draw.h | 10 +++++++--- swov.c | 6 +++++- 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..206e5c5 --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -euo pipefail + +unzip $SHARED_CLAUDE/swall/shared.zip +unzip $SHARED_CLAUDE/swall/swov.zip +cp swov/* . +cp shared/* . +rm -rf swov shared/ +make clean +make all + diff --git a/commit_message.txt b/commit_message.txt index a6923be..b6fbb3e 100644 --- a/commit_message.txt +++ b/commit_message.txt @@ -1,44 +1,15 @@ -shared: a rasteriser fast enough for a full-screen overlay - -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: - - - 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. - -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. - -sw_keymap.h: a built-in US layout as a fallback. Any keycode the parsed -keymap has nothing for, and every key when the parse failed outright, comes -from a compact evdev table instead of returning nothing. A keymap this -parser cannot read now costs the user their layout, not their keyboard. - -sw_wl.h: SW_DEBUG_KEYS=1 in the environment narrates the keyboard to stderr -— the keymap's size and whether it parsed, keyboard enter and leave, and -every key with its code, keysym, modifiers and character. +sw_draw: size a font by its em square, not by ascent-to-descent + +sw_font(px) asked stb_truetype for ScaleForPixelHeight, which makes the +ascent-to-descent span px pixels tall. Every other toolkit — FreeType's +set_pixel_sizes, SDL_ttf's TTF_OpenFont, CSS — means the em square by a font +size. The gap is the font's line height over its em, 1.21 for Inter and +about 1.16 for DejaVu, so text came out roughly a fifth smaller than the +number asked for. It is ScaleForMappingEmToPixels now. + +Note for swbr, which still has its own copy of this code: rebuilding it +against this header makes its text that much larger, so its px values want +lowering by about a sixth to keep the bar looking the way it does. 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 cca1c2c..458796d 100644 --- a/sw_draw.h +++ b/sw_draw.h @@ -428,9 +428,13 @@ static Font *sw_font_get(int px, bool bold) f->px = px; f->bold = bold; f->synth = bold && !sw_font_bld.ok; - f->sc_pri = sw_font_pri.ok ? stbtt_ScaleForPixelHeight(&sw_font_pri.info, (float)px) : 1.0f; - f->sc_alt = sw_font_alt.ok ? stbtt_ScaleForPixelHeight(&sw_font_alt.info, (float)px) : 1.0f; - f->sc_bold = sw_font_bld.ok ? stbtt_ScaleForPixelHeight(&sw_font_bld.info, (float)px) : 1.0f; + /* px is the em square, which is what every other toolkit means by a font + size — FreeType's set_pixel_sizes, SDL_ttf's TTF_OpenFont, CSS. Scaling + by ascent-descent instead, as this did at first, draws a fifth smaller + than the number in the config asks for. */ + f->sc_pri = sw_font_pri.ok ? stbtt_ScaleForMappingEmToPixels(&sw_font_pri.info, (float)px) : 1.0f; + f->sc_alt = sw_font_alt.ok ? stbtt_ScaleForMappingEmToPixels(&sw_font_alt.info, (float)px) : 1.0f; + f->sc_bold = sw_font_bld.ok ? stbtt_ScaleForMappingEmToPixels(&sw_font_bld.info, (float)px) : 1.0f; { FontFile *mf = (bold && sw_font_bld.ok) ? &sw_font_bld : &sw_font_pri; float msc = (bold && sw_font_bld.ok) ? f->sc_bold : f->sc_pri; diff --git a/swov.c b/swov.c index 9c42481..5142d94 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.2" +#define SWOV_VERSION "1.3.3" #ifndef SWOV_BUILD /* set by the Makefile: md5 of this file */ #define SWOV_BUILD "unknown" #endif @@ -7587,6 +7587,10 @@ int main(int argc, char **argv) sel_active = BACKDROP ? false : (C.start_selection != 0); if (!BACKDROP && C.start_selection == 2 && NWS > 0) WSS[sel_ws].sel = ws_first_visible(&WSS[sel_ws]); + /* The numbers ws_slots asks for are there from the first frame, not only + after the first drag. Without this the grid opened with whatever sway + happened to have, which is not what `ws_slots=1-10` says. */ + ghosts_default(); layout(); apply_filter(); rebuild_chrome();