-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
131 lines (119 loc) · 3.17 KB
/
window.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
package main
import (
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/xrect"
)
type Window struct {
*Dispatcher
Id xproto.Window
X *xgbutil.XUtil
Geom *xrect.XRect
/* Name string
Class string
States []xprop.Atom
Types []xprop.Atom
Protocols []xprop.Atom*/
}
func NewWindow(X *xgbutil.XUtil, Id xproto.Window) *Window {
win := new(Window)
win.Id = Id
win.X = X
win.Dispatcher = NewDispatcher()
win.Geometry()
return win
}
func (w *Window) Geometry() (*xrect.XRect, error) {
cookie := xproto.GetGeometry(w.X.Conn(), xproto.Drawable(w.Id))
reply, err := cookie.Reply()
if err != nil {
return nil, err
}
w.Geom = xrect.New(int(reply.X), int(reply.Y),
int(reply.Width), int(reply.Height))
return w.Geom, nil
}
func (w *Window) GeometrySet(rect *xrect.XRect) {
if rect.Width() == 0 || rect.Height() == 0 {
w.SendConfigNotify()
return
}
if rect.Width() != w.Geom.Width() ||
rect.Height() != w.Geom.Height() ||
rect.X() != w.Geom.X() ||
rect.Y() != w.Geom.Y() {
w.Configure(xproto.ConfigWindowX|xproto.ConfigWindowY|
xproto.ConfigWindowWidth|xproto.ConfigWindowHeight, rect.X(), rect.Y(), rect.Width(), rect.Height(), 0, 0, 0)
if rect.Width() == w.Geom.Width() && rect.Height() == w.Geom.Height() {
w.SendConfigNotify()
}
}
w.Geom = rect
}
func (win *Window) Configure(flags, x, y, w, h, borderWidth int, sibling xproto.Window, stackMode byte) {
if win == nil {
return
}
vals := []uint32{}
if xproto.ConfigWindowX&flags > 0 {
vals = append(vals, uint32(x))
}
if xproto.ConfigWindowY&flags > 0 {
vals = append(vals, uint32(y))
}
if xproto.ConfigWindowWidth&flags > 0 {
if int16(w) <= 0 {
w = 1
}
vals = append(vals, uint32(w))
}
if xproto.ConfigWindowHeight&flags > 0 {
if int16(h) <= 0 {
h = 1
}
vals = append(vals, uint32(h))
}
if xproto.ConfigWindowBorderWidth&flags > 0 {
vals = append(vals, uint32(sibling))
}
if xproto.ConfigWindowSibling&flags > 0 {
vals = append(vals, uint32(sibling))
}
if xproto.ConfigWindowStackMode&flags > 0 {
vals = append(vals, uint32(stackMode))
}
xproto.ConfigureWindow(win.X.Conn(), win.Id, uint16(flags), vals)
}
func (w *Window) Map() {
xproto.MapWindow(w.X.Conn(), w.Id)
}
func (w *Window) Unmap() {
xproto.UnmapWindow(w.X.Conn(), w.Id)
}
func (w *Window) SendConfigNotify() {
ev := xproto.ConfigureNotifyEvent{
Event: w.Id,
Window: w.Id,
AboveSibling: 0,
X: int16(w.Geom.X()),
Y: int16(w.Geom.Y()),
Width: uint16(w.Geom.Width()),
Height: uint16(w.Geom.Height()),
BorderWidth: 0,
OverrideRedirect: false,
}
xproto.SendEvent(w.X.Conn(), false, w.Id,
xproto.EventMaskStructureNotify, string(ev.Bytes()))
}
func (w *Window) ConfigureRequest(event xgb.Event) {
ev := event.(xproto.ConfigureRequestEvent)
w.GeometrySet(xrect.New(int(ev.X), int(ev.Y), int(ev.Width), int(ev.Height)))
w.PullHook("window::configured", w.Id)
}
func (w *Window) UnmapNotify(event xgb.Event) {
w.PullHook("window::unmapped", w.Id)
}
func (w *Window) DestroyNotify(event xgb.Event) {
w.PullHook("window::destroyed", w.Id)
}