Debian Codegraph @

ui/configure.go

raw symbols SCIP
1 package ui
2
3 import (
4 "fmt"
5 //"github.com/dkolbly/wl"
6 "github.com/dkolbly/wl/xdg"
7 )
8
9 type Config struct {
10 Width int
11 Height int
12 Active bool
13 }
14
15 // see description of xdg_surface.configure
16 //
17 // Basically, we will receive a series of events on our role
18 // object (e.g., a xdg.Toplevel) which are accumulating latchable
19 // state. When the xdg.Surface get a configure event, we "latch"
20 // those changes, do whatever we need to do, and then respond with
21 // an AckConfigure request.
22
23 // the compositor wants the surface to be closed, based on user action
24 func (w *Window) HandleToplevelClose(ev xdg.ToplevelCloseEvent) {
25 fmt.Printf("toplevel close request: %v\n", ev)
26 }
27
28 func (w *Window) HandleToplevelConfigure(ev xdg.ToplevelConfigureEvent) {
29 fmt.Printf("toplevel configured: %v\n", ev)
30
31 pend := Config{
32 Width: int(ev.Width),
33 Height: int(ev.Height),
34 }
35 for _, state := range ev.States {
36 if state == xdg.ToplevelStateActivated {
37 pend.Active = true
38 }
39 }
40 w.pending = pend
41 }
42
43 func (w *Window) HandleSurfaceConfigure(ev xdg.SurfaceConfigureEvent) {
44 fmt.Printf("surface configured; committing %#v\n", w.pending)
45 // and ack it
46 w.xdgSurface.AckConfigure(ev.Serial)
47
48 // apply the changes
49 w.current = w.pending
50 }
51
52 func (w *Window) setupXDGTopLevel() error {
53
54 d := w.display
55
56 /*fmt.Printf("creating xdg_wm_base\n")
57 wm := xdg.NewXdgWmBase(d.Context())
58 fmt.Printf("==> %#v\n", wm)
59 */
60 s, err := d.wmBase.GetXdgSurface(w.surface)
61 if err != nil {
62 fmt.Printf("failed to get surface: %s", err)
63 } else {
64 fmt.Printf("surface is: %p\n", s)
65 }
66
67 w.xdgSurface = s
68 /*ping := wl.HandlerFunc(func(x interface{}) {
69 if ev, ok := x.(xdg.WmBasePingEvent); ok {
70 fmt.Printf("ping <%d>\n", ev.Serial)
71 d.wmBase.Pong(ev.Serial)
72 } else {
73 fmt.Printf("umm, what %#v\n", x)
74 }
75 })
76 foo := wl.HandlerFunc(func(x interface{}) {
77 fmt.Printf("surface configured: %#v\n", x)
78 })*/
79
80 s.AddConfigureHandler(w)
81
82 top, err := s.GetToplevel()
83 if err != nil {
84 panic(err)
85 }
86 fmt.Printf("top level is: %p\n", top)
87
88 top.SetTitle("Hello!")
89 top.SetAppId("go.hello")
90 /*bar := wl.HandlerFunc(func(x interface{}) {
91 fmt.Printf("toplevel configured: %#v\n", x)
92 })
93 barc := wl.HandlerFunc(func(x interface{}) {
94 fmt.Printf("toplevel closed: %#v\n", x)
95 })*/
96 top.AddConfigureHandler(w)
97 top.AddCloseHandler(w)
98
99 err = s.SetWindowGeometry(10, 10, 300, 300)
100 if err != nil {
101 panic(err)
102 }
103 // we need to commit the underlying wl_surface before
104 // doing much else (see description of xdg_surface)
105 err = w.surface.Commit()
106 if err != nil {
107 return fmt.Errorf("Surface.Commit failed: %s", err)
108 }
109
110 fmt.Printf("ok...\n")
111 return nil
112 }