2024-06-15 09:57:11 +02:00
|
|
|
(define-module (swayipc info)
|
|
|
|
#:use-module (swayipc connection)
|
|
|
|
#:use-module (swayipc records)
|
|
|
|
#:use-module (oop goops)
|
2024-06-25 23:45:38 +02:00
|
|
|
#:use-module (sjson)
|
2024-06-15 09:57:11 +02:00
|
|
|
#:use-module (srfi srfi-9)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
|
|
|
#:export (sway-get-workspaces
|
|
|
|
sway-get-outputs
|
|
|
|
sway-get-tree
|
|
|
|
sway-get-marks
|
|
|
|
sway-get-bars
|
|
|
|
sway-get-bar-config
|
|
|
|
sway-get-version
|
|
|
|
sway-get-binding-modes
|
|
|
|
sway-get-config
|
|
|
|
sway-get-binding-state
|
|
|
|
sway-get-inputs
|
|
|
|
sway-get-seats))
|
|
|
|
|
|
|
|
(define (custom-exception-handler exc command-id payload)
|
2024-06-22 18:49:34 +02:00
|
|
|
(format #t "An error occurred: ~a \n" exc)
|
2024-06-18 18:05:39 +02:00
|
|
|
(format #t "command: ~a, payload: ~a\n" command-id payload))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-send-query message-id payload)
|
|
|
|
"returns the ipc response from sway after sending the message-id and payload"
|
|
|
|
(with-exception-handler
|
|
|
|
(lambda (exc)
|
2024-06-22 18:49:34 +02:00
|
|
|
(custom-exception-handler exc message-id payload))
|
2024-06-15 09:57:11 +02:00
|
|
|
(lambda () (begin
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-write-msg SWAY-COMMAND-SOCKET
|
2024-06-15 09:57:11 +02:00
|
|
|
message-id
|
|
|
|
payload)
|
2024-06-23 18:27:00 +02:00
|
|
|
(let* ((out (sway-read-msg SWAY-COMMAND-SOCKET)))
|
2024-06-15 09:57:11 +02:00
|
|
|
(list-ref out 1))))
|
|
|
|
#:unwind? #t))
|
|
|
|
|
|
|
|
(define (sway-get-workspaces)
|
|
|
|
"Retrieves the list of workspaces."
|
|
|
|
(map
|
|
|
|
(lambda (workspace)
|
|
|
|
(scm->sway-workspace workspace))
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-WORKSPACES "")))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-outputs)
|
|
|
|
"Retrieve the list of outputs."
|
|
|
|
(map
|
|
|
|
(lambda (output)
|
|
|
|
(scm->sway-output output))
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-OUTPUTS "")))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-tree)
|
|
|
|
"Retrieve a representation of the tree."
|
2024-06-23 18:27:00 +02:00
|
|
|
(json->sway-tree (sway-send-query SWAY-MSG-ID-GET-TREE "")))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-marks)
|
|
|
|
"Retrieve the currently set marks."
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-MARKS ""))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-bars)
|
|
|
|
"retrieves the list of configured bar IDs."
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-BAR-CONFIG ""))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-bar-config bar-id)
|
|
|
|
"retrieves the config associated with the specified by the bar ID."
|
2024-06-23 18:27:00 +02:00
|
|
|
(json->sway-bar-config (sway-send-query SWAY-MSG-ID-GET-BAR-CONFIG bar-id)))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-version)
|
|
|
|
"Retrieve version information about the sway process."
|
2024-06-23 18:27:00 +02:00
|
|
|
(json->sway-version (sway-send-query SWAY-MSG-ID-GET-VERSION "")))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-binding-modes)
|
|
|
|
"Retrieve the list of binding modes that currently configured."
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-BINDING-MODES ""))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-config)
|
|
|
|
"Retrieve the list of binding modes that currently configured."
|
2024-06-23 18:27:00 +02:00
|
|
|
(json->sway-config (sway-send-query SWAY-MSG-ID-GET-CONFIG "")))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-binding-state)
|
|
|
|
"Returns the currently active binding mode."
|
2024-06-23 18:27:00 +02:00
|
|
|
(json->sway-binding-state (sway-send-query SWAY-MSG-ID-GET-BINDING-STATE "")))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-inputs)
|
|
|
|
"Retrieve a list of the input devices currently available."
|
|
|
|
(map
|
|
|
|
(lambda (input)
|
|
|
|
(scm->sway-input input))
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-INPUTS "")))))
|
2024-06-15 09:57:11 +02:00
|
|
|
|
|
|
|
(define (sway-get-seats)
|
|
|
|
"Retrieve a list of the seats currently configured."
|
|
|
|
(map
|
|
|
|
(lambda (seat)
|
|
|
|
(scm->sway-seat seat))
|
|
|
|
(vector->list
|
|
|
|
(json-string->scm
|
2024-06-23 18:27:00 +02:00
|
|
|
(sway-send-query SWAY-MSG-ID-GET-SEATS "")))))
|