The window: window-set-size!, set-fullscreen!, fullscreen? and monitor-size
For Harkfell's D37 (a small window at whole scales of its view, and fullscreen at the largest whole scale that fits). set-fullscreen! takes the monitor the window covers most of (on Wayland, which reports no window position, the primary monitor), at its own video mode, and comes back to the windowed size and position (the position where the platform reports one). monitor-size is a proper list: its tail is SIGIL_EMPTY (review: SIGIL_NIL is not the empty list; it made an improper list; the only list built in desktop.c).
Tests: test/test-window.sgl (all four answer #f without a window) and test/test-window-live.sgl (with a window, on a display: monitor-size a proper list of two positive integers, fullscreen at the monitor's size and back, window-set-size! taken; it checks nothing without a display). The live test went red on the SIGIL_NIL code (2 of 5) before the fix; 56/56 with a display, 52/52 without. desktop.c compiles clean with -Wall for aarch64-macos, x86_64-macos, x86_64-windows-gnu and x86_64-linux-gnu, and the windows-amd64 config builds.
CHANGELOG.md | 23 +++++++++++++++++++++++
src/c/desktop-internal.h | 8 ++++++++
src/c/desktop.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/sigil/desktop.sgl | 1 +
test/test-window-live.sgl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/test-window.sgl | 18 ++++++++++++++++++
6 files changed, 263 insertions(+)CHANGELOG.mdmodified
The format is based on [Keep a Changelog](https://keepachangelog.com/),and this project adheres to [Semantic Versioning](https://semver.org/).## [Unreleased]### Added- **The window: its size, fullscreen, the monitor.** Wanted by Harkfell (ruling D37, David, 2026-09-24: a Knytt-style small window at whole scales of the view, and fullscreen at the largest whole scale that fits). - `(window-set-size! width height)` asks for a window of that size in screen units (on a scaled Wayland output the framebuffer is that times the scale). While fullscreen it sets the size the window comes back to. A tiling window manager may not grant it: read `frame-width` and `frame-height` after. - `(set-fullscreen! on?)` makes the window take the whole of the monitor it covers most of, at that monitor's own video mode (no mode change), keeping its windowed size and position (the position where the platform reports one: Wayland does not, and the compositor places the window when it comes back); `#f` goes back to them. `(fullscreen?)` answers which. - `(monitor-size)` answers `(width height)` of that monitor's video mode. On Wayland, which reports no window position, "the monitor the window covers most of" is the primary monitor, for `set-fullscreen!` too. - Without a window, all four answer `#f` (`test/test-window.sgl`); with one, `test/test-window-live.sgl` drives them on a display (Xvfb).## [0.10.2] - 2026-09-21### Addedsrc/c/desktop-internal.hmodified
int win_width; int win_height; /* The windowed geometry kept while the window is fullscreen * (set-fullscreen!), in screen units, restored when it leaves. */ bool have_windowed; int windowed_x; int windowed_y; int windowed_w; int windowed_h; /* Frame timing */ double last_time; /* glfwGetTime() at the previous frame */ double frame_time; /* Seconds since last frame */src/c/desktop.cmodified
return SIGIL_NIL;}/* ============================================================ * THE WINDOW: SIZE, FULLSCREEN, THE MONITOR * ============================================================ *//* The monitor the window covers most of (a windowed window has no monitor * of its own in GLFW); the primary monitor when it covers none or where * the platform cannot say where a window is (Wayland reports no window * position). NULL without monitors. */static GLFWmonitor *window_monitor(GLFWwindow *window){ GLFWmonitor *own = glfwGetWindowMonitor(window); if (own) return own; int count = 0; GLFWmonitor **monitors = glfwGetMonitors(&count); if (!monitors || count == 0) return NULL; int wx = 0, wy = 0, ww = 0, wh = 0; if (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND) glfwGetWindowPos(window, &wx, &wy); glfwGetWindowSize(window, &ww, &wh); GLFWmonitor *best = glfwGetPrimaryMonitor(); long best_area = 0; for (int i = 0; i < count; i++) { int mx = 0, my = 0; glfwGetMonitorPos(monitors[i], &mx, &my); const GLFWvidmode *mode = glfwGetVideoMode(monitors[i]); if (!mode) continue; int x0 = wx > mx ? wx : mx; int y0 = wy > my ? wy : my; int x1 = (wx + ww) < (mx + mode->width) ? (wx + ww) : (mx + mode->width); int y1 = (wy + wh) < (my + mode->height) ? (wy + wh) : (my + mode->height); long area = (x1 > x0 && y1 > y0) ? (long)(x1 - x0) * (long)(y1 - y0) : 0; if (area > best_area) { best_area = area; best = monitors[i]; } } return best ? best : monitors[0];}/* * (window-set-size! width height) -> #t, or #f without a window (or for a * size that is not two positive integers) * * Asks for a window of width x height screen units (on a scaled Wayland * output the framebuffer is that times the scale). While fullscreen it * sets the size the window comes back to. A tiling window manager may not * grant it: read (frame-width) and (frame-height) after, never assume. */static Value native_window_set_size(SigilVM *vm, int argc, Value *args){ (void)vm; (void)argc; if (!g_desktop || !g_desktop->window) return SIGIL_FALSE; if (!sigil_is_fixnum(args[0]) || !sigil_is_fixnum(args[1])) return SIGIL_FALSE; int w = (int)sigil_as_fixnum(args[0]); int h = (int)sigil_as_fixnum(args[1]); if (w < 1 || h < 1) return SIGIL_FALSE; if (glfwGetWindowMonitor(g_desktop->window)) { g_desktop->windowed_w = w; g_desktop->windowed_h = h; return SIGIL_TRUE; } glfwSetWindowSize(g_desktop->window, w, h); return SIGIL_TRUE;}/* * (fullscreen?) -> #t while the window is fullscreen, else #f (and #f * without a window) */static Value native_fullscreen_p(SigilVM *vm, int argc, Value *args){ (void)vm; (void)argc; (void)args; if (!g_desktop || !g_desktop->window) return SIGIL_FALSE; return glfwGetWindowMonitor(g_desktop->window) ? SIGIL_TRUE : SIGIL_FALSE;}/* * (set-fullscreen! on?) -> #t once the window is as asked, #f without a * window or a monitor * * On: the window takes the whole of the monitor it covers most of, at * that monitor's own video mode (no mode change: the desktop's resolution * and refresh rate), and its windowed position and size are kept. Off: it * goes back to them. Asking for what already is does nothing. */static Value native_set_fullscreen(SigilVM *vm, int argc, Value *args){ (void)vm; (void)argc; if (!g_desktop || !g_desktop->window) return SIGIL_FALSE; GLFWwindow *window = g_desktop->window; bool on = !sigil_is_false(args[0]); bool is = glfwGetWindowMonitor(window) != NULL; if (on == is) return SIGIL_TRUE; if (on) { GLFWmonitor *monitor = window_monitor(window); const GLFWvidmode *mode = monitor ? glfwGetVideoMode(monitor) : NULL; if (!mode) return SIGIL_FALSE; /* Wayland does not say where a window is (GLFW reports it as an error); the * compositor places the window when it comes back */ if (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND) glfwGetWindowPos(window, &g_desktop->windowed_x, &g_desktop->windowed_y); glfwGetWindowSize(window, &g_desktop->windowed_w, &g_desktop->windowed_h); g_desktop->have_windowed = true; glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); } else { int w = g_desktop->have_windowed ? g_desktop->windowed_w : 800; int h = g_desktop->have_windowed ? g_desktop->windowed_h : 600; int x = g_desktop->have_windowed ? g_desktop->windowed_x : 64; int y = g_desktop->have_windowed ? g_desktop->windowed_y : 64; glfwSetWindowMonitor(window, NULL, x, y, w, h, 0); } return SIGIL_TRUE;}/* * (monitor-size) -> (width height), the video mode of the monitor the * window covers most of (on Wayland, which reports no window position, * the primary monitor), or #f without a window or a monitor. A proper * list: its tail is SIGIL_EMPTY, the empty list (SIGIL_NIL is not one). */static Value native_monitor_size(SigilVM *vm, int argc, Value *args){ (void)argc; (void)args; if (!g_desktop || !g_desktop->window) return SIGIL_FALSE; GLFWmonitor *monitor = window_monitor(g_desktop->window); const GLFWvidmode *mode = monitor ? glfwGetVideoMode(monitor) : NULL; if (!mode) return SIGIL_FALSE; return sigil_cons(vm, sigil_fixnum(mode->width), sigil_cons(vm, sigil_fixnum(mode->height), SIGIL_EMPTY));}/* ============================================================ * MODULE INITIALIZATION * ============================================================ */ sigil_module_register_native(vm, "request-quit", native_request_quit, SIGIL_ARITY_EXACT(0), "Request application quit"); /* The window: size, fullscreen, the monitor (0.11.0) */ sigil_module_register_native(vm, "window-set-size!", native_window_set_size, SIGIL_ARITY_EXACT(2), "Ask for a window of width x height screen units"); sigil_module_register_native(vm, "fullscreen?", native_fullscreen_p, SIGIL_ARITY_EXACT(0), "Is the window fullscreen"); sigil_module_register_native(vm, "set-fullscreen!", native_set_fullscreen, SIGIL_ARITY_EXACT(1), "Take the whole monitor, or go back to the window"); sigil_module_register_native(vm, "monitor-size", native_monitor_size, SIGIL_ARITY_EXACT(0), "The monitor the window is on: (width height)"); /* Export all */ sigil_module_export(vm, "app-run"); sigil_module_export(vm, "frame-width"); sigil_module_export(vm, "key-code"); sigil_module_export(vm, "quit-requested?"); sigil_module_export(vm, "request-quit"); sigil_module_export(vm, "window-set-size!"); sigil_module_export(vm, "fullscreen?"); sigil_module_export(vm, "set-fullscreen!"); sigil_module_export(vm, "monitor-size"); sigil_end_module(vm);}src/sigil/desktop.sglmodified
mouse-down? mouse-pressed? mouse-released? key-down? key-pressed? key-released? key-code quit-requested? request-quit window-set-size! fullscreen? set-fullscreen! monitor-size ;; Cooperative frame scheduling run-gametest/test-window-live.sgladded
;;; The window calls with a window open (0.11.0). Needs a display: run it;;; on a headless X server, never on someone's desktop, e.g.;;;;;; Xvfb :74 -screen 0 1700x900x24 +extension GLX -nolisten tcp &;;; env -u WAYLAND_DISPLAY DISPLAY=:74 sigil test test/test-window-live.sgl;;;;;; With no display (DISPLAY and WAYLAND_DISPLAY both unset) it says so and;;; checks nothing; the no-window answers are test-window.sgl's.;;;;;; On the first frame: monitor-size is a proper list of two positive;;; integers; set-fullscreen! #t makes fullscreen? #t and the framebuffer;;; the monitor's size (a frame later: the platform resizes between frames);;;; set-fullscreen! #f brings back the windowed size; window-set-size! asks;;; for a new size and gets it (no window manager on Xvfb to refuse).(import (sigil test) (sigil desktop) (sigil list) (sigil process))(define (display?) (or (getenv "DISPLAY") (getenv "WAYLAND_DISPLAY")))(define *seen* '()) ; (name . value) in the order seen(define (see! name v) (set! *seen* (append *seen* (list (cons name v)))))(define (seen name) (let ((e (assoc name *seen*))) (and e (cdr e))))(define *n* 0)(define (frame dt) (set! *n* (+ *n* 1)) (case *n* ((1) (see! "monitor-size" (monitor-size)) (see! "windowed" (list (frame-width) (frame-height))) (see! "fullscreen? before" (fullscreen?)) (see! "set-fullscreen! on" (set-fullscreen! #t))) ((4) (see! "fullscreen? on" (fullscreen?)) (see! "size on" (list (frame-width) (frame-height))) (see! "set-fullscreen! off" (set-fullscreen! #f))) ((7) (see! "fullscreen? off" (fullscreen?)) (see! "size off" (list (frame-width) (frame-height))) (see! "window-set-size!" (window-set-size! 400 176))) ((10) (see! "size set" (list (frame-width) (frame-height))) (request-quit)) (else #f)))(when (display?) (app-run (lambda () #f) frame (lambda () #f) "sigil-desktop window test" 640 360))(define (positive-ints? l n) (and (list? l) (= (length l) n) (every (lambda (x) (and (integer? x) (> x 0))) l)))(test-group "the window, with a window open" (if (not (display?)) (test "no display: nothing checked (see the header)" (assert-true #t)) (begin (test "monitor-size is a proper list of two positive integers" (assert-true (positive-ints? (seen "monitor-size") 2))) (test "the window opened at its asked size" (assert-equal (list 640 360) (seen "windowed"))) (test "set-fullscreen! #t: fullscreen, at the monitor's size" (assert-false (seen "fullscreen? before")) (assert-true (seen "set-fullscreen! on")) (assert-true (seen "fullscreen? on")) (assert-equal (seen "monitor-size") (seen "size on"))) (test "set-fullscreen! #f: back to the windowed size" (assert-true (seen "set-fullscreen! off")) (assert-false (seen "fullscreen? off")) (assert-equal (list 640 360) (seen "size off"))) (test "window-set-size! asks, and the window takes it" (assert-true (seen "window-set-size!")) (assert-equal (list 400 176) (seen "size set"))))))test/test-window.sgladded
;;; The window calls (0.11.0) answer safely before (and without) a window:;;; a program can call them from init, or from a headless test, and get #f;;; rather than a crash. With a window they are driven by hand (a Harkfell;;; native build: F11, a resize), since a test cannot open one here.(import (sigil test) (sigil desktop))(test-group "the window, with no window open" (test "fullscreen? is #f" (assert-false (fullscreen?))) (test "monitor-size is #f" (assert-false (monitor-size))) (test "window-set-size! is #f" (assert-false (window-set-size! 800 352))) (test "set-fullscreen! is #f, on or off" (assert-false (set-fullscreen! #t)) (assert-false (set-fullscreen! #f))))