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 "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) } } }
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 *conf) 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) } // "keyStr" is actually made up of a key string // and a toggle of "down" or "up" corresponding to a key press // or a key release, respectively. Look for that. // If it isn't there, assume 'down' spacei := strings.Index(keyStr, " ") down := true if spacei > -1 { if keyStr[spacei+1:] == "up" { down = false } keyStr = keyStr[:spacei] } // 'cmd' might have space separated parameters cmdName, args := commandParse(cmd) kcmd := keyCommand{ cmd: cmdName, args: args, down: down, keyStr: keyStr, } conf.key[section] = append(conf.key[section], kcmd) } } }
// 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. func (conf *conf) 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) } // "mouseStr" is actually made up of a button string // and a toggle of "down" or "up" corresponding to a button press // or a button release, respectively. Look for that. // If it isn't there, assume 'down' spacei := strings.Index(mouseStr, " ") down := true buttonStr := mouseStr if spacei > -1 { buttonStr = mouseStr[:spacei] if mouseStr[spacei+1:] == "up" { down = false } } // 'cmd' can sometimes take parameters. For mouse commands, // only one such command does so: Resize. Check for that. // (The parameter is which way to resize. If it's absent, default // to "Infer".) var direction uint32 = ewmh.Infer if len(cmd) > 6 && strings.ToLower(cmd[:6]) == "resize" { spacei := strings.Index(cmd, " ") if spacei > -1 { direction = strToDirection(cmd[spacei+1:]) cmd = cmd[:spacei] } } mcmd := mouseCommand{ cmd: cmd, down: down, buttonStr: buttonStr, direction: direction, } conf.mouse[ident] = append(conf.mouse[ident], mcmd) } } }
func (conf *conf) 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 "always_floating": if alwaysFloating, ok := getLastString(key); ok { conf.alwaysFloating = strings.Split(alwaysFloating, " ") } case "focus_follows_mouse": setBool(key, &conf.ffm) case "cancel": setString(key, &conf.cancelKey) case "confirm": setString(key, &conf.confirmKey) } } }
// 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 }