diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-05 18:22:40 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-05 18:22:40 -0400 |
commit | 99bc76de54729df5494faa944d4da96a8885d51e (patch) | |
tree | a855999db11daed23007aaab866e273ffd275b86 /nexgb/examples/window.go | |
parent | 369ad0d33e51035a3e48436fc85f60130b201437 (diff) | |
download | haven-99bc76de54729df5494faa944d4da96a8885d51e.tar.gz haven-99bc76de54729df5494faa944d4da96a8885d51e.tar.xz haven-99bc76de54729df5494faa944d4da96a8885d51e.zip |
examples. some should be tests
Diffstat (limited to 'nexgb/examples/window.go')
-rw-r--r-- | nexgb/examples/window.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/nexgb/examples/window.go b/nexgb/examples/window.go new file mode 100644 index 0000000..68fe27b --- /dev/null +++ b/nexgb/examples/window.go @@ -0,0 +1,61 @@ +package main + +import ( + "fmt" + "log" + + "github.com/BurntSushi/xgb" +) + +func main() { + X, err := xgb.NewConn() + if err != nil { + log.Fatal(err) + } + + wid, _ := X.NewId() + X.CreateWindow(X.DefaultScreen().RootDepth, wid, X.DefaultScreen().Root, + 0, 0, 500, 500, 0, + xgb.WindowClassInputOutput, X.DefaultScreen().RootVisual, + 0, []uint32{}) + X.ChangeWindowAttributes(wid, xgb.CwEventMask | xgb.CwBackPixel, + []uint32{0xffffffff, xgb.EventMaskKeyPress | xgb.EventMaskKeyRelease}) + + err = X.MapWindowChecked(wid).Check() + if err != nil { + fmt.Printf("Checked Error for mapping window %d: %s\n", wid, err) + } else { + fmt.Printf("Map window %d successful!\n", wid) + } + + err = X.MapWindowChecked(0x1).Check() + if err != nil { + fmt.Printf("Checked Error for mapping window 0x1: %s\n", err) + } else { + fmt.Printf("Map window 0x1 successful!\n") + } + + for { + ev, xerr := X.WaitForEvent() + if ev == nil && xerr == nil { + log.Fatal("Both event and error are nil. Exiting...") + } + + if ev != nil { + fmt.Printf("Event: %s\n", ev) + } + if xerr != nil { + fmt.Printf("Error: %s\n", xerr) + } + + if xerr == nil { + geom, err := X.GetGeometry(0x1).Reply() + if err != nil { + fmt.Printf("Geom Error: %#v\n", err) + } else { + fmt.Printf("Geometry: %#v\n", geom) + } + } + } +} + |