diff --git a/examples/playground/example.scm b/examples/playground/example.scm index 7cdfa88..c34a329 100755 --- a/examples/playground/example.scm +++ b/examples/playground/example.scm @@ -1,4 +1,4 @@ -#!/usr/bin/guile +#!/usr/bin/env guile !# ;; assuming your are running from a path relative to swaypic & modules @@ -25,14 +25,15 @@ (ice-9 pretty-print) (swayipc)) +(SWAY-CONNECT-SOCKTES!) ;; get focused workspace from a list of workspaces (define (focused-workspace-name workspaces) (cond - ((null? workspaces) #f) - ((equal? #t (sway-workspace-focused (car workspaces))) - (sway-workspace-name (car workspaces))) - (else (focused-workspace-name (cdr workspaces))))) + ((null? workspaces) #f) + ((equal? #t (sway-workspace-focused (car workspaces))) + (sway-workspace-name (car workspaces))) + (else (focused-workspace-name (cdr workspaces))))) (format #t "output record from function #sway-get-workspaces:\n ~a\n" (sway-get-workspaces)) diff --git a/swayipc/connection.scm b/swayipc/connection.scm index 38b7e74..ecbf03d 100755 --- a/swayipc/connection.scm +++ b/swayipc/connection.scm @@ -38,6 +38,7 @@ SWAY-SOCKET-PATH SWAY-COMMAND-SOCKET + SWAY-CONNECT-SOCKETS! SWAY-LISTENER-SOCKET SWAY-LISTENER-THREAD SWAY-MSG-MAGIC @@ -96,12 +97,14 @@ ;; sway listen socket, this is used to listen to subscribed events ;; from sway via IPC. (define SWAY-LISTENER-SOCKET (socket AF_UNIX SOCK_STREAM 0)) -(connect SWAY-LISTENER-SOCKET (make-socket-address AF_UNIX SWAY-SOCKET-PATH)) ;; sway command socket, this is used to send commands and queries ;; to sway via IPC. (define SWAY-COMMAND-SOCKET (socket AF_UNIX SOCK_STREAM 0)) -(connect SWAY-COMMAND-SOCKET (make-socket-address AF_UNIX SWAY-SOCKET-PATH)) + +(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))) ;; Hashtable of mutexes for synchronization, keeps each socket separate. ;; This is important to lock sockets while reading/writing.