This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
/
keys.go
86 lines (71 loc) · 2.29 KB
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"github.com/BurntSushi/xgbutil/keybind"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/xevent"
"time"
)
const (
CMD_FREQ = time.Millisecond * 200
MOVE_STEP = 30
)
func (self *Window) bindKeys() {
// navigate
self.freqLimitedFunc(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
file := self.set.Next()
if file != nil {
self.currentFile = file
file.Draw()
}
}).Connect(X, self.Id, "Space", false)
self.freqLimitedFunc(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
file := self.set.Prev()
if file != nil {
self.currentFile = file
file.Draw()
}
}).Connect(X, self.Id, "c", false)
self.freqLimitedFunc(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
file := self.set.Rand()
if file != nil {
self.currentFile = file
file.Draw()
}
}).Connect(X, self.Id, "f", false)
// image operations
self.freqLimitedFunc(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.ZoomIn()
self.currentFile.Draw()
}).Connect(X, self.Id, "z", false)
self.freqLimitedFunc(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.ZoomOut()
self.currentFile.Draw()
}).Connect(X, self.Id, "x", false)
keybind.KeyPressFun(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.Move(0, MOVE_STEP)
self.currentFile.Draw()
}).Connect(X, self.Id, "w", false)
keybind.KeyPressFun(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.Move(0, -MOVE_STEP)
self.currentFile.Draw()
}).Connect(X, self.Id, "s", false)
keybind.KeyPressFun(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.Move(MOVE_STEP, 0)
self.currentFile.Draw()
}).Connect(X, self.Id, "a", false)
keybind.KeyPressFun(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
self.currentFile.Move(-MOVE_STEP, 0)
self.currentFile.Draw()
}).Connect(X, self.Id, "d", false)
}
func (self *Window) freqLimitedFunc(fun func(*xgbutil.XUtil, xevent.KeyPressEvent)) keybind.KeyPressFun {
return keybind.KeyPressFun(func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
if self.forbidCommand { return }
fun(X, ev)
self.forbidCommand = true
go func() {
<-time.After(CMD_FREQ)
self.forbidCommand = false
}()
})
}