From 4ff696d06c2be4201373872da55c2c2c8bcd05fb Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Sun, 16 Aug 2026 21:35:43 +0900 Subject: [PATCH] popup: follow GDK_SCALE on HiDPI The popup was 32-pixel rows whatever the display; next to 2x application text it was small. Its metrics now scale with the daemon's GDK_SCALE, the setting the applications use. --- README.md | 5 +++-- dat.h | 17 ++++++++++------- popup_layout.c | 2 ++ tests/font_test.c | 7 ++++--- tests/popup_test.c | 2 +- win.c | 4 ++++ 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7721450..3967467 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ sends `XNSpotLocation` gets the popup at that spot whatever its preedit style; otherwise the popup sits under the focus window, or under the client window when no focus window is set. -The popup is an X11 window, XIM is X11-only, and GTK popup placement converts -the GTK caret to X11 root coordinates. There is no native Wayland popup +The popup is an X11 window sized by `GDK_SCALE` on HiDPI displays, XIM is +X11-only, and GTK popup placement converts the GTK caret to X11 root +coordinates. There is no native Wayland popup surface or Wayland caret positioning. GTK and IBus clients can still use inline preedit where their display environment supports it. diff --git a/dat.h b/dat.h index 6a6085d..25b055e 100644 --- a/dat.h +++ b/dat.h @@ -18,12 +18,6 @@ enum LangEMOJI = 0x05, LangVI = 0x16, - Fontsz = 32, - PopupPad = 4, - PopupSep = 1, - PopupNumw = Fontsz, - PopupTextw = 12*Fontsz, - PopupBasew = 2*PopupPad + PopupNumw + PopupTextw, Maxrunes = 64, Maxutf = Maxrunes * UTFmax + 1, }; @@ -33,7 +27,6 @@ enum Maxclients = 64, Maxkouho = 128, Maxdisp = 9, - Imgh = 2*PopupPad + (Maxdisp + 2)*Fontsz + PopupSep, Colfg = 0x000000, Colbg = 0xffffff, @@ -42,6 +35,16 @@ enum Colselfg = 0xffffff, }; +/* Popup metrics in pixels; popupscale is GDK_SCALE, for HiDPI. */ +extern int popupscale; +#define Fontsz (32*popupscale) +#define PopupPad (4*popupscale) +#define PopupSep popupscale +#define PopupNumw Fontsz +#define PopupTextw (12*Fontsz) +#define PopupBasew (2*PopupPad + PopupNumw + PopupTextw) +#define Imgh (2*PopupPad + (Maxdisp + 2)*Fontsz + PopupSep) + typedef struct Str Str; struct Str { diff --git a/popup_layout.c b/popup_layout.c index 376fc41..4849c1a 100644 --- a/popup_layout.c +++ b/popup_layout.c @@ -5,6 +5,8 @@ enum { Asciitofull = 0xFEE0, }; +int popupscale = 1; + static void fill(u32int *buf, int n, u32int color) { diff --git a/tests/font_test.c b/tests/font_test.c index 73d982d..aaab744 100644 --- a/tests/font_test.c +++ b/tests/font_test.c @@ -5,12 +5,13 @@ enum { Guard = 8, - Testw = 6 * Fontsz, - Testh = 3 * Fontsz, - Testn = Testw * Testh, Rgbmask = 0xffffff, }; +#define Testw (6 * Fontsz) +#define Testh (3 * Fontsz) +#define Testn (Testw * Testh) + static u32int guardcolor = 0x5a5a5a5a; static void diff --git a/tests/popup_test.c b/tests/popup_test.c index a257163..1f3fc4e 100644 --- a/tests/popup_test.c +++ b/tests/popup_test.c @@ -40,7 +40,7 @@ checkpadding(struct ct *t, u32int *img, Popup *p) void popup_layout(struct ct *t) { - static int tinyheight[] = { + int tinyheight[] = { 1, PopupPad, 2*PopupPad + Fontsz - 1, }; static const struct { diff --git a/win.c b/win.c index f0c57cb..6e16c81 100644 --- a/win.c +++ b/win.c @@ -206,7 +206,11 @@ wininit(void) xcb_randr_query_version_cookie_t rc; xcb_randr_query_version_reply_t *rr; const xcb_query_extension_reply_t *rext; + char *scale; + scale = getenv("GDK_SCALE"); + if(scale != nil && atoi(scale) > 1) + popupscale = min(atoi(scale), 4); conn = xcb_connect(nil, &n); if(xcb_connection_has_error(conn)){ fprint(2, "strans: popup disabled: cannot connect to X display\n");