From db00b914fc408587cf9bde4431fe511d2cc02df8 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 12 Feb 2026 18:27:35 -0700 Subject: [PATCH] window focus and scrolling working gooood --- src/cg/10-os.cg | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/cg/10-os.cg b/src/cg/10-os.cg index bf39524..a61fe4e 100644 --- a/src/cg/10-os.cg +++ b/src/cg/10-os.cg @@ -37,6 +37,26 @@ closeWindowById = id \ i = index id (map (w \ w.id) osState.windows); closeWindowByIndex (unwrapOr 0 i); +scrollToWindow = index \ + windows = osState.windows; + widths = map (w \ w.width) windows; + gap = 1; + windowX = (sum (take index widths)) + (index * gap); + windowW = unwrapOr 400 (nth index widths); + scrollOffset = osState.wm.scrollOffset; + vw = viewport.width; + (windowX < scrollOffset + | True \ windowX + | False \ (windowX + windowW > scrollOffset + vw + | True \ windowX + windowW - vw + | False \ scrollOffset)); + +focusWindow = index \ + batch [ + osState.wm.focusedIndex := index, + osState.wm.scrollOffset := scrollToWindow index + ]; + onSelect = input \ result = eval input; result @@ -100,8 +120,8 @@ windowComponent = config \ ui.stateful { focusable = True, init = {}, update = state event \ event - | Focused \ { state = state, emit = [osState.wm.focusedIndex := config.index] } - | ChildFocused \ { state = state, emit = [osState.wm.focusedIndex := config.index] } + | Focused \ { state = state, emit = [focusWindow config.index] } + | ChildFocused \ { state = state, emit = [focusWindow config.index] } | _ \ { state = state, emit = [] }, view = state \ renderWindow config.window config.isActive }; @@ -120,20 +140,6 @@ renderWindows = _ \ } }; -scrollToWindow = index \ - windows = osState.windows; - widths = map (w \ w.width) windows; - gap = 1; - windowX = (sum (take index widths)) + (index * gap); - windowW = unwrapOr 400 (nth index widths); - scrollOffset = osState.wm.scrollOffset; - vw = viewport.width; - (windowX < scrollOffset - | True \ windowX - | False \ (windowX + windowW > scrollOffset + vw - | True \ windowX + windowW - vw - | False \ scrollOffset)); - os = ui.stateful { key = "os", autoFocus = True, @@ -146,18 +152,12 @@ os = ui.stateful { | Key { key = "ArrowLeft", meta = True } \ ( newIndex = max 0 (osState.wm.focusedIndex - 1); - { state = state, emit = [ - osState.wm.focusedIndex := newIndex, - osState.wm.scrollOffset := scrollToWindow newIndex - ] } + { state = state, emit = [focusWindow newIndex] } ) | Key { key = "ArrowRight", meta = True } \ ( newIndex = min (len osState.windows - 1) (osState.wm.focusedIndex + 1); - { state = state, emit = [ - osState.wm.focusedIndex := newIndex, - osState.wm.scrollOffset := scrollToWindow newIndex - ] } + { state = state, emit = [focusWindow newIndex] } ) | Key { key = "d", meta = True } \ { state = state, emit = [closeFocusedWindow 0] }