/
configure.go
112 lines (95 loc) · 2.58 KB
/
configure.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
package ui
import (
"fmt"
//"github.com/dkolbly/wl"
"github.com/dkolbly/wl/xdg"
)
type Config struct {
Width int
Height int
Active bool
}
// see description of xdg_surface.configure
//
// Basically, we will receive a series of events on our role
// object (e.g., a xdg.Toplevel) which are accumulating latchable
// state. When the xdg.Surface get a configure event, we "latch"
// those changes, do whatever we need to do, and then respond with
// an AckConfigure request.
// the compositor wants the surface to be closed, based on user action
func (w *Window) HandleToplevelClose(ev xdg.ToplevelCloseEvent) {
fmt.Printf("toplevel close request: %v\n", ev)
}
func (w *Window) HandleToplevelConfigure(ev xdg.ToplevelConfigureEvent) {
fmt.Printf("toplevel configured: %v\n", ev)
pend := Config{
Width: int(ev.Width),
Height: int(ev.Height),
}
for _, state := range ev.States {
if state == xdg.ToplevelStateActivated {
pend.Active = true
}
}
w.pending = pend
}
func (w *Window) HandleSurfaceConfigure(ev xdg.SurfaceConfigureEvent) {
fmt.Printf("surface configured; committing %#v\n", w.pending)
// and ack it
w.xdgSurface.AckConfigure(ev.Serial)
// apply the changes
w.current = w.pending
}
func (w *Window) setupXDGTopLevel() error {
d := w.display
/*fmt.Printf("creating xdg_wm_base\n")
wm := xdg.NewXdgWmBase(d.Context())
fmt.Printf("==> %#v\n", wm)
*/
s, err := d.wmBase.GetXdgSurface(w.surface)
if err != nil {
fmt.Printf("failed to get surface: %s", err)
} else {
fmt.Printf("surface is: %p\n", s)
}
w.xdgSurface = s
/*ping := wl.HandlerFunc(func(x interface{}) {
if ev, ok := x.(xdg.WmBasePingEvent); ok {
fmt.Printf("ping <%d>\n", ev.Serial)
d.wmBase.Pong(ev.Serial)
} else {
fmt.Printf("umm, what %#v\n", x)
}
})
foo := wl.HandlerFunc(func(x interface{}) {
fmt.Printf("surface configured: %#v\n", x)
})*/
s.AddConfigureHandler(w)
top, err := s.GetToplevel()
if err != nil {
panic(err)
}
fmt.Printf("top level is: %p\n", top)
top.SetTitle("Hello!")
top.SetAppId("go.hello")
/*bar := wl.HandlerFunc(func(x interface{}) {
fmt.Printf("toplevel configured: %#v\n", x)
})
barc := wl.HandlerFunc(func(x interface{}) {
fmt.Printf("toplevel closed: %#v\n", x)
})*/
top.AddConfigureHandler(w)
top.AddCloseHandler(w)
err = s.SetWindowGeometry(10, 10, 300, 300)
if err != nil {
panic(err)
}
// we need to commit the underlying wl_surface before
// doing much else (see description of xdg_surface)
err = w.surface.Commit()
if err != nil {
return fmt.Errorf("Surface.Commit failed: %s", err)
}
fmt.Printf("ok...\n")
return nil
}