aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-07-08 01:33:54 -0700
committerGravatar Tom Willemse2026-08-26 23:04:25 -0700
commit5aa8d484f27883778ccd105e034f8bcd8bfe48a2 (patch)
tree23bce257b1ca4107a382f1b3285df137d943ebf0
parentecb6ad32c50660be9fd7e571ca9ff62b923a089a (diff)
downloadnew-dotfiles-5aa8d484f27883778ccd105e034f8bcd8bfe48a2.tar.gz
new-dotfiles-5aa8d484f27883778ccd105e034f8bcd8bfe48a2.zip
hammerspoon: Apply layout changes automatically
Whenever one of the applications that I care about is opened, or when the screen size changes, apply the layout as specified.
-rw-r--r--hammerspoon/.hammerspoon/init.fnl61
1 files changed, 44 insertions, 17 deletions
diff --git a/hammerspoon/.hammerspoon/init.fnl b/hammerspoon/.hammerspoon/init.fnl
index fda2cb0..15640c5 100644
--- a/hammerspoon/.hammerspoon/init.fnl
+++ b/hammerspoon/.hammerspoon/init.fnl
@@ -7,25 +7,52 @@
(hs.hotkey.bind ["cmd" "alt" "ctrl"] "e" show-window-title)
(hs.hotkey.bind ["cmd" "shift"] "r" hs.reload)
-(let [my-screen (hs.screen.primaryScreen)
- screen-mode (: my-screen :currentMode)
- geom [(. screen-mode "w") (. screen-mode "h")]
- max (. hs "layout" "maximized")]
- (case geom
- [3440 1440] (hs.layout.apply
- [["Emacs" nil nil (. hs "layout" "left70") nil nil]
- ["Wezterm" nil nil (. hs "layout" "right30") nil nil]
- ["Glide" nil nil max nil nil]])
+;;; Layout -- Automatically put windows in their place.
- [5120 1440] (hs.layout.apply
- [["Glide" nil nil (. hs "layout" "left25") nil nil]
- ["Emacs" nil nil (hs.geometry.rect 0.25 0 0.5 1) nil nil]
- ["Wezterm" nil nil (. hs "layout" "right25") nil nil]])
+(fn apply-layout []
+ (let [my-screen (hs.screen.primaryScreen)
+ screen-mode (: my-screen :currentMode)
+ geom [(. screen-mode "w") (. screen-mode "h")]
+ max (. hs "layout" "maximized")]
+ (case geom
+ [3440 1440] (hs.layout.apply
+ [["Emacs" nil nil (. hs "layout" "left70") nil nil]
+ ["WezTerm" nil nil (. hs "layout" "right30") nil nil]
+ ["Glide" nil nil max nil nil]])
- _ (hs.layout.apply
- [["Glide" nil nil max nil nil]
- ["Emacs" nil nil max nil nil]
- ["Wezterm" nil nil max nil nil]])))
+ [5120 1440] (hs.layout.apply
+ [["Glide" nil nil (. hs "layout" "left25") nil nil]
+ ["Emacs" nil nil (hs.geometry.rect 0.25 0 0.5 1) nil nil]
+ ["WezTerm" nil nil (. hs "layout" "right25") nil nil]])
+
+ _ (hs.layout.apply
+ [["Glide" nil nil max nil nil]
+ ["Emacs" nil nil max nil nil]
+ ["WezTerm" nil nil max nil nil]]))))
+
+(fn make-application-watcher []
+ (fn match-application [name event-type application]
+ (print (.. "Application " name " had event " event-type "; compared to " (. hs :application :watcher :launched)
+ "; deciision " (tostring (and (= event-type (. hs :application :watcher :launched))
+ (or (= name "Emacs")
+ (= name "Wezterm")
+ (= name "Glide"))))))
+ (when (and (= event-type (. hs :application :watcher :launched))
+ (or (= name "Emacs")
+ (= name "WezTerm")
+ (= name "Glide")))
+ (apply-layout)))
+ (hs.application.watcher.new match-application))
+
+(fn make-screen-watcher []
+ (hs.screen.watcher.new apply-layout))
+
+(apply-layout)
+
+(let [watcher (make-application-watcher)]
+ (watcher:start))
+(let [watcher (make-screen-watcher)]
+ (watcher:start))
;;; Mouse -- Automatically set primary button based on mouse connected.