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:
@@ -30,6 +30,7 @@ type hyprlandBackend struct {
|
||||
|
||||
// outputPath overrides the generated monitor config file path.
|
||||
// Empty means the default: ~/.config/hypr/monitors.conf.
|
||||
// Read from backend_config.output_path at construction time.
|
||||
outputPath string
|
||||
|
||||
// conn is the current socket2 connection; guarded by mu.
|
||||
@@ -40,9 +41,12 @@ type hyprlandBackend struct {
|
||||
// NewHyprland creates a Hyprland backend. The backend auto-detects the
|
||||
// Hyprland instance signature from the environment.
|
||||
//
|
||||
// outputPath overrides the generated monitor config file location.
|
||||
// When empty, defaults to ~/.config/hypr/monitors.conf.
|
||||
func NewHyprland(logger *slog.Logger, outputPath string) (Backend, error) {
|
||||
// opts carries backend-specific configuration from the config file's
|
||||
// backend_config section. Hyprland supports:
|
||||
//
|
||||
// output_path — path to the generated monitor config file
|
||||
// (default: ~/.config/hypr/monitors.conf)
|
||||
func NewHyprland(logger *slog.Logger, opts map[string]any) (Backend, error) {
|
||||
sig := os.Getenv("HYPRLAND_INSTANCE_SIGNATURE")
|
||||
if sig == "" {
|
||||
return nil, errors.New("HYPRLAND_INSTANCE_SIGNATURE is not set; is Hyprland running?")
|
||||
@@ -57,6 +61,13 @@ func NewHyprland(logger *slog.Logger, outputPath string) (Backend, error) {
|
||||
return nil, fmt.Errorf("socket2 not found at %s: %w", socketPath, err)
|
||||
}
|
||||
|
||||
var outputPath string
|
||||
if opts != nil {
|
||||
if v, ok := opts["output_path"]; ok {
|
||||
outputPath, _ = v.(string)
|
||||
}
|
||||
}
|
||||
|
||||
return &hyprlandBackend{logger: logger, outputPath: outputPath}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user