-
Notifications
You must be signed in to change notification settings - Fork 5
Sway Info
Almarhoon Ibraheem edited this page Jan 28, 2025
·
5 revisions
The swayipc info
module provides various functions to retrieve information from Sway. This module utilizes the Sway IPC protocol to query Sway for different types of information such as workspaces, outputs, tree structure, and more.
Note: import ice-9
pretty-print
to print the records in a nice format.
All the examples below will use pretty-print
to enhance the readability.
Ensure that you import any needed package before issuing the below commands in REPL
or new file. Also, ensure that you open a sway socket connection before sending any queries or commands to sway by calling the function sway-connect-sockets!
immediately after the imports so the socket becomes available to the rest of expressions.
(use-modules (oop goops)
(srfi srfi-18)
(guile-swayer modules workspace-groups)
(guile-swayer modules workspace-grid)
(ice-9 pretty-print)
(guile-swayer swayipc connection)
(guile-swayer swayipc records)
(guile-swayer swayipc info)
(guile-swayer swayipc events)
(guile-swayer swayipc dispatcher))
(sway-connect-sockets!)
;; your code here
(let ((workspaces (sway-get-workspaces)))
(display "output record from function sway-get-workspaces:\n")
(pretty-print workspaces))
- Description: Retrieves the list of workspaces.
- Parameters: None
- Returns: A list of workspace records.
- Example
(let ((workspaces (sway-get-workspaces)))
(display "output record from function sway-get-workspaces:\n")
(pretty-print workspaces))
- Output
(#<<sway-workspace> num: 2 name: "2" visible: #f focused: #f urgent: #f rect: #<<sway-rect> x: 0 y: 0 width: 1920 height: 1080> output: "HDMI-A-2">
#<<sway-workspace> num: 11 name: "11-browser" visible: #f focused: #f urgent: #f rect: #<<sway-rect> x: 10 y: 10 width: 1900 height: 1060> output: "HDMI-A-2">
#<<sway-workspace> num: 14 name: "14-communication" visible: #f focused: #f urgent: #f rect: #<<sway-rect> x: 10 y: 10 width: 1900 height: 1060> output: "HDMI-A-2">
#<<sway-workspace> num: 39 name: "39-media" visible: #f focused: #f urgent: #f rect: #<<sway-rect> x: 3850 y: 10 width: 1900 height: 1060> output: "DP-2">)
- Description: Retrieves the list of outputs.
- Parameters: None
- Returns: A list of output records.
- Example
(let ((outputs (sway-get-outputs)))
(display "output record from function sway-get-outputs:\n")
(pretty-print outputs))
- Output
(#<<sway-output> name: "HDMI-A-1" make: "Acer Technologies" model: "ED242QR A" serial: "TBDAA0023900" active: #t primary: #f scale: 1 subpixel-hinting: "unknown" transform: "normal" current-workspace: "18-development" modes: () current-mode: #<<sway-mode> picture-aspect-ratio: "none" refresh: 120192 height: 1080 width: 1920>>
#<<sway-output> name: "HDMI-A-2" make: "Acer Technologies" model: "ED242QR A" serial: "TBDAA0023900" active: #t primary: #f scale: 1 subpixel-hinting: "unknown" transform: "normal" current-workspace: "19-development" modes: () current-mode: #<<sway-mode> picture-aspect-ratio: "none" refresh: 120192 height: 1080 width: 1920>>)
- Description: Retrieves a representation of the tree.
- Parameters: None
- Returns: A tree record.
- Example
(let ((tree (sway-get-tree)))
(display "output record from function sway-get-tree:\n")
(pretty-print tree))
- Output
#<<sway-tree> id: 1 name: "root" type: "root" border: "none" current-border-width: 0 layout: "splith" orientation: "horizontal" percent: null rect: #<<sway-rect> x: 0 y: 0 width: 5760 height: 1080> window-rect: #<<sway-rect> x: 0 y: 0 width: 0 height: 0> deco-rect: #<<sway-rect> x: 0 y: 0 width: 0 height: 0> geometry: #<<sway-rect> x: 0 y: 0 width: 0 height: 0> urgent: #f sticky: #f marks: #() focused: #f focus: #(574 575 7) nodes: () floating-nodes: () representation: #<unspecified> fullscreen-mode: 0 app-id: #<unspecified> pid: #<unspecified> visible: #<unspecified> shell: #<unspecified> inhibit-idle: #<unspecified> idle-inhibitors: #<unspecified> window: null window-properties: #<unspecified>>
- Description: Retrieves the currently set marks.
- Parameters: None
- Returns: A list of marks.
- Example
(let ((marks (sway-get-marks)))
(display "output record from function sway-get-marks:\n")
(pretty-print marks))
- Output [TODO]
- Description: Retrieves the list of configured bar IDs.
- Parameters: None
- Returns: A list of bar IDs.
- Example
(let ((bars (sway-get-bars)))
(display "output record from function sway-get-bars:\n")
(pretty-print bars))
- Output
("bar-0")
- Description: Retrieves the configuration associated with the specified bar ID.
-
Parameters:
- bar-id: The ID of the bar (string).
- Returns: A bar configuration record.
- Example
(let ((bar-config (sway-get-bar-config "bar-0")))
(display "output record from function sway-get-bar-config:\n")
(pretty-print bar-config))
- Output
#<<sway-bar-config> id: "bar-0" mode: "dock" position: "top" status-command: "i3blocks" font: "Iosevka SS14 12" workspace-buttons: #t workspace-min-width: 0 binding-mode-indicator: #<unspecified> verbose: #f colors: #<<sway-bar-color> background: "#323232ff" status-line: "#c6a0f6ff" separator: "#b8c0e0ff" focused-background: "#323232ff" focused-statusline: "#c6a0f6ff" focused-separator: "#b8c0e0ff" focused-workspace-text: "#c6a0f6ff" focused-workspace-background: "#323232ff" focused-workspace-border: "#323232ff" active-workspace-text: "#c6a0f6ff" active-workspace-background: "#323232ff" active-workspace-border: "#323232ff" inactive-workspace-text: "#cad3f5ff" inactive-workspace-background: "#32323200" inactive-workspace-border: "#323232ff" urgent-workspace-text: "#ed8796ff" urgent-workspace-background: "#323232ff" urgent-workspace-border: "#323232ff" binding-mode-text: "#ed8796ff" binding-mode-background: "#323232ff" binding-mode-border: "#323232ff"> gaps: #<<sway-bar-gap> top: 5 right: 5 bottom: 5 left: 5> bar-height: 0 status-padding: 1 status-edge-padding: 3>
- Description: Retrieves version information about the Sway process.
- Parameters: None
- Returns: A version record.
- Example
(let ((version (sway-get-version)))
(display "output record from function sway-get-version:\n")
(pretty-print version))
- Output
#<<sway-version> major: 1 minor: 9 patch: 0 human-readable: "1.9" loaded-config-file-name: "/home/ebeem/.config/sway/config">
- Description: Retrieves the list of binding modes currently configured.
- Parameters: None
- Returns: A list of binding modes.
- Example
(let ((binding-modes (sway-get-binding-modes)))
(display "output record from function sway-get-binding-modes:\n")
(pretty-print binding-modes))
- Output
("default"
"Leader"
"Rofi"
"Screenshot"
"DelayedScreenshot"
"Session"
"Window")
- Description: Retrieves the current Sway configuration.
- Parameters: None
- Returns: A configuration record.
- Example
(let ((config (sway-get-config)))
(display "output record from function sway-get-config:\n")
(pretty-print config))
- Output
#<<sway-config> config: "include /etc/sway/config.d/*\nexec \"waybar\"\nexec_always \"pkill -f '.*guile.*sway/init.scm'\"\nexec_always \"sleep 1 && ~/.config/sway/init.scm\"\n\n# # Logo key. Use Mod1 for Alt.\nset $mod Mod4\nset $term alacaritty\nbindsym $mod+t exec $term\n">
- Description: Returns the currently active binding mode.
- Parameters: None
- Returns: A binding state record.
- Example
(let ((binding-state (sway-get-binding-state)))
(display "output record from function sway-get-binding-state:\n")
(pretty-print binding-state))
- Output
#<<sway-binding-state> name: "default">
- Description: Retrieves a list of the input devices currently available.
- Parameters: None
- Returns: A list of input device records.
- Example
(let ((inputs (sway-get-inputs)))
(display "output record from function sway-get-inputs:\n")
(pretty-print inputs))
- Output
(#<<sway-input> identifier: "6940:6957:ckb1:_Corsair_Gaming_K95_RGB_PLATINUM_Keyboard_vM" name: "ckb1: Corsair Gaming K95 RGB PLATINUM Keyboard vM" vendor: 6940 product: 6957 type: "pointer" xkb-active-layout-name: #<unspecified> xkb-layout-names: #<unspecified> scroll-factor: 1 libinput: #<unspecified>>
#<<sway-input> identifier: "0:1:Power_Button" name: "Power Button" vendor: 0 product: 1 type: "keyboard" xkb-active-layout-name: "English (US)" xkb-layout-names: #("English (US)") scroll-factor: #<unspecified> libinput: #<unspecified>>
#<<sway-input> identifier: "0:1:Power_Button" name: "Power Button" vendor: 0 product: 1 type: "keyboard" xkb-active-layout-name: "English (US)" xkb-layout-names: #("English (US)") scroll-factor: #<unspecified> libinput: #<unspecified>>)
- Description: Retrieves a list of the seats currently configured.
- Parameters: None
- Returns: A list of seat records.
- Example
(let ((seats (sway-get-seats)))
(display "output record from function sway-get-seats:\n")
(pretty-print seats))
- Output
(#<<sway-seat> name: "seat0" capabilities: 3 focus: 513 devices: (#<<sway-input> identifier: "6940:6957:ckb1:_Corsair_Gaming_K95_RGB_PLATINUM_Keyboard_vM" name: "ckb1: Corsair Gaming K95 RGB PLATINUM Keyboard vM" vendor: 6940 product: 6957 type: "pointer" xkb-active-layout-name: #<unspecified> xkb-layout-names: #<unspecified> scroll-factor: 1 libinput: #<unspecified>>)>)