aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-10-01 16:11:28 -0700
committerGravatar Tom Willemse2026-10-01 16:11:28 -0700
commita382920bbc6bdacf82103aeaba21e432dc888c84 (patch)
tree9b13f3ed14ebad1ceb2cfde5153ec165879114f8
parent6354c40ae3604876ca731dab6040f208837499bf (diff)
downloadnew-dotfiles-a382920bbc6bdacf82103aeaba21e432dc888c84.tar.gz
new-dotfiles-a382920bbc6bdacf82103aeaba21e432dc888c84.zip
Sway: Add run-or-raise command for switching applications
-rw-r--r--oni/home/config/data.scm4
-rw-r--r--sway/.config/sway/init.scm93
2 files changed, 91 insertions, 6 deletions
diff --git a/oni/home/config/data.scm b/oni/home/config/data.scm
index e7e16d3..38e3cff 100644
--- a/oni/home/config/data.scm
+++ b/oni/home/config/data.scm
@@ -65,7 +65,9 @@
"emacs-posframe"
;; Includes tree-sitter-tsx
- "tree-sitter-typescript"))
+ "tree-sitter-typescript"
+
+ "guile-srfi-180"))
(list
pick-random-wallpaper
emacs-org-contacts
diff --git a/sway/.config/sway/init.scm b/sway/.config/sway/init.scm
index 3fa67ec..a4cb3e0 100644
--- a/sway/.config/sway/init.scm
+++ b/sway/.config/sway/init.scm
@@ -1,18 +1,101 @@
(use-modules (guile-swayer)
- (srfi srfi-18))
+ ;; Lists
+ (srfi srfi-1)
+ ;; Vectors
+ (srfi srfi-43)
+ ;; Json
+ (srfi srfi-180)
+ ;; Multithreading
+ (srfi srfi-18)
+ (ice-9 textual-ports))
(system (format #f "pgrep -f '.*guile.*sway/init.scm' | grep -v ~a | while read mypid; do kill $mypid; done" (getpid)))
+(define (vector-filter pred vec)
+ (vector-fold
+ (lambda (idx state item)
+ (if (pred idx item)
+ (cons item state)
+ state))
+ '()
+ vec))
+
+(define (parse-window-information raw)
+ (vector-fold
+ (lambda (_ state n)
+ (vector-append state n))
+ #()
+ (vector-fold
+ (lambda (_ state n)
+ (vector-append state n))
+ #()
+ (vector-map
+ (lambda (_ n)
+ (vector-map
+ (lambda (_ n)
+ (vector-map
+ (lambda (_ n) (cons* (cdr (assoc 'app_id n))
+ (cdr (assoc 'id n))
+ (cdr (assoc 'focused n))))
+ (cdr (assoc 'nodes n))))
+ (cdr (assoc 'nodes n))))
+ raw))))
+
+(define (sway-get-tree)
+ (let ((capture (pipe)))
+ (spawn "swaymsg" '("swaybg" "-t" "get_tree") #:output (cdr capture))
+ (close-port (cdr capture))
+ (cdr (assoc 'nodes (json-read (car capture))))))
+
+(define (sway-focus id)
+ (system* "swaymsg" (format #f "[con_id=~d]" id) "focus"))
+
+(define (filter-windows-by-app app-id windows)
+ (map cdr (vector-filter
+ (lambda (_ n)
+ (string= (car n) app-id))
+ windows)))
+
+(define (next-window-id windows)
+ (car (let ((found (drop-while (lambda (window) (not (cdr window))) windows)))
+ (if (or (null? found)
+ (null? (cdr found)))
+ (car windows)
+ (cadr found)))))
+
+;; app_id emacs
+;; app_id glide-glide
+;; app_id org.wezfurlong.wezterm
+
+(define (run-or-raise app-id command)
+ (let* ((tree (sway-get-tree))
+ (windows (filter-windows-by-app app-id (parse-window-information tree))))
+ (if (null? windows)
+ (spawn "sh" `("sh" "-c" ,command))
+ (sway-focus (next-window-id windows)))))
+
(sway-connect-sockets!)
+(kbd-init)
+
+(general-configure #:keybinding-translator kbd-translate)
+(general-init)
+
+(general-define-keys
+ `("s-e" (run-or-raise "emacs" "emacsclient --create-frame --no-wait"))
+ `("s-t" (run-or-raise "org.wezfurlong.wezterm" "wezterm"))
+ `("s-b" (run-or-raise "glide-glide" "~/Downloads/glide/glide")))
+
+(sway-subscribe-all)
+
(sway-bindsym "Mod4+d" "exec wmenu-run")
(sway-bindsym "Mod4+Shift+c" "reload")
(sway-bindsym "Mod4+shift+q" "kill")
-(sway-bindsym "Mod4+f" "focus right")
-(sway-bindsym "Mod4+b" "focus left")
-(sway-bindsym "Mod4+p" "focus up")
-(sway-bindsym "Mod4+n" "focus down")
+;; (sway-bindsym "Mod4+f" "focus right")
+;; (sway-bindsym "Mod4+b" "focus left")
+;; (sway-bindsym "Mod4+p" "focus up")
+;; (sway-bindsym "Mod4+n" "focus down")
(sway-bindsym "Mod4+1" "workspace number 1")
(sway-bindsym "Mod4+2" "workspace number 2")