From 0c50dc6241fa21712e041cfa2bfb9db4ccaef10a Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 17:01:42 -0400 Subject: a huge commit. splitting extensions into their own sub-packages. --- nexgb/xtest/xtest.go | 355 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 nexgb/xtest/xtest.go (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go new file mode 100644 index 0000000..e035fe5 --- /dev/null +++ b/nexgb/xtest/xtest.go @@ -0,0 +1,355 @@ +package xtest + +/* + This file was generated by xtest.xml on May 10 2012 4:20:29pm EDT. + This file is automatically generated. Edit at your peril! +*/ + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XTEST extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 5, "XTEST").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XTEST could be found on on the server.") + } + + xgb.ExtLock.Lock() + c.Extensions["XTEST"] = reply.MajorOpcode + for evNum, fun := range xgb.NewExtEventFuncs["XTEST"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XTEST"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + xgb.ExtLock.Unlock() + + return nil +} + +func init() { + xgb.NewExtEventFuncs["XTEST"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) +} + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Card32' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +const ( + CursorNone = 0 + CursorCurrent = 1 +) + +// Request GetVersion +// size: 8 +type GetVersionCookie struct { + *xgb.Cookie +} + +func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) + return GetVersionCookie{cookie} +} + +func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) + return GetVersionCookie{cookie} +} + +// Request reply for GetVersion +// size: 10 +type GetVersionReply struct { + Sequence uint16 + Length uint32 + MajorVersion byte + MinorVersion uint16 +} + +// Waits and reads reply data from request GetVersion +func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getVersionReply(buf), nil +} + +// Read reply into structure from buffer for GetVersion +func getVersionReply(buf []byte) *GetVersionReply { + v := new(GetVersionReply) + b := 1 // skip reply determinant + + v.MajorVersion = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for GetVersion +func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XTEST"] + b += 1 + + buf[b] = 0 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = MajorVersion + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], MinorVersion) + b += 2 + + return buf +} + +// Request CompareCursor +// size: 12 +type CompareCursorCookie struct { + *xgb.Cookie +} + +func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) + return CompareCursorCookie{cookie} +} + +func CompareCursorUnchecked(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) + return CompareCursorCookie{cookie} +} + +// Request reply for CompareCursor +// size: 8 +type CompareCursorReply struct { + Sequence uint16 + Length uint32 + Same bool +} + +// Waits and reads reply data from request CompareCursor +func (cook CompareCursorCookie) Reply() (*CompareCursorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return compareCursorReply(buf), nil +} + +// Read reply into structure from buffer for CompareCursor +func compareCursorReply(buf []byte) *CompareCursorReply { + v := new(CompareCursorReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.Same = true + } else { + v.Same = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + return v +} + +// Write request to wire for CompareCursor +func compareCursorRequest(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XTEST"] + b += 1 + + buf[b] = 1 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + return buf +} + +// Request FakeInput +// size: 36 +type FakeInputCookie struct { + *xgb.Cookie +} + +// Write request to wire for FakeInput +func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) + return FakeInputCookie{cookie} +} + +func FakeInputChecked(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) + return FakeInputCookie{cookie} +} + +func (cook FakeInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FakeInput +func fakeInputRequest(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) []byte { + size := 36 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XTEST"] + b += 1 + + buf[b] = 2 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Type + b += 1 + + buf[b] = Detail + b += 1 + + b += 2 // padding + + xgb.Put32(buf[b:], Time) + b += 4 + + xgb.Put32(buf[b:], uint32(Root)) + b += 4 + + b += 8 // padding + + xgb.Put16(buf[b:], uint16(RootX)) + b += 2 + + xgb.Put16(buf[b:], uint16(RootY)) + b += 2 + + b += 7 // padding + + buf[b] = Deviceid + b += 1 + + return buf +} + +// Request GrabControl +// size: 8 +type GrabControlCookie struct { + *xgb.Cookie +} + +// Write request to wire for GrabControl +func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(grabControlRequest(c, Impervious), cookie) + return GrabControlCookie{cookie} +} + +func GrabControlChecked(c *xgb.Conn, Impervious bool) GrabControlCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(grabControlRequest(c, Impervious), cookie) + return GrabControlCookie{cookie} +} + +func (cook GrabControlCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GrabControl +func grabControlRequest(c *xgb.Conn, Impervious bool) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XTEST"] + b += 1 + + buf[b] = 3 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + if Impervious { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} -- cgit v1.2.3 From a3363755cdfdafdf02d5a772bd47a462e99af057 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 20:06:22 -0400 Subject: adding package header comments --- nexgb/xtest/xtest.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index e035fe5..357b325 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -1,7 +1,8 @@ +// Package xtest is the X client API for the XTEST extension. package xtest /* - This file was generated by xtest.xml on May 10 2012 4:20:29pm EDT. + This file was generated by xtest.xml on May 10 2012 8:04:33pm EDT. This file is automatically generated. Edit at your peril! */ @@ -39,10 +40,6 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Void' - -// Skipping definition for base type 'Byte' - // Skipping definition for base type 'Int8' // Skipping definition for base type 'Card16' @@ -63,6 +60,10 @@ func init() { // Skipping definition for base type 'Int32' +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + const ( CursorNone = 0 CursorCurrent = 1 -- cgit v1.2.3 From c00652934e4ec68016a152b9bea10273b0be8726 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 23:57:34 -0400 Subject: better docs --- nexgb/xtest/xtest.go | 62 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 357b325..e2a2d80 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on May 10 2012 8:04:33pm EDT. + This file was generated by xtest.xml on May 10 2012 11:56:20pm EDT. This file is automatically generated. Edit at your peril! */ @@ -69,34 +69,36 @@ const ( CursorCurrent = 1 ) -// Request GetVersion -// size: 8 +// GetVersionCookie is a cookie used only for GetVersion requests. type GetVersionCookie struct { *xgb.Cookie } +// GetVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { cookie := c.NewCookie(true, true) c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) return GetVersionCookie{cookie} } +// GetVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { cookie := c.NewCookie(false, true) c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) return GetVersionCookie{cookie} } -// Request reply for GetVersion -// size: 10 +// GetVersionReply represents the data returned from a GetVersion request. type GetVersionReply struct { - Sequence uint16 - Length uint32 + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply MajorVersion byte MinorVersion uint16 } -// Waits and reads reply data from request GetVersion +// Reply blocks and returns the reply data for a GetVersion request. func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -108,7 +110,7 @@ func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { return getVersionReply(buf), nil } -// Read reply into structure from buffer for GetVersion +// getVersionReply reads a byte slice into a GetVersionReply value. func getVersionReply(buf []byte) *GetVersionReply { v := new(GetVersionReply) b := 1 // skip reply determinant @@ -129,6 +131,7 @@ func getVersionReply(buf []byte) *GetVersionReply { } // Write request to wire for GetVersion +// getVersionRequest writes a GetVersion request to a byte slice. func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []byte { size := 8 b := 0 @@ -154,33 +157,35 @@ func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []by return buf } -// Request CompareCursor -// size: 12 +// CompareCursorCookie is a cookie used only for CompareCursor requests. type CompareCursorCookie struct { *xgb.Cookie } +// CompareCursor sends a checked request. +// If an error occurs, it will be returned with the reply by calling CompareCursorCookie.Reply() func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { cookie := c.NewCookie(true, true) c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) return CompareCursorCookie{cookie} } +// CompareCursorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CompareCursorUnchecked(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { cookie := c.NewCookie(false, true) c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) return CompareCursorCookie{cookie} } -// Request reply for CompareCursor -// size: 8 +// CompareCursorReply represents the data returned from a CompareCursor request. type CompareCursorReply struct { - Sequence uint16 - Length uint32 + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply Same bool } -// Waits and reads reply data from request CompareCursor +// Reply blocks and returns the reply data for a CompareCursor request. func (cook CompareCursorCookie) Reply() (*CompareCursorReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -192,7 +197,7 @@ func (cook CompareCursorCookie) Reply() (*CompareCursorReply, error) { return compareCursorReply(buf), nil } -// Read reply into structure from buffer for CompareCursor +// compareCursorReply reads a byte slice into a CompareCursorReply value. func compareCursorReply(buf []byte) *CompareCursorReply { v := new(CompareCursorReply) b := 1 // skip reply determinant @@ -214,6 +219,7 @@ func compareCursorReply(buf []byte) *CompareCursorReply { } // Write request to wire for CompareCursor +// compareCursorRequest writes a CompareCursor request to a byte slice. func compareCursorRequest(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) []byte { size := 12 b := 0 @@ -237,30 +243,35 @@ func compareCursorRequest(c *xgb.Conn, Window xproto.Window, Cursor xproto.Curso return buf } -// Request FakeInput -// size: 36 +// FakeInputCookie is a cookie used only for FakeInput requests. type FakeInputCookie struct { *xgb.Cookie } -// Write request to wire for FakeInput +// FakeInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { cookie := c.NewCookie(false, false) c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) return FakeInputCookie{cookie} } +// FakeInputChecked sends a checked request. +// If an error occurs, it can be retrieved using FakeInputCookie.Check() func FakeInputChecked(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { cookie := c.NewCookie(true, false) c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) return FakeInputCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook FakeInputCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for FakeInput +// fakeInputRequest writes a FakeInput request to a byte slice. func fakeInputRequest(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) []byte { size := 36 b := 0 @@ -305,30 +316,35 @@ func fakeInputRequest(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xpr return buf } -// Request GrabControl -// size: 8 +// GrabControlCookie is a cookie used only for GrabControl requests. type GrabControlCookie struct { *xgb.Cookie } -// Write request to wire for GrabControl +// GrabControl sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { cookie := c.NewCookie(false, false) c.NewRequest(grabControlRequest(c, Impervious), cookie) return GrabControlCookie{cookie} } +// GrabControlChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabControlCookie.Check() func GrabControlChecked(c *xgb.Conn, Impervious bool) GrabControlCookie { cookie := c.NewCookie(true, false) c.NewRequest(grabControlRequest(c, Impervious), cookie) return GrabControlCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook GrabControlCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for GrabControl +// grabControlRequest writes a GrabControl request to a byte slice. func grabControlRequest(c *xgb.Conn, Impervious bool) []byte { size := 8 b := 0 -- cgit v1.2.3 From 3e6b3544934cb71e3a3b0edf9bc184241ac1ad7f Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Fri, 11 May 2012 01:58:52 -0400 Subject: add a little more docs for errors --- nexgb/xtest/xtest.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index e2a2d80..8f964e4 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on May 10 2012 11:56:20pm EDT. + This file was generated by xtest.xml on May 11 2012 1:58:37am EDT. This file is automatically generated. Edit at your peril! */ @@ -40,6 +40,16 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + // Skipping definition for base type 'Int8' // Skipping definition for base type 'Card16' @@ -54,16 +64,6 @@ func init() { // Skipping definition for base type 'Float' -// Skipping definition for base type 'Card8' - -// Skipping definition for base type 'Int16' - -// Skipping definition for base type 'Int32' - -// Skipping definition for base type 'Void' - -// Skipping definition for base type 'Byte' - const ( CursorNone = 0 CursorCurrent = 1 -- cgit v1.2.3 From 29942bf078c92fea681e42ca5029592526f00718 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Fri, 11 May 2012 23:58:52 -0400 Subject: panic when an extension request is issued before an extension has been initialized. but give a nice error message for the happy people. --- nexgb/xtest/xtest.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 8f964e4..3fab056 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on May 11 2012 1:58:37am EDT. + This file was generated by xtest.xml on May 11 2012 11:57:20pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,10 +40,6 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Card8' - -// Skipping definition for base type 'Int16' - // Skipping definition for base type 'Int32' // Skipping definition for base type 'Void' @@ -64,6 +60,10 @@ func init() { // Skipping definition for base type 'Float' +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Int16' + const ( CursorNone = 0 CursorCurrent = 1 @@ -77,6 +77,9 @@ type GetVersionCookie struct { // GetVersion sends a checked request. // If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) return GetVersionCookie{cookie} @@ -85,6 +88,9 @@ func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionC // GetVersionUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) return GetVersionCookie{cookie} @@ -165,6 +171,9 @@ type CompareCursorCookie struct { // CompareCursor sends a checked request. // If an error occurs, it will be returned with the reply by calling CompareCursorCookie.Reply() func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'CompareCursor' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) return CompareCursorCookie{cookie} @@ -173,6 +182,9 @@ func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) Comp // CompareCursorUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CompareCursorUnchecked(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'CompareCursor' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) return CompareCursorCookie{cookie} @@ -251,6 +263,9 @@ type FakeInputCookie struct { // FakeInput sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'FakeInput' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) return FakeInputCookie{cookie} @@ -259,6 +274,9 @@ func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Win // FakeInputChecked sends a checked request. // If an error occurs, it can be retrieved using FakeInputCookie.Check() func FakeInputChecked(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'FakeInput' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(fakeInputRequest(c, Type, Detail, Time, Root, RootX, RootY, Deviceid), cookie) return FakeInputCookie{cookie} @@ -324,6 +342,9 @@ type GrabControlCookie struct { // GrabControl sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GrabControl' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(grabControlRequest(c, Impervious), cookie) return GrabControlCookie{cookie} @@ -332,6 +353,9 @@ func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { // GrabControlChecked sends a checked request. // If an error occurs, it can be retrieved using GrabControlCookie.Check() func GrabControlChecked(c *xgb.Conn, Impervious bool) GrabControlCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GrabControl' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(grabControlRequest(c, Impervious), cookie) return GrabControlCookie{cookie} -- cgit v1.2.3 From 4ea94ca0fef7786ce21722cbb02a9cf069bdedd9 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 26 May 2012 18:24:52 -0400 Subject: Bug fix in the generator that was outputting %(MISSING) crud. --- nexgb/xtest/xtest.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 3fab056..3612649 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on May 11 2012 11:57:20pm EDT. + This file was generated by xtest.xml on May 26 2012 6:23:14pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,12 +40,6 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Int32' - -// Skipping definition for base type 'Void' - -// Skipping definition for base type 'Byte' - // Skipping definition for base type 'Int8' // Skipping definition for base type 'Card16' @@ -64,6 +58,12 @@ func init() { // Skipping definition for base type 'Int16' +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + const ( CursorNone = 0 CursorCurrent = 1 -- cgit v1.2.3 From a9eae45cb3977bce5983e817d00d4584d176b044 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Tue, 5 Jun 2012 00:14:34 -0400 Subject: Refresh build. Eh. --- nexgb/xtest/xtest.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 3612649..30d96ec 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on May 26 2012 6:23:14pm EDT. + This file was generated by xtest.xml on Jun 5 2012 12:12:00am EDT. This file is automatically generated. Edit at your peril! */ @@ -40,6 +40,10 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + // Skipping definition for base type 'Int8' // Skipping definition for base type 'Card16' @@ -60,10 +64,6 @@ func init() { // Skipping definition for base type 'Int32' -// Skipping definition for base type 'Void' - -// Skipping definition for base type 'Byte' - const ( CursorNone = 0 CursorCurrent = 1 -- cgit v1.2.3 From 0685fb57e14104ee4ad9f70ec94f787a9a22c028 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:43:26 -0400 Subject: Update to latest xproto XML. --- nexgb/xtest/xtest.go | 212 +++++++++++++++++++++++++-------------------------- 1 file changed, 106 insertions(+), 106 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 30d96ec..505622a 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -2,7 +2,7 @@ package xtest /* - This file was generated by xtest.xml on Jun 5 2012 12:12:00am EDT. + This file was generated by xtest.xml on Aug 11 2013 8:39:44pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,128 +40,34 @@ func init() { xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Void' +const ( + CursorNone = 0 + CursorCurrent = 1 +) -// Skipping definition for base type 'Byte' +// Skipping definition for base type 'Bool' -// Skipping definition for base type 'Int8' +// Skipping definition for base type 'Byte' -// Skipping definition for base type 'Card16' +// Skipping definition for base type 'Card8' // Skipping definition for base type 'Char' -// Skipping definition for base type 'Card32' +// Skipping definition for base type 'Void' // Skipping definition for base type 'Double' -// Skipping definition for base type 'Bool' - // Skipping definition for base type 'Float' -// Skipping definition for base type 'Card8' - // Skipping definition for base type 'Int16' // Skipping definition for base type 'Int32' -const ( - CursorNone = 0 - CursorCurrent = 1 -) - -// GetVersionCookie is a cookie used only for GetVersion requests. -type GetVersionCookie struct { - *xgb.Cookie -} - -// GetVersion sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() -func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { - if _, ok := c.Extensions["XTEST"]; !ok { - panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, true) - c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) - return GetVersionCookie{cookie} -} - -// GetVersionUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { - if _, ok := c.Extensions["XTEST"]; !ok { - panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") - } - cookie := c.NewCookie(false, true) - c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) - return GetVersionCookie{cookie} -} - -// GetVersionReply represents the data returned from a GetVersion request. -type GetVersionReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - MajorVersion byte - MinorVersion uint16 -} - -// Reply blocks and returns the reply data for a GetVersion request. -func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil - } - return getVersionReply(buf), nil -} - -// getVersionReply reads a byte slice into a GetVersionReply value. -func getVersionReply(buf []byte) *GetVersionReply { - v := new(GetVersionReply) - b := 1 // skip reply determinant - - v.MajorVersion = buf[b] - b += 1 - - v.Sequence = xgb.Get16(buf[b:]) - b += 2 - - v.Length = xgb.Get32(buf[b:]) // 4-byte units - b += 4 - - v.MinorVersion = xgb.Get16(buf[b:]) - b += 2 - - return v -} - -// Write request to wire for GetVersion -// getVersionRequest writes a GetVersion request to a byte slice. -func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []byte { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XTEST"] - b += 1 - - buf[b] = 0 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - buf[b] = MajorVersion - b += 1 - - b += 1 // padding +// Skipping definition for base type 'Int8' - xgb.Put16(buf[b:], MinorVersion) - b += 2 +// Skipping definition for base type 'Card16' - return buf -} +// Skipping definition for base type 'Card32' // CompareCursorCookie is a cookie used only for CompareCursor requests. type CompareCursorCookie struct { @@ -334,6 +240,100 @@ func fakeInputRequest(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xpr return buf } +// GetVersionCookie is a cookie used only for GetVersion requests. +type GetVersionCookie struct { + *xgb.Cookie +} + +// GetVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() +func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) + return GetVersionCookie{cookie} +} + +// GetVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + if _, ok := c.Extensions["XTEST"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getVersionRequest(c, MajorVersion, MinorVersion), cookie) + return GetVersionCookie{cookie} +} + +// GetVersionReply represents the data returned from a GetVersion request. +type GetVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + MajorVersion byte + MinorVersion uint16 +} + +// Reply blocks and returns the reply data for a GetVersion request. +func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getVersionReply(buf), nil +} + +// getVersionReply reads a byte slice into a GetVersionReply value. +func getVersionReply(buf []byte) *GetVersionReply { + v := new(GetVersionReply) + b := 1 // skip reply determinant + + v.MajorVersion = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for GetVersion +// getVersionRequest writes a GetVersion request to a byte slice. +func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XTEST"] + b += 1 + + buf[b] = 0 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = MajorVersion + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], MinorVersion) + b += 2 + + return buf +} + // GrabControlCookie is a cookie used only for GrabControl requests. type GrabControlCookie struct { *xgb.Cookie -- cgit v1.2.3 From b06a8ca97625c1134449c3af65d9ac3fb251a613 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:45:36 -0400 Subject: Don't needlessly change source files every time. --- nexgb/xtest/xtest.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 505622a..982e9f9 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -1,10 +1,7 @@ // Package xtest is the X client API for the XTEST extension. package xtest -/* - This file was generated by xtest.xml on Aug 11 2013 8:39:44pm EDT. - This file is automatically generated. Edit at your peril! -*/ +// This file is automatically generated from xtest.xml. Edit at your peril! import ( "github.com/BurntSushi/xgb" -- cgit v1.2.3 From becaf43dcb3e9832c3eb951ff9908ed697868152 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 1 Mar 2016 15:41:38 +0100 Subject: Read/Write mutex for Extensions map --- nexgb/xtest/xtest.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'nexgb/xtest') diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go index 982e9f9..182760e 100644 --- a/nexgb/xtest/xtest.go +++ b/nexgb/xtest/xtest.go @@ -19,16 +19,15 @@ func Init(c *xgb.Conn) error { return xgb.Errorf("No extension named XTEST could be found on on the server.") } - xgb.ExtLock.Lock() + c.ExtLock.Lock() c.Extensions["XTEST"] = reply.MajorOpcode + c.ExtLock.Unlock() for evNum, fun := range xgb.NewExtEventFuncs["XTEST"] { xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun } for errNum, fun := range xgb.NewExtErrorFuncs["XTEST"] { xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun } - xgb.ExtLock.Unlock() - return nil } @@ -74,6 +73,8 @@ type CompareCursorCookie struct { // CompareCursor sends a checked request. // If an error occurs, it will be returned with the reply by calling CompareCursorCookie.Reply() func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'CompareCursor' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -85,6 +86,8 @@ func CompareCursor(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) Comp // CompareCursorUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CompareCursorUnchecked(c *xgb.Conn, Window xproto.Window, Cursor xproto.Cursor) CompareCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'CompareCursor' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -140,7 +143,9 @@ func compareCursorRequest(c *xgb.Conn, Window xproto.Window, Cursor xproto.Curso b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() b += 1 buf[b] = 1 // request opcode @@ -166,6 +171,8 @@ type FakeInputCookie struct { // FakeInput sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'FakeInput' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -177,6 +184,8 @@ func FakeInput(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Win // FakeInputChecked sends a checked request. // If an error occurs, it can be retrieved using FakeInputCookie.Check() func FakeInputChecked(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xproto.Window, RootX int16, RootY int16, Deviceid byte) FakeInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'FakeInput' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -198,7 +207,9 @@ func fakeInputRequest(c *xgb.Conn, Type byte, Detail byte, Time uint32, Root xpr b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() b += 1 buf[b] = 2 // request opcode @@ -245,6 +256,8 @@ type GetVersionCookie struct { // GetVersion sends a checked request. // If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -256,6 +269,8 @@ func GetVersion(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionC // GetVersionUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetVersionUnchecked(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -311,7 +326,9 @@ func getVersionRequest(c *xgb.Conn, MajorVersion byte, MinorVersion uint16) []by b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() b += 1 buf[b] = 0 // request opcode @@ -339,6 +356,8 @@ type GrabControlCookie struct { // GrabControl sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'GrabControl' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -350,6 +369,8 @@ func GrabControl(c *xgb.Conn, Impervious bool) GrabControlCookie { // GrabControlChecked sends a checked request. // If an error occurs, it can be retrieved using GrabControlCookie.Check() func GrabControlChecked(c *xgb.Conn, Impervious bool) GrabControlCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XTEST"]; !ok { panic("Cannot issue request 'GrabControl' using the uninitialized extension 'XTEST'. xtest.Init(connObj) must be called first.") } @@ -371,7 +392,9 @@ func grabControlRequest(c *xgb.Conn, Impervious bool) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() b += 1 buf[b] = 3 // request opcode -- cgit v1.2.3