From 84d8ab6a3ad97697a717a770c42010e9ec9076e5 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 27 May 2026 14:36:57 -0500 Subject: feat(window): remember a side window's size across toggles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The F10 music playlist opened at a fixed fraction every time, so any manual resize was lost the moment it was toggled closed. Now the toggle captures the window's size on close and reopens at that height, for the rest of the session. The mechanism is generic, not music-specific. cj/window-size-fraction (geometry-lib) is the pure kernel: a clamped window/frame ratio. cj/side-window-capture-size and cj/side-window-display (toggle-lib) wrap it for any display-buffer-in-side-window consumer — height for top/bottom, width for left/right — storing the remembered fraction in a caller-supplied state var. It mirrors the direction-split toggle pattern the vterm dispatchers already use, but for atomic side windows that can't be split. music-config wires F10 to it: cj/music-playlist-window-height is the default, cj/--music-playlist-height holds the remembered value (in-memory, resets each session). 12 new tests across the two libs, Normal/Boundary/Error each covered. --- modules/cj-window-geometry-lib.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/cj-window-geometry-lib.el') diff --git a/modules/cj-window-geometry-lib.el b/modules/cj-window-geometry-lib.el index 1c1ab9fd..cc638f76 100644 --- a/modules/cj-window-geometry-lib.el +++ b/modules/cj-window-geometry-lib.el @@ -112,5 +112,22 @@ a fresh half." (not (window-in-direction (nth 1 perp) w)))) (window-list (or frame (selected-frame)) 'never))))) +(defun cj/window-size-fraction (window-size frame-size &optional min-frac max-frac) + "Return WINDOW-SIZE as a fraction of FRAME-SIZE, clamped to [MIN-FRAC, MAX-FRAC]. + +WINDOW-SIZE and FRAME-SIZE are line or column counts. MIN-FRAC and +MAX-FRAC default to 0.05 and 0.95: a side window pinned to either extreme +is almost certainly a mistake, and a 0.0 fraction makes +`display-buffer-in-side-window' unusable. Returns nil when FRAME-SIZE is +not a positive number, or WINDOW-SIZE is not a number, so a caller can +fall back to its own default instead of dividing by zero. + +This is the kernel for remembering a side window's user-resized size: capture +the fraction at toggle-off, replay it on the next toggle-on." + (when (and (numberp window-size) (numberp frame-size) (> frame-size 0)) + (let ((lo (or min-frac 0.05)) + (hi (or max-frac 0.95))) + (max lo (min hi (/ (float window-size) frame-size)))))) + (provide 'cj-window-geometry-lib) ;;; cj-window-geometry-lib.el ends here -- cgit v1.2.3