Skip to content

Commit

Permalink
WTF-718 Fixes missing grid issue when running CmdRunner (#740)
Browse files Browse the repository at this point in the history
Closes #718 and closes #730.

Signed-off-by: Chris Cummer <[email protected]>
  • Loading branch information
senorprogrammer authored Nov 9, 2019
1 parent 7c22408 commit a18fce8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions _sample_configs/dynamic_sizing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
wtf:
grid:
mods:
battery:
type: power
Expand Down
7 changes: 5 additions & 2 deletions modules/cmdrunner/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Settings struct {

// NewSettingsFromYAML loads the cmdrunner portion of the WTF config
func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig *config.Config) *Settings {

settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, moduleConfig, globalConfig),

Expand All @@ -37,7 +36,11 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig
maxLines: moduleConfig.UInt("maxLines", 256),
}

settings.width, settings.height = utils.CalculateDimensions(moduleConfig, globalConfig)
width, height, err := utils.CalculateDimensions(moduleConfig, globalConfig)
if err == nil {
settings.width = width
settings.height = height
}

return &settings
}
15 changes: 10 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,21 @@ func ParseJSON(obj interface{}, text io.Reader) error {
}

// CalculateDimensions reads the module dimensions from the module and global config. The border is already substracted.
func CalculateDimensions(moduleConfig, globalConfig *config.Config) (int, int) {
func CalculateDimensions(moduleConfig, globalConfig *config.Config) (int, int, error) {
grid, err := globalConfig.Get("wtf.grid")
if err != nil {
return 0, 0, err
}

cols := ToInts(grid.UList("wtf.grid.columns"))
rows := ToInts(grid.UList("wtf.grid.rows"))

// Read the source data from the config
left := moduleConfig.UInt("position.left", 0)
top := moduleConfig.UInt("position.top", 0)
width := moduleConfig.UInt("position.width", 0)
height := moduleConfig.UInt("position.height", 0)

cols := ToInts(globalConfig.UList("wtf.grid.columns"))
rows := ToInts(globalConfig.UList("wtf.grid.rows"))

// Make sure the values are in bounds
left = Clamp(left, 0, len(cols)-1)
top = Clamp(top, 0, len(rows)-1)
Expand All @@ -157,7 +162,7 @@ func CalculateDimensions(moduleConfig, globalConfig *config.Config) (int, int) {
w = MaxInt(w, 0)
h = MaxInt(h, 0)

return w, h
return w, h, nil
}

// MaxInt returns the larger of x or y
Expand Down

0 comments on commit a18fce8

Please sign in to comment.