use KDL instead of TOML

This commit is contained in:
2024-12-18 04:35:15 +00:00
parent 986b1039ed
commit ce5bb9f4af
4 changed files with 146 additions and 119 deletions

View File

@@ -5,55 +5,35 @@
[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`).
Monitors and layouts are configured in a [KDL](https://kdl.dev) file
(`~/.config/swayout/config.kdl`).
Example `config.toml`:
Example `config.kdl`:
```toml
# This is my laptop's built-in screen.
[monitors.laptop]
make = "Unknown"
model = "0x403D"
serial = "0x00000000"
```kdl
// This is my laptop's built-in screen.
monitor "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"
// 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 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"
// 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.
[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 I have "left" and "right" hooked up, I want this layout.
layout "two4k" {
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.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 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 you pass a layout name (or monitor name, or output name) as a command line argument to `swayout`,