Files
swayout/README.md
2024-12-12 04:22:16 +00:00

83 lines
2.5 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 toml file
(`~/.config/swayout/config.toml`).
Example `config.toml`:
```toml
# This is my laptop's built-in screen.
[monitors.laptop]
make = "Unknown"
model = "0x403D"
serial = "0x00000000"
# I usually have it hooked up to this monitor, which is the top one on my desk.
[monitors.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 rotated 270 degrees.
[monitors.left]
make = "Goldstar Company Ltd"
model = "LG HDR 4K"
serial = "0x0000B9C0"
[monitors.right]
make = "Goldstar Company Ltd"
model = "LG HDR 4K"
serial = "0x0000B9BF"
# When I have "left" and "right" hooked up, I want this layout.
[layouts.two4k.left]
mode = "3840x2160"
scale = "1.5"
x = 0
y = 0
transform = "270"
[layouts.two4k.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.toml` for which the monitors are currently available. E.g.: `two4k`.
* All monitors defined in `config.toml` 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 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
```
## TODO
Things I might do someday:
### Automatic
Add a `automatic` option to layouts and an `--automatic` flag to `swayout`, and have it automatically enable the
first layout with `automatic=true` for which all outputs are available.
This could be run by `bindswitch lid:toggle exec swayout --automatic`.
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)?