-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinmanager.go
54 lines (47 loc) · 1.64 KB
/
winmanager.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
package main
import (
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/xrect"
"github.com/BurntSushi/xgbutil/xwindow"
)
type WindowManager struct {
X *xgbutil.XUtil
WinTree *Tree
*EventLoop
}
func NewWindowManager(X *xgbutil.XUtil) *WindowManager {
w := &WindowManager{X: X, Windows: &Tree{}, EventLoop: NewEventLoop(X)}
w.AddCallback("MapRequestEvent", w.X.RootWin(), w.MapRequest)
w.AddCallback("ConfigureRequestEvent", w.X.RootWin(), w.ConfigureRequest)
return w
}
func (w *WindowManager) LayoutWindows(args ...interface{}) {
w.Windows.Layout(xrect.New(0, 0, 800, 600))
}
func (w *WindowManager) Manage(window xproto.Window) {
win := NewWindow(w.X, window)
//attach window hooks to allow it to handle unmanaging and configuring itself
w.AddCallback("UnmapNotifyEvent", win.Id, win.UnmapNotify)
w.AddCallback("ConfigureRequestEvent", win.Id, win.ConfigureRequest)
//this order is important because there are some hooks that are
//attached inside the tree that need to be pulled before
//we call the layout again.
w.WinTree.Insert(win)
win.AttachToHook("window::unmapped", w.LayoutWindows)
win.AttachToHook("window::configured", w.LayoutWindows)
win.Map()
w.LayoutWindows()
}
//Event Handlers
func (w *WindowManager) MapRequest(event xgb.Event) {
ev := event.(xproto.MapRequestEvent)
w.Manage(ev.Window)
}
func (w *WindowManager) ConfigureRequest(event xgb.Event) {
ev := event.(xproto.ConfigureRequestEvent)
xwindow.New(w.X, ev.Window).Configure(int(ev.ValueMask),
int(ev.X), int(ev.Y), int(ev.Width), int(ev.Height),
ev.Sibling, ev.StackMode)
}