...

Source file src/edge-infra.dev/pkg/sds/display/k8s/controllers/displayctl/internal/displayconfig/displayconfig.go

Documentation: edge-infra.dev/pkg/sds/display/k8s/controllers/displayctl/internal/displayconfig

     1  package displayconfig
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"edge-infra.dev/pkg/sds/display/displaymanager/manager"
     8  	"edge-infra.dev/pkg/sds/display/displaymanager/reader"
     9  	v2 "edge-infra.dev/pkg/sds/display/k8s/apis/v2"
    10  )
    11  
    12  var readerOpts = []reader.Option{
    13  	reader.WithDefaultLayout(),
    14  	reader.WithIgnoreRelativeInputDevices(),
    15  	reader.WithIgnoreSupportedResolutions(),
    16  }
    17  
    18  // Apply applies the custom display configuration defined by customDisplayConfig.
    19  //
    20  // The current display configuration is read from the node. This is merged with the default configuration,
    21  // then merged with the custom configuration. If the custom configuration is nil, the configuration
    22  // remains as default.
    23  //
    24  // The resulting DisplayConfig is applied to the node and returned.
    25  func Apply(ctx context.Context, customDisplayConfig *v2.DisplayConfig, displayManager manager.DisplayManager) (*v2.DisplayConfig, error) {
    26  	// wait for display manager to become ready before applying configuration
    27  	if err := displayManager.Wait(ctx); err != nil {
    28  		return nil, fmt.Errorf("display manager did not become ready: %w", err)
    29  	}
    30  
    31  	// read displays and input devices from node
    32  	displayConfig, inputDevices, err := displayManager.Read(ctx, readerOpts...)
    33  	if err != nil {
    34  		return nil, fmt.Errorf("unable to read display configuration from node: %w", err)
    35  	}
    36  
    37  	// apply the default configuration
    38  	displayConfig, err = displayConfig.GenerateDefaultDisplayConfig(v2.Defaults, inputDevices)
    39  	if err != nil {
    40  		return nil, fmt.Errorf("unable to apply defaults to node display configuration: %w", err)
    41  	}
    42  
    43  	// merge in custom DisplayConfig (does nothing when nil)
    44  	displayConfig, err = displayConfig.Merge(customDisplayConfig)
    45  	if err != nil {
    46  		return nil, fmt.Errorf("unable to merge node display configuration with NodeDisplayConfig: %w", err)
    47  	}
    48  
    49  	// apply the node display configuration
    50  	displayConfig, err = displayManager.Apply(ctx, displayConfig)
    51  	if err != nil {
    52  		return nil, fmt.Errorf("unable to apply node display configuration: %w", err)
    53  	}
    54  
    55  	return displayConfig, nil
    56  }
    57  

View as plain text