Skip to content

Commit

Permalink
feat(vrsjmp): Add window switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
leoshimo committed Jan 21, 2025
1 parent 2c40c47 commit 10eea5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
14 changes: 13 additions & 1 deletion scripts/os_window.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
# os_window.ll - OS Window Controls
#

(defn get_windows ()
"(get_windows) - Get all windows"
(def (:ok res) (exec "./scripts/yabai_window_shim.sh"))
(read res))

# TODO: Consider dynamic type check - e.g. `islist?` / `isstring?` to accept flexible window selector
(defn focus_window (window_id)
"(focus_window WINDOW_ID) - Focus window with given ID"
(exec "yabai" "-m" "window" (str window_id) "--focus"))

(defn yabai_grid (grid_str)
(try (exec "yabai" "--message" "window" "--grid" grid_str)))

Expand Down Expand Up @@ -62,5 +72,7 @@
window_bottom_left window_bottom_right
window_to_main window_to_aux
window_split
show_desktop))
show_desktop
get_windows
focus_window))

36 changes: 19 additions & 17 deletions scripts/vrsjmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,27 @@
(list 'open_url (format "https://www.amazon.com/s?k={}" query)))
)))

# TODO: Idea: Window Selector w/ `yabai -m query --windows` -> List of Windows -> Change Focus?
(defn window_items (query)
"Return item for window commands"
# Only match if query contains win
(if (not? (contains? query "win"))
'()
(list
(make_item "Window - Split" '(window_split))
(make_item "Window - Fullscreen" '(window_fullscreen))
(make_item "Window - Center" '(window_center))
(make_item "Window - Left" '(window_left))
(make_item "Window - Right" '(window_right))
(make_item "Window - Top Left" '(window_top_left))
(make_item "Window - Top Right" '(window_top_right))
(make_item "Window - Bottom Left" '(window_bottom_left))
(make_item "Window - Bottom Right" '(window_bottom_right))
(make_item "Window - Main Display" '(window_to_main))
(make_item "Window - Aux Display" '(window_to_aux))
)))
(if (not? (contains? query "w:"))
'()
(+
(map (get_windows)
(fn (w) (make_item (format "w: {} - {}" (get w :app) (get w :title))
(list 'focus_window (get w :id)))))
(list
(make_item "w: Split" '(window_split))
(make_item "w: Fullscreen" '(window_fullscreen))
(make_item "w: Center" '(window_center))
(make_item "w: Left" '(window_left))
(make_item "w: Right" '(window_right))
(make_item "w: Top Left" '(window_top_left))
(make_item "w: Top Right" '(window_top_right))
(make_item "w: Bottom Left" '(window_bottom_left))
(make_item "w: Bottom Right" '(window_bottom_right))
(make_item "w: Main Display" '(window_to_main))
(make_item "w: Aux Display" '(window_to_aux)))
)))

(defn scheduler_items (query)
"Return item for scheduler commands"
Expand Down
11 changes: 11 additions & 0 deletions scripts/yabai_window_shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# yabai_window_shim.sh - Shim for Yabai WM
#

# TODO: Investigate bugs in `read` that breaks escaped quotes in quotes occassionally
echo -n "("
yabai -m query --windows | \
jq '[.[] | select(."is-visible" == true)]' | \
jq -r '.[] | "(:id \(.id | @json) :app \(.app | @json) :title \(.title | @json))"' \
| sed -E 's/\\"//g'
echo -n ")"

0 comments on commit 10eea5a

Please sign in to comment.