| 1 |
package ui |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/dkolbly/wl/xdg" |
| 7 |
) |
| 8 |
|
| 9 |
type Config struct { |
| 10 |
Width int |
| 11 |
Height int |
| 12 |
Active bool |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 46 |
w.xdgSurface.AckConfigure(ev.Serial) |
| 47 |
|
| 48 |
|
| 49 |
w.current = w.pending |
| 50 |
} |
| 51 |
|
| 52 |
func (w *Window) setupXDGTopLevel() error { |
| 53 |
|
| 54 |
d := w.display |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 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 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 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 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 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 |
|
| 104 |
|
| 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 |
} |