func (conf *Configuration) loadKeyConfigSection( cdata *wini.Data, section string) { for _, key := range cdata.Keys(section) { keyStr := key.Name() for _, cmd := range key.Strings() { if _, ok := conf.key[section]; !ok { conf.key[section] = make([]keyCommand, 0) } if err := gribbleEnv.Check(cmd); err != nil { logger.Warning.Printf( "Could not parse command '%s' because: %s", cmd, err) } else { down, justKeyStr := isDown(keyStr) kcmd := keyCommand{ cmdStr: cmd, cmdName: gribbleEnv.CommandName(cmd), down: down, keyStr: justKeyStr, } conf.key[section] = append(conf.key[section], kcmd) } } } }
func (conf *Configuration) loadOptionsConfigSection( cdata *wini.Data, section string) { for _, key := range cdata.Keys(section) { option := key.Name() switch option { case "workspaces": if workspaces, ok := getLastString(key); ok { conf.Workspaces = strings.Split(workspaces, " ") } case "default_layout": setString(key, &conf.DefaultLayout) case "focus_follows_mouse": setBool(key, &conf.Ffm) case "focus_follows_mouse_focus": setBool(key, &conf.FfmFocus) case "focus_follows_mouse_raise": setBool(key, &conf.FfmRaise) case "focus_follows_mouse_startup_focus": setBool(key, &conf.FfmStartupFocus) case "focus_follows_mouse_head": setBool(key, &conf.FfmHead) case "popup_time": setInt(key, &conf.PopupTime) case "show_popup_fyi": setBool(key, &conf.ShowFyi) case "show_popup_errors": setBool(key, &conf.ShowErrors) case "cancel": setString(key, &conf.CancelKey) case "confirm": setString(key, &conf.ConfirmKey) case "audio_play_cmd": setString(key, &conf.AudioProgram) } } }
// loadMouseConfigSection does two things: // 1) Inspects the section name to infer the identifier. In general, the // "mouse" prefix is removed, and whatever remains is the identifier. There // are two special cases: "MouseBorders*" turns into "borders_*" and // "MouseFull*" turns into "full_*". // 2) Constructs a "mouseCommand" for *every* value. // // The idents are used for attaching mouse commands to the corresponding // frames. (See the mouseCommand methods.) func (conf *Configuration) loadMouseConfigSection( cdata *wini.Data, section string) { ident := "" switch { case len(section) > 7 && section[:7] == "borders": ident = "borders_" + section[7:] case len(section) > 4 && section[:4] == "full": ident = "full_" + section[4:] default: ident = section } for _, key := range cdata.Keys(section) { mouseStr := key.Name() for _, cmd := range key.Strings() { if _, ok := conf.mouse[ident]; !ok { conf.mouse[ident] = make([]mouseCommand, 0) } if err := gribbleEnv.Check(cmd); err != nil { logger.Warning.Printf( "Could not parse command '%s' because: %s", cmd, err) } else { down, justMouseStr := isDown(mouseStr) mcmd := mouseCommand{ cmdStr: cmd, cmdName: gribbleEnv.CommandName(cmd), down: down, buttonStr: justMouseStr, } conf.mouse[ident] = append(conf.mouse[ident], mcmd) } } } }
// readSection loads a particular section from the configuration file into // the hook groups. One section may result in the same hook being added to // multiple groups. func readSection(cdata *wini.Data, section string) error { // First lets roll up the match conditions. match := cdata.GetKey(section, "match") if match == nil { return fmt.Errorf("Could not find 'match' in the '%s' hook.", section) } satisfies := make([]string, len(match.Strings())) copy(satisfies, match.Strings()) // Check each satisfies command to make sure it's a valid Gribble command. if cmd, err := checkCommands(satisfies); err != nil { return fmt.Errorf("The match command '%s' in the '%s' hook could "+ "not be parsed: %s", cmd, section, err) } // Now try to find whether it's a conjunction or not. conjunction := true conjunctionKey := cdata.GetKey(section, "conjunction") if conjunctionKey != nil { if vals, err := conjunctionKey.Bools(); err != nil { logger.Warning.Println(err) } else { conjunction = vals[0] } } // Now traverse all of the keys in the section. We'll skip "match" since // we've already grabbed the data. Any other key should correspond to // a hook group name. addedOne := false for _, key := range cdata.Keys(section) { groupName := Type(key.Name()) if groupName == "match" || groupName == "conjunction" { continue } if _, ok := groups[groupName]; !ok { return fmt.Errorf("Unrecognized hook group '%s' in the '%s' hook.", groupName, section) } consequences := make([]string, len(key.Strings())) copy(consequences, key.Strings()) // Check each consequent command to make sure it's valid. if cmd, err := checkCommands(consequences); err != nil { return fmt.Errorf("The '%s' command '%s' in the '%s' hook could "+ "not be parsed: %s", groupName, cmd, section, err) } hook := hook{ name: section, satisfies: satisfies, conjunction: conjunction, consequences: consequences, } groups[groupName] = append(groups[groupName], hook) addedOne = true } if !addedOne { return fmt.Errorf( "No hook groups were detected in the '%s' hook.", section) } return nil }