Ejemplo n.º 1
0
func loadConfig(fileName string) *Config {
	dat, err := wini.Parse(fileName)
	utils.FailMeMaybe(err)

	cfg := &Config{}

	// Main thing.

	loadInt(dat, "Main", "Size", &cfg.BarSize)
	loadInt(dat, "Main", "Width", &cfg.BarWidth)
	loadString(dat, "Main", "Position", "", &cfg.Position)

	// Clock.

	loadSection(dat, "Clock", true, &cfg.Clock)
	loadString(dat, "Clock", "Format", "2006-01-02 15:04:05", &cfg.ClockFormat)

	// Tracker

	loadSection(dat, "App Tracker", false, &cfg.Tracker)

	// Command Tray

	loadSection(dat, "CommandTray", true, &cfg.Command)
	loadString(dat, "CommandTray", "Accel", "", &cfg.CommandAccel)

	// Status Bar

	loadSection(dat, "StatusBar", false, &cfg.StatusBar)

	return cfg
}
Ejemplo n.º 2
0
// 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
}
Ejemplo n.º 3
0
// 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)
		}
	}
}
Ejemplo n.º 4
0
func loadThemeFile() (*wini.Data, error) {
	return wini.Parse("config/theme.wini")
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
func loadOptionsConfigFile() (*wini.Data, error) {
	return wini.Parse("config/options.wini")
}
Ejemplo n.º 7
0
func loadKeyConfigFile() (*wini.Data, error) {
	return wini.Parse("config/key.wini")
}
Ejemplo n.º 8
0
func loadMouseConfigFile() (*wini.Data, error) {
	return wini.Parse("config/mouse.wini")
}