Ejemplo n.º 1
0
//DispatchKeys interface method
func (sw *Switcher) DispatchKeys(t *sdl.KeyDownEvent) int {
	app := sw.App
	T := app.Widget
	key := sdl.GetScancodeName(t.Keysym.Scancode)
	if (key == "N" && t.Keysym.Mod == 64) || key == "Down" {
		T.SetLine(sw.Selected, sw.getLine(sw.Selected, sw.Clients[sw.Selected], false))
		if sw.Selected < len(sw.Clients)-1 {
			sw.Selected++
		} else {
			sw.Selected = 0
		}
		T.SetLine(sw.Selected, sw.getLine(sw.Selected, sw.Clients[sw.Selected], true))
		return 1
	}
	if (key == "P" && t.Keysym.Mod == 64) || key == "Up" {
		T.SetLine(sw.Selected, sw.getLine(sw.Selected, sw.Clients[sw.Selected], false))
		if sw.Selected > 0 {
			sw.Selected--
		} else {
			sw.Selected = len(sw.Clients) - 1
		}
		T.SetLine(sw.Selected, sw.getLine(sw.Selected, sw.Clients[sw.Selected], true))
		return 1
	}
	if key == "X" && t.Keysym.Mod == 64 {
		wid := sw.Clients[sw.Selected].WID
		ewmh.CloseWindow(X, wid)
		sdl.Delay(500)
		sw.Clients = GetClients()
		sw.Draw()
		return 1
	}
	if (key == "J" && t.Keysym.Mod == 64) || key == "Return" {
		wid := sw.Clients[sw.Selected].WID
		ewmh.ActiveWindowReq(X, wid)
		return 0
	}
	if strings.Index("0123456789", key) > -1 {
		i, err := strconv.Atoi(key)
		if err == nil && len(sw.Clients) > i {
			sw.Selected = i
			if t.Keysym.Mod == 64 {
				wid := sw.Clients[sw.Selected].WID
				ewmh.ActiveWindowReq(X, wid)
				return 0
			}
			sw.Draw()
			return 1
		}
	}
	if t.Keysym.Sym == sdl.K_ESCAPE || t.Keysym.Sym == sdl.K_CAPSLOCK {
		return 0
	}
	return 1
}
Ejemplo n.º 2
0
//DispatchKeys interface method
func (U *Ultra) DispatchKeys(t *sdl.KeyDownEvent) int {
	app := U.App
	T := app.Widget
	fmt.Printf("[%d ms] Keyboard\ttype:%d\tname:%s\tmodifiers:%d\tstate:%d\trepeat:%d\tsym: %c\n",
		t.Timestamp, t.Type, sdl.GetScancodeName(t.Keysym.Scancode), t.Keysym.Mod, t.State, t.Repeat, t.Keysym.Sym)
	key := sdl.GetScancodeName(t.Keysym.Scancode)
	if t.Keysym.Sym == sdl.K_ESCAPE || t.Keysym.Sym == sdl.K_CAPSLOCK {
		return 0
	}
	if (key == "A" && t.Keysym.Mod == 64) || key == "Home" {
		T.MoveCursor(T.Cursor.Row, 0)
		return 1
	}
	if (key == "U" && t.Keysym.Mod == 64) || key == "End" {
		T.MoveCursor(T.Cursor.Row, len(T.Content[T.Cursor.Row].Content))
		return 1
	}
	if (key == "H" && t.Keysym.Mod == 64) || key == "Backspace" {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeString(1)
		U.update()
		return 1
	}
	if key == "Delete" {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeStringForward(1)
		U.update()
		return 1
	}
	if key == "C" && t.Keysym.Mod == 64 {
		line := T.Content[0]
		T.MoveCursor(0, 0)
		line.Content = ""
		T.ChangeLine(0, line)
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		return 1
	}
	if key == "V" && t.Keysym.Mod == 64 {
		s, _ := sdl.GetClipboardText()
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.addString(s)
		U.update()
		return 1
	}
	if key == "W" && t.Keysym.Mod == 64 {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		T.removeWord()
		U.update()
		return 1
	}
	if key == "Left" {
		T.MoveCursorLeft()
		// U.update()
		return 1
	}
	if key == "Right" {
		T.MoveCursorRight()
		// U.update()
		return 1
	}
	if key == "Down" || (key == "N" && t.Keysym.Mod == 64) {
		U.next()
		return 1
	}
	if key == "Up" || (key == "P" && t.Keysym.Mod == 64) {
		U.prev()
		return 1
	}
	if key == "Tab" {
		U.autocomplete()
		return 1
	}
	if (key == "J" && t.Keysym.Mod == 64) || t.Keysym.Sym == sdl.K_RETURN {
		ret := U.execInput(T.Content[0].Content)
		if ret != 0 {
			T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "red", "default"}})
			T.drawCursor()
		}
		return ret
	}
	if isASCII(string(t.Keysym.Sym)) && t.Keysym.Mod <= 1 {
		T.SetRules(0, []HighlightRule{HighlightRule{0, -1, "foreground", "default"}})
		char := string(t.Keysym.Sym)
		if t.Keysym.Mod == 1 {
			char = strings.ToUpper(char)
			sub, ok := symbols[char]
			if ok {
				char = sub
			}
		}
		T.addString(char)
		U.update()
		return 1
	}
	return 1
}