SwayOSD icon indicating copy to clipboard operation
SwayOSD copied to clipboard

Add config file and implement config file parsing

Open Ferdi265 opened this issue 1 year ago • 5 comments

This PR adds a TOML config file for the server, client, and libinput backend.

There are two config files

  • <SYSTEM_CONFIG_DIRS>/swayosd/backend.toml for the backend components that run with elevated privileges. This file should never be read from a user configuration folder.
  • <SYSTEM_CONFIG_DIRS>/swayosd/config.toml or <USER_CONFIG_DIR>/swayosd/config.toml for the server and client that run as the user. This file should be read from the user configuration folder if it exists and fall back to the system configuration directories otherwise

The config files are structured like this:

Backend configuration

[input]
# libinput backend configuration options (none so far)

# ... sections for future backend components that need elevated privileges ...
# [foo]
# bar = "baz"

Server and Client configuration

[server]
style = "/path/to/my/style.css"
top_margin = 0.85
# show_percentage = true (once #69 is merged)

[client]
# client configuration options (none so far)

Implementation Design

The parsing uses serde and toml to parse the TOML file directly into a struct.

Sections and options in the config file are optional, but misspelling them is an error.

Fixes #42.

Ferdi265 avatar Feb 18 '24 13:02 Ferdi265

Thanks a ton for working on this! I'll have time to review early next week. If I forget, don't be afraid to ping me here :)

ErikReider avatar Feb 21 '24 22:02 ErikReider

Any updates on this?

I understand if you don't have much time due to other commitments, but just wanted to check in.

Ferdi265 avatar Mar 13 '24 22:03 Ferdi265

Any updates on this?

I understand if you don't have much time due to other commitments, but just wanted to check in.

I'll get to this next week after my finals :)

ErikReider avatar Mar 13 '24 22:03 ErikReider

Good luck on your finals then!

Ferdi265 avatar Mar 13 '24 23:03 Ferdi265

(fixed rustfmt difference in latest push)

Ferdi265 avatar May 06 '24 17:05 Ferdi265

Hi, any updates on this PR?

CelticBoozer avatar Aug 25 '24 13:08 CelticBoozer

The next step would be to clean out some of the cmdline args and move them into the config

ErikReider avatar Aug 25 '24 14:08 ErikReider

The next step would be to clean out some of the cmdline args and move them into the config

--top-margin, --style, and max volume already have config settings, so those options could potentially be removed, but some people might have scripts that depend on them.

The "show percentage" PR could also remove its CLI option if you want to move away from settings via CLI options.

Ferdi265 avatar Aug 25 '24 15:08 Ferdi265