refactor: move backend options into backend_config section

- Add BackendConfig map[string]any to Config struct
- Deprecate top-level output_path (backward compatible via EffectiveBackendConfig())
- NewHyprland now accepts opts map[string]any instead of raw outputPath
- Factory signature unified to func(*slog.Logger, map[string]any) for all backends
- Update README with backend_config docs and fix Sway skeleton signature
- Update example.yaml to show backend_config instead of output_path
This commit is contained in:
Maksim Totmin
2026-06-22 20:49:02 +07:00
parent 15691c0918
commit cc1137608c
5 changed files with 74 additions and 13 deletions
+26
View File
@@ -52,9 +52,16 @@ type Config struct {
// OutputPath overrides the generated monitor config file path.
// Supports ~ for home directory expansion.
// Deprecated: use backend_config.output_path instead.
// Empty means the default: ~/.config/hypr/monitors.conf.
OutputPath string `yaml:"output_path"`
// BackendConfig holds backend-specific configuration options.
// Keys and values vary by the selected backend.
// Hyprland supports:
// output_path — path to the generated monitor config file
BackendConfig map[string]any `yaml:"backend_config"`
// External lists monitor identifiers that trigger docked mode.
// Each entry is a name (DP-1) or a desc: prefix (desc:Dell U2723QE).
External []string `yaml:"external"`
@@ -158,6 +165,25 @@ func (c *Config) validate() error {
return nil
}
// EffectiveBackendConfig merges top-level deprecated backend keys
// (OutputPath) into the BackendConfig map. backend_config values
// take priority over deprecated top-level keys.
//
// The caller receives a non-nil map even when no backend_config is
// set and no deprecated keys are present.
func (c *Config) EffectiveBackendConfig() map[string]any {
bc := c.BackendConfig
if bc == nil {
bc = make(map[string]any)
}
if c.OutputPath != "" {
if _, exists := bc["output_path"]; !exists {
bc["output_path"] = c.OutputPath
}
}
return bc
}
// countEnabled returns how many MonitorEntries are enabled.
func countEnabled(entries []MonitorEntry) int {
n := 0