Commit15491641Recorded25 Sep 2026Repositorysigil-desktop
window-width and window-height: the window's size in screen units
Message
frame-width is framebuffer pixels; on a scaled output the framebuffer is the scale times the window, and window-set-size! takes screen units, so a program snapping its window to whole multiples of a view could not ask for the right size there (Harkfell's D37). Both read GLFW at the call and answer #f without a window. Tests: test-window.sgl (no window) and test-window-live.sgl (Xvfb: 640x360 at open, 400x176 after window-set-size!), the live test seen red with window-width answering the height. 59/59 with a display, 54/54 without. desktop.c compiles clean with -Wall for aarch64-macos, x86_64-macos, x86_64-windows-gnu and x86_64-linux-gnu; the windows-amd64 config builds.
Changed
CHANGELOG.md | 12 ++++++++++++
src/c/desktop.c | 34 ++++++++++++++++++++++++++++++++++
src/sigil/desktop.sgl | 1 +
test/test-window-live.sgl | 8 +++++++-
test/test-window.sgl | 5 ++++-
5 files changed, 58 insertions(+), 2 deletions(-)Diff
CHANGELOG.mdmodified
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
9
10
## [Unreleased] 11
+12
### Added+13
+14
- `(window-width)` and `(window-height)`: the window's size in screen+15
units, the units `window-set-size!` takes, read from GLFW at the call+16
(`#f` without a window). `frame-width` / `window-width` is the device+17
pixel ratio, so a program sizing its window to whole multiples of a+18
pixel-art view can ask for the right size on a scaled output (HiDPI+19
Wayland, a Retina Mac). Wanted by Harkfell's D37 snap, which without it+20
could not snap on a scaled output at all (David, 2026-09-25).+21
`test/test-window.sgl` and `test/test-window-live.sgl` cover both, the+22
live test seen red with a planted defect.+23
24
## [0.12.0] - 2026-09-25 25
26
### Addedsrc/c/desktop.cmodified
@@ -966,6 +966,34 @@ static Value native_monitor_size(SigilVM *vm, int argc, Value *args)
966
sigil_cons(vm, sigil_fixnum(mode->height), SIGIL_EMPTY)); 967
} 968
+969
/*+970
* (window-width) (window-height) -> the window's size in SCREEN UNITS, the+971
* units window-set-size! takes, or #f without a window+972
*+973
* (frame-width) and (frame-height) are framebuffer pixels; on a scaled+974
* output (a HiDPI Wayland, a Retina Mac) the framebuffer is the scale times+975
* the window, so frame-width / window-width is the device pixel ratio.+976
* Read from GLFW at the call, not from the size callback, so a size asked+977
* for with window-set-size! shows as soon as the platform has granted it.+978
*/+979
static Value native_window_width(SigilVM *vm, int argc, Value *args)+980
{+981
(void)vm; (void)argc; (void)args;+982
if (!g_desktop || !g_desktop->window) return SIGIL_FALSE;+983
int w = 0, h = 0;+984
glfwGetWindowSize(g_desktop->window, &w, &h);+985
return sigil_fixnum(w);+986
}+987
+988
static Value native_window_height(SigilVM *vm, int argc, Value *args)+989
{+990
(void)vm; (void)argc; (void)args;+991
if (!g_desktop || !g_desktop->window) return SIGIL_FALSE;+992
int w = 0, h = 0;+993
glfwGetWindowSize(g_desktop->window, &w, &h);+994
return sigil_fixnum(h);+995
}+996
997
/* ============================================================ 998
* MODULE INITIALIZATION 999
* ============================================================ */@@ -1039,6 +1067,10 @@ void sigil__init_sigil_desktop_module(SigilVM *vm)
1067
SIGIL_ARITY_EXACT(1), "Take the whole monitor, or go back to the window"); 1068
sigil_module_register_native(vm, "monitor-size", native_monitor_size, 1069
SIGIL_ARITY_EXACT(0), "The monitor the window is on: (width height)");+1070
sigil_module_register_native(vm, "window-width", native_window_width,+1071
SIGIL_ARITY_EXACT(0), "The window's width in screen units");+1072
sigil_module_register_native(vm, "window-height", native_window_height,+1073
SIGIL_ARITY_EXACT(0), "The window's height in screen units"); 1074
1075
/* Export all */ 1076
sigil_module_export(vm, "app-run");@@ -1065,6 +1097,8 @@ void sigil__init_sigil_desktop_module(SigilVM *vm)
1097
sigil_module_export(vm, "fullscreen?"); 1098
sigil_module_export(vm, "set-fullscreen!"); 1099
sigil_module_export(vm, "monitor-size");+1100
sigil_module_export(vm, "window-width");+1101
sigil_module_export(vm, "window-height"); 1102
1103
sigil_end_module(vm); 1104
}src/sigil/desktop.sglmodified
@@ -22,6 +22,7 @@
22
key-down? key-pressed? key-released? key-code 23
quit-requested? request-quit 24
window-set-size! fullscreen? set-fullscreen! monitor-size+25
window-width window-height 26
27
;; Cooperative frame scheduling 28
run-gametest/test-window-live.sglmodified
@@ -30,6 +30,7 @@
30
(set! *n* (+ *n* 1)) 31
(case *n* 32
((1) (see! "monitor-size" (monitor-size))+33
(see! "window size" (list (window-width) (window-height))) 34
(see! "windowed" (list (frame-width) (frame-height))) 35
(see! "fullscreen? before" (fullscreen?)) 36
(see! "set-fullscreen! on" (set-fullscreen! #t)))@@ -40,6 +41,7 @@
41
(see! "size off" (list (frame-width) (frame-height))) 42
(see! "window-set-size!" (window-set-size! 400 176))) 43
((10) (see! "size set" (list (frame-width) (frame-height)))+44
(see! "window size set" (list (window-width) (window-height))) 45
(request-quit)) 46
(else #f))) 47
@@ -69,4 +71,8 @@
71
(assert-equal (list 640 360) (seen "size off"))) 72
(test "window-set-size! asks, and the window takes it" 73
(assert-true (seen "window-set-size!"))−72
(assert-equal (list 400 176) (seen "size set"))))))+74
(assert-equal (list 400 176) (seen "size set")))+75
;; Xvfb has no output scale: screen units are framebuffer pixels+76
(test "window-width and window-height: the window in screen units"+77
(assert-equal (list 640 360) (seen "window size"))+78
(assert-equal (list 400 176) (seen "window size set"))))))test/test-window.sglmodified
@@ -15,4 +15,7 @@
15
(assert-false (window-set-size! 800 352))) 16
(test "set-fullscreen! is #f, on or off" 17
(assert-false (set-fullscreen! #t))−18
(assert-false (set-fullscreen! #f))))+18
(assert-false (set-fullscreen! #f)))+19
(test "window-width and window-height are #f"+20
(assert-false (window-width))+21
(assert-false (window-height))))