Skip to content

Instantly share code, notes, and snippets.

@telent
Created April 14, 2022 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telent/a51f9cd3c413002a4f8aabac4cf88c3c to your computer and use it in GitHub Desktop.
Save telent/a51f9cd3c413002a4f8aabac4cf88c3c to your computer and use it in GitHub Desktop.
;; lib.fnl
;; surely there is a better way to do this
(fn next-key [tbl current-key]
(let [first (next tbl)
n
(accumulate [is-next nil
id view (pairs tbl)
:until (and is-next (not (= is-next current-key)))]
(if is-next
id
(= id current-key)
current-key
nil))]
(if (= n current-key)
first
n)))
;(assert (= (next-key { :a 5 :b 7 999 17 } :a) 999))
;(assert (= (next-key { :a 5 :b 7 999 17 } :b) :a))
;(assert (= (next-key { :a 5 :b 7 999 17 } 999) :b))
{ : next-key }
(local cursor (kiwmi:cursor))
(local {:view inspect : repl} (require :fennel))
(local { : next-key } (require :lib))
(cursor:on "motion"
#(match (cursor:view_at_pos) view (view:focus)))
(cursor:on "button_up" #(kiwmi:stop_interactive))
(local all-views {})
(fn focus-view [view]
(view:focus))
(fn view-attributes []
(collect
[k v
(pairs all-views)]
k [(v:id) (v:title)]))
(fn cycle-focus []
(let [next-view (next-key all-views (: (kiwmi:focused_view) :id))]
(: (. all-views next-view) :focus)))
(kiwmi:on "view"
(fn [view]
; (repl {:env {:aa 42 :kiwmi kiwmi :view view }})
(let [(w h) (: (kiwmi:active_output) :size)]
(view:resize w h))
(view:focus)
(view:show)
(tset all-views (view:id) view)
(print (inspect (view-attributes)))
(view:on "request_move" #(view:imove))
(view:on "request_resize" (fn [ev] (view:iresize ev.edges)))))
(local keybinds {
:Escape #(kiwmi:quit)
:Return #(kiwmi:spawn "foot")
:Tab cycle-focus
:w #(match (kiwmi:focused_view) view (view:close))
})
(kiwmi:on "keyboard"
(fn [keyboard]
(keyboard:on "key_down"
(fn [ev]
(if (. (ev.keyboard:modifiers) :alt)
(match (. keybinds ev.key)
bind (or (bind ev) true)
nil false)
false)))))
(kiwmi:spawn "swaybg -c '#ff00ff'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment