-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathevents.go
161 lines (149 loc) · 3.81 KB
/
events.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"github.com/ziutek/mdtwm/xgb_patched"
"io"
"os"
)
func handleEvent(event xgb.Event, err error) {
if err != nil {
if err == io.EOF {
conn.Close()
l.Print("Connection closed by server")
os.Exit(0)
}
logFuncErr(err)
return
}
switch e := event.(type) {
// Request events
case xgb.MapRequestEvent:
mapRequest(e)
case xgb.ConfigureRequestEvent:
configureRequest(e)
// Notify events
case xgb.EnterNotifyEvent:
enterNotify(e)
case xgb.MapNotifyEvent:
mapNotify(e)
case xgb.UnmapNotifyEvent:
unmapNotify(e)
case xgb.DestroyNotifyEvent:
destroyNotify(e)
case xgb.ReparentNotifyEvent:
reparentNotify(e)
// Keyboard and mouse events
case xgb.KeyPressEvent:
keyPress(e)
case xgb.ButtonPressEvent:
buttonPress(e)
case xgb.ButtonReleaseEvent:
buttonRelease(e)
case xgb.MotionNotifyEvent:
motionNotify(e)
default:
d.Printf("Unhandled event: %T: %+v", e, e)
}
}
func mapRequest(e xgb.MapRequestEvent) {
d.Printf("%T: %+v", e, e)
manage(Window(e.Window), currentPanel(), false)
}
// For windows with override-redirect flag
func mapNotify(e xgb.MapNotifyEvent) {
d.Printf("%T: %+v", e, e)
manage(Window(e.Window), currentPanel(), false)
}
func enterNotify(e xgb.EnterNotifyEvent) {
d.Printf("%T: %+v", e, e)
if e.Mode != xgb.NotifyModeNormal {
return
}
setFocus(Window(e.Event), e.Time)
}
func reparentNotify(e xgb.ReparentNotifyEvent) {
d.Printf("%T: %+v", e, e)
// If we move window beetwen boxes there is not EnterNotify for this window
setFocus(Window(e.Window), xgb.TimeCurrentTime)
}
func setFocus(w Window, t xgb.Timestamp) {
f := (currentDesk.Window() == w)
currentDesk.SetFocus(f, t)
if f {
currentBox = currentDesk
}
// Iterate over all boxes in current desk
bi := currentDesk.Children().FrontIter()
for b := bi.Next(); b != nil; b = bi.Next() {
f = (b.Window() == w)
b.SetFocus(f, t)
if f {
currentBox = b
}
}
if currentBox != nil {
root.Window().ChangeProp(xgb.PropModeReplace, AtomNetActiveWindow,
xgb.AtomWindow, currentBox.Window())
}
statusLog()
}
func destroyNotify(e xgb.DestroyNotifyEvent) {
d.Printf("%T: %+v", e, e)
unmanage(Window(e.Window))
}
func unmapNotify(e xgb.UnmapNotifyEvent) {
d.Printf("%T: %+v", e, e)
// We mask UnmapNotify during reparenting, so these events have
// e.Event == root. root isn't managed so unamange(root) do nothing.
unmanage(Window(e.Event))
}
func configureRequest(e xgb.ConfigureRequestEvent) {
d.Printf("%T: %+v", e, e)
w := Window(e.Window)
b := root.Children().BoxByWindow(w, true)
mask := (xgb.ConfigWindowX | xgb.ConfigWindowY |
xgb.ConfigWindowWidth | xgb.ConfigWindowHeight |
xgb.ConfigWindowBorderWidth | xgb.ConfigWindowSibling |
xgb.ConfigWindowStackMode) & e.ValueMask
v := make([]interface{}, 0, 7)
if b == nil || b.Float() {
// We accept request from floating windows.
// Unmanaged window will be configured by manage() function after
// MapNotify event so now we can simply execute its request.
if mask&xgb.ConfigWindowX != 0 {
v = append(v, e.X)
}
if mask&xgb.ConfigWindowY != 0 {
v = append(v, e.Y)
}
if mask&xgb.ConfigWindowWidth != 0 {
v = append(v, e.Width)
}
if mask&xgb.ConfigWindowHeight != 0 {
v = append(v, e.Height)
}
if mask&xgb.ConfigWindowBorderWidth != 0 {
v = append(v, e.BorderWidth)
}
if mask&xgb.ConfigWindowSibling != 0 {
v = append(v, e.Sibling)
}
if mask&xgb.ConfigWindowStackMode != 0 {
v = append(v, e.StackMode)
}
w.Configure(mask, v...)
return
}
// Force window configuration
g := b.Geometry()
cne := xgb.ConfigureNotifyEvent{
Event: e.Window,
Window: e.Window,
AboveSibling: xgb.WindowNone,
X: g.X,
Y: g.Y,
Width: Pint16(g.W),
Height: Pint16(g.H),
BorderWidth: Pint16(g.B),
}
w.Send(false, xgb.EventMaskStructureNotify, cne)
}