Nimbin[12]?Sway / SwAS / commits / 5ccdee4

SwAS git · main

SwAS - app switcher for sway (SVG/PNG icons, themeable)

sway wayland c launcher · first commit 2026-08-08 · last commit 2026-11-10 (13 days ago) · synced 1 hour ago · upstream: github.com/nimbin2/SwAS

C 97.9% Markdown 1.4%
git clone https://git.christianimmanuel.de/sway/SwAS.gitwget https://git.christianimmanuel.de/sway/SwAS/archive/SwAS.tar.gz

Smaller default font

Christian Immanuel · 2026-11-10 17:11 · 5ccdee4633ad5a68a10e1af52b807a6793ff6730

 commit_message.txt | 18 ++++++++----------
 sw_draw.h          | 15 +++++++++++++++
 swas.c             |  7 ++++---
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/commit_message.txt b/commit_message.txt
index b6fbb3e..d201d33 100644
--- a/commit_message.txt
+++ b/commit_message.txt
@@ -1,15 +1,13 @@
-sw_draw: size a font by its em square, not by ascent-to-descent
+sw_draw: sw_font_h(), a font sized by its line height
 
-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.
+sw_font(px) means the em square, which is what a font size is everywhere
+else. Some callers do not have a font size, they have a box: the wheel in
+swas places a label at cy - height/2 and wants text that tall. For those,
+sw_font_h(px) returns the face whose line height is about px, found by
+measuring one and scaling.
 
-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.
+Both are now available and neither guesses on the other's behalf: ask for a
+size with sw_font, for a height with sw_font_h.
 
 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 458796d..395fd4d 100644
--- a/sw_draw.h
+++ b/sw_draw.h
@@ -96,6 +96,9 @@ Font *sw_font(int px);                       /* cached per pixel size */
    face by drawing each glyph twice, a third of a pixel apart. */
 void  sw_fonts_bold(const char *path);
 Font *sw_font_bold(int px);
+/* A font whose line height is about px tall, for callers that size text by
+   the box it has to fill rather than by the font size. */
+Font *sw_font_h(int px);
 float sw_text_width(Font *f, const char *s);
 
 void  sw_canvas_clip(Canvas *cv, int x0, int y0, int x1, int y1);
@@ -451,6 +454,18 @@ static Font *sw_font_get(int px, bool bold)
 Font *sw_font(int px)      { return sw_font_get(px, false); }
 Font *sw_font_bold(int px) { return sw_font_get(px, true); }
 
+Font *sw_font_h(int px)
+{
+    Font *f;
+    int want;
+    if (px < 4) px = 4;
+    f = sw_font_get(px, false);
+    if (f->lineh <= 0.0f) return f;
+    want = (int)((float)px * (float)f->px / f->lineh + 0.5f);
+    if (want < 4) want = 4;
+    return want == f->px ? f : sw_font_get(want, false);
+}
+
 static unsigned sw_utf8_next(const char **p)
 {
     const unsigned char *s = (const unsigned char *)*p;
diff --git a/swas.c b/swas.c
index 96ccbac..0831c89 100644
--- a/swas.c
+++ b/swas.c
@@ -57,7 +57,7 @@ typedef struct { float x,y,w,h; } Rect;
 
 #define APP_ID "swas"          /* wayland app_id / X11 WM_CLASS */
 
-#define SWAS_VERSION "1.3.3"
+#define SWAS_VERSION "1.3.4"
 #ifndef SWAS_BUILD             /* set by the Makefile: md5 of this file */
 #define SWAS_BUILD "unknown"
 #endif
@@ -360,13 +360,14 @@ static int font_load(UiFont*ft,const char*path,int px){
 static float text_width(UiFont*ft,float px_h,const char*s){
     (void)ft;
     int px=(int)(px_h+0.5f); if(px<4)px=4;
-    return sw_text_width(sw_font(px),s);
+    return sw_text_width(sw_font_h(px),s);
 }
 /* y is the top of the line, as it always was here; sw_text wants a baseline. */
 static void text_draw(Canvas*cv,UiFont*ft,float x,float y,float px_h,Col c,const char*s){
     (void)ft;
     int px=(int)(px_h+0.5f); if(px<4)px=4;
-    Font *f=sw_font(px);
+    /* the wheel sizes text by the height it has to fit, not by a font size */
+    Font *f=sw_font_h(px);
     sw_text(cv,f,x,y+f->ascent,c,s);
 }
 static void text_centered(Canvas*cv,UiFont*ft,float cx,float cy,float px_h,Col c,const char*s){