-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbox.go
196 lines (156 loc) · 3.81 KB
/
box.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package main
import (
"github.com/ziutek/mdtwm/xgb_patched"
"fmt"
"unicode/utf16"
)
type Box interface {
String() string
Window() Window
Parent() ParentBox
SetParent(p ParentBox)
Children() *BoxList
// Methods for implement an element of BoxList
Next() Box
SetNext(next Box)
Prev() Box
SetPrev(prev Box)
List() *BoxList
SetList(l *BoxList)
Geometry() Geometry // Get internal geometry
PosSize() (x, y, width, height int16) // Get externel geometry
SetPosSize(x, y, width, height int16) // Set external geometry
SetFocus(f bool, t xgb.Timestamp)
Raise()
Float() bool
SetFloat(float bool)
Hints() Hints
SetHints(h Hints)
// Properties
Name() string
NameX() []uint16 // UCS2 encoded name
SetName(name string)
Class() (instance, class string)
SetClass(instance, class string)
}
type ParentBox interface {
Box
Append(b Box)
InsertNextTo(b, mark Box, x, y int16)
Remove(b Box)
}
type Hints struct {
W, H, MinW, MinH, MaxW, MaxH, IncW, IncH, BaseW, BaseH int16
MinAspect, MaxAspect [2]int16
Gravity byte
}
type commonBox struct {
w Window // window stored in this box
parent ParentBox // parent panel
children *BoxList // child boxes contains childs of this box
prev, next Box
list *BoxList
eventMask uint32
float bool
hints Hints
// Box configuration
x, y, width, height int16
}
func (b *commonBox) String() string {
return fmt.Sprintf("%s (%s)", b.Name(), b.w)
}
func (b *commonBox) Window() Window {
return b.w
}
func (b *commonBox) init(w Window, eventMask uint32) {
b.w = w
b.parent = root
b.children = NewBoxList()
b.eventMask = eventMask
b.w.SetEventMask(eventMask)
}
func (b *commonBox) Parent() ParentBox {
return b.parent
}
func (b *commonBox) SetParent(p ParentBox) {
// Translate current coordinates to new parent coordinates (useful when new
// parent is root and window should stay in place.
var ok bool
b.x, b.y, _, _, ok = p.Window().TranslateCoordinates(
b.parent.Window(), b.x, b.y,
)
if !ok {
return
}
b.parent = p
b.w.SetEventMask(xgb.EventMaskNoEvent) // avoid UnmpNotify
b.w.Reparent(p.Window(), b.x, b.y)
b.w.SetEventMask(b.eventMask)
}
func (b *commonBox) Children() *BoxList {
return b.children
}
func (b *commonBox) Prev() Box {
return b.prev
}
func (b *commonBox) SetPrev(prev Box) {
b.prev = prev
}
func (b *commonBox) Next() Box {
return b.next
}
func (b *commonBox) SetNext(next Box) {
b.next = next
}
func (b *commonBox) List() *BoxList {
return b.list
}
func (b *commonBox) SetList(l *BoxList) {
b.list = l
}
func (b *commonBox) Float() bool {
return b.float
}
func (b *commonBox) SetFloat(float bool) {
b.float = float
}
func (b *commonBox) Hints() Hints {
return b.hints
}
func (b *commonBox) SetHints(h Hints) {
b.hints = h
}
// Properties
func (b *commonBox) Name() string {
// We prefer utf8 version
if p := b.w.Prop(AtomNetWmName, 128); p != nil && len(p.Value) > 0 {
return string(p.Value)
}
if p := b.w.Prop(xgb.AtomWmName, 128); p != nil && len(p.Value) > 0 {
return string(p.Value)
}
return ""
}
func (b *commonBox) NameX() []uint16 {
return utf16.Encode([]rune(b.Name()))
}
func (b *commonBox) SetName(name string) {
b.w.ChangeProp(xgb.PropModeReplace, xgb.AtomWmName, xgb.AtomString, name)
b.w.ChangeProp(xgb.PropModeReplace, AtomNetWmName, AtomUtf8String, name)
}
func (b *commonBox) PosSize() (x, y, width, height int16) {
return b.x, b.y, b.width, b.height
}
func (b *commonBox) Raise() {
b.Window().Configure(xgb.ConfigWindowStackMode, uint32(xgb.StackModeAbove))
}
func (b *commonBox) Class() (instance, class string) {
return b.w.Class()
}
func (b *commonBox) SetClass(instance, class string) {
v := make([]byte, 0, len(instance)+len(class)+2)
v = append(v, instance...)
v = append(v, 0)
v = append(v, class...)
b.w.ChangeProp(xgb.PropModeReplace, xgb.AtomWmClass, xgb.AtomString, v)
}