diff options
Diffstat (limited to 'nexgb')
-rw-r--r-- | nexgb/examples/randr.go | 48 | ||||
-rw-r--r-- | nexgb/examples/seq-nowrap.go | 29 | ||||
-rw-r--r-- | nexgb/examples/seq-wrap.go | 24 | ||||
-rw-r--r-- | nexgb/examples/window.go | 61 | ||||
-rw-r--r-- | nexgb/examples/xinerama.go | 29 |
5 files changed, 191 insertions, 0 deletions
diff --git a/nexgb/examples/randr.go b/nexgb/examples/randr.go new file mode 100644 index 0000000..064856d --- /dev/null +++ b/nexgb/examples/randr.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "log" + + "github.com/BurntSushi/xgb" +) + +func main() { + X, _ := xgb.NewConn() + + err := X.RegisterExtension("randr") + if err != nil { + log.Fatal(err) + } + + resources, err := X.RandrGetScreenResources(X.DefaultScreen().Root).Reply() + if err != nil { + log.Fatal(err) + } + + for _, output := range resources.Outputs { + info, err := X.RandrGetOutputInfo(output, 0).Reply() + if err != nil { + log.Fatal(err) + } + + bestMode := info.Modes[0] + for _, mode := range resources.Modes { + if mode.Id == uint32(bestMode) { + fmt.Printf("Width: %d, Height: %d\n", mode.Width, mode.Height) + } + } + } + + fmt.Println("\n") + + for _, crtc := range resources.Crtcs { + info, err := X.RandrGetCrtcInfo(crtc, 0).Reply() + if err != nil { + log.Fatal(err) + } + fmt.Printf("X: %d, Y: %d, Width: %d, Height: %d\n", + info.X, info.Y, info.Width, info.Height) + } +} + diff --git a/nexgb/examples/seq-nowrap.go b/nexgb/examples/seq-nowrap.go new file mode 100644 index 0000000..994a07b --- /dev/null +++ b/nexgb/examples/seq-nowrap.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + + "github.com/BurntSushi/xgb" +) + +func main() { + X, _ := xgb.NewConn() + + for i := 1; i <= 1<<16 + 10; i++ { + X.NoOperation() + // fmt.Printf("%d. No-Op\n", i) + } + + aname := "_NET_ACTIVE_WINDOW" + + for i := 1; i <= 10; i++ { + atom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply() + if err != nil { + fmt.Println(err) + } else { + fmt.Printf("%d. Sequence: %d, Atom: %d\n", + i, atom.Sequence, atom.Atom) + } + } +} + diff --git a/nexgb/examples/seq-wrap.go b/nexgb/examples/seq-wrap.go new file mode 100644 index 0000000..b5bc834 --- /dev/null +++ b/nexgb/examples/seq-wrap.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + "github.com/BurntSushi/xgb" +) + +func main() { + X, _ := xgb.NewConn() + + aname := "_NET_ACTIVE_WINDOW" + + for i := 1; i <= 1<<16 + 10; i++ { + atom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply() + if err != nil { + fmt.Println(err) + } else { + fmt.Printf("%d. Sequence: %d, Atom: %d\n", + i, atom.Sequence, atom.Atom) + } + } +} + 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) + } + } + } +} + diff --git a/nexgb/examples/xinerama.go b/nexgb/examples/xinerama.go new file mode 100644 index 0000000..7fe9984 --- /dev/null +++ b/nexgb/examples/xinerama.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "log" + + "github.com/BurntSushi/xgb" +) + +func main() { + X, _ := xgb.NewConn() + + err := X.RegisterExtension("xinerama") + if err != nil { + log.Fatal(err) + } + + reply, err := X.XineramaQueryScreens().Reply() + if err != nil { + log.Fatal(err) + } + + fmt.Printf("Xinerama number: %d\n", reply.Number) + for i, screen := range reply.ScreenInfo { + fmt.Printf("%d :: X: %d, Y: %d, Width: %d, Height: %d\n", + i, screen.XOrg, screen.YOrg, screen.Width, screen.Height) + } +} + |