// ParseString takes a string of the format '[Mod[-Mod[...]]]-BUTTONNUMBER',
// i.e., 'Mod4-1', and returns a modifiers/button combination.
// "Mod" could also be one of {button1, button2, button3, button4, button5}.
// An error is returned if the string is malformed or if no BUTTONNUMBER
// could be found.
func ParseString(xu *xgbutil.XUtil, str string) (uint16, xproto.Button, error) {
	mods, button := uint16(0), xproto.Button(0)
	for _, part := range strings.Split(str, "-") {
		switch strings.ToLower(part) {
		case "shift":
			mods |= xproto.ModMaskShift
		case "lock":
			mods |= xproto.ModMaskLock
		case "control":
			mods |= xproto.ModMaskControl
		case "mod1":
			mods |= xproto.ModMask1
		case "mod2":
			mods |= xproto.ModMask2
		case "mod3":
			mods |= xproto.ModMask3
		case "mod4":
			mods |= xproto.ModMask4
		case "mod5":
			mods |= xproto.ModMask5
		case "button1":
			mods |= xproto.ButtonMask1
		case "button2":
			mods |= xproto.ButtonMask2
		case "button3":
			mods |= xproto.ButtonMask3
		case "button4":
			mods |= xproto.ButtonMask4
		case "button5":
			mods |= xproto.ButtonMask5
		case "any":
			mods |= xproto.ButtonMaskAny
		default: // a button!
			if button == 0 { // only accept the first button we see
				possible, err := strconv.ParseUint(part, 10, 8)
				if err == nil {
					button = xproto.Button(possible)
				} else {
					return 0, 0, fmt.Errorf("Could not convert '%s' to a "+
						"valid 8-bit integer.", part)
				}
			}
		}
	}

	if button == 0 {
		return 0, 0, fmt.Errorf("Could not find a valid button in the "+
			"string '%s'. Mouse binding failed.", str)
	}

	return mods, button, nil
}
Exemple #2
0
func ParseMouseInput(s string) (uint16, xproto.Button, error) {
	mods, button := uint16(0), xproto.Button(0)
	for _, part := range strings.Split(s, "+") {
		switch strings.ToLower(part) {
		case "shift":
			mods |= xproto.ModMaskShift
		case "lock":
			mods |= xproto.ModMaskLock
		case "control", "ctrl":
			mods |= xproto.ModMaskControl
		case "mod1", "alt":
			mods |= xproto.ModMask1
		case "mod2":
			mods |= xproto.ModMask2
		case "mod3":
			mods |= xproto.ModMask3
		case "mod4", "super":
			mods |= xproto.ModMask4
		case "mod5":
			mods |= xproto.ModMask5
		default:
			switch part {
			case "button1":
				button = xproto.Button(1)
			case "button2":
				button = xproto.Button(2)
			case "button3":
				button = xproto.Button(3)
			case "button4":
				button = xproto.Button(4)
			case "button5":
				button = xproto.Button(5)
			case "buttonany":
				button = xproto.ButtonIndexAny
			}
		}
	}
	if button == 0 {
		return 0, button, ButtonParseError(s)
	}
	return mods, button, nil
}
Exemple #3
0
	+'0': {doWindowN, 9},

	+xkF1:  {doWorkspaceN, 0},
	+xkF2:  {doWorkspaceN, 1},
	+xkF3:  {doWorkspaceN, 2},
	+xkF4:  {doWorkspaceN, 3},
	+xkF5:  {doWorkspaceN, 4},
	+xkF6:  {doWorkspaceN, 5},
	+xkF7:  {doWorkspaceN, 6},
	+xkF8:  {doWorkspaceN, 7},
	+xkF9:  {doWorkspaceN, 8},
	+xkF10: {doWorkspaceN, 9},
	+xkF11: {doWorkspaceN, 10},
	+xkF12: {doWorkspaceN, 11},

	+'i': {doSynthetic, xp.Button(4)},
	^'I': {doSynthetic, xp.Button(4)},
	+'m': {doSynthetic, xp.Button(5)},
	^'M': {doSynthetic, xp.Button(5)},
	+'y': {doSynthetic, xp.Keysym(xkHome)},
	^'Y': {doSynthetic, xp.Keysym(xkHome)},
	+'u': {doSynthetic, xp.Keysym(xkPageUp)},
	^'U': {doSynthetic, xp.Keysym(xkPageUp)},
	+'h': {doSynthetic, xp.Keysym(xkLeft)},
	^'H': {doSynthetic, xp.Keysym(xkLeft)},
	+'j': {doSynthetic, xp.Keysym(xkDown)},
	^'J': {doSynthetic, xp.Keysym(xkDown)},
	+'k': {doSynthetic, xp.Keysym(xkUp)},
	^'K': {doSynthetic, xp.Keysym(xkUp)},
	+'l': {doSynthetic, xp.Keysym(xkRight)},
	^'L': {doSynthetic, xp.Keysym(xkRight)},