-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinput.go
136 lines (127 loc) · 2.75 KB
/
input.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"time"
xp "github.com/BurntSushi/xgb/xproto"
)
func handleButtonPress(e xp.ButtonPressEvent) {
s := screenContaining(e.RootX, e.RootY)
button := e.Detail
if e.State&xp.ModMaskControl != 0 {
// Control-click is treated as a Middle Mouse Button.
button = 2
} else if e.State&xp.ModMask1 != 0 {
// Alt-click is treated as a Right Mouse Button.
button = 3
}
if button == 2 {
// Middle Mouse Button is treated as Mouse-Wheel Up/Down.
if e.State&xp.ModMaskShift != 0 {
button = 4
} else {
button = 5
}
}
k := s.workspace
if k.listing != listNone && button > 3 {
return
}
if k.listing == listWindows {
button = 1
} else if k.listing == listWorkspaces {
button = 3
}
switch button {
case 1:
if k.index >= 0 {
if iw, ok := k.list[k.index].(*window); ok {
k.listing, k.list, k.index = listNone, nil, -1
changeWindow(k.focusedFrame, k.focusedFrame.window, iw)
}
s.repaint()
} else {
doList(k, listWindows)
}
case 3:
if k.index >= 0 {
if ik, ok := k.list[k.index].(*workspace); ok {
k.listing, k.list, k.index = listNone, nil, -1
changeWorkspace(s, k, ik)
}
s.repaint()
} else {
doList(k, listWorkspaces)
}
case 4:
doWindow(k, prev)
case 5:
doWindow(k, next)
}
if button <= 3 {
k = s.workspace
w := k.focusedFrame.window
if k.listing != listNone {
w = nil
}
focus(w)
}
}
func handleEnterNotify(e xp.EnterNotifyEvent) {
w := findWindow(func(w *window) bool { return w.xWin == e.Event })
if w == nil || w.frame == nil {
return
}
k := w.frame.workspace
f0 := k.focusedFrame
k.focusFrame(w.frame)
if k.listing == listWindows && k.focusedFrame != f0 {
k.makeList()
}
}
func handleKeyPress(e xp.KeyPressEvent) {
shift := 0
if e.State&xp.ModMaskShift != 0 {
shift = 1
}
keysym := int32(keysyms[e.Detail][shift])
if shift != 0 {
if keysym == 0 {
keysym = int32(keysyms[e.Detail][0])
}
keysym = ^keysym
}
if a := actions[keysym]; a.do != nil {
if a.do(screenContaining(e.RootX, e.RootY).workspace, a.arg) {
pulseChan <- time.Now()
}
}
}
func handleMotionNotify(e xp.MotionNotifyEvent) {
s := screenContaining(e.RootX, e.RootY)
k := s.workspace
f0 := k.focusedFrame
if !k.fullscreen && k.listing != listWorkspaces {
k.focusFrame(k.frameContaining(e.RootX, e.RootY))
}
if k.listing == listNone {
return
}
i1, i0 := k.indexForPoint(e.RootX, e.RootY), k.index
k.index = i1
if k.listing == listWindows && k.focusedFrame != f0 {
k.makeList()
return
}
if i1 == i0 {
return
}
x, y := clip(k)
setForeground(colorPulseFocused)
y += int16(fontHeight + fontHeight1)
if i0 != -1 {
drawText(x+int16(fontWidth), y+int16(i0*fontHeight), " ")
}
if i1 != -1 {
drawText(x+int16(fontWidth), y+int16(i1*fontHeight), ">")
}
unclip()
}