diff --git a/README.org b/README.org index fb93e74..09a18e3 100644 --- a/README.org +++ b/README.org @@ -47,6 +47,13 @@ You can retrieve information about =Sway=, such as list of available =workspaces (focused-workspace-name (sway-get-workspaces))) #+end_src +Note: To send commands to Sway, you must connect to the Sway sockets. Without connecting to the socket your commands won't be sent to Sway. use the function =(SWAY-CONNECT-SOCKTES!)= immediately after the imports in your =init.scm= to ensure that the rest of the expressions can successfully send commands to Sway. + +#+begin_src scheme + ;; connect to sway sockets + (sway-connect-sockets!) +#+end_src + *** Assign Keybindings You can assign keybindings that execute Guile code! Obviously, running shell commands is straightforward since you're operating within Guile. Additionally, you have full access to Sway/i3 specific commands (refer to =swayipc/dispatcher.scm=). diff --git a/examples/layout-alternating/layout-alternating.scm b/examples/layout-alternating/layout-alternating.scm index d936c62..41acb7c 100755 --- a/examples/layout-alternating/layout-alternating.scm +++ b/examples/layout-alternating/layout-alternating.scm @@ -24,6 +24,7 @@ (ice-9 pretty-print) (swayipc)) +(sway-connect-sockets!) (layout-alternating-configure) (layout-alternating-init) diff --git a/examples/playground/example.scm b/examples/playground/example.scm index c34a329..daf1ec0 100755 --- a/examples/playground/example.scm +++ b/examples/playground/example.scm @@ -25,7 +25,7 @@ (ice-9 pretty-print) (swayipc)) -(SWAY-CONNECT-SOCKTES!) +(sway-connect-sockets!) ;; get focused workspace from a list of workspaces (define (focused-workspace-name workspaces) diff --git a/examples/stumpwm-inspired/init.scm b/examples/stumpwm-inspired/init.scm index 5c79cca..c32bf8d 100755 --- a/examples/stumpwm-inspired/init.scm +++ b/examples/stumpwm-inspired/init.scm @@ -26,16 +26,21 @@ (modules which-key) (swayipc)) +(sway-connect-sockets!) + ;; load look and feel +;; a separate scheme file for look and feel configuration (load "behavior.scm") ;; init keybindings +;; a separate scheme file for keybindings (using general) (load "keybindings.scm") (keybindings-init) ;; subscribe to all events (sway-subscribe-all) +;; configure workspace groups to sync groups (define OUTPUTS '("HDMI-A-2" "DP-1" "DP-2")) (define GROUPS '(("11-browser" "21-browser" "31-browser") @@ -51,6 +56,7 @@ (workspace-groups-configure #:groups GROUPS #:outputs OUTPUTS) (workspace-groups-init) +;; configure workspace grid to arrange workspaces in a matrix (define ROWS 3) (define COLUMNS 3) (define WORKSPACES (apply map list GROUPS)) @@ -58,11 +64,12 @@ (workspace-grid-configure #:rows ROWS #:columns COLUMNS #:workspaces WORKSPACES) (workspace-grid-init) +;; configure auto reload to automatically reload sway when a config file changes (auto-reload-configure #:directories `(,(string-append (getenv "HOME") "/.config/sway/"))) (auto-reload-init) -;; init which-key +;; configure which key to show available keybindings (which-key-configure #:delay-idle 1.2) (which-key-init) @@ -75,24 +82,28 @@ (system "pkill -f '.*rofi -e.*'")) (define (show-which-key submap bindings) - ;; show your which-key viewer (rofi, eww, etc.) (format #t "Displaying Submap ~a Bindings:\n" submap) (let ((message "")) + ;; printing to display (via repl/terminal) (for-each (lambda (ls) (let ((nmsg (format #f " - ~a -> ~a\n" (list-ref ls 1) (list-ref ls 3)))) (display nmsg) (set! message (string-append message nmsg)))) bindings) + + ;; showing in rofi (show-rofi-message message))) (define (hide-which-key submap) - ;; hide your which-key viewer (rofi, eww, etc.) (format #t "Hiding Submap Bindings:\n") + ;; hide your which-key viewer (rofi, eww, etc.) (hide-rofi-message)) +;; add the display and hide hook functions (add-hook! which-key-display-keybindings-hook show-which-key) (add-hook! which-key-hide-keybindings-hook hide-which-key) +;; start listening to sway events (sway-start-event-listener-thread) (thread-join! SWAY-LISTENER-THREAD) diff --git a/swayipc/connection.scm b/swayipc/connection.scm index ecbf03d..fc5218c 100755 --- a/swayipc/connection.scm +++ b/swayipc/connection.scm @@ -38,11 +38,11 @@ SWAY-SOCKET-PATH SWAY-COMMAND-SOCKET - SWAY-CONNECT-SOCKETS! SWAY-LISTENER-SOCKET SWAY-LISTENER-THREAD SWAY-MSG-MAGIC + sway-connect-sockets! sway-start-event-listener-thread sway-start-event-listener sway-data-received-hook @@ -102,7 +102,7 @@ ;; to sway via IPC. (define SWAY-COMMAND-SOCKET (socket AF_UNIX SOCK_STREAM 0)) -(define (SWAY-CONNECT-SOCKETS!) +(define (sway-connect-sockets!) (connect SWAY-LISTENER-SOCKET (make-socket-address AF_UNIX SWAY-SOCKET-PATH)) (connect SWAY-COMMAND-SOCKET (make-socket-address AF_UNIX SWAY-SOCKET-PATH)))