diff options
Diffstat (limited to 'nexgb/examples')
-rw-r--r-- | nexgb/examples/create-window/main.go | 33 | ||||
-rw-r--r-- | nexgb/examples/get-active-window/main.go | 20 | ||||
-rw-r--r-- | nexgb/examples/randr/main.go | 23 | ||||
-rw-r--r-- | nexgb/examples/xinerama/main.go | 5 |
4 files changed, 50 insertions, 31 deletions
diff --git a/nexgb/examples/create-window/main.go b/nexgb/examples/create-window/main.go index 6996f37..73a0099 100644 --- a/nexgb/examples/create-window/main.go +++ b/nexgb/examples/create-window/main.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/xproto" ) func main() { @@ -17,15 +18,23 @@ func main() { return } + // xproto.Setup retrieves the Setup information from the setup bytes + // gathered during connection. + setup := xproto.Setup(X) + + // This is the default screen with all its associated info. + screen := setup.DefaultScreen(X) + // Any time a new resource (i.e., a window, pixmap, graphics context, etc.) - // is created, we need to generate a resource identifier with NewId. - wid, _ := X.NewId() + // is created, we need to generate a resource identifier. + // If the resource is a window, then use xproto.NewWindowId. If it's for + // a pixmap, then use xproto.NewPixmapId. And so on... + wid, _ := xproto.NewWindowId(X) // CreateWindow takes a boatload of parameters. - X.CreateWindow(X.DefaultScreen().RootDepth, wid, X.DefaultScreen().Root, + xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root, 0, 0, 500, 500, 0, - xgb.WindowClassInputOutput, X.DefaultScreen().RootVisual, - 0, []uint32{}) + xproto.WindowClassInputOutput, screen.RootVisual, 0, []uint32{}) // This call to ChangeWindowAttributes could be factored out and // included with the above CreateWindow call, but it is left here for @@ -34,13 +43,13 @@ func main() { // etc.) and when a key press or a key release has been made when the // window has focus. // We also set the 'BackPixel' to white so that the window isn't butt ugly. - X.ChangeWindowAttributes(wid, - xgb.CwBackPixel|xgb.CwEventMask, + xproto.ChangeWindowAttributes(X, wid, + xproto.CwBackPixel|xproto.CwEventMask, []uint32{ // values must be in the order defined by the protocol 0xffffffff, - xgb.EventMaskStructureNotify | - xgb.EventMaskKeyPress | - xgb.EventMaskKeyRelease}) + xproto.EventMaskStructureNotify | + xproto.EventMaskKeyPress | + xproto.EventMaskKeyRelease}) // MapWindow makes the window we've created appear on the screen. // We demonstrated the use of a 'checked' request here. @@ -58,7 +67,7 @@ func main() { // // Note that requests without replies are by default unchecked while // requests *with* replies are checked by default. - err = X.MapWindowChecked(wid).Check() + err = xproto.MapWindowChecked(X, wid).Check() if err != nil { fmt.Printf("Checked Error for mapping window %d: %s\n", wid, err) } else { @@ -67,7 +76,7 @@ func main() { // This is an example of an invalid MapWindow request and what an error // looks like. - err = X.MapWindowChecked(0).Check() + err = xproto.MapWindowChecked(X, 0).Check() if err != nil { fmt.Printf("Checked Error for mapping window 0x1: %s\n", err) } else { // neva diff --git a/nexgb/examples/get-active-window/main.go b/nexgb/examples/get-active-window/main.go index e90563c..48e020c 100644 --- a/nexgb/examples/get-active-window/main.go +++ b/nexgb/examples/get-active-window/main.go @@ -7,6 +7,7 @@ import ( "log" "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/xproto" ) func main() { @@ -16,18 +17,21 @@ func main() { } // Get the window id of the root window. - root := X.DefaultScreen().Root + setup := xproto.Setup(X) + root := setup.DefaultScreen(X).Root // Get the atom id (i.e., intern an atom) of "_NET_ACTIVE_WINDOW". aname := "_NET_ACTIVE_WINDOW" - activeAtom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply() + activeAtom, err := xproto.InternAtom(X, true, uint16(len(aname)), + aname).Reply() if err != nil { log.Fatal(err) } // Get the atom id (i.e., intern an atom) of "_NET_WM_NAME". aname = "_NET_WM_NAME" - nameAtom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply() + nameAtom, err := xproto.InternAtom(X, true, uint16(len(aname)), + aname).Reply() if err != nil { log.Fatal(err) } @@ -37,19 +41,19 @@ func main() { // XGB helper function, 'Get32', to pull an unsigned 32-bit integer out // of the byte slice. We then convert it to an X resource id so it can // be used to get the name of the window in the next GetProperty request. - reply, err := X.GetProperty(false, root, activeAtom.Atom, - xgb.GetPropertyTypeAny, 0, (1<<32)-1).Reply() + reply, err := xproto.GetProperty(X, false, root, activeAtom.Atom, + xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply() if err != nil { log.Fatal(err) } - windowId := xgb.Id(xgb.Get32(reply.Value)) + windowId := xproto.Window(xgb.Get32(reply.Value)) fmt.Printf("Active window id: %X\n", windowId) // Now get the value of _NET_WM_NAME for the active window. // Note that this time, we simply convert the resulting byte slice, // reply.Value, to a string. - reply, err = X.GetProperty(false, windowId, nameAtom.Atom, - xgb.GetPropertyTypeAny, 0, (1<<32)-1).Reply() + reply, err = xproto.GetProperty(X, false, windowId, nameAtom.Atom, + xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply() if err != nil { log.Fatal(err) } diff --git a/nexgb/examples/randr/main.go b/nexgb/examples/randr/main.go index 5c56609..ad575ee 100644 --- a/nexgb/examples/randr/main.go +++ b/nexgb/examples/randr/main.go @@ -15,27 +15,32 @@ import ( "log" "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/randr" + "github.com/BurntSushi/xgb/xproto" ) func main() { X, _ := xgb.NewConn() // Every extension must be initialized before it can be used. - err := X.RandrInit() + err := randr.Init(X) if err != nil { log.Fatal(err) } + // Get the root window on the default screen. + root := xproto.Setup(X).DefaultScreen(X).Root + // Gets the current screen resources. Screen resources contains a list // of names, crtcs, outputs and modes, among other things. - resources, err := X.RandrGetScreenResources(X.DefaultScreen().Root).Reply() + resources, err := randr.GetScreenResources(X, root).Reply() if err != nil { log.Fatal(err) } // Iterate through all of the outputs and show some of their info. for _, output := range resources.Outputs { - info, err := X.RandrGetOutputInfo(output, 0).Reply() + info, err := randr.GetOutputInfo(X, output, 0).Reply() if err != nil { log.Fatal(err) } @@ -52,7 +57,7 @@ func main() { // Iterate through all of the crtcs and show some of their info. for _, crtc := range resources.Crtcs { - info, err := X.RandrGetCrtcInfo(crtc, 0).Reply() + info, err := randr.GetCrtcInfo(X, crtc, 0).Reply() if err != nil { log.Fatal(err) } @@ -61,11 +66,11 @@ func main() { } // Tell RandR to send us events. (I think these are all of them, as of 1.3.) - err = X.RandrSelectInputChecked(X.DefaultScreen().Root, - xgb.RandrNotifyMaskScreenChange| - xgb.RandrNotifyMaskCrtcChange| - xgb.RandrNotifyMaskOutputChange| - xgb.RandrNotifyMaskOutputProperty).Check() + err = randr.SelectInputChecked(X, root, + randr.NotifyMaskScreenChange| + randr.NotifyMaskCrtcChange| + randr.NotifyMaskOutputChange| + randr.NotifyMaskOutputProperty).Check() if err != nil { log.Fatal(err) } diff --git a/nexgb/examples/xinerama/main.go b/nexgb/examples/xinerama/main.go index ec7f46a..896bb63 100644 --- a/nexgb/examples/xinerama/main.go +++ b/nexgb/examples/xinerama/main.go @@ -6,6 +6,7 @@ import ( "log" "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/xinerama" ) func main() { @@ -17,13 +18,13 @@ func main() { // Initialize the Xinerama extension. // The appropriate 'Init' function must be run for *every* // extension before any of its requests can be used. - err = X.XineramaInit() + err = xinerama.Init(X) if err != nil { log.Fatal(err) } // Issue a request to get the screen information. - reply, err := X.XineramaQueryScreens().Reply() + reply, err := xinerama.QueryScreens(X).Reply() if err != nil { log.Fatal(err) } |