aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-07 04:09:19 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-07 04:09:19 -0400
commitdc48249e1acea54b391f53b95f16e515dead7c97 (patch)
tree3467fee8294f8800977de0df3030d82e69bb7528
parent3bf376bd6648e011de9131c1d90a39c6d3890d65 (diff)
downloadhaven-dc48249e1acea54b391f53b95f16e515dead7c97.tar.gz
haven-dc48249e1acea54b391f53b95f16e515dead7c97.tar.xz
haven-dc48249e1acea54b391f53b95f16e515dead7c97.zip
lots of docs and examples
-rw-r--r--nexgb/Makefile6
-rw-r--r--nexgb/doc.go152
-rw-r--r--nexgb/examples/atom.go27
-rw-r--r--nexgb/examples/create-window/main.go98
-rw-r--r--nexgb/examples/doc.go21
-rw-r--r--nexgb/examples/get-active-window/main.go57
-rw-r--r--nexgb/examples/property.go41
-rw-r--r--nexgb/examples/randr.go48
-rw-r--r--nexgb/examples/randr/main.go84
-rw-r--r--nexgb/examples/seq-nowrap.go29
-rw-r--r--nexgb/examples/seq-wrap.go24
-rw-r--r--nexgb/examples/window.go61
-rw-r--r--nexgb/examples/xinerama.go29
-rw-r--r--nexgb/examples/xinerama/main.go39
-rw-r--r--nexgb/xgb.go6
-rw-r--r--nexgb/xgb_test.go6
-rw-r--r--nexgb/xgbgen/context.go2
-rw-r--r--nexgb/xgbgen/field.go4
-rw-r--r--nexgb/xgbgen/go_error.go2
-rw-r--r--nexgb/xgbgen/go_event.go5
-rw-r--r--nexgb/xgbgen/go_list.go1
-rw-r--r--nexgb/xgbgen/go_request_reply.go18
-rw-r--r--nexgb/xgbgen/go_union.go1
-rw-r--r--nexgb/xgbgen/protocol.go1
-rw-r--r--nexgb/xgbgen/request_reply.go4
-rw-r--r--nexgb/xgbgen/translation.go2
-rw-r--r--nexgb/xgbgen/xml.go32
27 files changed, 495 insertions, 305 deletions
diff --git a/nexgb/Makefile b/nexgb/Makefile
index c70b01c..7ba1cb4 100644
--- a/nexgb/Makefile
+++ b/nexgb/Makefile
@@ -1,5 +1,6 @@
# This Makefile is used by the developer. It is not needed in any way to build
# a checkout of the XGB repository.
+# It will be useful, however, if you are hacking at the code generator.
XPROTO=/usr/share/xcb
@@ -20,3 +21,8 @@ test:
bench:
go test -run 'nomatch' -bench '.*' -cpu 1,2,6
+gofmt:
+ gofmt -w *.go xgbgen/*.go examples/*.go examples/*/*.go
+ colcheck xgbgen/*.go examples/*.go examples/*/*.go \
+ auth.go conn.go cookie.go doc.go xgb.go xgb_help.go xgb_test.go
+
diff --git a/nexgb/doc.go b/nexgb/doc.go
new file mode 100644
index 0000000..b6c956f
--- /dev/null
+++ b/nexgb/doc.go
@@ -0,0 +1,152 @@
+/*
+Package XGB provides the X Go Binding, which is a low-level API to communicate
+with the core X protocol and many of the X extensions.
+
+It is *very* closely modeled on XCB, so that experience with XCB (or xpyb) is
+easily translatable to XGB. That is, it uses the same cookie/reply model
+and is thread safe. There are otherwise no major differences (in the API).
+
+Most uses of XGB typically fall under the realm of window manager and GUI kit
+development, but other applications (like pagers, panels, tilers, etc.) may
+also require XGB. Moreover, it is a near certainty that if you need to work
+with X, xgbutil will be of great use to you as well:
+https://github.com/BurntSushi/xgbutil
+
+Example
+
+This is an extremely terse example that demonstrates how to connect to X,
+create a window, listen to StructureNotify events and Key{Press,Release}
+events, map the window, and print out all events received. An example with
+accompanying documentation can be found in examples/create-window.
+
+ package main
+
+ import (
+ "fmt"
+ "github.com/BurntSushi/xgb"
+ )
+
+ func main() {
+ X, err := xgb.NewConn()
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ wid, _ := X.NewId()
+ X.CreateWindow(X.DefaultScreen().RootDepth, wid, X.DefaultScreen().Root,
+ 0, 0, 500, 500, 0,
+ xgb.WindowClassInputOutput, X.DefaultScreen().RootVisual,
+ xgb.CwBackPixel | xgb.CwEventMask,
+ []uint32{ // values must be in the order defined by the protocol
+ 0xffffffff,
+ xgb.EventMaskStructureNotify |
+ xgb.EventMaskKeyPress |
+ xgb.EventMaskKeyRelease})
+
+ X.MapWindow(wid)
+ for {
+ ev, xerr := X.WaitForEvent()
+ if ev == nil && xerr == nil {
+ fmt.Println("Both event and error are nil. Exiting...")
+ return
+ }
+
+ if ev != nil {
+ fmt.Printf("Event: %s\n", ev)
+ }
+ if xerr != nil {
+ fmt.Printf("Error: %s\n", xerr)
+ }
+ }
+ }
+
+Xinerama Example
+
+This is another small example that shows how to query Xinerama for geometry
+information of each active head. Accompanying documentation for this example
+can be found in examples/xinerama.
+
+ package main
+
+ import (
+ "fmt"
+ "log"
+ "github.com/BurntSushi/xgb"
+ )
+
+ func main() {
+ X, err := xgb.NewConn()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // 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()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ reply, err := X.XineramaQueryScreens().Reply()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Printf("Number of heads: %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)
+ }
+ }
+
+Parallelism
+
+XGB can benefit greatly from parallelism due to its concurrent design. For
+evidence of this claim, please see the benchmarks in xgb_test.go.
+
+Tests
+
+xgb_test.go contains a number of contrived tests that stress particular corners
+of XGB that I presume could be problem areas. Namely: requests with no replies,
+requests with replies, checked errors, unchecked errors, sequence number
+wrapping, cookie buffer flushing (i.e., forcing a round trip every N requests
+made that don't have a reply), getting/setting properties and creating a window
+and listening to StructureNotify events.
+
+Code Generator
+
+Both XCB and xpyb use the same Python module (xcbgen) for a code generator. XGB
+(before this fork) used the same code generator as well, but in my attempt to
+add support for more extensions, I found the code generator extremely difficult
+to work with. Therefore, I re-wrote the code generator in Go. It can be found
+in its own sub-package, xgbgen, of xgb. My design of xgbgen includes a rough
+consideration that it could be used for other languages.
+
+What works
+
+I am reasonably confident that the core X protocol is in full working form. I've
+also tested the Xinerama and RandR extensions sparingly. Many of the other
+existing extensions have Go source generated (and are compilable) and are
+included in this package, but I am currently unsure of their status. They
+*should* work.
+
+What does not work
+
+XKB is the only extension that intentionally does not work, although I suspect
+that GLX also does not work (however, there is Go source code for GLX that
+compiles, unlike XKB). I don't currently have any intention of getting XKB
+working, due to its complexity and my current mental incapacity to test it.
+
+There are so many functions
+
+Indeed. Everything below this initial overview is useful insomuch as your
+browser's "Find" feature is useful. The following list of types and functions
+should act as a reference to the Go representation of a request, type or reply
+of something you *already know about*. To search the following list in hopes
+of attaining understanding is a quest in folly. For understanding, please see
+the X Protocol Reference Manual: http://goo.gl/aMd2e
+
+*/
+package xgb
diff --git a/nexgb/examples/atom.go b/nexgb/examples/atom.go
deleted file mode 100644
index 2cb7132..0000000
--- a/nexgb/examples/atom.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package main
-
-import (
- // "fmt"
- "log"
-
- "github.com/BurntSushi/xgb"
-)
-
-func init() {
- log.SetFlags(0)
-}
-
-func main() {
- X, err := xgb.NewConn()
- if err != nil {
- log.Fatal(err)
- }
-
- aname := "_NET_ACTIVE_WINDOW"
- atom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply()
- if err != nil {
- log.Fatal(err)
- }
- log.Printf("%d", atom.Atom)
-}
-
diff --git a/nexgb/examples/create-window/main.go b/nexgb/examples/create-window/main.go
new file mode 100644
index 0000000..6996f37
--- /dev/null
+++ b/nexgb/examples/create-window/main.go
@@ -0,0 +1,98 @@
+// Example create-window shows how to create a window, map it, resize it,
+// and listen to structure and key events (i.e., when the window is resized
+// by the window manager, or when key presses/releases are made when the
+// window has focus). The events are printed to stdout.
+package main
+
+import (
+ "fmt"
+
+ "github.com/BurntSushi/xgb"
+)
+
+func main() {
+ X, err := xgb.NewConn()
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ // 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()
+
+ // CreateWindow takes a boatload of parameters.
+ X.CreateWindow(X.DefaultScreen().RootDepth, wid, X.DefaultScreen().Root,
+ 0, 0, 500, 500, 0,
+ xgb.WindowClassInputOutput, X.DefaultScreen().RootVisual,
+ 0, []uint32{})
+
+ // This call to ChangeWindowAttributes could be factored out and
+ // included with the above CreateWindow call, but it is left here for
+ // instructive purposes. It tells X to send us events when the 'structure'
+ // of the window is changed (i.e., when it is resized, mapped, unmapped,
+ // 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,
+ []uint32{ // values must be in the order defined by the protocol
+ 0xffffffff,
+ xgb.EventMaskStructureNotify |
+ xgb.EventMaskKeyPress |
+ xgb.EventMaskKeyRelease})
+
+ // MapWindow makes the window we've created appear on the screen.
+ // We demonstrated the use of a 'checked' request here.
+ // A checked request is a fancy way of saying, "do error handling
+ // synchronously." Namely, if there is a problem with the MapWindow request,
+ // we'll get the error *here*. If we were to do a normal unchecked
+ // request (like the above CreateWindow and ChangeWindowAttributes
+ // requests), then we would only see the error arrive in the main event
+ // loop.
+ //
+ // Typically, checked requests are useful when you need to make sure they
+ // succeed. Since they are synchronous, they incur a round trip cost before
+ // the program can continue, but this is only going to be noticeable if
+ // you're issuing tons of requests in succession.
+ //
+ // Note that requests without replies are by default unchecked while
+ // requests *with* replies are checked by default.
+ 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)
+ }
+
+ // This is an example of an invalid MapWindow request and what an error
+ // looks like.
+ err = X.MapWindowChecked(0).Check()
+ if err != nil {
+ fmt.Printf("Checked Error for mapping window 0x1: %s\n", err)
+ } else { // neva
+ fmt.Printf("Map window 0x1 successful!\n")
+ }
+
+ // Start the main event loop.
+ for {
+ // WaitForEvent either returns an event or an error and never both.
+ // If both are nil, then something went wrong and the loop should be
+ // halted.
+ //
+ // An error can only be seen here as a response to an unchecked
+ // request.
+ ev, xerr := X.WaitForEvent()
+ if ev == nil && xerr == nil {
+ fmt.Println("Both event and error are nil. Exiting...")
+ return
+ }
+
+ if ev != nil {
+ fmt.Printf("Event: %s\n", ev)
+ }
+ if xerr != nil {
+ fmt.Printf("Error: %s\n", xerr)
+ }
+ }
+}
diff --git a/nexgb/examples/doc.go b/nexgb/examples/doc.go
new file mode 100644
index 0000000..80ea5b7
--- /dev/null
+++ b/nexgb/examples/doc.go
@@ -0,0 +1,21 @@
+/*
+Package examples contains a few different use cases of XGB, like creating
+a window, reading properties, and querying for information about multiple
+heads using the Xinerama or RandR extensions.
+
+If you're looking to get started quickly, I recommend checking out the
+create-window example first. It is the most documented and probably covers
+some of the more common bare bones cases of creating windows and responding
+to events.
+
+If you're looking to query information about your window manager,
+get-active-window is a start. However, to do anything extensive requires
+a lot of boiler plate. To that end, I'd recommend use of my higher level
+library, xgbutil: https://github.com/BurntSushi/xgbutil
+
+There are also examples of using the Xinerama and RandR extensions, if you're
+interested in querying information about your active heads. In RandR's case,
+you can also reconfigure your heads, but the example doesn't cover that.
+
+*/
+package documentation
diff --git a/nexgb/examples/get-active-window/main.go b/nexgb/examples/get-active-window/main.go
new file mode 100644
index 0000000..e90563c
--- /dev/null
+++ b/nexgb/examples/get-active-window/main.go
@@ -0,0 +1,57 @@
+// Example get-active-window reads the _NET_ACTIVE_WINDOW property of the root
+// window and uses the result (a window id) to get the name of the window.
+package main
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/BurntSushi/xgb"
+)
+
+func main() {
+ X, err := xgb.NewConn()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Get the window id of the root window.
+ root := X.DefaultScreen().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()
+ 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()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Get the actual value of _NET_ACTIVE_WINDOW.
+ // Note that 'reply.Value' is just a slice of bytes, so we use an
+ // 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()
+ if err != nil {
+ log.Fatal(err)
+ }
+ windowId := xgb.Id(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()
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf("Active window name: %s\n", string(reply.Value))
+}
diff --git a/nexgb/examples/property.go b/nexgb/examples/property.go
deleted file mode 100644
index 45144c7..0000000
--- a/nexgb/examples/property.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package main
-
-import (
- "log"
-
- "github.com/BurntSushi/xgb"
-)
-
-func init() {
- log.SetFlags(0)
-}
-
-func get32(buf []byte) uint32 {
- v := uint32(buf[0])
- v |= uint32(buf[1]) << 8
- v |= uint32(buf[2]) << 16
- v |= uint32(buf[3]) << 24
- return v
-}
-
-func main() {
- X, err := xgb.NewConn()
- if err != nil {
- log.Fatal(err)
- }
-
- root := X.DefaultScreen().Root
-
- aname := "_NET_ACTIVE_WINDOW"
- atom, err := X.InternAtom(true, uint16(len(aname)), aname).Reply()
- if err != nil {
- log.Fatal(err)
- }
-
- reply, err := X.GetProperty(false, root, atom.Atom,
- xgb.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
- if err != nil {
- log.Fatal(err)
- }
- log.Printf("%X", get32(reply.Value))
-}
diff --git a/nexgb/examples/randr.go b/nexgb/examples/randr.go
deleted file mode 100644
index 064856d..0000000
--- a/nexgb/examples/randr.go
+++ /dev/null
@@ -1,48 +0,0 @@
-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/randr/main.go b/nexgb/examples/randr/main.go
new file mode 100644
index 0000000..5c56609
--- /dev/null
+++ b/nexgb/examples/randr/main.go
@@ -0,0 +1,84 @@
+// Example randr uses the randr protocol to get information about the active
+// heads. It also listens for events that are sent when the head configuration
+// changes. Since it listens to events, you'll have to manually kill this
+// process when you're done (i.e., ctrl+c.)
+//
+// While this program is running, if you use 'xrandr' to reconfigure your
+// heads, you should see event information dumped to standard out.
+//
+// For more information, please see the RandR protocol spec:
+// http://www.x.org/releases/X11R7.6/doc/randrproto/randrproto.txt
+package main
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/BurntSushi/xgb"
+)
+
+func main() {
+ X, _ := xgb.NewConn()
+
+ // Every extension must be initialized before it can be used.
+ err := X.RandrInit()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // 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()
+ 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()
+ 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")
+
+ // Iterate through all of the crtcs and show some of their info.
+ 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)
+ }
+
+ // 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()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Listen to events and just dump them to standard out.
+ // A more involved approach will have to read the 'U' field of
+ // RandrNotifyEvent, which is a union (really a struct) of type
+ // RanrNotifyDataUnion.
+ for {
+ ev, err := X.WaitForEvent()
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Println(ev)
+ }
+}
diff --git a/nexgb/examples/seq-nowrap.go b/nexgb/examples/seq-nowrap.go
deleted file mode 100644
index 994a07b..0000000
--- a/nexgb/examples/seq-nowrap.go
+++ /dev/null
@@ -1,29 +0,0 @@
-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
deleted file mode 100644
index b5bc834..0000000
--- a/nexgb/examples/seq-wrap.go
+++ /dev/null
@@ -1,24 +0,0 @@
-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
deleted file mode 100644
index 68fe27b..0000000
--- a/nexgb/examples/window.go
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index 7fe9984..0000000
--- a/nexgb/examples/xinerama.go
+++ /dev/null
@@ -1,29 +0,0 @@
-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)
- }
-}
-
diff --git a/nexgb/examples/xinerama/main.go b/nexgb/examples/xinerama/main.go
new file mode 100644
index 0000000..ec7f46a
--- /dev/null
+++ b/nexgb/examples/xinerama/main.go
@@ -0,0 +1,39 @@
+// Example xinerama shows how to query the geometry of all active heads.
+package main
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/BurntSushi/xgb"
+)
+
+func main() {
+ X, err := xgb.NewConn()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // 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()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Issue a request to get the screen information.
+ reply, err := X.XineramaQueryScreens().Reply()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // reply.Number is the number of active heads, while reply.ScreenInfo
+ // is a slice of XineramaScreenInfo containing the rectangle geometry
+ // of each head.
+ fmt.Printf("Number of heads: %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)
+ }
+}
diff --git a/nexgb/xgb.go b/nexgb/xgb.go
index 581b8fa..c9a265f 100644
--- a/nexgb/xgb.go
+++ b/nexgb/xgb.go
@@ -1,9 +1,3 @@
-// Copyright 2009 The XGB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// The XGB package implements the X11 core protocol.
-// It is based on XCB: http://xcb.freedesktop.org/
package xgb
import (
diff --git a/nexgb/xgb_test.go b/nexgb/xgb_test.go
index 9665164..b70ff5e 100644
--- a/nexgb/xgb_test.go
+++ b/nexgb/xgb_test.go
@@ -45,8 +45,8 @@ func init() {
// Tests
/******************************************************************************/
-// TestSynchronousError purposefully causes a BadLength error in an
-// InternAtom request, and checks it synchronously.
+// TestSynchronousError purposefully causes a BadWindow error in a
+// MapWindow request, and checks it synchronously.
func TestSynchronousError(t *testing.T) {
err := X.MapWindowChecked(0).Check() // resource id 0 is always invalid
if err == nil {
@@ -205,7 +205,7 @@ func TestWindowEvents(t *testing.T) {
// BenchmarkInternAtomsGood shows how many requests with replies
// *should* be sent and gathered from the server. Namely, send as many
// requests as you can at once, then go back and gather up all the replies.
-// More importantly, this approach can exploit parallelism better when
+// More importantly, this approach can exploit parallelism when
// GOMAXPROCS > 1.
// Run with `go test -run 'nomatch' -bench '.*' -cpu 1,2,6` if you have
// multiple cores to see the improvement that parallelism brings.
diff --git a/nexgb/xgbgen/context.go b/nexgb/xgbgen/context.go
index 35dd37e..f1762d3 100644
--- a/nexgb/xgbgen/context.go
+++ b/nexgb/xgbgen/context.go
@@ -86,7 +86,7 @@ func (c *Context) Morph(xmlBytes []byte) {
c.Putln("case err != nil:")
c.Putln("return err")
c.Putln("case !reply.Present:")
- c.Putln("return newError(\"No extension named %s could be found on " +
+ c.Putln("return newError(\"No extension named %s could be found on "+
"on the server.\")", xname)
c.Putln("}")
c.Putln("")
diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go
index 4452408..7c83f1a 100644
--- a/nexgb/xgbgen/field.go
+++ b/nexgb/xgbgen/field.go
@@ -220,7 +220,7 @@ func (f *ExprField) Initialize(p *Protocol) {
// integers. The mask specifies which kinds of values are in the list.
// (i.e., See ConfigureWindow, CreateWindow, ChangeWindowAttributes, etc.)
type ValueField struct {
- Parent interface{}
+ Parent interface{}
MaskType Type
MaskName string
ListName string
@@ -247,7 +247,7 @@ func (f *ValueField) Size() Size {
listSize := newExpressionSize(&Function{
Name: "pad",
Expr: &BinaryOp{
- Op: "*",
+ Op: "*",
Expr1: &Value{v: 4},
Expr2: &PopCount{
Expr: &Function{
diff --git a/nexgb/xgbgen/go_error.go b/nexgb/xgbgen/go_error.go
index 0222289..9e01042 100644
--- a/nexgb/xgbgen/go_error.go
+++ b/nexgb/xgbgen/go_error.go
@@ -133,7 +133,7 @@ func (e *ErrorCopy) ImplementsError(c *Context) {
func ErrorFieldString(c *Context, fields []Field, errName string) {
c.Putln("fieldVals := make([]string, 0, %d)", len(fields))
c.Putln("fieldVals = append(fieldVals, \"NiceName: \" + err.NiceName)")
- c.Putln("fieldVals = append(fieldVals, " +
+ c.Putln("fieldVals = append(fieldVals, "+
"sprintf(\"Sequence: %s\", err.Sequence))", "%d")
for _, field := range fields {
switch field.(type) {
diff --git a/nexgb/xgbgen/go_event.go b/nexgb/xgbgen/go_event.go
index ce54e19..f55e26f 100644
--- a/nexgb/xgbgen/go_event.go
+++ b/nexgb/xgbgen/go_event.go
@@ -165,7 +165,7 @@ func (e *EventCopy) Write(c *Context) {
func EventFieldString(c *Context, fields []Field, evName string) {
c.Putln("fieldVals := make([]string, 0, %d)", len(fields))
if evName != "KeymapNotify" {
- c.Putln("fieldVals = append(fieldVals, " +
+ c.Putln("fieldVals = append(fieldVals, "+
"sprintf(\"Sequence: %s\", v.Sequence))", "%d")
}
for _, field := range fields {
@@ -177,7 +177,8 @@ func EventFieldString(c *Context, fields []Field, evName string) {
case *Base:
case *Resource:
case *TypeDef:
- default: continue
+ default:
+ continue
}
switch field.SrcType() {
diff --git a/nexgb/xgbgen/go_list.go b/nexgb/xgbgen/go_list.go
index 41cfb76..ad859bb 100644
--- a/nexgb/xgbgen/go_list.go
+++ b/nexgb/xgbgen/go_list.go
@@ -107,4 +107,3 @@ func (f *ListField) Write(c *Context, prefix string) {
f.XmlName(), f.Type)
}
}
-
diff --git a/nexgb/xgbgen/go_request_reply.go b/nexgb/xgbgen/go_request_reply.go
index 451667f..a9e624d 100644
--- a/nexgb/xgbgen/go_request_reply.go
+++ b/nexgb/xgbgen/go_request_reply.go
@@ -71,14 +71,14 @@ func (r *Request) ReadReply(c *Context) {
c.Putln("// Waits and reads reply data from request %s", r.SrcName())
c.Putln("func (cook %s) Reply() (*%s, error) {",
r.CookieName(), r.ReplyTypeName())
- c.Putln("buf, err := cook.reply()")
- c.Putln("if err != nil {")
- c.Putln("return nil, err")
- c.Putln("}")
- c.Putln("if buf == nil {")
- c.Putln("return nil, nil")
- c.Putln("}")
- c.Putln("return %s(buf), nil", r.ReplyName())
+ c.Putln("buf, err := cook.reply()")
+ c.Putln("if err != nil {")
+ c.Putln("return nil, err")
+ c.Putln("}")
+ c.Putln("if buf == nil {")
+ c.Putln("return nil, nil")
+ c.Putln("}")
+ c.Putln("return %s(buf), nil", r.ReplyName())
c.Putln("}")
c.Putln("")
@@ -107,7 +107,7 @@ func (r *Request) ReadReply(c *Context) {
func (r *Request) WriteRequest(c *Context) {
writeSize := func() {
- c.Putln("Put16(buf[b:], uint16(size / 4)) "+
+ c.Putln("Put16(buf[b:], uint16(size / 4)) " +
"// write request size in 4-byte units")
c.Putln("b += 2")
c.Putln("")
diff --git a/nexgb/xgbgen/go_union.go b/nexgb/xgbgen/go_union.go
index 9f339af..73e85f7 100644
--- a/nexgb/xgbgen/go_union.go
+++ b/nexgb/xgbgen/go_union.go
@@ -139,4 +139,3 @@ func (u *Union) WriteListSize(c *Context) {
c.Putln("}")
c.Putln("")
}
-
diff --git a/nexgb/xgbgen/protocol.go b/nexgb/xgbgen/protocol.go
index e01bc17..83dde14 100644
--- a/nexgb/xgbgen/protocol.go
+++ b/nexgb/xgbgen/protocol.go
@@ -38,4 +38,3 @@ func (p *Protocol) Initialize() {
func (p *Protocol) isExt() bool {
return strings.ToLower(p.Name) != "xproto"
}
-
diff --git a/nexgb/xgbgen/request_reply.go b/nexgb/xgbgen/request_reply.go
index c7a4cf8..4daa4ac 100644
--- a/nexgb/xgbgen/request_reply.go
+++ b/nexgb/xgbgen/request_reply.go
@@ -13,9 +13,9 @@ type Request struct {
srcName string // The Go name of this request.
xmlName string // The XML name of this request.
Opcode int
- Combine bool // Not currently used.
+ Combine bool // Not currently used.
Fields []Field // All fields in the request.
- Reply *Reply // A reply, if one exists for this request.
+ Reply *Reply // A reply, if one exists for this request.
}
// Initialize creates the proper Go source name for this request.
diff --git a/nexgb/xgbgen/translation.go b/nexgb/xgbgen/translation.go
index 592c152..e4d81bc 100644
--- a/nexgb/xgbgen/translation.go
+++ b/nexgb/xgbgen/translation.go
@@ -339,7 +339,7 @@ func (x *XMLField) Translate(parent interface{}) Field {
}
case "valueparam":
return &ValueField{
- Parent: parent,
+ Parent: parent,
MaskType: newTranslation(x.ValueMaskType),
MaskName: x.ValueMaskName,
ListName: x.ValueListName,
diff --git a/nexgb/xgbgen/xml.go b/nexgb/xgbgen/xml.go
index df21433..440d0a8 100644
--- a/nexgb/xgbgen/xml.go
+++ b/nexgb/xgbgen/xml.go
@@ -17,11 +17,11 @@ type XML struct {
// Types for all top-level elements.
// First are the simple ones.
- Imports XMLImports `xml:"import"`
- Enums []*XMLEnum `xml:"enum"`
- Xids []*XMLXid `xml:"xidtype"`
- XidUnions []*XMLXid `xml:"xidunion"`
- TypeDefs []*XMLTypeDef `xml:"typedef"`
+ Imports XMLImports `xml:"import"`
+ Enums []*XMLEnum `xml:"enum"`
+ Xids []*XMLXid `xml:"xidtype"`
+ XidUnions []*XMLXid `xml:"xidunion"`
+ TypeDefs []*XMLTypeDef `xml:"typedef"`
EventCopies []*XMLEventCopy `xml:"eventcopy"`
ErrorCopies []*XMLErrorCopy `xml:"errorcopy"`
@@ -93,21 +93,21 @@ type XMLErrorCopy struct {
}
type XMLStruct struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Fields []*XMLField `xml:",any"`
}
type XMLUnion struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Fields []*XMLField `xml:",any"`
}
type XMLRequest struct {
- Name string `xml:"name,attr"`
- Opcode int `xml:"opcode,attr"`
- Combine bool `xml:"combine-adjacent,attr"`
+ Name string `xml:"name,attr"`
+ Opcode int `xml:"opcode,attr"`
+ Combine bool `xml:"combine-adjacent,attr"`
Fields []*XMLField `xml:",any"`
- Reply *XMLReply `xml:"reply"`
+ Reply *XMLReply `xml:"reply"`
}
type XMLReply struct {
@@ -115,15 +115,15 @@ type XMLReply struct {
}
type XMLEvent struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
- NoSequence bool `xml:"no-sequence-number,attr"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ NoSequence bool `xml:"no-sequence-number,attr"`
Fields []*XMLField `xml:",any"`
}
type XMLError struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
Fields []*XMLField `xml:",any"`
}