aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile2
-rw-r--r--hammerspoon/.hammerspoon/init.fnl70
-rw-r--r--hammerspoon/.hammerspoon/init.lua6
3 files changed, 77 insertions, 1 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 1840e34..7389aac 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -166,7 +166,7 @@ surfingkeys/dist/punt.js: surfingkeys/punt.ts surfingkeys/home.ts
## Diamond Interactive MacOS
-diamond-interactive: ssh-keygen brew-install wezterm-install glide-install git-install zsh-install _mbsetupuser-install change-macos-defaults
+diamond-interactive: ssh-keygen brew-install wezterm-install glide-install git-install zsh-install _mbsetupuser-install change-macos-defaults hammerspoon-install
ssh-keygen: $(HOME)/.ssh/id_ed25519.pub
diff --git a/hammerspoon/.hammerspoon/init.fnl b/hammerspoon/.hammerspoon/init.fnl
new file mode 100644
index 0000000..fda2cb0
--- /dev/null
+++ b/hammerspoon/.hammerspoon/init.fnl
@@ -0,0 +1,70 @@
+(fn show-window-title []
+ (let [window (hs.window.focusedWindow)]
+ (if (= window nil)
+ (hs.alert.show "no window")
+ (hs.alert.show (: (hs.window.focusedWindow) :title)))))
+
+(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]])
+
+ [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]])))
+
+;;; Mouse -- Automatically set primary button based on mouse connected.
+
+(fn set-mouse-buttons! [swap?]
+ (let [task (hs.task.new
+ "/usr/bin/defaults" nil []
+ ["-currentHost"
+ "write"
+ ".GlobalPreferences"
+ "com.apple.mouse.swapLeftRightButton"
+ "-bool"
+ (tostring swap?)])]
+ (task:start)
+ (task:waitUntilExit))
+ (print (.. "Changed mouse button to: " (if swap? "left" "right"))))
+
+(fn make-mouse-watcher []
+ (fn match-device [{:eventType event-type :productName name}]
+ (let [connected? (= event-type "added")]
+ (print (.. "Device " (if connected? "" "dis") "connected: " name))
+ (when (= name "USB Optical Mouse")
+ (set-mouse-buttons! connected?))))
+ (hs.usb.watcher.new match-device))
+
+(fn mouse-connected? []
+ (fn find-mouse-device [devices]
+ (if (= (next devices) nil)
+ false
+ (let [device (table.remove devices 1)]
+ (if (= (. device "productName") "USB Optical Mouse")
+ true
+ (tail! (find-mouse-device devices))))))
+ (find-mouse-device (hs.usb.attachedDevices)))
+
+(set-mouse-buttons! (mouse-connected?))
+
+(let [watcher (make-mouse-watcher)]
+ (watcher:start))
+
+;; Done
+
+(hs.alert.show "Loaded!" [] (hs.screen.primaryScreen) 0.5)
diff --git a/hammerspoon/.hammerspoon/init.lua b/hammerspoon/.hammerspoon/init.lua
new file mode 100644
index 0000000..b21f91a
--- /dev/null
+++ b/hammerspoon/.hammerspoon/init.lua
@@ -0,0 +1,6 @@
+if hs.fs.displayName("fennel.lua") == nil then
+ print("Downloading fennel")
+ os.execute("curl -o fennel.lua https://fennel-lang.org/downloads/fennel-1.6.1.lua")
+end
+
+require("fennel").install().dofile('init.fnl')