62 lines
2.7 KiB
Markdown
62 lines
2.7 KiB
Markdown
# swayout
|
|
|
|
`swayout` is a utility to configure [sway](https://swaywm.org/) outputs.
|
|
|
|
[kanshi](https://sr.ht/~emersion/kanshi/) and [way-displays](https://github.com/alex-courtis/way-displays) certainly
|
|
do a better job of this. I wrote this because I wanted a project to learn Rust.
|
|
|
|
Monitors and layouts are configured in a [KDL](https://kdl.dev) file
|
|
(`~/.config/swayout/config.kdl`).
|
|
|
|
Example `config.kdl`:
|
|
|
|
```kdl
|
|
// This is my laptop's built-in screen.
|
|
monitor "laptop" make="Unknown" model="0x403D" serial="0x00000000" lid="LID"
|
|
|
|
// I usually have it hooked up to this monitor, which is the top one on my desk.
|
|
monitor "top" make="Dell Inc." model="DELL U2415" serial="CFV9N99T0Y0U"
|
|
|
|
// Sometimes I hook it up to these monitors, which are left and right.
|
|
// The left is in portrait.
|
|
monitor "left" make="Goldstar Company Ltd" model="LG HDR 4K" serial="0x0000B9C0"
|
|
monitor "right" make="Goldstar Company Ltd" model="LG HDR 4K" serial="0x0000B9BF"
|
|
|
|
// When I have "left" and "right" hooked up, I want this layout.
|
|
layout "two4k" automatic=#true {
|
|
output "left" mode="3840x2160" scale="1.5" x=0 y=0 transform="270"
|
|
output "right" mode="3840x2160" scale="1.5" x=1440 y=1120 transform="normal"
|
|
}
|
|
```
|
|
|
|
When you run `swayout`, it prints all available layout names to standard output, one per line.
|
|
Printed layouts include:
|
|
|
|
* All layouts defined in `config.kdl` for which the monitors are currently available. E.g.: `two4k`.
|
|
* All monitors defined in `config.kdl` that are currently available. E.g.: `laptop`, `left`, `right`.
|
|
* All available outputs that are not matched by a configured monitor. E.g.: `HDMI-2`.
|
|
|
|
If a monitor has its `lid` property is set to the name of a directory in `/proc/acpi/button/lid/`, if the `state` file
|
|
in that directory indicates that the lid is closed, the monitor will not be considered available.
|
|
|
|
If you pass a layout name (or monitor name, or output name) as a command line argument to `swayout`,
|
|
it calls `swaymsg` to configure that layout.
|
|
If a monitor name or output name is passed, only that monitor or output is enabled, and the output's defaults are used.
|
|
|
|
This behavior is useful in conjunction with [tofi](https://github.com/philj56/tofi).
|
|
My sway configuration has:
|
|
|
|
```
|
|
set $select_layout swayout | tofi | xargs swayout
|
|
bindsym $mod+Shift+m exec $select_layout
|
|
```
|
|
|
|
If `swayout` is called with the `--automatic` switch, the first layout with `automatic=#true` for which all outputs
|
|
are available is enabled. If no automatic layouts are available, `swayout` exits with code 2.
|
|
|
|
This could be run by `bindswitch lid:toggle exec swayout --automatic`.
|
|
|
|
## TODO
|
|
|
|
How to call when an output is connected or disconnected?
|
|
Wayland events via [wayland_client](https://docs.rs/wayland-client/latest/wayland_client/index.html)? |