Beispiel #1
0
func xgbGrab(shortcut string) bool {
	if len(shortcut) < 1 {
		return false
	}

	mod, codes, err := keybind.ParseString(X, shortcut)
	if err != nil {
		fmt.Printf("Parse shortcut '%s' failed: %v\n", shortcut, err)
		return false
	}

	for _, code := range codes {
		if err := keybind.GrabChecked(X, X.RootWin(),
			mod, code); err != nil {
			fmt.Printf("Grab '%s' failed: %v\n", shortcut, err)
			xgbUngrab(shortcut)
			return false
		}
	}

	return true
}
Beispiel #2
0
func grabKeyPress(wid xproto.Window, shortcut string) bool {
	if len(shortcut) < 1 {
		logger.Warning("grabKeyPress args error...")
		return false
	}

	shortcut = convertKeysym2Weird(shortcut)
	mod, keys, err := keybind.ParseString(X, shortcut)
	if err != nil {
		logger.Warning("In GrabKey Parse shortcut failed:", err)
		return false
	}

	for _, k := range keys {
		if err = keybind.GrabChecked(X, wid, mod, k); err != nil {
			logger.Warningf("Grab '%s' failed: %v", shortcut, err)
			ungrabKey(wid, shortcut)
			return false
		}
	}

	return true
}