aboutsummaryrefslogtreecommitdiff
path: root/modules/cj-window-geometry-lib.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-27 14:36:57 -0500
committerCraig Jennings <c@cjennings.net>2026-05-27 14:36:57 -0500
commit84d8ab6a3ad97697a717a770c42010e9ec9076e5 (patch)
tree3abf00cdbce3e04b4afb22cb80b346b9e2eeeb0b /modules/cj-window-geometry-lib.el
parent8635f7d2221f92763247e2330070f1c0796d23d7 (diff)
downloaddotemacs-84d8ab6a3ad97697a717a770c42010e9ec9076e5.tar.gz
dotemacs-84d8ab6a3ad97697a717a770c42010e9ec9076e5.zip
feat(window): remember a side window's size across toggles
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.
Diffstat (limited to 'modules/cj-window-geometry-lib.el')
-rw-r--r--modules/cj-window-geometry-lib.el17
1 files changed, 17 insertions, 0 deletions
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