[hammerspoon] extract with-ax-hotfix to utils
change tqmuksskwwuuzokpsolwuznrtpupvwss
commit 5264e410ae472fff291d105fbd7d75b14026151e
author Alpha Chen <alpha@kejadlen.dev>
date
parent ryppkkql
diff --git a/.hammerspoon/little-ff.fnl b/.hammerspoon/little-ff.fnl
index f1b8e0b4..4861e56f 100644
--- a/.hammerspoon/little-ff.fnl
+++ b/.hammerspoon/little-ff.fnl
@@ -1,4 +1,6 @@
-(local log (hs.logger.new :init :info))
+(local {: with-ax-hotfix} (require :utils))
+
+(local log (hs.logger.new :little-ff :info))
 
 (local ff-bin
        "/Applications/Firefox\\ Developer\\ Edition.app/Contents/MacOS/firefox")
@@ -17,20 +19,12 @@
   (let [win (is-ff-focused)]
     (if win (cb win) (log:w "Firefox not focused"))))
 
-; https://github.com/Hammerspoon/hammerspoon/issues/3224#issuecomment-1294359070
-(λ with-ax-hotfix [app cb]
-  (let [ax-app (hs.axuielement.applicationElement app)
-        prev-val ax-app.AXEnhancedUserInterface]
-    (set ax-app.AXEnhancedUserInterface false)
-    (cb)
-    (set ax-app.AXEnhancedUserInterface prev-val)))
-
 (λ resize-little-ff []
   (check-ff (fn [win]
-              (with-ax-hotfix (win:application)
-                #(win:moveToUnit "[20,10,80,90]"))
-              ;; hide sidebar
-              (hs.eventtap.keyStroke [:ctrl] :z))))
+              (let [hide-sidebar #(hs.eventtap.keyStroke [:ctrl] :z)]
+                (with-ax-hotfix win
+                  #(win:moveToUnit "[20,10,80,90]"))
+                (hide-sidebar)))))
 
 (λ wait-for-little-ff [cb]
   (let [timer (hs.timer.waitUntil is-ff-focused cb 0.05)]
@@ -66,4 +60,4 @@
                                             ;; little ff window all that well
                                             )))))
 
-{: open : rehome : is-ff-focused : with-ax-hotfix}
+{: open : rehome : is-ff-focused}
diff --git a/.hammerspoon/utils.fnl b/.hammerspoon/utils.fnl
index 55602215..bb93fc2b 100644
--- a/.hammerspoon/utils.fnl
+++ b/.hammerspoon/utils.fnl
@@ -32,4 +32,13 @@
   (each [_ cmd (ipairs [...])]
     (execute cmd)))
 
-{: chomp : paste : replace-selection : run}
+; https://github.com/Hammerspoon/hammerspoon/issues/3224#issuecomment-1294359070
+(λ with-ax-hotfix [win cb]
+  (let [app (win:application)
+        ax-app (hs.axuielement.applicationElement app)
+        prev-val ax-app.AXEnhancedUserInterface]
+    (set ax-app.AXEnhancedUserInterface false)
+    (cb)
+    (set ax-app.AXEnhancedUserInterface prev-val)))
+
+{: chomp : paste : replace-selection : run : with-ax-hotfix}
diff --git a/.hammerspoon/wm.fnl b/.hammerspoon/wm.fnl
index 676539f6..24de463b 100644
--- a/.hammerspoon/wm.fnl
+++ b/.hammerspoon/wm.fnl
@@ -1,9 +1,9 @@
 ;; Ported from https://github.com/miromannino/miro-windows-manager/blob/master/MiroWindowsManager.spoon/init.lua#L95-L121
 
 (local {:fnutils {:indexOf index-of} : grid : logger : window} hs)
-(local {: is-ff-focused : with-ax-hotfix} (require :little-ff))
+(local {: with-ax-hotfix} (require :utils))
 
-(local log (logger.new :init :info))
+(local log (logger.new :wm :info))
 
 ;; fnlfmt: skip
 (local steps (let [full           {:x 0 :y 0 :w 8 :h 8}
@@ -24,9 +24,7 @@
                               (or -1)
                               (% (length steps))
                               (+ 1))
-          next-step (. steps next-step-index)
-          around (if (is-ff-focused) #(with-ax-hotfix (win:application) $1)
-                     #($1))]
-      (around #(grid.set win next-step screen)))))
+          next-step (. steps next-step-index)]
+      (with-ax-hotfix win #(grid.set win next-step screen)))))
 
 {: init : step}