// loadConfig reads all configuration files and loads them into the // a single config value. // // Most of this code is incredibly boring. func loadConfig() (*Configuration, error) { conf := newConfig() // globally defined in wingo.go type confFile struct { fpath string loadSection func(*Configuration, *wini.Data, string) } cfiles := []confFile{ { misc.ConfigFile("mouse.wini"), (*Configuration).loadMouseConfigSection, }, { misc.ConfigFile("key.wini"), (*Configuration).loadKeyConfigSection, }, { misc.ConfigFile("options.wini"), (*Configuration).loadOptionsConfigSection, }, // FYI hooks.wini is loaded in the hook package. } for _, cfile := range cfiles { cdata, err := wini.Parse(cfile.fpath) if err != nil { return nil, err } for _, section := range cdata.Sections() { cfile.loadSection(conf, cdata, section) } } return conf, nil }
// Initializes the hooks package with a Gribble execution environment and // a file path to a wini formatted hooks configuration file. If the // initialization fails, only a warning is logged since hooks are not // essential for Wingo to run. func Initialize(env *gribble.Environment, fpath string) { gribbleEnv = env cdata, err := wini.Parse(fpath) if err != nil { logger.Warning.Printf("Could not parse '%s': %s", fpath, err) return } for _, hookName := range cdata.Sections() { if err := readSection(cdata, hookName); err != nil { logger.Warning.Printf("Could not load hook '%s': %s", hookName, err) } } }
func loadTheme() (*ThemeConfig, error) { theme := newTheme() tdata, err := wini.Parse(misc.ConfigFile("theme.wini")) if err != nil { return nil, err } for _, section := range tdata.Sections() { switch section { case "misc": for _, key := range tdata.Keys(section) { loadMiscOption(theme, key) } case "full": for _, key := range tdata.Keys(section) { loadFullOption(theme, key) } case "borders": for _, key := range tdata.Keys(section) { loadBorderOption(theme, key) } case "slim": for _, key := range tdata.Keys(section) { loadSlimOption(theme, key) } case "prompt": for _, key := range tdata.Keys(section) { loadPromptOption(theme, key) } } } // re-color some images colorize := func(im *xgraphics.Image, clr render.Color) { var i int r, g, b := clr.RGB8() im.ForExp(func(x, y int) (uint8, uint8, uint8, uint8) { i = im.PixOffset(x, y) return r, g, b, im.Pix[i+3] }) } colorize(theme.Full.aCloseButton, theme.Full.aCloseColor) colorize(theme.Full.iCloseButton, theme.Full.iCloseColor) colorize(theme.Full.aMaximizeButton, theme.Full.aMaximizeColor) colorize(theme.Full.iMaximizeButton, theme.Full.iMaximizeColor) colorize(theme.Full.aMinimizeButton, theme.Full.aMinimizeColor) colorize(theme.Full.iMinimizeButton, theme.Full.iMinimizeColor) // Scale some images... theme.Full.aCloseButton = theme.Full.aCloseButton.Scale( theme.Full.titleSize, theme.Full.titleSize) theme.Full.iCloseButton = theme.Full.iCloseButton.Scale( theme.Full.titleSize, theme.Full.titleSize) theme.Full.aMaximizeButton = theme.Full.aMaximizeButton.Scale( theme.Full.titleSize, theme.Full.titleSize) theme.Full.iMaximizeButton = theme.Full.iMaximizeButton.Scale( theme.Full.titleSize, theme.Full.titleSize) theme.Full.aMinimizeButton = theme.Full.aMinimizeButton.Scale( theme.Full.titleSize, theme.Full.titleSize) theme.Full.iMinimizeButton = theme.Full.iMinimizeButton.Scale( theme.Full.titleSize, theme.Full.titleSize) return theme, nil }