examples. some should be tests
This commit is contained in:
parent
369ad0d33e
commit
99bc76de54
48
nexgb/examples/randr.go
Normal file
48
nexgb/examples/randr.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
|
29
nexgb/examples/seq-nowrap.go
Normal file
29
nexgb/examples/seq-nowrap.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
nexgb/examples/seq-wrap.go
Normal file
24
nexgb/examples/seq-wrap.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
61
nexgb/examples/window.go
Normal file
61
nexgb/examples/window.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
nexgb/examples/xinerama.go
Normal file
29
nexgb/examples/xinerama.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user