eufon.fnl (5894B)
1 ;; -*- mode: Fennel; 2 3 (local { : view } (require :fennel)) 4 5 (local texture (require :texture)) 6 (local matrix (require :matrix)) 7 (local socket-repl (require :socket-repl)) 8 9 (local app-state 10 { 11 :in-overview false 12 :focus-view nil 13 :views [] 14 }) 15 16 (let [repl-socket-name 17 (.. 18 (: (os.getenv "XDG_RUNTIME_DIR") :gsub "/$" "") 19 "/kiwmi-repl." 20 (os.getenv "WAYLAND_DISPLAY") 21 ".socket" 22 )] 23 (socket-repl.start repl-socket-name)) 24 25 (fn resize-wayland-backend [output] 26 (when (string.find (output:name) "^WL-") 27 (output:set_mode 360 720 0))) 28 29 (fn kill-window [] 30 (print "DIE") 31 true) 32 33 (fn launch [] 34 (print "WHOOSH") 35 true) 36 37 (fn eufon-path [f] 38 (.. (os.getenv "EUFON_PATH") "/" f)) 39 40 (fn show-overview [] 41 (let [facets 64 42 angle (/ (* 2 math.pi) facets) 43 scale 0.6 44 y-offset (+ (* 1 680) 45 (/ (* 360 facets) (* 2 math.pi))) 46 ] 47 (each [i view (ipairs app-state.views)] 48 (doto view 49 (: :set_matrix 50 (-> matrix.identity 51 (matrix.scale scale scale) 52 (matrix.translate (* 2 180) (+ y-offset)) 53 (matrix.rotate (/ (* (- i 2 54 ) angle) 1)) 55 (matrix.translate (* -2 180) (- y-offset)) 56 (matrix.translate 120 150) 57 )) 58 (: :show))))) 59 60 61 (fn hide-overview [] 62 (each [k view (pairs app-state.views)] 63 (view:set_matrix matrix.identity) 64 (if (= (view:id) (app-state.focus-view:id)) 65 (doto view 66 (: :show) 67 (: :focus)) 68 (view:hide)))) 69 70 (fn carousel [] 71 (let [was app-state.in-overview] 72 (if was 73 (hide-overview) 74 (show-overview)) 75 (: (kiwmi:active_output) :redraw) 76 (tset app-state :in-overview (not was)))) 77 78 (fn placements [output] 79 (let [(width height) (output:size) 80 bar-height (/ height 15)] 81 { 82 83 :application { 84 :x 0 85 :y 0 86 :w width 87 :h (- height (* bar-height 1.1)) 88 } 89 :bar { 90 :x 0 91 :y (- height (* bar-height 1.1)) 92 :w width 93 :h (* bar-height 1.1) 94 } 95 :kill { 96 :x (- (* width 0.25) (/ bar-height 2)) 97 :y (- height bar-height) 98 :w bar-height 99 :h bar-height 100 :on-press kill-window 101 } 102 :launch { 103 :x (- (* width 0.5) (/ bar-height 2)) 104 :y (- height bar-height) 105 :w bar-height 106 :h bar-height 107 :on-press launch 108 } 109 :overview { 110 :x (- (* width 0.75) (/ bar-height 2)) 111 :y (- height bar-height) 112 :w bar-height 113 :h bar-height 114 :on-press carousel 115 } 116 })) 117 118 (fn choose-view-at [x y] 119 (let [view (kiwmi:view_at x y)] 120 (tset app-state :focus-view view) 121 (tset app-state :in-overview false) 122 (hide-overview) 123 true)) 124 125 (let [cursor (kiwmi:cursor)] 126 (cursor:on "button_up" 127 (fn [button-id] 128 (when app-state.in-overview 129 (let [geom (placements (kiwmi:active_output)) 130 (x y) (cursor:pos)] 131 (if (< y geom.application.h) 132 (choose-view-at x y) 133 false)))))) 134 135 (kiwmi:on 136 "output" 137 (fn [output] 138 (resize-wayland-backend output) 139 (let [(width height) (output:size) 140 r (output:renderer) 141 kill (texture.from-file r (eufon-path "close-window.png")) 142 launch (texture.from-file r (eufon-path "launcher.png")) 143 overview (texture.from-file r (eufon-path "carousel.png"))] 144 (output:on "render" 145 (fn [{: output : renderer}] 146 (let [buttons (placements output)] 147 (renderer:draw_rect :#77000077 148 buttons.bar.x buttons.bar.y 149 buttons.bar.w buttons.bar.h) 150 (renderer:draw_texture 151 kill 152 matrix.identity 153 buttons.kill.x buttons.kill.y 154 0.7) 155 (renderer:draw_texture 156 launch 157 matrix.identity 158 buttons.launch.x buttons.launch.y 159 0.7) 160 (renderer:draw_texture 161 overview 162 matrix.identity 163 buttons.overview.x buttons.overview.y 164 0.7))))))) 165 166 167 (let [cursor (kiwmi:cursor)] 168 (cursor:on "button_down" 169 (fn [button] 170 (let [(x y) (cursor:pos)] 171 (each [name attribs (pairs (placements (kiwmi:active_output)))] 172 (if (and 173 (<= attribs.x x) 174 (< x (+ attribs.x attribs.w)) 175 (<= attribs.y y) 176 (< y (+ attribs.y attribs.h))) 177 (if attribs.on-press (attribs.on-press)))))))) 178 179 (kiwmi:on "view" 180 (fn [view] 181 (let [geom (placements (kiwmi:active_output))] 182 (view:resize geom.application.w geom.application.h) 183 (view:move geom.application.x geom.application.y)) 184 (view:focus) 185 (view:show) 186 (tset app-state :focus-view view) 187 (table.insert app-state.views view) 188 (view:on "request_move" #(view:imove)) 189 (view:on "request_resize" (fn [ev] (view:iresize ev.edges))))) 190 191 (kiwmi:spawn "swaybg -c '#ff00ff'") 192 (kiwmi:spawn "lua -l fennelrun modeline") 193 ;(kiwmi:spawn "lua -l fennelrun saturn") 194 (kiwmi:spawn "lua -l fennelrun crier") 195 (kiwmi:spawn "lua -l fennelrun just https://brvt.telent.net") 196 ;(kiwmi:spawn "foot") 197 198 ;; Local Variables: 199 ;; inferior-lisp-program: "eufonctl" 200 ;; End: