diff options
71 files changed, 69355 insertions, 0 deletions
diff --git a/nexgb/.gitignore b/nexgb/.gitignore new file mode 100644 index 0000000..179f830 --- /dev/null +++ b/nexgb/.gitignore @@ -0,0 +1,2 @@ +xgbgen/xgbgen +.*.swp diff --git a/nexgb/AUTHORS b/nexgb/AUTHORS new file mode 100644 index 0000000..08fc0cd --- /dev/null +++ b/nexgb/AUTHORS @@ -0,0 +1,18 @@ +Andrew Gallant is the maintainer of this fork. What follows is the original +list of authors for the x-go-binding. + +# This is the official list of XGB authors for copyright purposes. +# This file is distinct from the CONTRIBUTORS files. +# See the latter for an explanation. + +# Names should be added to this file as +# Name or Organization <email address> +# The email address is not required for organizations. + +# Please keep the list sorted. + +Anthony Martin <ality@pbrane.org> +Firmansyah Adiputra <frm.adiputra@gmail.com> +Google Inc. +Scott Lawrence <bytbox@gmail.com> +Tor Andersson <tor.andersson@gmail.com> diff --git a/nexgb/CONTRIBUTORS b/nexgb/CONTRIBUTORS new file mode 100644 index 0000000..46dc4b0 --- /dev/null +++ b/nexgb/CONTRIBUTORS @@ -0,0 +1,39 @@ +Andrew Gallant is the maintainer of this fork. What follows is the original +list of contributors for the x-go-binding. + +# This is the official list of people who can contribute +# (and typically have contributed) code to the XGB repository. +# The AUTHORS file lists the copyright holders; this file +# lists people. For example, Google employees are listed here +# but not in AUTHORS, because Google holds the copyright. +# +# The submission process automatically checks to make sure +# that people submitting code are listed in this file (by email address). +# +# Names should be added to this file only after verifying that +# the individual or the individual's organization has agreed to +# the appropriate Contributor License Agreement, found here: +# +# http://code.google.com/legal/individual-cla-v1.0.html +# http://code.google.com/legal/corporate-cla-v1.0.html +# +# The agreement for individuals can be filled out on the web. +# +# When adding J Random Contributor's name to this file, +# either J's name or J's organization's name should be +# added to the AUTHORS file, depending on whether the +# individual or corporate CLA was used. + +# Names should be added to this file like so: +# Name <email address> + +# Please keep the list sorted. + +Anthony Martin <ality@pbrane.org> +Firmansyah Adiputra <frm.adiputra@gmail.com> +Ian Lance Taylor <iant@golang.org> +Nigel Tao <nigeltao@golang.org> +Robert Griesemer <gri@golang.org> +Russ Cox <rsc@golang.org> +Scott Lawrence <bytbox@gmail.com> +Tor Andersson <tor.andersson@gmail.com> diff --git a/nexgb/LICENSE b/nexgb/LICENSE new file mode 100644 index 0000000..d99cd90 --- /dev/null +++ b/nexgb/LICENSE @@ -0,0 +1,42 @@ +// Copyright (c) 2009 The XGB Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Subject to the terms and conditions of this License, Google hereby +// grants to You a perpetual, worldwide, non-exclusive, no-charge, +// royalty-free, irrevocable (except as stated in this section) patent +// license to make, have made, use, offer to sell, sell, import, and +// otherwise transfer this implementation of XGB, where such license +// applies only to those patent claims licensable by Google that are +// necessarily infringed by use of this implementation of XGB. If You +// institute patent litigation against any entity (including a +// cross-claim or counterclaim in a lawsuit) alleging that this +// implementation of XGB or a Contribution incorporated within this +// implementation of XGB constitutes direct or contributory patent +// infringement, then any patent licenses granted to You under this +// License for this implementation of XGB shall terminate as of the date +// such litigation is filed. diff --git a/nexgb/Makefile b/nexgb/Makefile new file mode 100644 index 0000000..c0ee531 --- /dev/null +++ b/nexgb/Makefile @@ -0,0 +1,80 @@ +# 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. +# i.e., after making a change to the code generator, run 'make' in the +# xgb directory. This will build xgbgen and regenerate each sub-package. +# 'make test' will then run any appropriate tests (just tests xproto right now). +# 'make bench' will test a couple of benchmarks. +# 'make build-all' will then try to build each extension. This isn't strictly +# necessary, but it's a good idea to make sure each sub-package is a valid +# Go package. + +# My path to the X protocol XML descriptions. +ifndef XPROTO +XPROTO=/usr/share/xcb +endif + +# All of the XML files in my /usr/share/xcb directory EXCEPT XKB. -_- +# This is intended to build xgbgen and generate Go code for each supported +# extension. +all: build-xgbgen \ + bigreq.xml composite.xml damage.xml dpms.xml dri2.xml \ + ge.xml glx.xml randr.xml record.xml render.xml res.xml \ + screensaver.xml shape.xml shm.xml xc_misc.xml \ + xevie.xml xf86dri.xml xf86vidmode.xml xfixes.xml xinerama.xml \ + xprint.xml xproto.xml xselinux.xml xtest.xml \ + xvmc.xml xv.xml + +build-xgbgen: + (cd xgbgen && go build) + +# Builds each individual sub-package to make sure its valid Go code. +build-all: bigreq.b composite.b damage.b dpms.b dri2.b ge.b glx.b randr.b \ + record.b render.b res.b screensaver.b shape.b shm.b xcmisc.b \ + xevie.b xf86dri.b xf86vidmode.b xfixes.b xinerama.b \ + xprint.b xproto.b xselinux.b xtest.b xv.b xvmc.b + +%.b: + (cd $* ; go build) + +# Installs each individual sub-package. +install: bigreq.i composite.i damage.i dpms.i dri2.i ge.i glx.i randr.i \ + record.i render.i res.i screensaver.i shape.i shm.i xcmisc.i \ + xevie.i xf86dri.i xf86vidmode.i xfixes.i xinerama.i \ + xprint.i xproto.i xselinux.i xtest.i xv.i xvmc.i + go install + +%.i: + (cd $* ; go install) + +# xc_misc is special because it has an underscore. +# There's probably a way to do this better, but Makefiles aren't my strong suit. +xc_misc.xml: build-xgbgen + mkdir -p xcmisc + xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/xc_misc.xml > xcmisc/xcmisc.go + +%.xml: build-xgbgen + mkdir -p $* + xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/$*.xml > $*/$*.go + +# Just test the xproto core protocol for now. +test: + (cd xproto ; go test) + +# Force all xproto benchmarks to run and no tests. +bench: + (cd xproto ; go test -run 'nomatch' -bench '.*' -cpu 1,2,3,6) + +# gofmt all non-auto-generated code. +# (auto-generated code is already gofmt'd.) +# Also do a column check (80 cols) after a gofmt. +# But don't check columns on auto-generated code, since I don't care if they +# break 80 cols. +gofmt: + gofmt -w *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go + colcheck *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go + +push: + git push origin master + git push github master + diff --git a/nexgb/README b/nexgb/README new file mode 100644 index 0000000..c96a5fb --- /dev/null +++ b/nexgb/README @@ -0,0 +1,54 @@ +XGB is 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 closely modeled after +XCB and xpyb. + +It is thread safe and gets immediate improvement from parallelism when +GOMAXPROCS > 1. (See the benchmarks in xproto/xproto_test.go for evidence.) + +Please see doc.go for more info. + +Note that unless you know you need XGB, you can probably make your life +easier by using a slightly higher level library: xgbutil. + +Quick Usage +=========== +go get github.com/BurntSushi/xgb +go run go/path/src/github.com/BurntSushi/xgb/examples/create-window/main.go + +BurntSushi's Fork +================= +I've forked the XGB repository from Google Code due to inactivty upstream. + +Godoc documentation can be found here: +http://godoc.burntsushi.net/pkg/github.com/BurntSushi/xgb/ + +Much of the code has been rewritten in an effort to support thread safety +and multiple extensions. Namely, go_client.py has been thrown away in favor +of an xgbgen package. + +The biggest parts that *haven't* been rewritten by me are the connection and +authentication handshakes. They're inherently messy, and there's really no +reason to re-work them. The rest of XGB has been completely rewritten. + +I like to release my code under the WTFPL, but since I'm starting with someone +else's work, I'm leaving the original license/contributor/author information +in tact. + +I suppose I can legitimately release xgbgen under the WTFPL. To be fair, it is +at least as complex as XGB itself. *sigh* + +What follows is the original README: + +XGB README +========== +XGB is the X protocol Go language Binding. + +It is the Go equivalent of XCB, the X protocol C-language Binding +(http://xcb.freedesktop.org/). + +Unless otherwise noted, the XGB source files are distributed +under the BSD-style license found in the LICENSE file. + +Contributions should follow the same procedure as for the Go project: +http://golang.org/doc/contribute.html + diff --git a/nexgb/STYLE b/nexgb/STYLE new file mode 100644 index 0000000..b827c3c --- /dev/null +++ b/nexgb/STYLE @@ -0,0 +1,29 @@ +I like to keep all my code to 80 columns or less. I have plenty of screen real +estate, but enjoy 80 columns so that I can have multiple code windows open side +to side and not be plagued by the ugly auto-wrapping of a text editor. + +If you don't oblige me, I will fix any patch you submit to abide 80 columns. + +Note that this style restriction does not preclude gofmt, but introduces a few +peculiarities. The first is that gofmt will occasionally add spacing (typically +to comments) that ends up going over 80 columns. Either shorten the comment or +put it on its own line. + +The second and more common hiccup is when a function definition extends beyond +80 columns. If one adds line breaks to keep it below 80 columns, gofmt will +indent all subsequent lines in a function definition to the same indentation +level of the function body. This results in a less-than-ideal separation +between function definition and function body. To remedy this, simply add a +line break like so: + + func RestackWindowExtra(xu *xgbutil.XUtil, win xproto.Window, stackMode int, + sibling xproto.Window, source int) error { + + return ClientEvent(xu, win, "_NET_RESTACK_WINDOW", source, int(sibling), + stackMode) + } + +Something similar should also be applied to long 'if' or 'for' conditionals, +although it would probably be preferrable to break up the conditional to +smaller chunks with a few helper variables. + diff --git a/nexgb/auth.go b/nexgb/auth.go new file mode 100644 index 0000000..ec51d10 --- /dev/null +++ b/nexgb/auth.go @@ -0,0 +1,110 @@ +package xgb + +/* +auth.go contains functions to facilitate the parsing of .Xauthority files. + +It is largely unmodified from the original XGB package that I forked. +*/ + +import ( + "encoding/binary" + "errors" + "io" + "os" +) + +// readAuthority reads the X authority file for the DISPLAY. +// If hostname == "" or hostname == "localhost", +// then use the system's hostname (as returned by os.Hostname) instead. +func readAuthority(hostname, display string) ( + name string, data []byte, err error) { + + // b is a scratch buffer to use and should be at least 256 bytes long + // (i.e. it should be able to hold a hostname). + b := make([]byte, 256) + + // As per /usr/include/X11/Xauth.h. + const familyLocal = 256 + const familyWild = 65535 + + if len(hostname) == 0 || hostname == "localhost" { + hostname, err = os.Hostname() + if err != nil { + return "", nil, err + } + } + + fname := os.Getenv("XAUTHORITY") + if len(fname) == 0 { + home := os.Getenv("HOME") + if len(home) == 0 { + err = errors.New("Xauthority not found: $XAUTHORITY, $HOME not set") + return "", nil, err + } + fname = home + "/.Xauthority" + } + + r, err := os.Open(fname) + if err != nil { + return "", nil, err + } + defer r.Close() + + for { + var family uint16 + if err := binary.Read(r, binary.BigEndian, &family); err != nil { + return "", nil, err + } + + addr, err := getString(r, b) + if err != nil { + return "", nil, err + } + + disp, err := getString(r, b) + if err != nil { + return "", nil, err + } + + name0, err := getString(r, b) + if err != nil { + return "", nil, err + } + + data0, err := getBytes(r, b) + if err != nil { + return "", nil, err + } + + addrmatch := (family == familyWild) || + (family == familyLocal && addr == hostname) + dispmatch := (disp == "") || (disp == display) + + if addrmatch && dispmatch { + return name0, data0, nil + } + } + panic("unreachable") +} + +func getBytes(r io.Reader, b []byte) ([]byte, error) { + var n uint16 + if err := binary.Read(r, binary.BigEndian, &n); err != nil { + return nil, err + } else if n > uint16(len(b)) { + return nil, errors.New("bytes too long for buffer") + } + + if _, err := io.ReadFull(r, b[0:n]); err != nil { + return nil, err + } + return b[0:n], nil +} + +func getString(r io.Reader, b []byte) (string, error) { + b, err := getBytes(r, b) + if err != nil { + return "", err + } + return string(b), nil +} diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go new file mode 100644 index 0000000..6590376 --- /dev/null +++ b/nexgb/bigreq/bigreq.go @@ -0,0 +1,152 @@ +// Package bigreq is the X client API for the BIG-REQUESTS extension. +package bigreq + +// This file is automatically generated from bigreq.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the BIG-REQUESTS extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 12, "BIG-REQUESTS").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named BIG-REQUESTS could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["BIG-REQUESTS"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["BIG-REQUESTS"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// EnableCookie is a cookie used only for Enable requests. +type EnableCookie struct { + *xgb.Cookie +} + +// Enable sends a checked request. +// If an error occurs, it will be returned with the reply by calling EnableCookie.Reply() +func Enable(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{cookie} +} + +// EnableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func EnableUnchecked(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{cookie} +} + +// EnableReply represents the data returned from a Enable request. +type EnableReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MaximumRequestLength uint32 +} + +// Reply blocks and returns the reply data for a Enable request. +func (cook EnableCookie) Reply() (*EnableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return enableReply(buf), nil +} + +// enableReply reads a byte slice into a EnableReply value. +func enableReply(buf []byte) *EnableReply { + v := new(EnableReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MaximumRequestLength = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for Enable +// enableRequest writes a Enable request to a byte slice. +func enableRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["BIG-REQUESTS"] + c.ExtLock.RUnlock() + 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 + + return buf +} diff --git a/nexgb/composite/composite.go b/nexgb/composite/composite.go new file mode 100644 index 0000000..1373f8b --- /dev/null +++ b/nexgb/composite/composite.go @@ -0,0 +1,721 @@ +// Package composite is the X client API for the Composite extension. +package composite + +// This file is automatically generated from composite.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xfixes" + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the Composite extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 9, "Composite").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named Composite could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["Composite"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["Composite"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["Composite"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["Composite"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["Composite"] = make(map[int]xgb.NewErrorFun) +} + +const ( + RedirectAutomatic = 0 + RedirectManual = 1 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CreateRegionFromBorderClipCookie is a cookie used only for CreateRegionFromBorderClip requests. +type CreateRegionFromBorderClipCookie struct { + *xgb.Cookie +} + +// CreateRegionFromBorderClip sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegionFromBorderClip(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) CreateRegionFromBorderClipCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'CreateRegionFromBorderClip' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionFromBorderClipRequest(c, Region, Window), cookie) + return CreateRegionFromBorderClipCookie{cookie} +} + +// CreateRegionFromBorderClipChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionFromBorderClipCookie.Check() +func CreateRegionFromBorderClipChecked(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) CreateRegionFromBorderClipCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'CreateRegionFromBorderClip' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionFromBorderClipRequest(c, Region, Window), cookie) + return CreateRegionFromBorderClipCookie{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 CreateRegionFromBorderClipCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegionFromBorderClip +// createRegionFromBorderClipRequest writes a CreateRegionFromBorderClip request to a byte slice. +func createRegionFromBorderClipRequest(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Region)) + b += 4 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// GetOverlayWindowCookie is a cookie used only for GetOverlayWindow requests. +type GetOverlayWindowCookie struct { + *xgb.Cookie +} + +// GetOverlayWindow sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetOverlayWindowCookie.Reply() +func GetOverlayWindow(c *xgb.Conn, Window xproto.Window) GetOverlayWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'GetOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getOverlayWindowRequest(c, Window), cookie) + return GetOverlayWindowCookie{cookie} +} + +// GetOverlayWindowUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetOverlayWindowUnchecked(c *xgb.Conn, Window xproto.Window) GetOverlayWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'GetOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getOverlayWindowRequest(c, Window), cookie) + return GetOverlayWindowCookie{cookie} +} + +// GetOverlayWindowReply represents the data returned from a GetOverlayWindow request. +type GetOverlayWindowReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + OverlayWin xproto.Window + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a GetOverlayWindow request. +func (cook GetOverlayWindowCookie) Reply() (*GetOverlayWindowReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getOverlayWindowReply(buf), nil +} + +// getOverlayWindowReply reads a byte slice into a GetOverlayWindowReply value. +func getOverlayWindowReply(buf []byte) *GetOverlayWindowReply { + v := new(GetOverlayWindowReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.OverlayWin = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for GetOverlayWindow +// getOverlayWindowRequest writes a GetOverlayWindow request to a byte slice. +func getOverlayWindowRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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 + + return buf +} + +// NameWindowPixmapCookie is a cookie used only for NameWindowPixmap requests. +type NameWindowPixmapCookie struct { + *xgb.Cookie +} + +// NameWindowPixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func NameWindowPixmap(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) NameWindowPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'NameWindowPixmap' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(nameWindowPixmapRequest(c, Window, Pixmap), cookie) + return NameWindowPixmapCookie{cookie} +} + +// NameWindowPixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using NameWindowPixmapCookie.Check() +func NameWindowPixmapChecked(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) NameWindowPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'NameWindowPixmap' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(nameWindowPixmapRequest(c, Window, Pixmap), cookie) + return NameWindowPixmapCookie{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 NameWindowPixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for NameWindowPixmap +// nameWindowPixmapRequest writes a NameWindowPixmap request to a byte slice. +func nameWindowPixmapRequest(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Pixmap)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], ClientMajorVersion) + b += 4 + + xgb.Put32(buf[b:], ClientMinorVersion) + b += 4 + + return buf +} + +// RedirectSubwindowsCookie is a cookie used only for RedirectSubwindows requests. +type RedirectSubwindowsCookie struct { + *xgb.Cookie +} + +// RedirectSubwindows sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RedirectSubwindows(c *xgb.Conn, Window xproto.Window, Update byte) RedirectSubwindowsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'RedirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(redirectSubwindowsRequest(c, Window, Update), cookie) + return RedirectSubwindowsCookie{cookie} +} + +// RedirectSubwindowsChecked sends a checked request. +// If an error occurs, it can be retrieved using RedirectSubwindowsCookie.Check() +func RedirectSubwindowsChecked(c *xgb.Conn, Window xproto.Window, Update byte) RedirectSubwindowsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'RedirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(redirectSubwindowsRequest(c, Window, Update), cookie) + return RedirectSubwindowsCookie{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 RedirectSubwindowsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RedirectSubwindows +// redirectSubwindowsRequest writes a RedirectSubwindows request to a byte slice. +func redirectSubwindowsRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + buf[b] = Update + b += 1 + + b += 3 // padding + + return buf +} + +// RedirectWindowCookie is a cookie used only for RedirectWindow requests. +type RedirectWindowCookie struct { + *xgb.Cookie +} + +// RedirectWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RedirectWindow(c *xgb.Conn, Window xproto.Window, Update byte) RedirectWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'RedirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(redirectWindowRequest(c, Window, Update), cookie) + return RedirectWindowCookie{cookie} +} + +// RedirectWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using RedirectWindowCookie.Check() +func RedirectWindowChecked(c *xgb.Conn, Window xproto.Window, Update byte) RedirectWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'RedirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(redirectWindowRequest(c, Window, Update), cookie) + return RedirectWindowCookie{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 RedirectWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RedirectWindow +// redirectWindowRequest writes a RedirectWindow request to a byte slice. +func redirectWindowRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + 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 + + buf[b] = Update + b += 1 + + b += 3 // padding + + return buf +} + +// ReleaseOverlayWindowCookie is a cookie used only for ReleaseOverlayWindow requests. +type ReleaseOverlayWindowCookie struct { + *xgb.Cookie +} + +// ReleaseOverlayWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ReleaseOverlayWindow(c *xgb.Conn, Window xproto.Window) ReleaseOverlayWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'ReleaseOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(releaseOverlayWindowRequest(c, Window), cookie) + return ReleaseOverlayWindowCookie{cookie} +} + +// ReleaseOverlayWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using ReleaseOverlayWindowCookie.Check() +func ReleaseOverlayWindowChecked(c *xgb.Conn, Window xproto.Window) ReleaseOverlayWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'ReleaseOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(releaseOverlayWindowRequest(c, Window), cookie) + return ReleaseOverlayWindowCookie{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 ReleaseOverlayWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ReleaseOverlayWindow +// releaseOverlayWindowRequest writes a ReleaseOverlayWindow request to a byte slice. +func releaseOverlayWindowRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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 + + return buf +} + +// UnredirectSubwindowsCookie is a cookie used only for UnredirectSubwindows requests. +type UnredirectSubwindowsCookie struct { + *xgb.Cookie +} + +// UnredirectSubwindows sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnredirectSubwindows(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectSubwindowsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'UnredirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(unredirectSubwindowsRequest(c, Window, Update), cookie) + return UnredirectSubwindowsCookie{cookie} +} + +// UnredirectSubwindowsChecked sends a checked request. +// If an error occurs, it can be retrieved using UnredirectSubwindowsCookie.Check() +func UnredirectSubwindowsChecked(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectSubwindowsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'UnredirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(unredirectSubwindowsRequest(c, Window, Update), cookie) + return UnredirectSubwindowsCookie{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 UnredirectSubwindowsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnredirectSubwindows +// unredirectSubwindowsRequest writes a UnredirectSubwindows request to a byte slice. +func unredirectSubwindowsRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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 + + buf[b] = Update + b += 1 + + b += 3 // padding + + return buf +} + +// UnredirectWindowCookie is a cookie used only for UnredirectWindow requests. +type UnredirectWindowCookie struct { + *xgb.Cookie +} + +// UnredirectWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnredirectWindow(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'UnredirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(unredirectWindowRequest(c, Window, Update), cookie) + return UnredirectWindowCookie{cookie} +} + +// UnredirectWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using UnredirectWindowCookie.Check() +func UnredirectWindowChecked(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Composite"]; !ok { + panic("Cannot issue request 'UnredirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(unredirectWindowRequest(c, Window, Update), cookie) + return UnredirectWindowCookie{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 UnredirectWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnredirectWindow +// unredirectWindowRequest writes a UnredirectWindow request to a byte slice. +func unredirectWindowRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Composite"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + buf[b] = Update + b += 1 + + b += 3 // padding + + return buf +} diff --git a/nexgb/conn.go b/nexgb/conn.go new file mode 100644 index 0000000..1b7d838 --- /dev/null +++ b/nexgb/conn.go @@ -0,0 +1,185 @@ +package xgb + +/* +conn.go contains a couple of functions that do some real dirty work related +to the initial connection handshake with X. + +This code is largely unmodified from the original XGB package that I forked. +*/ + +import ( + "errors" + "fmt" + "io" + "net" + "os" + "strconv" + "strings" +) + +// connect connects to the X server given in the 'display' string, +// and does all the necessary setup handshaking. +// If 'display' is empty it will be taken from os.Getenv("DISPLAY"). +// Note that you should read and understand the "Connection Setup" of the +// X Protocol Reference Manual before changing this function: +// http://goo.gl/4zGQg +func (c *Conn) connect(display string) error { + err := c.dial(display) + if err != nil { + return err + } + + return c.postConnect() +} + +// connect init from to the net.Conn, +func (c *Conn) connectNet(netConn net.Conn) error { + c.conn = netConn + return c.postConnect() +} + +// do the postConnect action after Conn get it's underly net.Conn +func (c *Conn) postConnect() error { + // Get authentication data + authName, authData, err := readAuthority(c.host, c.display) + noauth := false + if err != nil { + Logger.Printf("Could not get authority info: %v", err) + Logger.Println("Trying connection without authority info...") + authName = "" + authData = []byte{} + noauth = true + } + + // Assume that the authentication protocol is "MIT-MAGIC-COOKIE-1". + if !noauth && (authName != "MIT-MAGIC-COOKIE-1" || len(authData) != 16) { + return errors.New("unsupported auth protocol " + authName) + } + + buf := make([]byte, 12+Pad(len(authName))+Pad(len(authData))) + buf[0] = 0x6c + buf[1] = 0 + Put16(buf[2:], 11) + Put16(buf[4:], 0) + Put16(buf[6:], uint16(len(authName))) + Put16(buf[8:], uint16(len(authData))) + Put16(buf[10:], 0) + copy(buf[12:], []byte(authName)) + copy(buf[12+Pad(len(authName)):], authData) + if _, err = c.conn.Write(buf); err != nil { + return err + } + + head := make([]byte, 8) + if _, err = io.ReadFull(c.conn, head[0:8]); err != nil { + return err + } + code := head[0] + reasonLen := head[1] + major := Get16(head[2:]) + minor := Get16(head[4:]) + dataLen := Get16(head[6:]) + + if major != 11 || minor != 0 { + return fmt.Errorf("x protocol version mismatch: %d.%d", major, minor) + } + + buf = make([]byte, int(dataLen)*4+8, int(dataLen)*4+8) + copy(buf, head) + if _, err = io.ReadFull(c.conn, buf[8:]); err != nil { + return err + } + + if code == 0 { + reason := buf[8 : 8+reasonLen] + return fmt.Errorf("x protocol authentication refused: %s", + string(reason)) + } + + // Unfortunately, it isn't really feasible to read the setup bytes here, + // since the code to do so is in a different package. + // Users must call 'xproto.Setup(X)' to get the setup info. + c.SetupBytes = buf + + // But also read stuff that we *need* to get started. + c.setupResourceIdBase = Get32(buf[12:]) + c.setupResourceIdMask = Get32(buf[16:]) + + return nil +} + +// dial initializes the actual net connection with X. +func (c *Conn) dial(display string) error { + if len(display) == 0 { + display = os.Getenv("DISPLAY") + } + + display0 := display + if len(display) == 0 { + return errors.New("empty display string") + } + + colonIdx := strings.LastIndex(display, ":") + if colonIdx < 0 { + return errors.New("bad display string: " + display0) + } + + var protocol, socket string + + if display[0] == '/' { + socket = display[0:colonIdx] + } else { + slashIdx := strings.LastIndex(display, "/") + if slashIdx >= 0 { + protocol = display[0:slashIdx] + c.host = display[slashIdx+1 : colonIdx] + } else { + c.host = display[0:colonIdx] + } + } + + display = display[colonIdx+1 : len(display)] + if len(display) == 0 { + return errors.New("bad display string: " + display0) + } + + var scr string + dotIdx := strings.LastIndex(display, ".") + if dotIdx < 0 { + c.display = display[0:] + } else { + c.display = display[0:dotIdx] + scr = display[dotIdx+1:] + } + + var err error + c.DisplayNumber, err = strconv.Atoi(c.display) + if err != nil || c.DisplayNumber < 0 { + return errors.New("bad display string: " + display0) + } + + if len(scr) != 0 { + c.DefaultScreen, err = strconv.Atoi(scr) + if err != nil { + return errors.New("bad display string: " + display0) + } + } + + // Connect to server + if len(socket) != 0 { + c.conn, err = net.Dial("unix", socket+":"+c.display) + } else if len(c.host) != 0 { + if protocol == "" { + protocol = "tcp" + } + c.conn, err = net.Dial(protocol, + c.host+":"+strconv.Itoa(6000+c.DisplayNumber)) + } else { + c.conn, err = net.Dial("unix", "/tmp/.X11-unix/X"+c.display) + } + + if err != nil { + return errors.New("cannot connect to " + display0 + ": " + err.Error()) + } + return nil +} diff --git a/nexgb/cookie.go b/nexgb/cookie.go new file mode 100644 index 0000000..d5cdb29 --- /dev/null +++ b/nexgb/cookie.go @@ -0,0 +1,165 @@ +package xgb + +import ( + "errors" +) + +// Cookie is the internal representation of a cookie, where one is generated +// for *every* request sent by XGB. +// 'cookie' is most frequently used by embedding it into a more specific +// kind of cookie, i.e., 'GetInputFocusCookie'. +type Cookie struct { + conn *Conn + Sequence uint16 + replyChan chan []byte + errorChan chan error + pingChan chan bool +} + +// NewCookie creates a new cookie with the correct channels initialized +// depending upon the values of 'checked' and 'reply'. Together, there are +// four different kinds of cookies. (See more detailed comments in the +// function for more info on those.) +// Note that a sequence number is not set until just before the request +// corresponding to this cookie is sent over the wire. +// +// Unless you're building requests from bytes by hand, this method should +// not be used. +func (c *Conn) NewCookie(checked, reply bool) *Cookie { + cookie := &Cookie{ + conn: c, + Sequence: 0, // we add the sequence id just before sending a request + replyChan: nil, + errorChan: nil, + pingChan: nil, + } + + // There are four different kinds of cookies: + // Checked requests with replies get a reply channel and an error channel. + // Unchecked requests with replies get a reply channel and a ping channel. + // Checked requests w/o replies get a ping channel and an error channel. + // Unchecked requests w/o replies get no channels. + // The reply channel is used to send reply data. + // The error channel is used to send error data. + // The ping channel is used when one of the 'reply' or 'error' channels + // is missing but the other is present. The ping channel is way to force + // the blocking to stop and basically say "the error has been received + // in the main event loop" (when the ping channel is coupled with a reply + // channel) or "the request you made that has no reply was successful" + // (when the ping channel is coupled with an error channel). + if checked { + cookie.errorChan = make(chan error, 1) + if !reply { + cookie.pingChan = make(chan bool, 1) + } + } + if reply { + cookie.replyChan = make(chan []byte, 1) + if !checked { + cookie.pingChan = make(chan bool, 1) + } + } + + return cookie +} + +// Reply detects whether this is a checked or unchecked cookie, and calls +// 'replyChecked' or 'replyUnchecked' appropriately. +// +// Unless you're building requests from bytes by hand, this method should +// not be used. +func (c Cookie) Reply() ([]byte, error) { + // checked + if c.errorChan != nil { + return c.replyChecked() + } + return c.replyUnchecked() +} + +// replyChecked waits for a response on either the replyChan or errorChan +// channels. If the former arrives, the bytes are returned with a nil error. +// If the latter arrives, no bytes are returned (nil) and the error received +// is returned. +// +// Unless you're building requests from bytes by hand, this method should +// not be used. +func (c Cookie) replyChecked() ([]byte, error) { + if c.replyChan == nil { + return nil, errors.New("Cannot call 'replyChecked' on a cookie that " + + "is not expecting a *reply* or an error.") + } + if c.errorChan == nil { + return nil, errors.New("Cannot call 'replyChecked' on a cookie that " + + "is not expecting a reply or an *error*.") + } + + select { + case reply := <-c.replyChan: + return reply, nil + case err := <-c.errorChan: + return nil, err + } +} + +// replyUnchecked waits for a response on either the replyChan or pingChan +// channels. If the former arrives, the bytes are returned with a nil error. +// If the latter arrives, no bytes are returned (nil) and a nil error +// is returned. (In the latter case, the corresponding error can be retrieved +// from (Wait|Poll)ForEvent asynchronously.) +// In all honesty, you *probably* don't want to use this method. +// +// Unless you're building requests from bytes by hand, this method should +// not be used. +func (c Cookie) replyUnchecked() ([]byte, error) { + if c.replyChan == nil { + return nil, errors.New("Cannot call 'replyUnchecked' on a cookie " + + "that is not expecting a *reply*.") + } + + select { + case reply := <-c.replyChan: + return reply, nil + case <-c.pingChan: + return nil, nil + } +} + +// Check is used for checked requests that have no replies. It is a mechanism +// by which to report "success" or "error" in a synchronous fashion. (Therefore, +// unchecked requests without replies cannot use this method.) +// If the request causes an error, it is sent to this cookie's errorChan. +// If the request was successful, there is no response from the server. +// Thus, pingChan is sent a value when the *next* reply is read. +// If no more replies are being processed, we force a round trip request with +// GetInputFocus. +// +// Unless you're building requests from bytes by hand, this method should +// not be used. +func (c Cookie) Check() error { + if c.replyChan != nil { + return errors.New("Cannot call 'Check' on a cookie that is " + + "expecting a *reply*. Use 'Reply' instead.") + } + if c.errorChan == nil { + return errors.New("Cannot call 'Check' on a cookie that is " + + "not expecting a possible *error*.") + } + + // First do a quick non-blocking check to see if we've been pinged. + select { + case err := <-c.errorChan: + return err + case <-c.pingChan: + return nil + default: + } + + // Now force a round trip and try again, but block this time. + c.conn.Sync() + select { + case err := <-c.errorChan: + return err + case <-c.pingChan: + return nil + } +} diff --git a/nexgb/damage/damage.go b/nexgb/damage/damage.go new file mode 100644 index 0000000..26eca04 --- /dev/null +++ b/nexgb/damage/damage.go @@ -0,0 +1,592 @@ +// Package damage is the X client API for the DAMAGE extension. +package damage + +// This file is automatically generated from damage.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xfixes" + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the DAMAGE extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "DAMAGE").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named DAMAGE could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["DAMAGE"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["DAMAGE"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["DAMAGE"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["DAMAGE"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["DAMAGE"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadDamage is the error number for a BadBadDamage. +const BadBadDamage = 0 + +type BadDamageError struct { + Sequence uint16 + NiceName string +} + +// BadDamageErrorNew constructs a BadDamageError value that implements xgb.Error from a byte slice. +func BadDamageErrorNew(buf []byte) xgb.Error { + v := BadDamageError{} + v.NiceName = "BadDamage" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadDamage error. +// This is mostly used internally. +func (err BadDamageError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadDamage error. If no bad value exists, 0 is returned. +func (err BadDamageError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadDamage error. + +func (err BadDamageError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadDamage {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["DAMAGE"][0] = BadDamageErrorNew +} + +type Damage uint32 + +func NewDamageId(c *xgb.Conn) (Damage, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Damage(id), nil +} + +// Notify is the event number for a NotifyEvent. +const Notify = 0 + +type NotifyEvent struct { + Sequence uint16 + Level byte + Drawable xproto.Drawable + Damage Damage + Timestamp xproto.Timestamp + Area xproto.Rectangle + Geometry xproto.Rectangle +} + +// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. +func NotifyEventNew(buf []byte) xgb.Event { + v := NotifyEvent{} + b := 1 // don't read event number + + v.Level = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.Damage = Damage(xgb.Get32(buf[b:])) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Area = xproto.Rectangle{} + b += xproto.RectangleRead(buf[b:], &v.Area) + + v.Geometry = xproto.Rectangle{} + b += xproto.RectangleRead(buf[b:], &v.Geometry) + + return v +} + +// Bytes writes a NotifyEvent value to a byte slice. +func (v NotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.Level + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Damage)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + { + structBytes := v.Area.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.Geometry.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf +} + +// SequenceId returns the sequence id attached to the Notify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NotifyEvent. +func (v NotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Level: %d", v.Level)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("Damage: %d", v.Damage)) + fieldVals = append(fieldVals, xgb.Sprintf("Timestamp: %d", v.Timestamp)) + return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["DAMAGE"][0] = NotifyEventNew +} + +const ( + ReportLevelRawRectangles = 0 + ReportLevelDeltaRectangles = 1 + ReportLevelBoundingBox = 2 + ReportLevelNonEmpty = 3 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AddCookie is a cookie used only for Add requests. +type AddCookie struct { + *xgb.Cookie +} + +// Add sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Add(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) AddCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Add' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(addRequest(c, Drawable, Region), cookie) + return AddCookie{cookie} +} + +// AddChecked sends a checked request. +// If an error occurs, it can be retrieved using AddCookie.Check() +func AddChecked(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) AddCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Add' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(addRequest(c, Drawable, Region), cookie) + return AddCookie{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 AddCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Add +// addRequest writes a Add request to a byte slice. +func addRequest(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DAMAGE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Region)) + b += 4 + + return buf +} + +// CreateCookie is a cookie used only for Create requests. +type CreateCookie struct { + *xgb.Cookie +} + +// Create sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Create(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) CreateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Create' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRequest(c, Damage, Drawable, Level), cookie) + return CreateCookie{cookie} +} + +// CreateChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateCookie.Check() +func CreateChecked(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) CreateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Create' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRequest(c, Damage, Drawable, Level), cookie) + return CreateCookie{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 CreateCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Create +// createRequest writes a Create request to a byte slice. +func createRequest(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DAMAGE"] + c.ExtLock.RUnlock() + 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(Damage)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + buf[b] = Level + b += 1 + + b += 3 // padding + + return buf +} + +// DestroyCookie is a cookie used only for Destroy requests. +type DestroyCookie struct { + *xgb.Cookie +} + +// Destroy sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Destroy(c *xgb.Conn, Damage Damage) DestroyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Destroy' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyRequest(c, Damage), cookie) + return DestroyCookie{cookie} +} + +// DestroyChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyCookie.Check() +func DestroyChecked(c *xgb.Conn, Damage Damage) DestroyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Destroy' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyRequest(c, Damage), cookie) + return DestroyCookie{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 DestroyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Destroy +// destroyRequest writes a Destroy request to a byte slice. +func destroyRequest(c *xgb.Conn, Damage Damage) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DAMAGE"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Damage)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DAMAGE"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], ClientMajorVersion) + b += 4 + + xgb.Put32(buf[b:], ClientMinorVersion) + b += 4 + + return buf +} + +// SubtractCookie is a cookie used only for Subtract requests. +type SubtractCookie struct { + *xgb.Cookie +} + +// Subtract sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Subtract(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) SubtractCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Subtract' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(subtractRequest(c, Damage, Repair, Parts), cookie) + return SubtractCookie{cookie} +} + +// SubtractChecked sends a checked request. +// If an error occurs, it can be retrieved using SubtractCookie.Check() +func SubtractChecked(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) SubtractCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DAMAGE"]; !ok { + panic("Cannot issue request 'Subtract' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(subtractRequest(c, Damage, Repair, Parts), cookie) + return SubtractCookie{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 SubtractCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Subtract +// subtractRequest writes a Subtract request to a byte slice. +func subtractRequest(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DAMAGE"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Damage)) + b += 4 + + xgb.Put32(buf[b:], uint32(Repair)) + b += 4 + + xgb.Put32(buf[b:], uint32(Parts)) + b += 4 + + return buf +} diff --git a/nexgb/doc.go b/nexgb/doc.go new file mode 100644 index 0000000..64540e9 --- /dev/null +++ b/nexgb/doc.go @@ -0,0 +1,146 @@ +/* +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" + "github.com/BurntSushi/xgb/xproto" + ) + + func main() { + X, err := xgb.NewConn() + if err != nil { + fmt.Println(err) + return + } + + wid, _ := xproto.NewWindowId(X) + screen := xproto.Setup(X).DefaultScreen(X) + xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root, + 0, 0, 500, 500, 0, + xproto.WindowClassInputOutput, screen.RootVisual, + xproto.CwBackPixel | xproto.CwEventMask, + []uint32{ // values must be in the order defined by the protocol + 0xffffffff, + xproto.EventMaskStructureNotify | + xproto.EventMaskKeyPress | + xproto.EventMaskKeyRelease}) + + xproto.MapWindow(X, 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" + "github.com/BurntSushi/xgb/xinerama" + ) + + 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 = xinerama.Init(X) + if err != nil { + log.Fatal(err) + } + + reply, err := xinerama.QueryScreens(X).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 xproto/xproto_test.go. + +Tests + +xproto/xproto_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. + +*/ +package xgb diff --git a/nexgb/dpms/dpms.go b/nexgb/dpms/dpms.go new file mode 100644 index 0000000..4bf5883 --- /dev/null +++ b/nexgb/dpms/dpms.go @@ -0,0 +1,715 @@ +// Package dpms is the X client API for the DPMS extension. +package dpms + +// This file is automatically generated from dpms.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the DPMS extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 4, "DPMS").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named DPMS could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["DPMS"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["DPMS"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["DPMS"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["DPMS"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["DPMS"] = make(map[int]xgb.NewErrorFun) +} + +const ( + DPMSModeOn = 0 + DPMSModeStandby = 1 + DPMSModeSuspend = 2 + DPMSModeOff = 3 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CapableCookie is a cookie used only for Capable requests. +type CapableCookie struct { + *xgb.Cookie +} + +// Capable sends a checked request. +// If an error occurs, it will be returned with the reply by calling CapableCookie.Reply() +func Capable(c *xgb.Conn) CapableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Capable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(capableRequest(c), cookie) + return CapableCookie{cookie} +} + +// CapableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CapableUnchecked(c *xgb.Conn) CapableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Capable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(capableRequest(c), cookie) + return CapableCookie{cookie} +} + +// CapableReply represents the data returned from a Capable request. +type CapableReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Capable bool + // padding: 23 bytes +} + +// Reply blocks and returns the reply data for a Capable request. +func (cook CapableCookie) Reply() (*CapableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return capableReply(buf), nil +} + +// capableReply reads a byte slice into a CapableReply value. +func capableReply(buf []byte) *CapableReply { + v := new(CapableReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.Capable = true + } else { + v.Capable = false + } + b += 1 + + b += 23 // padding + + return v +} + +// Write request to wire for Capable +// capableRequest writes a Capable request to a byte slice. +func capableRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// DisableCookie is a cookie used only for Disable requests. +type DisableCookie struct { + *xgb.Cookie +} + +// Disable sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Disable(c *xgb.Conn) DisableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Disable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(disableRequest(c), cookie) + return DisableCookie{cookie} +} + +// DisableChecked sends a checked request. +// If an error occurs, it can be retrieved using DisableCookie.Check() +func DisableChecked(c *xgb.Conn) DisableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Disable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(disableRequest(c), cookie) + return DisableCookie{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 DisableCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Disable +// disableRequest writes a Disable request to a byte slice. +func disableRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// EnableCookie is a cookie used only for Enable requests. +type EnableCookie struct { + *xgb.Cookie +} + +// Enable sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Enable(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{cookie} +} + +// EnableChecked sends a checked request. +// If an error occurs, it can be retrieved using EnableCookie.Check() +func EnableChecked(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{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 EnableCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Enable +// enableRequest writes a Enable request to a byte slice. +func enableRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ForceLevelCookie is a cookie used only for ForceLevel requests. +type ForceLevelCookie struct { + *xgb.Cookie +} + +// ForceLevel sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ForceLevel(c *xgb.Conn, PowerLevel uint16) ForceLevelCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'ForceLevel' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(forceLevelRequest(c, PowerLevel), cookie) + return ForceLevelCookie{cookie} +} + +// ForceLevelChecked sends a checked request. +// If an error occurs, it can be retrieved using ForceLevelCookie.Check() +func ForceLevelChecked(c *xgb.Conn, PowerLevel uint16) ForceLevelCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'ForceLevel' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(forceLevelRequest(c, PowerLevel), cookie) + return ForceLevelCookie{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 ForceLevelCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ForceLevel +// forceLevelRequest writes a ForceLevel request to a byte slice. +func forceLevelRequest(c *xgb.Conn, PowerLevel uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], PowerLevel) + b += 2 + + return buf +} + +// GetTimeoutsCookie is a cookie used only for GetTimeouts requests. +type GetTimeoutsCookie struct { + *xgb.Cookie +} + +// GetTimeouts sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTimeoutsCookie.Reply() +func GetTimeouts(c *xgb.Conn) GetTimeoutsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'GetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTimeoutsRequest(c), cookie) + return GetTimeoutsCookie{cookie} +} + +// GetTimeoutsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTimeoutsUnchecked(c *xgb.Conn) GetTimeoutsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'GetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTimeoutsRequest(c), cookie) + return GetTimeoutsCookie{cookie} +} + +// GetTimeoutsReply represents the data returned from a GetTimeouts request. +type GetTimeoutsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + StandbyTimeout uint16 + SuspendTimeout uint16 + OffTimeout uint16 + // padding: 18 bytes +} + +// Reply blocks and returns the reply data for a GetTimeouts request. +func (cook GetTimeoutsCookie) Reply() (*GetTimeoutsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTimeoutsReply(buf), nil +} + +// getTimeoutsReply reads a byte slice into a GetTimeoutsReply value. +func getTimeoutsReply(buf []byte) *GetTimeoutsReply { + v := new(GetTimeoutsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.StandbyTimeout = xgb.Get16(buf[b:]) + b += 2 + + v.SuspendTimeout = xgb.Get16(buf[b:]) + b += 2 + + v.OffTimeout = xgb.Get16(buf[b:]) + b += 2 + + b += 18 // padding + + return v +} + +// Write request to wire for GetTimeouts +// getTimeoutsRequest writes a GetTimeouts request to a byte slice. +func getTimeoutsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + 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 + + 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, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), 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, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), 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 + // padding: 1 bytes + ServerMajorVersion uint16 + ServerMinorVersion 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 + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinorVersion = 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, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], ClientMajorVersion) + b += 2 + + xgb.Put16(buf[b:], ClientMinorVersion) + b += 2 + + return buf +} + +// InfoCookie is a cookie used only for Info requests. +type InfoCookie struct { + *xgb.Cookie +} + +// Info sends a checked request. +// If an error occurs, it will be returned with the reply by calling InfoCookie.Reply() +func Info(c *xgb.Conn) InfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Info' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(infoRequest(c), cookie) + return InfoCookie{cookie} +} + +// InfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func InfoUnchecked(c *xgb.Conn) InfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'Info' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(infoRequest(c), cookie) + return InfoCookie{cookie} +} + +// InfoReply represents the data returned from a Info request. +type InfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PowerLevel uint16 + State bool + // padding: 21 bytes +} + +// Reply blocks and returns the reply data for a Info request. +func (cook InfoCookie) Reply() (*InfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return infoReply(buf), nil +} + +// infoReply reads a byte slice into a InfoReply value. +func infoReply(buf []byte) *InfoReply { + v := new(InfoReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PowerLevel = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.State = true + } else { + v.State = false + } + b += 1 + + b += 21 // padding + + return v +} + +// Write request to wire for Info +// infoRequest writes a Info request to a byte slice. +func infoRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// SetTimeoutsCookie is a cookie used only for SetTimeouts requests. +type SetTimeoutsCookie struct { + *xgb.Cookie +} + +// SetTimeouts sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetTimeouts(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) SetTimeoutsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'SetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setTimeoutsRequest(c, StandbyTimeout, SuspendTimeout, OffTimeout), cookie) + return SetTimeoutsCookie{cookie} +} + +// SetTimeoutsChecked sends a checked request. +// If an error occurs, it can be retrieved using SetTimeoutsCookie.Check() +func SetTimeoutsChecked(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) SetTimeoutsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DPMS"]; !ok { + panic("Cannot issue request 'SetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setTimeoutsRequest(c, StandbyTimeout, SuspendTimeout, OffTimeout), cookie) + return SetTimeoutsCookie{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 SetTimeoutsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetTimeouts +// setTimeoutsRequest writes a SetTimeouts request to a byte slice. +func setTimeoutsRequest(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DPMS"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], StandbyTimeout) + b += 2 + + xgb.Put16(buf[b:], SuspendTimeout) + b += 2 + + xgb.Put16(buf[b:], OffTimeout) + b += 2 + + return buf +} diff --git a/nexgb/dri2/dri2.go b/nexgb/dri2/dri2.go new file mode 100644 index 0000000..820cf2b --- /dev/null +++ b/nexgb/dri2/dri2.go @@ -0,0 +1,1821 @@ +// Package dri2 is the X client API for the DRI2 extension. +package dri2 + +// This file is automatically generated from dri2.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the DRI2 extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 4, "DRI2").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named DRI2 could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["DRI2"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["DRI2"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["DRI2"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["DRI2"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["DRI2"] = make(map[int]xgb.NewErrorFun) +} + +type AttachFormat struct { + Attachment uint32 + Format uint32 +} + +// AttachFormatRead reads a byte slice into a AttachFormat value. +func AttachFormatRead(buf []byte, v *AttachFormat) int { + b := 0 + + v.Attachment = xgb.Get32(buf[b:]) + b += 4 + + v.Format = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// AttachFormatReadList reads a byte slice into a list of AttachFormat values. +func AttachFormatReadList(buf []byte, dest []AttachFormat) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = AttachFormat{} + b += AttachFormatRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a AttachFormat value to a byte slice. +func (v AttachFormat) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], v.Attachment) + b += 4 + + xgb.Put32(buf[b:], v.Format) + b += 4 + + return buf[:b] +} + +// AttachFormatListBytes writes a list of AttachFormat values to a byte slice. +func AttachFormatListBytes(buf []byte, list []AttachFormat) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + AttachmentBufferFrontLeft = 0 + AttachmentBufferBackLeft = 1 + AttachmentBufferFrontRight = 2 + AttachmentBufferBackRight = 3 + AttachmentBufferDepth = 4 + AttachmentBufferStencil = 5 + AttachmentBufferAccum = 6 + AttachmentBufferFakeFrontLeft = 7 + AttachmentBufferFakeFrontRight = 8 + AttachmentBufferDepthStencil = 9 + AttachmentBufferHiz = 10 +) + +// BufferSwapComplete is the event number for a BufferSwapCompleteEvent. +const BufferSwapComplete = 0 + +type BufferSwapCompleteEvent struct { + Sequence uint16 + // padding: 1 bytes + EventType uint16 + // padding: 2 bytes + Drawable xproto.Drawable + UstHi uint32 + UstLo uint32 + MscHi uint32 + MscLo uint32 + Sbc uint32 +} + +// BufferSwapCompleteEventNew constructs a BufferSwapCompleteEvent value that implements xgb.Event from a byte slice. +func BufferSwapCompleteEventNew(buf []byte) xgb.Event { + v := BufferSwapCompleteEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.EventType = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.UstHi = xgb.Get32(buf[b:]) + b += 4 + + v.UstLo = xgb.Get32(buf[b:]) + b += 4 + + v.MscHi = xgb.Get32(buf[b:]) + b += 4 + + v.MscLo = xgb.Get32(buf[b:]) + b += 4 + + v.Sbc = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Bytes writes a BufferSwapCompleteEvent value to a byte slice. +func (v BufferSwapCompleteEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put16(buf[b:], v.EventType) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put32(buf[b:], v.UstHi) + b += 4 + + xgb.Put32(buf[b:], v.UstLo) + b += 4 + + xgb.Put32(buf[b:], v.MscHi) + b += 4 + + xgb.Put32(buf[b:], v.MscLo) + b += 4 + + xgb.Put32(buf[b:], v.Sbc) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the BufferSwapComplete event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v BufferSwapCompleteEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of BufferSwapCompleteEvent. +func (v BufferSwapCompleteEvent) String() string { + fieldVals := make([]string, 0, 9) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("EventType: %d", v.EventType)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("UstHi: %d", v.UstHi)) + fieldVals = append(fieldVals, xgb.Sprintf("UstLo: %d", v.UstLo)) + fieldVals = append(fieldVals, xgb.Sprintf("MscHi: %d", v.MscHi)) + fieldVals = append(fieldVals, xgb.Sprintf("MscLo: %d", v.MscLo)) + fieldVals = append(fieldVals, xgb.Sprintf("Sbc: %d", v.Sbc)) + return "BufferSwapComplete {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["DRI2"][0] = BufferSwapCompleteEventNew +} + +type DRI2Buffer struct { + Attachment uint32 + Name uint32 + Pitch uint32 + Cpp uint32 + Flags uint32 +} + +// DRI2BufferRead reads a byte slice into a DRI2Buffer value. +func DRI2BufferRead(buf []byte, v *DRI2Buffer) int { + b := 0 + + v.Attachment = xgb.Get32(buf[b:]) + b += 4 + + v.Name = xgb.Get32(buf[b:]) + b += 4 + + v.Pitch = xgb.Get32(buf[b:]) + b += 4 + + v.Cpp = xgb.Get32(buf[b:]) + b += 4 + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// DRI2BufferReadList reads a byte slice into a list of DRI2Buffer values. +func DRI2BufferReadList(buf []byte, dest []DRI2Buffer) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = DRI2Buffer{} + b += DRI2BufferRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a DRI2Buffer value to a byte slice. +func (v DRI2Buffer) Bytes() []byte { + buf := make([]byte, 20) + b := 0 + + xgb.Put32(buf[b:], v.Attachment) + b += 4 + + xgb.Put32(buf[b:], v.Name) + b += 4 + + xgb.Put32(buf[b:], v.Pitch) + b += 4 + + xgb.Put32(buf[b:], v.Cpp) + b += 4 + + xgb.Put32(buf[b:], v.Flags) + b += 4 + + return buf[:b] +} + +// DRI2BufferListBytes writes a list of DRI2Buffer values to a byte slice. +func DRI2BufferListBytes(buf []byte, list []DRI2Buffer) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + DriverTypeDri = 0 + DriverTypeVdpau = 1 +) + +const ( + EventTypeExchangeComplete = 1 + EventTypeBlitComplete = 2 + EventTypeFlipComplete = 3 +) + +// InvalidateBuffers is the event number for a InvalidateBuffersEvent. +const InvalidateBuffers = 1 + +type InvalidateBuffersEvent struct { + Sequence uint16 + // padding: 1 bytes + Drawable xproto.Drawable +} + +// InvalidateBuffersEventNew constructs a InvalidateBuffersEvent value that implements xgb.Event from a byte slice. +func InvalidateBuffersEventNew(buf []byte) xgb.Event { + v := InvalidateBuffersEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a InvalidateBuffersEvent value to a byte slice. +func (v InvalidateBuffersEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the InvalidateBuffers event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v InvalidateBuffersEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of InvalidateBuffersEvent. +func (v InvalidateBuffersEvent) String() string { + fieldVals := make([]string, 0, 2) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + return "InvalidateBuffers {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["DRI2"][1] = InvalidateBuffersEventNew +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AuthenticateCookie is a cookie used only for Authenticate requests. +type AuthenticateCookie struct { + *xgb.Cookie +} + +// Authenticate sends a checked request. +// If an error occurs, it will be returned with the reply by calling AuthenticateCookie.Reply() +func Authenticate(c *xgb.Conn, Window xproto.Window, Magic uint32) AuthenticateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'Authenticate' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(authenticateRequest(c, Window, Magic), cookie) + return AuthenticateCookie{cookie} +} + +// AuthenticateUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AuthenticateUnchecked(c *xgb.Conn, Window xproto.Window, Magic uint32) AuthenticateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'Authenticate' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(authenticateRequest(c, Window, Magic), cookie) + return AuthenticateCookie{cookie} +} + +// AuthenticateReply represents the data returned from a Authenticate request. +type AuthenticateReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Authenticated uint32 +} + +// Reply blocks and returns the reply data for a Authenticate request. +func (cook AuthenticateCookie) Reply() (*AuthenticateReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return authenticateReply(buf), nil +} + +// authenticateReply reads a byte slice into a AuthenticateReply value. +func authenticateReply(buf []byte) *AuthenticateReply { + v := new(AuthenticateReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Authenticated = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for Authenticate +// authenticateRequest writes a Authenticate request to a byte slice. +func authenticateRequest(c *xgb.Conn, Window xproto.Window, Magic uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], Magic) + b += 4 + + return buf +} + +// ConnectCookie is a cookie used only for Connect requests. +type ConnectCookie struct { + *xgb.Cookie +} + +// Connect sends a checked request. +// If an error occurs, it will be returned with the reply by calling ConnectCookie.Reply() +func Connect(c *xgb.Conn, Window xproto.Window, DriverType uint32) ConnectCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'Connect' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(connectRequest(c, Window, DriverType), cookie) + return ConnectCookie{cookie} +} + +// ConnectUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ConnectUnchecked(c *xgb.Conn, Window xproto.Window, DriverType uint32) ConnectCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'Connect' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(connectRequest(c, Window, DriverType), cookie) + return ConnectCookie{cookie} +} + +// ConnectReply represents the data returned from a Connect request. +type ConnectReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + DriverNameLength uint32 + DeviceNameLength uint32 + // padding: 16 bytes + DriverName string // size: xgb.Pad((int(DriverNameLength) * 1)) + AlignmentPad []byte // size: xgb.Pad(((((int(DriverNameLength) + 3) & -4) - int(DriverNameLength)) * 1)) + DeviceName string // size: xgb.Pad((int(DeviceNameLength) * 1)) +} + +// Reply blocks and returns the reply data for a Connect request. +func (cook ConnectCookie) Reply() (*ConnectReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return connectReply(buf), nil +} + +// connectReply reads a byte slice into a ConnectReply value. +func connectReply(buf []byte) *ConnectReply { + v := new(ConnectReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.DriverNameLength = xgb.Get32(buf[b:]) + b += 4 + + v.DeviceNameLength = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + { + byteString := make([]byte, v.DriverNameLength) + copy(byteString[:v.DriverNameLength], buf[b:]) + v.DriverName = string(byteString) + b += int(v.DriverNameLength) + } + + v.AlignmentPad = make([]byte, (((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength))) + copy(v.AlignmentPad[:(((int(v.DriverNameLength)+3)&-4)-int(v.DriverNameLength))], buf[b:]) + b += int((((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength))) + + { + byteString := make([]byte, v.DeviceNameLength) + copy(byteString[:v.DeviceNameLength], buf[b:]) + v.DeviceName = string(byteString) + b += int(v.DeviceNameLength) + } + + return v +} + +// Write request to wire for Connect +// connectRequest writes a Connect request to a byte slice. +func connectRequest(c *xgb.Conn, Window xproto.Window, DriverType uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + 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:], DriverType) + b += 4 + + return buf +} + +// CopyRegionCookie is a cookie used only for CopyRegion requests. +type CopyRegionCookie struct { + *xgb.Cookie +} + +// CopyRegion sends a checked request. +// If an error occurs, it will be returned with the reply by calling CopyRegionCookie.Reply() +func CopyRegion(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) CopyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(copyRegionRequest(c, Drawable, Region, Dest, Src), cookie) + return CopyRegionCookie{cookie} +} + +// CopyRegionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyRegionUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) CopyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(copyRegionRequest(c, Drawable, Region, Dest, Src), cookie) + return CopyRegionCookie{cookie} +} + +// CopyRegionReply represents the data returned from a CopyRegion request. +type CopyRegionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes +} + +// Reply blocks and returns the reply data for a CopyRegion request. +func (cook CopyRegionCookie) Reply() (*CopyRegionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return copyRegionReply(buf), nil +} + +// copyRegionReply reads a byte slice into a CopyRegionReply value. +func copyRegionReply(buf []byte) *CopyRegionReply { + v := new(CopyRegionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + 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 CopyRegion +// copyRegionRequest writes a CopyRegion request to a byte slice. +func copyRegionRequest(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], Region) + b += 4 + + xgb.Put32(buf[b:], Dest) + b += 4 + + xgb.Put32(buf[b:], Src) + b += 4 + + return buf +} + +// CreateDrawableCookie is a cookie used only for CreateDrawable requests. +type CreateDrawableCookie struct { + *xgb.Cookie +} + +// CreateDrawable sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateDrawable(c *xgb.Conn, Drawable xproto.Drawable) CreateDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createDrawableRequest(c, Drawable), cookie) + return CreateDrawableCookie{cookie} +} + +// CreateDrawableChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateDrawableCookie.Check() +func CreateDrawableChecked(c *xgb.Conn, Drawable xproto.Drawable) CreateDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createDrawableRequest(c, Drawable), cookie) + return CreateDrawableCookie{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 CreateDrawableCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateDrawable +// createDrawableRequest writes a CreateDrawable request to a byte slice. +func createDrawableRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + return buf +} + +// DestroyDrawableCookie is a cookie used only for DestroyDrawable requests. +type DestroyDrawableCookie struct { + *xgb.Cookie +} + +// DestroyDrawable sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyDrawable(c *xgb.Conn, Drawable xproto.Drawable) DestroyDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyDrawableRequest(c, Drawable), cookie) + return DestroyDrawableCookie{cookie} +} + +// DestroyDrawableChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyDrawableCookie.Check() +func DestroyDrawableChecked(c *xgb.Conn, Drawable xproto.Drawable) DestroyDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyDrawableRequest(c, Drawable), cookie) + return DestroyDrawableCookie{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 DestroyDrawableCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyDrawable +// destroyDrawableRequest writes a DestroyDrawable request to a byte slice. +func destroyDrawableRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Drawable)) + b += 4 + + return buf +} + +// GetBuffersCookie is a cookie used only for GetBuffers requests. +type GetBuffersCookie struct { + *xgb.Cookie +} + +// GetBuffers sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetBuffersCookie.Reply() +func GetBuffers(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) GetBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getBuffersRequest(c, Drawable, Count, Attachments), cookie) + return GetBuffersCookie{cookie} +} + +// GetBuffersUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetBuffersUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) GetBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getBuffersRequest(c, Drawable, Count, Attachments), cookie) + return GetBuffersCookie{cookie} +} + +// GetBuffersReply represents the data returned from a GetBuffers request. +type GetBuffersReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Width uint32 + Height uint32 + Count uint32 + // padding: 12 bytes + Buffers []DRI2Buffer // size: xgb.Pad((int(Count) * 20)) +} + +// Reply blocks and returns the reply data for a GetBuffers request. +func (cook GetBuffersCookie) Reply() (*GetBuffersReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getBuffersReply(buf), nil +} + +// getBuffersReply reads a byte slice into a GetBuffersReply value. +func getBuffersReply(buf []byte) *GetBuffersReply { + v := new(GetBuffersReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = xgb.Get32(buf[b:]) + b += 4 + + v.Height = xgb.Get32(buf[b:]) + b += 4 + + v.Count = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Buffers = make([]DRI2Buffer, v.Count) + b += DRI2BufferReadList(buf[b:], v.Buffers) + + return v +} + +// Write request to wire for GetBuffers +// getBuffersRequest writes a GetBuffers request to a byte slice. +func getBuffersRequest(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Attachments) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], Count) + b += 4 + + for i := 0; i < int(len(Attachments)); i++ { + xgb.Put32(buf[b:], Attachments[i]) + b += 4 + } + + return buf +} + +// GetBuffersWithFormatCookie is a cookie used only for GetBuffersWithFormat requests. +type GetBuffersWithFormatCookie struct { + *xgb.Cookie +} + +// GetBuffersWithFormat sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetBuffersWithFormatCookie.Reply() +func GetBuffersWithFormat(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) GetBuffersWithFormatCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetBuffersWithFormat' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getBuffersWithFormatRequest(c, Drawable, Count, Attachments), cookie) + return GetBuffersWithFormatCookie{cookie} +} + +// GetBuffersWithFormatUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetBuffersWithFormatUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) GetBuffersWithFormatCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetBuffersWithFormat' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getBuffersWithFormatRequest(c, Drawable, Count, Attachments), cookie) + return GetBuffersWithFormatCookie{cookie} +} + +// GetBuffersWithFormatReply represents the data returned from a GetBuffersWithFormat request. +type GetBuffersWithFormatReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Width uint32 + Height uint32 + Count uint32 + // padding: 12 bytes + Buffers []DRI2Buffer // size: xgb.Pad((int(Count) * 20)) +} + +// Reply blocks and returns the reply data for a GetBuffersWithFormat request. +func (cook GetBuffersWithFormatCookie) Reply() (*GetBuffersWithFormatReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getBuffersWithFormatReply(buf), nil +} + +// getBuffersWithFormatReply reads a byte slice into a GetBuffersWithFormatReply value. +func getBuffersWithFormatReply(buf []byte) *GetBuffersWithFormatReply { + v := new(GetBuffersWithFormatReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = xgb.Get32(buf[b:]) + b += 4 + + v.Height = xgb.Get32(buf[b:]) + b += 4 + + v.Count = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Buffers = make([]DRI2Buffer, v.Count) + b += DRI2BufferReadList(buf[b:], v.Buffers) + + return v +} + +// Write request to wire for GetBuffersWithFormat +// getBuffersWithFormatRequest writes a GetBuffersWithFormat request to a byte slice. +func getBuffersWithFormatRequest(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Attachments) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], Count) + b += 4 + + b += AttachFormatListBytes(buf[b:], Attachments) + + return buf +} + +// GetMSCCookie is a cookie used only for GetMSC requests. +type GetMSCCookie struct { + *xgb.Cookie +} + +// GetMSC sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMSCCookie.Reply() +func GetMSC(c *xgb.Conn, Drawable xproto.Drawable) GetMSCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMSCRequest(c, Drawable), cookie) + return GetMSCCookie{cookie} +} + +// GetMSCUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMSCUnchecked(c *xgb.Conn, Drawable xproto.Drawable) GetMSCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMSCRequest(c, Drawable), cookie) + return GetMSCCookie{cookie} +} + +// GetMSCReply represents the data returned from a GetMSC request. +type GetMSCReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + UstHi uint32 + UstLo uint32 + MscHi uint32 + MscLo uint32 + SbcHi uint32 + SbcLo uint32 +} + +// Reply blocks and returns the reply data for a GetMSC request. +func (cook GetMSCCookie) Reply() (*GetMSCReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMSCReply(buf), nil +} + +// getMSCReply reads a byte slice into a GetMSCReply value. +func getMSCReply(buf []byte) *GetMSCReply { + v := new(GetMSCReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.UstHi = xgb.Get32(buf[b:]) + b += 4 + + v.UstLo = xgb.Get32(buf[b:]) + b += 4 + + v.MscHi = xgb.Get32(buf[b:]) + b += 4 + + v.MscLo = xgb.Get32(buf[b:]) + b += 4 + + v.SbcHi = xgb.Get32(buf[b:]) + b += 4 + + v.SbcLo = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GetMSC +// getMSCRequest writes a GetMSC request to a byte slice. +func getMSCRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // 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(Drawable)) + b += 4 + + return buf +} + +// GetParamCookie is a cookie used only for GetParam requests. +type GetParamCookie struct { + *xgb.Cookie +} + +// GetParam sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetParamCookie.Reply() +func GetParam(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) GetParamCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetParam' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getParamRequest(c, Drawable, Param), cookie) + return GetParamCookie{cookie} +} + +// GetParamUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetParamUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) GetParamCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'GetParam' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getParamRequest(c, Drawable, Param), cookie) + return GetParamCookie{cookie} +} + +// GetParamReply represents the data returned from a GetParam request. +type GetParamReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + IsParamRecognized bool + ValueHi uint32 + ValueLo uint32 +} + +// Reply blocks and returns the reply data for a GetParam request. +func (cook GetParamCookie) Reply() (*GetParamReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getParamReply(buf), nil +} + +// getParamReply reads a byte slice into a GetParamReply value. +func getParamReply(buf []byte) *GetParamReply { + v := new(GetParamReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.IsParamRecognized = true + } else { + v.IsParamRecognized = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ValueHi = xgb.Get32(buf[b:]) + b += 4 + + v.ValueLo = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GetParam +// getParamRequest writes a GetParam request to a byte slice. +func getParamRequest(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], Param) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + return buf +} + +// SwapBuffersCookie is a cookie used only for SwapBuffers requests. +type SwapBuffersCookie struct { + *xgb.Cookie +} + +// SwapBuffers sends a checked request. +// If an error occurs, it will be returned with the reply by calling SwapBuffersCookie.Reply() +func SwapBuffers(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) SwapBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(swapBuffersRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie) + return SwapBuffersCookie{cookie} +} + +// SwapBuffersUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SwapBuffersUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) SwapBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(swapBuffersRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie) + return SwapBuffersCookie{cookie} +} + +// SwapBuffersReply represents the data returned from a SwapBuffers request. +type SwapBuffersReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + SwapHi uint32 + SwapLo uint32 +} + +// Reply blocks and returns the reply data for a SwapBuffers request. +func (cook SwapBuffersCookie) Reply() (*SwapBuffersReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return swapBuffersReply(buf), nil +} + +// swapBuffersReply reads a byte slice into a SwapBuffersReply value. +func swapBuffersReply(buf []byte) *SwapBuffersReply { + v := new(SwapBuffersReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.SwapHi = xgb.Get32(buf[b:]) + b += 4 + + v.SwapLo = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for SwapBuffers +// swapBuffersRequest writes a SwapBuffers request to a byte slice. +func swapBuffersRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], TargetMscHi) + b += 4 + + xgb.Put32(buf[b:], TargetMscLo) + b += 4 + + xgb.Put32(buf[b:], DivisorHi) + b += 4 + + xgb.Put32(buf[b:], DivisorLo) + b += 4 + + xgb.Put32(buf[b:], RemainderHi) + b += 4 + + xgb.Put32(buf[b:], RemainderLo) + b += 4 + + return buf +} + +// SwapIntervalCookie is a cookie used only for SwapInterval requests. +type SwapIntervalCookie struct { + *xgb.Cookie +} + +// SwapInterval sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SwapInterval(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) SwapIntervalCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'SwapInterval' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(swapIntervalRequest(c, Drawable, Interval), cookie) + return SwapIntervalCookie{cookie} +} + +// SwapIntervalChecked sends a checked request. +// If an error occurs, it can be retrieved using SwapIntervalCookie.Check() +func SwapIntervalChecked(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) SwapIntervalCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'SwapInterval' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(swapIntervalRequest(c, Drawable, Interval), cookie) + return SwapIntervalCookie{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 SwapIntervalCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SwapInterval +// swapIntervalRequest writes a SwapInterval request to a byte slice. +func swapIntervalRequest(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], Interval) + b += 4 + + return buf +} + +// WaitMSCCookie is a cookie used only for WaitMSC requests. +type WaitMSCCookie struct { + *xgb.Cookie +} + +// WaitMSC sends a checked request. +// If an error occurs, it will be returned with the reply by calling WaitMSCCookie.Reply() +func WaitMSC(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) WaitMSCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'WaitMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(waitMSCRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie) + return WaitMSCCookie{cookie} +} + +// WaitMSCUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func WaitMSCUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) WaitMSCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'WaitMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(waitMSCRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie) + return WaitMSCCookie{cookie} +} + +// WaitMSCReply represents the data returned from a WaitMSC request. +type WaitMSCReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + UstHi uint32 + UstLo uint32 + MscHi uint32 + MscLo uint32 + SbcHi uint32 + SbcLo uint32 +} + +// Reply blocks and returns the reply data for a WaitMSC request. +func (cook WaitMSCCookie) Reply() (*WaitMSCReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return waitMSCReply(buf), nil +} + +// waitMSCReply reads a byte slice into a WaitMSCReply value. +func waitMSCReply(buf []byte) *WaitMSCReply { + v := new(WaitMSCReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.UstHi = xgb.Get32(buf[b:]) + b += 4 + + v.UstLo = xgb.Get32(buf[b:]) + b += 4 + + v.MscHi = xgb.Get32(buf[b:]) + b += 4 + + v.MscLo = xgb.Get32(buf[b:]) + b += 4 + + v.SbcHi = xgb.Get32(buf[b:]) + b += 4 + + v.SbcLo = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for WaitMSC +// waitMSCRequest writes a WaitMSC request to a byte slice. +func waitMSCRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], TargetMscHi) + b += 4 + + xgb.Put32(buf[b:], TargetMscLo) + b += 4 + + xgb.Put32(buf[b:], DivisorHi) + b += 4 + + xgb.Put32(buf[b:], DivisorLo) + b += 4 + + xgb.Put32(buf[b:], RemainderHi) + b += 4 + + xgb.Put32(buf[b:], RemainderLo) + b += 4 + + return buf +} + +// WaitSBCCookie is a cookie used only for WaitSBC requests. +type WaitSBCCookie struct { + *xgb.Cookie +} + +// WaitSBC sends a checked request. +// If an error occurs, it will be returned with the reply by calling WaitSBCCookie.Reply() +func WaitSBC(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) WaitSBCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'WaitSBC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(waitSBCRequest(c, Drawable, TargetSbcHi, TargetSbcLo), cookie) + return WaitSBCCookie{cookie} +} + +// WaitSBCUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func WaitSBCUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) WaitSBCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["DRI2"]; !ok { + panic("Cannot issue request 'WaitSBC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(waitSBCRequest(c, Drawable, TargetSbcHi, TargetSbcLo), cookie) + return WaitSBCCookie{cookie} +} + +// WaitSBCReply represents the data returned from a WaitSBC request. +type WaitSBCReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + UstHi uint32 + UstLo uint32 + MscHi uint32 + MscLo uint32 + SbcHi uint32 + SbcLo uint32 +} + +// Reply blocks and returns the reply data for a WaitSBC request. +func (cook WaitSBCCookie) Reply() (*WaitSBCReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return waitSBCReply(buf), nil +} + +// waitSBCReply reads a byte slice into a WaitSBCReply value. +func waitSBCReply(buf []byte) *WaitSBCReply { + v := new(WaitSBCReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.UstHi = xgb.Get32(buf[b:]) + b += 4 + + v.UstLo = xgb.Get32(buf[b:]) + b += 4 + + v.MscHi = xgb.Get32(buf[b:]) + b += 4 + + v.MscLo = xgb.Get32(buf[b:]) + b += 4 + + v.SbcHi = xgb.Get32(buf[b:]) + b += 4 + + v.SbcLo = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for WaitSBC +// waitSBCRequest writes a WaitSBC request to a byte slice. +func waitSBCRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["DRI2"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], TargetSbcHi) + b += 4 + + xgb.Put32(buf[b:], TargetSbcLo) + b += 4 + + return buf +} diff --git a/nexgb/examples/atoms/.gitignore b/nexgb/examples/atoms/.gitignore new file mode 100644 index 0000000..01e08a1 --- /dev/null +++ b/nexgb/examples/atoms/.gitignore @@ -0,0 +1,3 @@ +atoms +*.info +*.prof diff --git a/nexgb/examples/atoms/Makefile b/nexgb/examples/atoms/Makefile new file mode 100644 index 0000000..c192a37 --- /dev/null +++ b/nexgb/examples/atoms/Makefile @@ -0,0 +1,12 @@ +atoms: + go build + +test: atoms + ./atoms --requests 500000 --cpu 1 \ + --cpuprof cpu1.prof --memprof mem1.prof > atoms1.info 2>&1 + ./atoms --requests 500000 --cpu 2 \ + --cpuprof cpu2.prof --memprof mem2.prof > atoms2.info 2>&1 + ./atoms --requests 500000 --cpu 3 \ + --cpuprof cpu3.prof --memprof mem3.prof > atoms3.info 2>&1 + ./atoms --requests 500000 --cpu 6 \ + --cpuprof cpu6.prof --memprof mem6.prof > atoms6.info 2>&1 diff --git a/nexgb/examples/atoms/main.go b/nexgb/examples/atoms/main.go new file mode 100644 index 0000000..8985768 --- /dev/null +++ b/nexgb/examples/atoms/main.go @@ -0,0 +1,91 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "runtime" + "runtime/pprof" + "time" + + "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/xproto" +) + +var ( + flagRequests int + flagGOMAXPROCS int + flagCpuProfName string + flagMemProfName string +) + +func init() { + flag.IntVar(&flagRequests, "requests", 100000, "Number of atoms to intern.") + flag.IntVar(&flagGOMAXPROCS, "cpu", 1, "Value of GOMAXPROCS.") + flag.StringVar(&flagCpuProfName, "cpuprof", "cpu.prof", + "Name of CPU profile file.") + flag.StringVar(&flagMemProfName, "memprof", "mem.prof", + "Name of memory profile file.") + + flag.Parse() + + runtime.GOMAXPROCS(flagGOMAXPROCS) +} + +func seqNames(n int) []string { + names := make([]string, n) + for i := range names { + names[i] = fmt.Sprintf("NAME%d", i) + } + return names +} + +func main() { + X, err := xgb.NewConn() + if err != nil { + log.Fatal(err) + } + + names := seqNames(flagRequests) + + fcpu, err := os.Create(flagCpuProfName) + if err != nil { + log.Fatal(err) + } + defer fcpu.Close() + pprof.StartCPUProfile(fcpu) + defer pprof.StopCPUProfile() + + start := time.Now() + cookies := make([]xproto.InternAtomCookie, flagRequests) + for i := 0; i < flagRequests; i++ { + cookies[i] = xproto.InternAtom(X, + false, uint16(len(names[i])), names[i]) + } + for _, cookie := range cookies { + cookie.Reply() + } + fmt.Printf("Exec time: %s\n\n", time.Since(start)) + + fmem, err := os.Create(flagMemProfName) + if err != nil { + log.Fatal(err) + } + defer fmem.Close() + pprof.WriteHeapProfile(fmem) + + memStats := &runtime.MemStats{} + runtime.ReadMemStats(memStats) + + // This isn't right. I'm not sure what's wrong. + lastGcTime := time.Unix(int64(memStats.LastGC/1000000000), + int64(memStats.LastGC-memStats.LastGC/1000000000)) + + fmt.Printf("Alloc: %d\n", memStats.Alloc) + fmt.Printf("TotalAlloc: %d\n", memStats.TotalAlloc) + fmt.Printf("LastGC: %s\n", lastGcTime) + fmt.Printf("PauseTotalNs: %d\n", memStats.PauseTotalNs) + fmt.Printf("PauseNs: %d\n", memStats.PauseNs) + fmt.Printf("NumGC: %d\n", memStats.NumGC) +} diff --git a/nexgb/examples/create-window/main.go b/nexgb/examples/create-window/main.go new file mode 100644 index 0000000..73a0099 --- /dev/null +++ b/nexgb/examples/create-window/main.go @@ -0,0 +1,107 @@ +// 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" + "github.com/BurntSushi/xgb/xproto" +) + +func main() { + X, err := xgb.NewConn() + if err != nil { + fmt.Println(err) + 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. + // 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. + xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root, + 0, 0, 500, 500, 0, + 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 + // 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. + xproto.ChangeWindowAttributes(X, wid, + xproto.CwBackPixel|xproto.CwEventMask, + []uint32{ // values must be in the order defined by the protocol + 0xffffffff, + 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. + // 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 = xproto.MapWindowChecked(X, 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 = xproto.MapWindowChecked(X, 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..48e020c --- /dev/null +++ b/nexgb/examples/get-active-window/main.go @@ -0,0 +1,61 @@ +// 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" + "github.com/BurntSushi/xgb/xproto" +) + +func main() { + X, err := xgb.NewConn() + if err != nil { + log.Fatal(err) + } + + // Get the window id of the root window. + 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 := 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 := xproto.InternAtom(X, 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 := xproto.GetProperty(X, false, root, activeAtom.Atom, + xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply() + if err != nil { + log.Fatal(err) + } + 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 = xproto.GetProperty(X, false, windowId, nameAtom.Atom, + xproto.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/randr/main.go b/nexgb/examples/randr/main.go new file mode 100644 index 0000000..e349144 --- /dev/null +++ b/nexgb/examples/randr/main.go @@ -0,0 +1,92 @@ +// 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" + "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 := 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 := 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 := randr.GetOutputInfo(X, output, 0).Reply() + if err != nil { + log.Fatal(err) + } + + if info.Connection == randr.ConnectionConnected { + 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 := randr.GetCrtcInfo(X, 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 = randr.SelectInputChecked(X, root, + randr.NotifyMaskScreenChange| + randr.NotifyMaskCrtcChange| + randr.NotifyMaskOutputChange| + randr.NotifyMaskOutputProperty).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/xinerama/main.go b/nexgb/examples/xinerama/main.go new file mode 100644 index 0000000..896bb63 --- /dev/null +++ b/nexgb/examples/xinerama/main.go @@ -0,0 +1,40 @@ +// Example xinerama shows how to query the geometry of all active heads. +package main + +import ( + "fmt" + "log" + + "github.com/BurntSushi/xgb" + "github.com/BurntSushi/xgb/xinerama" +) + +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 = xinerama.Init(X) + if err != nil { + log.Fatal(err) + } + + // Issue a request to get the screen information. + reply, err := xinerama.QueryScreens(X).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/ge/ge.go b/nexgb/ge/ge.go new file mode 100644 index 0000000..f7e1ce4 --- /dev/null +++ b/nexgb/ge/ge.go @@ -0,0 +1,165 @@ +// Package ge is the X client API for the Generic Event Extension extension. +package ge + +// This file is automatically generated from ge.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the Generic Event Extension extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 23, "Generic Event Extension").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named Generic Event Extension could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["Generic Event Extension"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["Generic Event Extension"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["Generic Event Extension"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["Generic Event Extension"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["Generic Event Extension"] = make(map[int]xgb.NewErrorFun) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Generic Event Extension"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Generic Event Extension'. ge.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["Generic Event Extension"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Generic Event Extension'. ge.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + b += 20 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["Generic Event Extension"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], ClientMajorVersion) + b += 2 + + xgb.Put16(buf[b:], ClientMinorVersion) + b += 2 + + return buf +} diff --git a/nexgb/glx/glx.go b/nexgb/glx/glx.go new file mode 100644 index 0000000..0ecc3b5 --- /dev/null +++ b/nexgb/glx/glx.go @@ -0,0 +1,10922 @@ +// Package glx is the X client API for the GLX extension. +package glx + +// This file is automatically generated from glx.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the GLX extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 3, "GLX").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named GLX could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["GLX"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["GLX"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["GLX"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["GLX"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["GLX"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadContext is the error number for a BadBadContext. +const BadBadContext = 0 + +type BadContextError GenericError + +// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. +func BadContextErrorNew(buf []byte) xgb.Error { + v := BadContextError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadContext" + return v +} + +// SequenceId returns the sequence id attached to the BadBadContext error. +// This is mostly used internally. +func (err BadContextError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. +func (err BadContextError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadContext error. +func (err BadContextError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][0] = BadContextErrorNew +} + +// BadBadContextState is the error number for a BadBadContextState. +const BadBadContextState = 1 + +type BadContextStateError GenericError + +// BadContextStateErrorNew constructs a BadContextStateError value that implements xgb.Error from a byte slice. +func BadContextStateErrorNew(buf []byte) xgb.Error { + v := BadContextStateError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadContextState" + return v +} + +// SequenceId returns the sequence id attached to the BadBadContextState error. +// This is mostly used internally. +func (err BadContextStateError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadContextState error. If no bad value exists, 0 is returned. +func (err BadContextStateError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadContextState error. +func (err BadContextStateError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadContextState {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][1] = BadContextStateErrorNew +} + +// BadBadContextTag is the error number for a BadBadContextTag. +const BadBadContextTag = 4 + +type BadContextTagError GenericError + +// BadContextTagErrorNew constructs a BadContextTagError value that implements xgb.Error from a byte slice. +func BadContextTagErrorNew(buf []byte) xgb.Error { + v := BadContextTagError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadContextTag" + return v +} + +// SequenceId returns the sequence id attached to the BadBadContextTag error. +// This is mostly used internally. +func (err BadContextTagError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadContextTag error. If no bad value exists, 0 is returned. +func (err BadContextTagError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadContextTag error. +func (err BadContextTagError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadContextTag {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][4] = BadContextTagErrorNew +} + +// BadBadCurrentDrawable is the error number for a BadBadCurrentDrawable. +const BadBadCurrentDrawable = 11 + +type BadCurrentDrawableError GenericError + +// BadCurrentDrawableErrorNew constructs a BadCurrentDrawableError value that implements xgb.Error from a byte slice. +func BadCurrentDrawableErrorNew(buf []byte) xgb.Error { + v := BadCurrentDrawableError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadCurrentDrawable" + return v +} + +// SequenceId returns the sequence id attached to the BadBadCurrentDrawable error. +// This is mostly used internally. +func (err BadCurrentDrawableError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadCurrentDrawable error. If no bad value exists, 0 is returned. +func (err BadCurrentDrawableError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadCurrentDrawable error. +func (err BadCurrentDrawableError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadCurrentDrawable {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][11] = BadCurrentDrawableErrorNew +} + +// BadBadCurrentWindow is the error number for a BadBadCurrentWindow. +const BadBadCurrentWindow = 5 + +type BadCurrentWindowError GenericError + +// BadCurrentWindowErrorNew constructs a BadCurrentWindowError value that implements xgb.Error from a byte slice. +func BadCurrentWindowErrorNew(buf []byte) xgb.Error { + v := BadCurrentWindowError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadCurrentWindow" + return v +} + +// SequenceId returns the sequence id attached to the BadBadCurrentWindow error. +// This is mostly used internally. +func (err BadCurrentWindowError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadCurrentWindow error. If no bad value exists, 0 is returned. +func (err BadCurrentWindowError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadCurrentWindow error. +func (err BadCurrentWindowError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadCurrentWindow {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][5] = BadCurrentWindowErrorNew +} + +// BadBadDrawable is the error number for a BadBadDrawable. +const BadBadDrawable = 2 + +type BadDrawableError GenericError + +// BadDrawableErrorNew constructs a BadDrawableError value that implements xgb.Error from a byte slice. +func BadDrawableErrorNew(buf []byte) xgb.Error { + v := BadDrawableError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadDrawable" + return v +} + +// SequenceId returns the sequence id attached to the BadBadDrawable error. +// This is mostly used internally. +func (err BadDrawableError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadDrawable error. If no bad value exists, 0 is returned. +func (err BadDrawableError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadDrawable error. +func (err BadDrawableError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadDrawable {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][2] = BadDrawableErrorNew +} + +// BadBadFBConfig is the error number for a BadBadFBConfig. +const BadBadFBConfig = 9 + +type BadFBConfigError GenericError + +// BadFBConfigErrorNew constructs a BadFBConfigError value that implements xgb.Error from a byte slice. +func BadFBConfigErrorNew(buf []byte) xgb.Error { + v := BadFBConfigError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadFBConfig" + return v +} + +// SequenceId returns the sequence id attached to the BadBadFBConfig error. +// This is mostly used internally. +func (err BadFBConfigError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadFBConfig error. If no bad value exists, 0 is returned. +func (err BadFBConfigError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadFBConfig error. +func (err BadFBConfigError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadFBConfig {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][9] = BadFBConfigErrorNew +} + +// BadBadLargeRequest is the error number for a BadBadLargeRequest. +const BadBadLargeRequest = 7 + +type BadLargeRequestError GenericError + +// BadLargeRequestErrorNew constructs a BadLargeRequestError value that implements xgb.Error from a byte slice. +func BadLargeRequestErrorNew(buf []byte) xgb.Error { + v := BadLargeRequestError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadLargeRequest" + return v +} + +// SequenceId returns the sequence id attached to the BadBadLargeRequest error. +// This is mostly used internally. +func (err BadLargeRequestError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadLargeRequest error. If no bad value exists, 0 is returned. +func (err BadLargeRequestError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadLargeRequest error. +func (err BadLargeRequestError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadLargeRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][7] = BadLargeRequestErrorNew +} + +// BadBadPbuffer is the error number for a BadBadPbuffer. +const BadBadPbuffer = 10 + +type BadPbufferError GenericError + +// BadPbufferErrorNew constructs a BadPbufferError value that implements xgb.Error from a byte slice. +func BadPbufferErrorNew(buf []byte) xgb.Error { + v := BadPbufferError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadPbuffer" + return v +} + +// SequenceId returns the sequence id attached to the BadBadPbuffer error. +// This is mostly used internally. +func (err BadPbufferError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadPbuffer error. If no bad value exists, 0 is returned. +func (err BadPbufferError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadPbuffer error. +func (err BadPbufferError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadPbuffer {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][10] = BadPbufferErrorNew +} + +// BadBadPixmap is the error number for a BadBadPixmap. +const BadBadPixmap = 3 + +type BadPixmapError GenericError + +// BadPixmapErrorNew constructs a BadPixmapError value that implements xgb.Error from a byte slice. +func BadPixmapErrorNew(buf []byte) xgb.Error { + v := BadPixmapError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadPixmap" + return v +} + +// SequenceId returns the sequence id attached to the BadBadPixmap error. +// This is mostly used internally. +func (err BadPixmapError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadPixmap error. If no bad value exists, 0 is returned. +func (err BadPixmapError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadPixmap error. +func (err BadPixmapError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadPixmap {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][3] = BadPixmapErrorNew +} + +// BadBadRenderRequest is the error number for a BadBadRenderRequest. +const BadBadRenderRequest = 6 + +type BadRenderRequestError GenericError + +// BadRenderRequestErrorNew constructs a BadRenderRequestError value that implements xgb.Error from a byte slice. +func BadRenderRequestErrorNew(buf []byte) xgb.Error { + v := BadRenderRequestError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadRenderRequest" + return v +} + +// SequenceId returns the sequence id attached to the BadBadRenderRequest error. +// This is mostly used internally. +func (err BadRenderRequestError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadRenderRequest error. If no bad value exists, 0 is returned. +func (err BadRenderRequestError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadRenderRequest error. +func (err BadRenderRequestError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadRenderRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][6] = BadRenderRequestErrorNew +} + +// BadBadWindow is the error number for a BadBadWindow. +const BadBadWindow = 12 + +type BadWindowError GenericError + +// BadWindowErrorNew constructs a BadWindowError value that implements xgb.Error from a byte slice. +func BadWindowErrorNew(buf []byte) xgb.Error { + v := BadWindowError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "BadWindow" + return v +} + +// SequenceId returns the sequence id attached to the BadBadWindow error. +// This is mostly used internally. +func (err BadWindowError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadWindow error. If no bad value exists, 0 is returned. +func (err BadWindowError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadWindow error. +func (err BadWindowError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadWindow {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][12] = BadWindowErrorNew +} + +type Bool32 uint32 + +// BufferSwapComplete is the event number for a BufferSwapCompleteEvent. +const BufferSwapComplete = 1 + +type BufferSwapCompleteEvent struct { + Sequence uint16 + // padding: 1 bytes + EventType uint16 + // padding: 2 bytes + Drawable Drawable + UstHi uint32 + UstLo uint32 + MscHi uint32 + MscLo uint32 + Sbc uint32 +} + +// BufferSwapCompleteEventNew constructs a BufferSwapCompleteEvent value that implements xgb.Event from a byte slice. +func BufferSwapCompleteEventNew(buf []byte) xgb.Event { + v := BufferSwapCompleteEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.EventType = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Drawable = Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.UstHi = xgb.Get32(buf[b:]) + b += 4 + + v.UstLo = xgb.Get32(buf[b:]) + b += 4 + + v.MscHi = xgb.Get32(buf[b:]) + b += 4 + + v.MscLo = xgb.Get32(buf[b:]) + b += 4 + + v.Sbc = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Bytes writes a BufferSwapCompleteEvent value to a byte slice. +func (v BufferSwapCompleteEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put16(buf[b:], v.EventType) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put32(buf[b:], v.UstHi) + b += 4 + + xgb.Put32(buf[b:], v.UstLo) + b += 4 + + xgb.Put32(buf[b:], v.MscHi) + b += 4 + + xgb.Put32(buf[b:], v.MscLo) + b += 4 + + xgb.Put32(buf[b:], v.Sbc) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the BufferSwapComplete event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v BufferSwapCompleteEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of BufferSwapCompleteEvent. +func (v BufferSwapCompleteEvent) String() string { + fieldVals := make([]string, 0, 9) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("EventType: %d", v.EventType)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("UstHi: %d", v.UstHi)) + fieldVals = append(fieldVals, xgb.Sprintf("UstLo: %d", v.UstLo)) + fieldVals = append(fieldVals, xgb.Sprintf("MscHi: %d", v.MscHi)) + fieldVals = append(fieldVals, xgb.Sprintf("MscLo: %d", v.MscLo)) + fieldVals = append(fieldVals, xgb.Sprintf("Sbc: %d", v.Sbc)) + return "BufferSwapComplete {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["GLX"][1] = BufferSwapCompleteEventNew +} + +type Context uint32 + +func NewContextId(c *xgb.Conn) (Context, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Context(id), nil +} + +type ContextTag uint32 + +type Drawable uint32 + +func NewDrawableId(c *xgb.Conn) (Drawable, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Drawable(id), nil +} + +type Fbconfig uint32 + +func NewFbconfigId(c *xgb.Conn) (Fbconfig, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Fbconfig(id), nil +} + +type Float32 float64 + +type Float64 float64 + +// BadGLXBadProfileARB is the error number for a BadGLXBadProfileARB. +const BadGLXBadProfileARB = 13 + +type GLXBadProfileARBError GenericError + +// GLXBadProfileARBErrorNew constructs a GLXBadProfileARBError value that implements xgb.Error from a byte slice. +func GLXBadProfileARBErrorNew(buf []byte) xgb.Error { + v := GLXBadProfileARBError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "GLXBadProfileARB" + return v +} + +// SequenceId returns the sequence id attached to the BadGLXBadProfileARB error. +// This is mostly used internally. +func (err GLXBadProfileARBError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadGLXBadProfileARB error. If no bad value exists, 0 is returned. +func (err GLXBadProfileARBError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadGLXBadProfileARB error. +func (err GLXBadProfileARBError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadGLXBadProfileARB {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][13] = GLXBadProfileARBErrorNew +} + +const ( + GcGlCurrentBit = 1 + GcGlPointBit = 2 + GcGlLineBit = 4 + GcGlPolygonBit = 8 + GcGlPolygonStippleBit = 16 + GcGlPixelModeBit = 32 + GcGlLightingBit = 64 + GcGlFogBit = 128 + GcGlDepthBufferBit = 256 + GcGlAccumBufferBit = 512 + GcGlStencilBufferBit = 1024 + GcGlViewportBit = 2048 + GcGlTransformBit = 4096 + GcGlEnableBit = 8192 + GcGlColorBufferBit = 16384 + GcGlHintBit = 32768 + GcGlEvalBit = 65536 + GcGlListBit = 131072 + GcGlTextureBit = 262144 + GcGlScissorBit = 524288 + GcGlAllAttribBits = 16777215 +) + +// BadGeneric is the error number for a BadGeneric. +const BadGeneric = -1 + +type GenericError struct { + Sequence uint16 + NiceName string + BadValue uint32 + MinorOpcode uint16 + MajorOpcode byte + // padding: 21 bytes +} + +// GenericErrorNew constructs a GenericError value that implements xgb.Error from a byte slice. +func GenericErrorNew(buf []byte) xgb.Error { + v := GenericError{} + v.NiceName = "Generic" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.BadValue = xgb.Get32(buf[b:]) + b += 4 + + v.MinorOpcode = xgb.Get16(buf[b:]) + b += 2 + + v.MajorOpcode = buf[b] + b += 1 + + b += 21 // padding + + return v +} + +// SequenceId returns the sequence id attached to the BadGeneric error. +// This is mostly used internally. +func (err GenericError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadGeneric error. If no bad value exists, 0 is returned. +func (err GenericError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadGeneric error. + +func (err GenericError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadGeneric {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][-1] = GenericErrorNew +} + +const ( + PbcdtWindow = 32793 + PbcdtPbuffer = 32794 +) + +const ( + PbcetDamaged = 32791 + PbcetSaved = 32792 +) + +type Pbuffer uint32 + +func NewPbufferId(c *xgb.Conn) (Pbuffer, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Pbuffer(id), nil +} + +// PbufferClobber is the event number for a PbufferClobberEvent. +const PbufferClobber = 0 + +type PbufferClobberEvent struct { + Sequence uint16 + // padding: 1 bytes + EventType uint16 + DrawType uint16 + Drawable Drawable + BMask uint32 + AuxBuffer uint16 + X uint16 + Y uint16 + Width uint16 + Height uint16 + Count uint16 + // padding: 4 bytes +} + +// PbufferClobberEventNew constructs a PbufferClobberEvent value that implements xgb.Event from a byte slice. +func PbufferClobberEventNew(buf []byte) xgb.Event { + v := PbufferClobberEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.EventType = xgb.Get16(buf[b:]) + b += 2 + + v.DrawType = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.BMask = xgb.Get32(buf[b:]) + b += 4 + + v.AuxBuffer = xgb.Get16(buf[b:]) + b += 2 + + v.X = xgb.Get16(buf[b:]) + b += 2 + + v.Y = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Count = xgb.Get16(buf[b:]) + b += 2 + + b += 4 // padding + + return v +} + +// Bytes writes a PbufferClobberEvent value to a byte slice. +func (v PbufferClobberEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put16(buf[b:], v.EventType) + b += 2 + + xgb.Put16(buf[b:], v.DrawType) + b += 2 + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put32(buf[b:], v.BMask) + b += 4 + + xgb.Put16(buf[b:], v.AuxBuffer) + b += 2 + + xgb.Put16(buf[b:], v.X) + b += 2 + + xgb.Put16(buf[b:], v.Y) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.Count) + b += 2 + + b += 4 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the PbufferClobber event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v PbufferClobberEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of PbufferClobberEvent. +func (v PbufferClobberEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("EventType: %d", v.EventType)) + fieldVals = append(fieldVals, xgb.Sprintf("DrawType: %d", v.DrawType)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("BMask: %d", v.BMask)) + fieldVals = append(fieldVals, xgb.Sprintf("AuxBuffer: %d", v.AuxBuffer)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) + return "PbufferClobber {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["GLX"][0] = PbufferClobberEventNew +} + +type Pixmap uint32 + +func NewPixmapId(c *xgb.Conn) (Pixmap, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Pixmap(id), nil +} + +const ( + RmGlRender = 7168 + RmGlFeedback = 7169 + RmGlSelect = 7170 +) + +// BadUnsupportedPrivateRequest is the error number for a BadUnsupportedPrivateRequest. +const BadUnsupportedPrivateRequest = 8 + +type UnsupportedPrivateRequestError GenericError + +// UnsupportedPrivateRequestErrorNew constructs a UnsupportedPrivateRequestError value that implements xgb.Error from a byte slice. +func UnsupportedPrivateRequestErrorNew(buf []byte) xgb.Error { + v := UnsupportedPrivateRequestError(GenericErrorNew(buf).(GenericError)) + v.NiceName = "UnsupportedPrivateRequest" + return v +} + +// SequenceId returns the sequence id attached to the BadUnsupportedPrivateRequest error. +// This is mostly used internally. +func (err UnsupportedPrivateRequestError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadUnsupportedPrivateRequest error. If no bad value exists, 0 is returned. +func (err UnsupportedPrivateRequestError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadUnsupportedPrivateRequest error. +func (err UnsupportedPrivateRequestError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadUnsupportedPrivateRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["GLX"][8] = UnsupportedPrivateRequestErrorNew +} + +type Window uint32 + +func NewWindowId(c *xgb.Conn) (Window, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Window(id), nil +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AreTexturesResidentCookie is a cookie used only for AreTexturesResident requests. +type AreTexturesResidentCookie struct { + *xgb.Cookie +} + +// AreTexturesResident sends a checked request. +// If an error occurs, it will be returned with the reply by calling AreTexturesResidentCookie.Reply() +func AreTexturesResident(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) AreTexturesResidentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'AreTexturesResident' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(areTexturesResidentRequest(c, ContextTag, N, Textures), cookie) + return AreTexturesResidentCookie{cookie} +} + +// AreTexturesResidentUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AreTexturesResidentUnchecked(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) AreTexturesResidentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'AreTexturesResident' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(areTexturesResidentRequest(c, ContextTag, N, Textures), cookie) + return AreTexturesResidentCookie{cookie} +} + +// AreTexturesResidentReply represents the data returned from a AreTexturesResident request. +type AreTexturesResidentReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 + // padding: 20 bytes + Data []bool // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a AreTexturesResident request. +func (cook AreTexturesResidentCookie) Reply() (*AreTexturesResidentReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return areTexturesResidentReply(buf), nil +} + +// areTexturesResidentReply reads a byte slice into a AreTexturesResidentReply value. +func areTexturesResidentReply(buf []byte) *AreTexturesResidentReply { + v := new(AreTexturesResidentReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + v.Data = make([]bool, (int(v.Length) * 4)) + for i := 0; i < int((int(v.Length) * 4)); i++ { + if buf[b] == 1 { + v.Data[i] = true + } else { + v.Data[i] = false + } + b += 1 + } + + return v +} + +// Write request to wire for AreTexturesResident +// areTexturesResidentRequest writes a AreTexturesResident request to a byte slice. +func areTexturesResidentRequest(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((int(N) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 143 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(N)) + b += 4 + + for i := 0; i < int(N); i++ { + xgb.Put32(buf[b:], Textures[i]) + b += 4 + } + + return buf +} + +// ChangeDrawableAttributesCookie is a cookie used only for ChangeDrawableAttributes requests. +type ChangeDrawableAttributesCookie struct { + *xgb.Cookie +} + +// ChangeDrawableAttributes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeDrawableAttributes(c *xgb.Conn, Drawable Drawable, NumAttribs uint32, Attribs []uint32) ChangeDrawableAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ChangeDrawableAttributes' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeDrawableAttributesRequest(c, Drawable, NumAttribs, Attribs), cookie) + return ChangeDrawableAttributesCookie{cookie} +} + +// ChangeDrawableAttributesChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeDrawableAttributesCookie.Check() +func ChangeDrawableAttributesChecked(c *xgb.Conn, Drawable Drawable, NumAttribs uint32, Attribs []uint32) ChangeDrawableAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ChangeDrawableAttributes' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeDrawableAttributesRequest(c, Drawable, NumAttribs, Attribs), cookie) + return ChangeDrawableAttributesCookie{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 ChangeDrawableAttributesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeDrawableAttributes +// changeDrawableAttributesRequest writes a ChangeDrawableAttributes request to a byte slice. +func changeDrawableAttributesRequest(c *xgb.Conn, Drawable Drawable, NumAttribs uint32, Attribs []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad(((int(NumAttribs) * 2) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 30 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], NumAttribs) + b += 4 + + for i := 0; i < int((int(NumAttribs) * 2)); i++ { + xgb.Put32(buf[b:], Attribs[i]) + b += 4 + } + + return buf +} + +// ClientInfoCookie is a cookie used only for ClientInfo requests. +type ClientInfoCookie struct { + *xgb.Cookie +} + +// ClientInfo sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ClientInfo(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, StrLen uint32, String string) ClientInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ClientInfo' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(clientInfoRequest(c, MajorVersion, MinorVersion, StrLen, String), cookie) + return ClientInfoCookie{cookie} +} + +// ClientInfoChecked sends a checked request. +// If an error occurs, it can be retrieved using ClientInfoCookie.Check() +func ClientInfoChecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, StrLen uint32, String string) ClientInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ClientInfo' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(clientInfoRequest(c, MajorVersion, MinorVersion, StrLen, String), cookie) + return ClientInfoCookie{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 ClientInfoCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ClientInfo +// clientInfoRequest writes a ClientInfo request to a byte slice. +func clientInfoRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, StrLen uint32, String string) []byte { + size := xgb.Pad((16 + xgb.Pad((int(StrLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + xgb.Put32(buf[b:], StrLen) + b += 4 + + copy(buf[b:], String[:StrLen]) + b += int(StrLen) + + return buf +} + +// CopyContextCookie is a cookie used only for CopyContext requests. +type CopyContextCookie struct { + *xgb.Cookie +} + +// CopyContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyContext(c *xgb.Conn, Src Context, Dest Context, Mask uint32, SrcContextTag ContextTag) CopyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CopyContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(copyContextRequest(c, Src, Dest, Mask, SrcContextTag), cookie) + return CopyContextCookie{cookie} +} + +// CopyContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyContextCookie.Check() +func CopyContextChecked(c *xgb.Conn, Src Context, Dest Context, Mask uint32, SrcContextTag ContextTag) CopyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CopyContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(copyContextRequest(c, Src, Dest, Mask, SrcContextTag), cookie) + return CopyContextCookie{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 CopyContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyContext +// copyContextRequest writes a CopyContext request to a byte slice. +func copyContextRequest(c *xgb.Conn, Src Context, Dest Context, Mask uint32, SrcContextTag ContextTag) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // 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(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dest)) + b += 4 + + xgb.Put32(buf[b:], Mask) + b += 4 + + xgb.Put32(buf[b:], uint32(SrcContextTag)) + b += 4 + + return buf +} + +// CreateContextCookie is a cookie used only for CreateContext requests. +type CreateContextCookie struct { + *xgb.Cookie +} + +// CreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContext(c *xgb.Conn, Context Context, Visual xproto.Visualid, Screen uint32, ShareList Context, IsDirect bool) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createContextRequest(c, Context, Visual, Screen, ShareList, IsDirect), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateContextCookie.Check() +func CreateContextChecked(c *xgb.Conn, Context Context, Visual xproto.Visualid, Screen uint32, ShareList Context, IsDirect bool) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createContextRequest(c, Context, Visual, Screen, ShareList, IsDirect), cookie) + return CreateContextCookie{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 CreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. +func createContextRequest(c *xgb.Conn, Context Context, Visual xproto.Visualid, Screen uint32, ShareList Context, IsDirect bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + xgb.Put32(buf[b:], uint32(Visual)) + b += 4 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(ShareList)) + b += 4 + + if IsDirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// CreateContextAttribsARBCookie is a cookie used only for CreateContextAttribsARB requests. +type CreateContextAttribsARBCookie struct { + *xgb.Cookie +} + +// CreateContextAttribsARB sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContextAttribsARB(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, ShareList Context, IsDirect bool, NumAttribs uint32, Attribs []uint32) CreateContextAttribsARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateContextAttribsARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createContextAttribsARBRequest(c, Context, Fbconfig, Screen, ShareList, IsDirect, NumAttribs, Attribs), cookie) + return CreateContextAttribsARBCookie{cookie} +} + +// CreateContextAttribsARBChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateContextAttribsARBCookie.Check() +func CreateContextAttribsARBChecked(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, ShareList Context, IsDirect bool, NumAttribs uint32, Attribs []uint32) CreateContextAttribsARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateContextAttribsARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createContextAttribsARBRequest(c, Context, Fbconfig, Screen, ShareList, IsDirect, NumAttribs, Attribs), cookie) + return CreateContextAttribsARBCookie{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 CreateContextAttribsARBCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateContextAttribsARB +// createContextAttribsARBRequest writes a CreateContextAttribsARB request to a byte slice. +func createContextAttribsARBRequest(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, ShareList Context, IsDirect bool, NumAttribs uint32, Attribs []uint32) []byte { + size := xgb.Pad((28 + xgb.Pad(((int(NumAttribs) * 2) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 34 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], uint32(Fbconfig)) + b += 4 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(ShareList)) + b += 4 + + if IsDirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumAttribs) + b += 4 + + for i := 0; i < int((int(NumAttribs) * 2)); i++ { + xgb.Put32(buf[b:], Attribs[i]) + b += 4 + } + + return buf +} + +// CreateGLXPixmapCookie is a cookie used only for CreateGLXPixmap requests. +type CreateGLXPixmapCookie struct { + *xgb.Cookie +} + +// CreateGLXPixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateGLXPixmap(c *xgb.Conn, Screen uint32, Visual xproto.Visualid, Pixmap xproto.Pixmap, GlxPixmap Pixmap) CreateGLXPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateGLXPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createGLXPixmapRequest(c, Screen, Visual, Pixmap, GlxPixmap), cookie) + return CreateGLXPixmapCookie{cookie} +} + +// CreateGLXPixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateGLXPixmapCookie.Check() +func CreateGLXPixmapChecked(c *xgb.Conn, Screen uint32, Visual xproto.Visualid, Pixmap xproto.Pixmap, GlxPixmap Pixmap) CreateGLXPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateGLXPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createGLXPixmapRequest(c, Screen, Visual, Pixmap, GlxPixmap), cookie) + return CreateGLXPixmapCookie{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 CreateGLXPixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateGLXPixmap +// createGLXPixmapRequest writes a CreateGLXPixmap request to a byte slice. +func createGLXPixmapRequest(c *xgb.Conn, Screen uint32, Visual xproto.Visualid, Pixmap xproto.Pixmap, GlxPixmap Pixmap) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Visual)) + b += 4 + + xgb.Put32(buf[b:], uint32(Pixmap)) + b += 4 + + xgb.Put32(buf[b:], uint32(GlxPixmap)) + b += 4 + + return buf +} + +// CreateNewContextCookie is a cookie used only for CreateNewContext requests. +type CreateNewContextCookie struct { + *xgb.Cookie +} + +// CreateNewContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateNewContext(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, RenderType uint32, ShareList Context, IsDirect bool) CreateNewContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateNewContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createNewContextRequest(c, Context, Fbconfig, Screen, RenderType, ShareList, IsDirect), cookie) + return CreateNewContextCookie{cookie} +} + +// CreateNewContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateNewContextCookie.Check() +func CreateNewContextChecked(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, RenderType uint32, ShareList Context, IsDirect bool) CreateNewContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateNewContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createNewContextRequest(c, Context, Fbconfig, Screen, RenderType, ShareList, IsDirect), cookie) + return CreateNewContextCookie{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 CreateNewContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateNewContext +// createNewContextRequest writes a CreateNewContext request to a byte slice. +func createNewContextRequest(c *xgb.Conn, Context Context, Fbconfig Fbconfig, Screen uint32, RenderType uint32, ShareList Context, IsDirect bool) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 24 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], uint32(Fbconfig)) + b += 4 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], RenderType) + b += 4 + + xgb.Put32(buf[b:], uint32(ShareList)) + b += 4 + + if IsDirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// CreatePbufferCookie is a cookie used only for CreatePbuffer requests. +type CreatePbufferCookie struct { + *xgb.Cookie +} + +// CreatePbuffer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePbuffer(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pbuffer Pbuffer, NumAttribs uint32, Attribs []uint32) CreatePbufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreatePbuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createPbufferRequest(c, Screen, Fbconfig, Pbuffer, NumAttribs, Attribs), cookie) + return CreatePbufferCookie{cookie} +} + +// CreatePbufferChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePbufferCookie.Check() +func CreatePbufferChecked(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pbuffer Pbuffer, NumAttribs uint32, Attribs []uint32) CreatePbufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreatePbuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createPbufferRequest(c, Screen, Fbconfig, Pbuffer, NumAttribs, Attribs), cookie) + return CreatePbufferCookie{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 CreatePbufferCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePbuffer +// createPbufferRequest writes a CreatePbuffer request to a byte slice. +func createPbufferRequest(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pbuffer Pbuffer, NumAttribs uint32, Attribs []uint32) []byte { + size := xgb.Pad((20 + xgb.Pad(((int(NumAttribs) * 2) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 27 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Fbconfig)) + b += 4 + + xgb.Put32(buf[b:], uint32(Pbuffer)) + b += 4 + + xgb.Put32(buf[b:], NumAttribs) + b += 4 + + for i := 0; i < int((int(NumAttribs) * 2)); i++ { + xgb.Put32(buf[b:], Attribs[i]) + b += 4 + } + + return buf +} + +// CreatePixmapCookie is a cookie used only for CreatePixmap requests. +type CreatePixmapCookie struct { + *xgb.Cookie +} + +// CreatePixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePixmap(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pixmap xproto.Pixmap, GlxPixmap Pixmap, NumAttribs uint32, Attribs []uint32) CreatePixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createPixmapRequest(c, Screen, Fbconfig, Pixmap, GlxPixmap, NumAttribs, Attribs), cookie) + return CreatePixmapCookie{cookie} +} + +// CreatePixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePixmapCookie.Check() +func CreatePixmapChecked(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pixmap xproto.Pixmap, GlxPixmap Pixmap, NumAttribs uint32, Attribs []uint32) CreatePixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createPixmapRequest(c, Screen, Fbconfig, Pixmap, GlxPixmap, NumAttribs, Attribs), cookie) + return CreatePixmapCookie{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 CreatePixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePixmap +// createPixmapRequest writes a CreatePixmap request to a byte slice. +func createPixmapRequest(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Pixmap xproto.Pixmap, GlxPixmap Pixmap, NumAttribs uint32, Attribs []uint32) []byte { + size := xgb.Pad((24 + xgb.Pad(((int(NumAttribs) * 2) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Fbconfig)) + b += 4 + + xgb.Put32(buf[b:], uint32(Pixmap)) + b += 4 + + xgb.Put32(buf[b:], uint32(GlxPixmap)) + b += 4 + + xgb.Put32(buf[b:], NumAttribs) + b += 4 + + for i := 0; i < int((int(NumAttribs) * 2)); i++ { + xgb.Put32(buf[b:], Attribs[i]) + b += 4 + } + + return buf +} + +// CreateWindowCookie is a cookie used only for CreateWindow requests. +type CreateWindowCookie struct { + *xgb.Cookie +} + +// CreateWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateWindow(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Window xproto.Window, GlxWindow Window, NumAttribs uint32, Attribs []uint32) CreateWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateWindow' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createWindowRequest(c, Screen, Fbconfig, Window, GlxWindow, NumAttribs, Attribs), cookie) + return CreateWindowCookie{cookie} +} + +// CreateWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateWindowCookie.Check() +func CreateWindowChecked(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Window xproto.Window, GlxWindow Window, NumAttribs uint32, Attribs []uint32) CreateWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'CreateWindow' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createWindowRequest(c, Screen, Fbconfig, Window, GlxWindow, NumAttribs, Attribs), cookie) + return CreateWindowCookie{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 CreateWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateWindow +// createWindowRequest writes a CreateWindow request to a byte slice. +func createWindowRequest(c *xgb.Conn, Screen uint32, Fbconfig Fbconfig, Window xproto.Window, GlxWindow Window, NumAttribs uint32, Attribs []uint32) []byte { + size := xgb.Pad((24 + xgb.Pad(((int(NumAttribs) * 2) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 31 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Fbconfig)) + b += 4 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(GlxWindow)) + b += 4 + + xgb.Put32(buf[b:], NumAttribs) + b += 4 + + for i := 0; i < int((int(NumAttribs) * 2)); i++ { + xgb.Put32(buf[b:], Attribs[i]) + b += 4 + } + + return buf +} + +// DeleteListsCookie is a cookie used only for DeleteLists requests. +type DeleteListsCookie struct { + *xgb.Cookie +} + +// DeleteLists sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteLists(c *xgb.Conn, ContextTag ContextTag, List uint32, Range int32) DeleteListsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteLists' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteListsRequest(c, ContextTag, List, Range), cookie) + return DeleteListsCookie{cookie} +} + +// DeleteListsChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteListsCookie.Check() +func DeleteListsChecked(c *xgb.Conn, ContextTag ContextTag, List uint32, Range int32) DeleteListsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteLists' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteListsRequest(c, ContextTag, List, Range), cookie) + return DeleteListsCookie{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 DeleteListsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteLists +// deleteListsRequest writes a DeleteLists request to a byte slice. +func deleteListsRequest(c *xgb.Conn, ContextTag ContextTag, List uint32, Range int32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 103 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], List) + b += 4 + + xgb.Put32(buf[b:], uint32(Range)) + b += 4 + + return buf +} + +// DeleteQueriesARBCookie is a cookie used only for DeleteQueriesARB requests. +type DeleteQueriesARBCookie struct { + *xgb.Cookie +} + +// DeleteQueriesARB sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteQueriesARB(c *xgb.Conn, ContextTag ContextTag, N int32, Ids []uint32) DeleteQueriesARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteQueriesARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteQueriesARBRequest(c, ContextTag, N, Ids), cookie) + return DeleteQueriesARBCookie{cookie} +} + +// DeleteQueriesARBChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteQueriesARBCookie.Check() +func DeleteQueriesARBChecked(c *xgb.Conn, ContextTag ContextTag, N int32, Ids []uint32) DeleteQueriesARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteQueriesARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteQueriesARBRequest(c, ContextTag, N, Ids), cookie) + return DeleteQueriesARBCookie{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 DeleteQueriesARBCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteQueriesARB +// deleteQueriesARBRequest writes a DeleteQueriesARB request to a byte slice. +func deleteQueriesARBRequest(c *xgb.Conn, ContextTag ContextTag, N int32, Ids []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((int(N) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 161 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(N)) + b += 4 + + for i := 0; i < int(N); i++ { + xgb.Put32(buf[b:], Ids[i]) + b += 4 + } + + return buf +} + +// DeleteTexturesCookie is a cookie used only for DeleteTextures requests. +type DeleteTexturesCookie struct { + *xgb.Cookie +} + +// DeleteTextures sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteTextures(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) DeleteTexturesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteTextures' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteTexturesRequest(c, ContextTag, N, Textures), cookie) + return DeleteTexturesCookie{cookie} +} + +// DeleteTexturesChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteTexturesCookie.Check() +func DeleteTexturesChecked(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) DeleteTexturesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteTextures' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteTexturesRequest(c, ContextTag, N, Textures), cookie) + return DeleteTexturesCookie{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 DeleteTexturesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteTextures +// deleteTexturesRequest writes a DeleteTextures request to a byte slice. +func deleteTexturesRequest(c *xgb.Conn, ContextTag ContextTag, N int32, Textures []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((int(N) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 144 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(N)) + b += 4 + + for i := 0; i < int(N); i++ { + xgb.Put32(buf[b:], Textures[i]) + b += 4 + } + + return buf +} + +// DeleteWindowCookie is a cookie used only for DeleteWindow requests. +type DeleteWindowCookie struct { + *xgb.Cookie +} + +// DeleteWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteWindow(c *xgb.Conn, Glxwindow Window) DeleteWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteWindow' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteWindowRequest(c, Glxwindow), cookie) + return DeleteWindowCookie{cookie} +} + +// DeleteWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteWindowCookie.Check() +func DeleteWindowChecked(c *xgb.Conn, Glxwindow Window) DeleteWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DeleteWindow' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteWindowRequest(c, Glxwindow), cookie) + return DeleteWindowCookie{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 DeleteWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteWindow +// deleteWindowRequest writes a DeleteWindow request to a byte slice. +func deleteWindowRequest(c *xgb.Conn, Glxwindow Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 32 // 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(Glxwindow)) + b += 4 + + return buf +} + +// DestroyContextCookie is a cookie used only for DestroyContext requests. +type DestroyContextCookie struct { + *xgb.Cookie +} + +// DestroyContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyContext(c *xgb.Conn, Context Context) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyContextRequest(c, Context), cookie) + return DestroyContextCookie{cookie} +} + +// DestroyContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyContextCookie.Check() +func DestroyContextChecked(c *xgb.Conn, Context Context) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyContextRequest(c, Context), cookie) + return DestroyContextCookie{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 DestroyContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyContext +// destroyContextRequest writes a DestroyContext request to a byte slice. +func destroyContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Context)) + b += 4 + + return buf +} + +// DestroyGLXPixmapCookie is a cookie used only for DestroyGLXPixmap requests. +type DestroyGLXPixmapCookie struct { + *xgb.Cookie +} + +// DestroyGLXPixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyGLXPixmap(c *xgb.Conn, GlxPixmap Pixmap) DestroyGLXPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyGLXPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyGLXPixmapRequest(c, GlxPixmap), cookie) + return DestroyGLXPixmapCookie{cookie} +} + +// DestroyGLXPixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyGLXPixmapCookie.Check() +func DestroyGLXPixmapChecked(c *xgb.Conn, GlxPixmap Pixmap) DestroyGLXPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyGLXPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyGLXPixmapRequest(c, GlxPixmap), cookie) + return DestroyGLXPixmapCookie{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 DestroyGLXPixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyGLXPixmap +// destroyGLXPixmapRequest writes a DestroyGLXPixmap request to a byte slice. +func destroyGLXPixmapRequest(c *xgb.Conn, GlxPixmap Pixmap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // 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(GlxPixmap)) + b += 4 + + return buf +} + +// DestroyPbufferCookie is a cookie used only for DestroyPbuffer requests. +type DestroyPbufferCookie struct { + *xgb.Cookie +} + +// DestroyPbuffer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyPbuffer(c *xgb.Conn, Pbuffer Pbuffer) DestroyPbufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyPbuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyPbufferRequest(c, Pbuffer), cookie) + return DestroyPbufferCookie{cookie} +} + +// DestroyPbufferChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyPbufferCookie.Check() +func DestroyPbufferChecked(c *xgb.Conn, Pbuffer Pbuffer) DestroyPbufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyPbuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyPbufferRequest(c, Pbuffer), cookie) + return DestroyPbufferCookie{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 DestroyPbufferCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyPbuffer +// destroyPbufferRequest writes a DestroyPbuffer request to a byte slice. +func destroyPbufferRequest(c *xgb.Conn, Pbuffer Pbuffer) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 28 // 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(Pbuffer)) + b += 4 + + return buf +} + +// DestroyPixmapCookie is a cookie used only for DestroyPixmap requests. +type DestroyPixmapCookie struct { + *xgb.Cookie +} + +// DestroyPixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyPixmap(c *xgb.Conn, GlxPixmap Pixmap) DestroyPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyPixmapRequest(c, GlxPixmap), cookie) + return DestroyPixmapCookie{cookie} +} + +// DestroyPixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyPixmapCookie.Check() +func DestroyPixmapChecked(c *xgb.Conn, GlxPixmap Pixmap) DestroyPixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'DestroyPixmap' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyPixmapRequest(c, GlxPixmap), cookie) + return DestroyPixmapCookie{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 DestroyPixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyPixmap +// destroyPixmapRequest writes a DestroyPixmap request to a byte slice. +func destroyPixmapRequest(c *xgb.Conn, GlxPixmap Pixmap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 23 // 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(GlxPixmap)) + b += 4 + + return buf +} + +// EndListCookie is a cookie used only for EndList requests. +type EndListCookie struct { + *xgb.Cookie +} + +// EndList sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func EndList(c *xgb.Conn, ContextTag ContextTag) EndListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'EndList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(endListRequest(c, ContextTag), cookie) + return EndListCookie{cookie} +} + +// EndListChecked sends a checked request. +// If an error occurs, it can be retrieved using EndListCookie.Check() +func EndListChecked(c *xgb.Conn, ContextTag ContextTag) EndListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'EndList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(endListRequest(c, ContextTag), cookie) + return EndListCookie{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 EndListCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for EndList +// endListRequest writes a EndList request to a byte slice. +func endListRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 102 // 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(ContextTag)) + b += 4 + + return buf +} + +// FeedbackBufferCookie is a cookie used only for FeedbackBuffer requests. +type FeedbackBufferCookie struct { + *xgb.Cookie +} + +// FeedbackBuffer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FeedbackBuffer(c *xgb.Conn, ContextTag ContextTag, Size int32, Type int32) FeedbackBufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'FeedbackBuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(feedbackBufferRequest(c, ContextTag, Size, Type), cookie) + return FeedbackBufferCookie{cookie} +} + +// FeedbackBufferChecked sends a checked request. +// If an error occurs, it can be retrieved using FeedbackBufferCookie.Check() +func FeedbackBufferChecked(c *xgb.Conn, ContextTag ContextTag, Size int32, Type int32) FeedbackBufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'FeedbackBuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(feedbackBufferRequest(c, ContextTag, Size, Type), cookie) + return FeedbackBufferCookie{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 FeedbackBufferCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FeedbackBuffer +// feedbackBufferRequest writes a FeedbackBuffer request to a byte slice. +func feedbackBufferRequest(c *xgb.Conn, ContextTag ContextTag, Size int32, Type int32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 105 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Size)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + return buf +} + +// FinishCookie is a cookie used only for Finish requests. +type FinishCookie struct { + *xgb.Cookie +} + +// Finish sends a checked request. +// If an error occurs, it will be returned with the reply by calling FinishCookie.Reply() +func Finish(c *xgb.Conn, ContextTag ContextTag) FinishCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Finish' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(finishRequest(c, ContextTag), cookie) + return FinishCookie{cookie} +} + +// FinishUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FinishUnchecked(c *xgb.Conn, ContextTag ContextTag) FinishCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Finish' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(finishRequest(c, ContextTag), cookie) + return FinishCookie{cookie} +} + +// FinishReply represents the data returned from a Finish request. +type FinishReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes +} + +// Reply blocks and returns the reply data for a Finish request. +func (cook FinishCookie) Reply() (*FinishReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return finishReply(buf), nil +} + +// finishReply reads a byte slice into a FinishReply value. +func finishReply(buf []byte) *FinishReply { + v := new(FinishReply) + b := 1 // skip reply determinant + + b += 1 // padding + + 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 Finish +// finishRequest writes a Finish request to a byte slice. +func finishRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 108 // 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(ContextTag)) + b += 4 + + return buf +} + +// FlushCookie is a cookie used only for Flush requests. +type FlushCookie struct { + *xgb.Cookie +} + +// Flush sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Flush(c *xgb.Conn, ContextTag ContextTag) FlushCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Flush' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(flushRequest(c, ContextTag), cookie) + return FlushCookie{cookie} +} + +// FlushChecked sends a checked request. +// If an error occurs, it can be retrieved using FlushCookie.Check() +func FlushChecked(c *xgb.Conn, ContextTag ContextTag) FlushCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Flush' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(flushRequest(c, ContextTag), cookie) + return FlushCookie{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 FlushCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Flush +// flushRequest writes a Flush request to a byte slice. +func flushRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 142 // 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(ContextTag)) + b += 4 + + return buf +} + +// GenListsCookie is a cookie used only for GenLists requests. +type GenListsCookie struct { + *xgb.Cookie +} + +// GenLists sends a checked request. +// If an error occurs, it will be returned with the reply by calling GenListsCookie.Reply() +func GenLists(c *xgb.Conn, ContextTag ContextTag, Range int32) GenListsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenLists' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(genListsRequest(c, ContextTag, Range), cookie) + return GenListsCookie{cookie} +} + +// GenListsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GenListsUnchecked(c *xgb.Conn, ContextTag ContextTag, Range int32) GenListsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenLists' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(genListsRequest(c, ContextTag, Range), cookie) + return GenListsCookie{cookie} +} + +// GenListsReply represents the data returned from a GenLists request. +type GenListsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal uint32 +} + +// Reply blocks and returns the reply data for a GenLists request. +func (cook GenListsCookie) Reply() (*GenListsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return genListsReply(buf), nil +} + +// genListsReply reads a byte slice into a GenListsReply value. +func genListsReply(buf []byte) *GenListsReply { + v := new(GenListsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GenLists +// genListsRequest writes a GenLists request to a byte slice. +func genListsRequest(c *xgb.Conn, ContextTag ContextTag, Range int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 104 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Range)) + b += 4 + + return buf +} + +// GenQueriesARBCookie is a cookie used only for GenQueriesARB requests. +type GenQueriesARBCookie struct { + *xgb.Cookie +} + +// GenQueriesARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling GenQueriesARBCookie.Reply() +func GenQueriesARB(c *xgb.Conn, ContextTag ContextTag, N int32) GenQueriesARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenQueriesARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(genQueriesARBRequest(c, ContextTag, N), cookie) + return GenQueriesARBCookie{cookie} +} + +// GenQueriesARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GenQueriesARBUnchecked(c *xgb.Conn, ContextTag ContextTag, N int32) GenQueriesARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenQueriesARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(genQueriesARBRequest(c, ContextTag, N), cookie) + return GenQueriesARBCookie{cookie} +} + +// GenQueriesARBReply represents the data returned from a GenQueriesARB request. +type GenQueriesARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a GenQueriesARB request. +func (cook GenQueriesARBCookie) Reply() (*GenQueriesARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return genQueriesARBReply(buf), nil +} + +// genQueriesARBReply reads a byte slice into a GenQueriesARBReply value. +func genQueriesARBReply(buf []byte) *GenQueriesARBReply { + v := new(GenQueriesARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Data = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.Data[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GenQueriesARB +// genQueriesARBRequest writes a GenQueriesARB request to a byte slice. +func genQueriesARBRequest(c *xgb.Conn, ContextTag ContextTag, N int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 162 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(N)) + b += 4 + + return buf +} + +// GenTexturesCookie is a cookie used only for GenTextures requests. +type GenTexturesCookie struct { + *xgb.Cookie +} + +// GenTextures sends a checked request. +// If an error occurs, it will be returned with the reply by calling GenTexturesCookie.Reply() +func GenTextures(c *xgb.Conn, ContextTag ContextTag, N int32) GenTexturesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenTextures' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(genTexturesRequest(c, ContextTag, N), cookie) + return GenTexturesCookie{cookie} +} + +// GenTexturesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GenTexturesUnchecked(c *xgb.Conn, ContextTag ContextTag, N int32) GenTexturesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GenTextures' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(genTexturesRequest(c, ContextTag, N), cookie) + return GenTexturesCookie{cookie} +} + +// GenTexturesReply represents the data returned from a GenTextures request. +type GenTexturesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a GenTextures request. +func (cook GenTexturesCookie) Reply() (*GenTexturesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return genTexturesReply(buf), nil +} + +// genTexturesReply reads a byte slice into a GenTexturesReply value. +func genTexturesReply(buf []byte) *GenTexturesReply { + v := new(GenTexturesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Data = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.Data[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GenTextures +// genTexturesRequest writes a GenTextures request to a byte slice. +func genTexturesRequest(c *xgb.Conn, ContextTag ContextTag, N int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 145 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(N)) + b += 4 + + return buf +} + +// GetBooleanvCookie is a cookie used only for GetBooleanv requests. +type GetBooleanvCookie struct { + *xgb.Cookie +} + +// GetBooleanv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetBooleanvCookie.Reply() +func GetBooleanv(c *xgb.Conn, ContextTag ContextTag, Pname int32) GetBooleanvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetBooleanv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getBooleanvRequest(c, ContextTag, Pname), cookie) + return GetBooleanvCookie{cookie} +} + +// GetBooleanvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetBooleanvUnchecked(c *xgb.Conn, ContextTag ContextTag, Pname int32) GetBooleanvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetBooleanv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getBooleanvRequest(c, ContextTag, Pname), cookie) + return GetBooleanvCookie{cookie} +} + +// GetBooleanvReply represents the data returned from a GetBooleanv request. +type GetBooleanvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum bool + // padding: 15 bytes + Data []bool // size: xgb.Pad((int(N) * 1)) +} + +// Reply blocks and returns the reply data for a GetBooleanv request. +func (cook GetBooleanvCookie) Reply() (*GetBooleanvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getBooleanvReply(buf), nil +} + +// getBooleanvReply reads a byte slice into a GetBooleanvReply value. +func getBooleanvReply(buf []byte) *GetBooleanvReply { + v := new(GetBooleanvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + if buf[b] == 1 { + v.Datum = true + } else { + v.Datum = false + } + b += 1 + + b += 15 // padding + + v.Data = make([]bool, v.N) + for i := 0; i < int(v.N); i++ { + if buf[b] == 1 { + v.Data[i] = true + } else { + v.Data[i] = false + } + b += 1 + } + + return v +} + +// Write request to wire for GetBooleanv +// getBooleanvRequest writes a GetBooleanv request to a byte slice. +func getBooleanvRequest(c *xgb.Conn, ContextTag ContextTag, Pname int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 112 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Pname)) + b += 4 + + return buf +} + +// GetClipPlaneCookie is a cookie used only for GetClipPlane requests. +type GetClipPlaneCookie struct { + *xgb.Cookie +} + +// GetClipPlane sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetClipPlaneCookie.Reply() +func GetClipPlane(c *xgb.Conn, ContextTag ContextTag, Plane int32) GetClipPlaneCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetClipPlane' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getClipPlaneRequest(c, ContextTag, Plane), cookie) + return GetClipPlaneCookie{cookie} +} + +// GetClipPlaneUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetClipPlaneUnchecked(c *xgb.Conn, ContextTag ContextTag, Plane int32) GetClipPlaneCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetClipPlane' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getClipPlaneRequest(c, ContextTag, Plane), cookie) + return GetClipPlaneCookie{cookie} +} + +// GetClipPlaneReply represents the data returned from a GetClipPlane request. +type GetClipPlaneReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []Float64 // size: xgb.Pad(((int(Length) / 2) * 8)) +} + +// Reply blocks and returns the reply data for a GetClipPlane request. +func (cook GetClipPlaneCookie) Reply() (*GetClipPlaneReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getClipPlaneReply(buf), nil +} + +// getClipPlaneReply reads a byte slice into a GetClipPlaneReply value. +func getClipPlaneReply(buf []byte) *GetClipPlaneReply { + v := new(GetClipPlaneReply) + b := 1 // skip reply determinant + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 1 // padding + + b += 24 // padding + + v.Data = make([]Float64, (int(v.Length) / 2)) + for i := 0; i < int((int(v.Length) / 2)); i++ { + v.Data[i] = Float64(xgb.Get64(buf[b:])) + b += 8 + } + + return v +} + +// Write request to wire for GetClipPlane +// getClipPlaneRequest writes a GetClipPlane request to a byte slice. +func getClipPlaneRequest(c *xgb.Conn, ContextTag ContextTag, Plane int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 113 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Plane)) + b += 4 + + return buf +} + +// GetColorTableCookie is a cookie used only for GetColorTable requests. +type GetColorTableCookie struct { + *xgb.Cookie +} + +// GetColorTable sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetColorTableCookie.Reply() +func GetColorTable(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetColorTableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTable' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getColorTableRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetColorTableCookie{cookie} +} + +// GetColorTableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetColorTableUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetColorTableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTable' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getColorTableRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetColorTableCookie{cookie} +} + +// GetColorTableReply represents the data returned from a GetColorTable request. +type GetColorTableReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + Width int32 + // padding: 12 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetColorTable request. +func (cook GetColorTableCookie) Reply() (*GetColorTableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getColorTableReply(buf), nil +} + +// getColorTableReply reads a byte slice into a GetColorTableReply value. +func getColorTableReply(buf []byte) *GetColorTableReply { + v := new(GetColorTableReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.Width = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetColorTable +// getColorTableRequest writes a GetColorTable request to a byte slice. +func getColorTableRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 147 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetColorTableParameterfvCookie is a cookie used only for GetColorTableParameterfv requests. +type GetColorTableParameterfvCookie struct { + *xgb.Cookie +} + +// GetColorTableParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetColorTableParameterfvCookie.Reply() +func GetColorTableParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetColorTableParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTableParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getColorTableParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetColorTableParameterfvCookie{cookie} +} + +// GetColorTableParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetColorTableParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetColorTableParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTableParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getColorTableParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetColorTableParameterfvCookie{cookie} +} + +// GetColorTableParameterfvReply represents the data returned from a GetColorTableParameterfv request. +type GetColorTableParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetColorTableParameterfv request. +func (cook GetColorTableParameterfvCookie) Reply() (*GetColorTableParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getColorTableParameterfvReply(buf), nil +} + +// getColorTableParameterfvReply reads a byte slice into a GetColorTableParameterfvReply value. +func getColorTableParameterfvReply(buf []byte) *GetColorTableParameterfvReply { + v := new(GetColorTableParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetColorTableParameterfv +// getColorTableParameterfvRequest writes a GetColorTableParameterfv request to a byte slice. +func getColorTableParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 148 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetColorTableParameterivCookie is a cookie used only for GetColorTableParameteriv requests. +type GetColorTableParameterivCookie struct { + *xgb.Cookie +} + +// GetColorTableParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetColorTableParameterivCookie.Reply() +func GetColorTableParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetColorTableParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTableParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getColorTableParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetColorTableParameterivCookie{cookie} +} + +// GetColorTableParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetColorTableParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetColorTableParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetColorTableParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getColorTableParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetColorTableParameterivCookie{cookie} +} + +// GetColorTableParameterivReply represents the data returned from a GetColorTableParameteriv request. +type GetColorTableParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetColorTableParameteriv request. +func (cook GetColorTableParameterivCookie) Reply() (*GetColorTableParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getColorTableParameterivReply(buf), nil +} + +// getColorTableParameterivReply reads a byte slice into a GetColorTableParameterivReply value. +func getColorTableParameterivReply(buf []byte) *GetColorTableParameterivReply { + v := new(GetColorTableParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetColorTableParameteriv +// getColorTableParameterivRequest writes a GetColorTableParameteriv request to a byte slice. +func getColorTableParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 149 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetCompressedTexImageARBCookie is a cookie used only for GetCompressedTexImageARB requests. +type GetCompressedTexImageARBCookie struct { + *xgb.Cookie +} + +// GetCompressedTexImageARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCompressedTexImageARBCookie.Reply() +func GetCompressedTexImageARB(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32) GetCompressedTexImageARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetCompressedTexImageARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCompressedTexImageARBRequest(c, ContextTag, Target, Level), cookie) + return GetCompressedTexImageARBCookie{cookie} +} + +// GetCompressedTexImageARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCompressedTexImageARBUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32) GetCompressedTexImageARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetCompressedTexImageARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCompressedTexImageARBRequest(c, ContextTag, Target, Level), cookie) + return GetCompressedTexImageARBCookie{cookie} +} + +// GetCompressedTexImageARBReply represents the data returned from a GetCompressedTexImageARB request. +type GetCompressedTexImageARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + Size int32 + // padding: 12 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetCompressedTexImageARB request. +func (cook GetCompressedTexImageARBCookie) Reply() (*GetCompressedTexImageARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCompressedTexImageARBReply(buf), nil +} + +// getCompressedTexImageARBReply reads a byte slice into a GetCompressedTexImageARBReply value. +func getCompressedTexImageARBReply(buf []byte) *GetCompressedTexImageARBReply { + v := new(GetCompressedTexImageARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.Size = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetCompressedTexImageARB +// getCompressedTexImageARBRequest writes a GetCompressedTexImageARB request to a byte slice. +func getCompressedTexImageARBRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 160 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], uint32(Level)) + b += 4 + + return buf +} + +// GetConvolutionFilterCookie is a cookie used only for GetConvolutionFilter requests. +type GetConvolutionFilterCookie struct { + *xgb.Cookie +} + +// GetConvolutionFilter sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetConvolutionFilterCookie.Reply() +func GetConvolutionFilter(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetConvolutionFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionFilter' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getConvolutionFilterRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetConvolutionFilterCookie{cookie} +} + +// GetConvolutionFilterUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetConvolutionFilterUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetConvolutionFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionFilter' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getConvolutionFilterRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetConvolutionFilterCookie{cookie} +} + +// GetConvolutionFilterReply represents the data returned from a GetConvolutionFilter request. +type GetConvolutionFilterReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + Width int32 + Height int32 + // padding: 8 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetConvolutionFilter request. +func (cook GetConvolutionFilterCookie) Reply() (*GetConvolutionFilterReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getConvolutionFilterReply(buf), nil +} + +// getConvolutionFilterReply reads a byte slice into a GetConvolutionFilterReply value. +func getConvolutionFilterReply(buf []byte) *GetConvolutionFilterReply { + v := new(GetConvolutionFilterReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.Width = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Height = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 8 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetConvolutionFilter +// getConvolutionFilterRequest writes a GetConvolutionFilter request to a byte slice. +func getConvolutionFilterRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 150 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetConvolutionParameterfvCookie is a cookie used only for GetConvolutionParameterfv requests. +type GetConvolutionParameterfvCookie struct { + *xgb.Cookie +} + +// GetConvolutionParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetConvolutionParameterfvCookie.Reply() +func GetConvolutionParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetConvolutionParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getConvolutionParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetConvolutionParameterfvCookie{cookie} +} + +// GetConvolutionParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetConvolutionParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetConvolutionParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getConvolutionParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetConvolutionParameterfvCookie{cookie} +} + +// GetConvolutionParameterfvReply represents the data returned from a GetConvolutionParameterfv request. +type GetConvolutionParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetConvolutionParameterfv request. +func (cook GetConvolutionParameterfvCookie) Reply() (*GetConvolutionParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getConvolutionParameterfvReply(buf), nil +} + +// getConvolutionParameterfvReply reads a byte slice into a GetConvolutionParameterfvReply value. +func getConvolutionParameterfvReply(buf []byte) *GetConvolutionParameterfvReply { + v := new(GetConvolutionParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetConvolutionParameterfv +// getConvolutionParameterfvRequest writes a GetConvolutionParameterfv request to a byte slice. +func getConvolutionParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 151 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetConvolutionParameterivCookie is a cookie used only for GetConvolutionParameteriv requests. +type GetConvolutionParameterivCookie struct { + *xgb.Cookie +} + +// GetConvolutionParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetConvolutionParameterivCookie.Reply() +func GetConvolutionParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetConvolutionParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getConvolutionParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetConvolutionParameterivCookie{cookie} +} + +// GetConvolutionParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetConvolutionParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetConvolutionParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetConvolutionParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getConvolutionParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetConvolutionParameterivCookie{cookie} +} + +// GetConvolutionParameterivReply represents the data returned from a GetConvolutionParameteriv request. +type GetConvolutionParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetConvolutionParameteriv request. +func (cook GetConvolutionParameterivCookie) Reply() (*GetConvolutionParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getConvolutionParameterivReply(buf), nil +} + +// getConvolutionParameterivReply reads a byte slice into a GetConvolutionParameterivReply value. +func getConvolutionParameterivReply(buf []byte) *GetConvolutionParameterivReply { + v := new(GetConvolutionParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetConvolutionParameteriv +// getConvolutionParameterivRequest writes a GetConvolutionParameteriv request to a byte slice. +func getConvolutionParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 152 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetDoublevCookie is a cookie used only for GetDoublev requests. +type GetDoublevCookie struct { + *xgb.Cookie +} + +// GetDoublev sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDoublevCookie.Reply() +func GetDoublev(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetDoublevCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetDoublev' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDoublevRequest(c, ContextTag, Pname), cookie) + return GetDoublevCookie{cookie} +} + +// GetDoublevUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDoublevUnchecked(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetDoublevCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetDoublev' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDoublevRequest(c, ContextTag, Pname), cookie) + return GetDoublevCookie{cookie} +} + +// GetDoublevReply represents the data returned from a GetDoublev request. +type GetDoublevReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float64 + // padding: 8 bytes + Data []Float64 // size: xgb.Pad((int(N) * 8)) +} + +// Reply blocks and returns the reply data for a GetDoublev request. +func (cook GetDoublevCookie) Reply() (*GetDoublevReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDoublevReply(buf), nil +} + +// getDoublevReply reads a byte slice into a GetDoublevReply value. +func getDoublevReply(buf []byte) *GetDoublevReply { + v := new(GetDoublevReply) + b := 1 // skip reply determinant + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 1 // padding + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float64(xgb.Get64(buf[b:])) + b += 8 + + b += 8 // padding + + v.Data = make([]Float64, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float64(xgb.Get64(buf[b:])) + b += 8 + } + + return v +} + +// Write request to wire for GetDoublev +// getDoublevRequest writes a GetDoublev request to a byte slice. +func getDoublevRequest(c *xgb.Conn, ContextTag ContextTag, Pname uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 114 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetDrawableAttributesCookie is a cookie used only for GetDrawableAttributes requests. +type GetDrawableAttributesCookie struct { + *xgb.Cookie +} + +// GetDrawableAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDrawableAttributesCookie.Reply() +func GetDrawableAttributes(c *xgb.Conn, Drawable Drawable) GetDrawableAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetDrawableAttributes' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDrawableAttributesRequest(c, Drawable), cookie) + return GetDrawableAttributesCookie{cookie} +} + +// GetDrawableAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDrawableAttributesUnchecked(c *xgb.Conn, Drawable Drawable) GetDrawableAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetDrawableAttributes' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDrawableAttributesRequest(c, Drawable), cookie) + return GetDrawableAttributesCookie{cookie} +} + +// GetDrawableAttributesReply represents the data returned from a GetDrawableAttributes request. +type GetDrawableAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAttribs uint32 + // padding: 20 bytes + Attribs []uint32 // size: xgb.Pad(((int(NumAttribs) * 2) * 4)) +} + +// Reply blocks and returns the reply data for a GetDrawableAttributes request. +func (cook GetDrawableAttributesCookie) Reply() (*GetDrawableAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDrawableAttributesReply(buf), nil +} + +// getDrawableAttributesReply reads a byte slice into a GetDrawableAttributesReply value. +func getDrawableAttributesReply(buf []byte) *GetDrawableAttributesReply { + v := new(GetDrawableAttributesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAttribs = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Attribs = make([]uint32, (int(v.NumAttribs) * 2)) + for i := 0; i < int((int(v.NumAttribs) * 2)); i++ { + v.Attribs[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetDrawableAttributes +// getDrawableAttributesRequest writes a GetDrawableAttributes request to a byte slice. +func getDrawableAttributesRequest(c *xgb.Conn, Drawable Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 29 // 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(Drawable)) + b += 4 + + return buf +} + +// GetErrorCookie is a cookie used only for GetError requests. +type GetErrorCookie struct { + *xgb.Cookie +} + +// GetError sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetErrorCookie.Reply() +func GetError(c *xgb.Conn, ContextTag ContextTag) GetErrorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetError' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getErrorRequest(c, ContextTag), cookie) + return GetErrorCookie{cookie} +} + +// GetErrorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetErrorUnchecked(c *xgb.Conn, ContextTag ContextTag) GetErrorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetError' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getErrorRequest(c, ContextTag), cookie) + return GetErrorCookie{cookie} +} + +// GetErrorReply represents the data returned from a GetError request. +type GetErrorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Error int32 +} + +// Reply blocks and returns the reply data for a GetError request. +func (cook GetErrorCookie) Reply() (*GetErrorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getErrorReply(buf), nil +} + +// getErrorReply reads a byte slice into a GetErrorReply value. +func getErrorReply(buf []byte) *GetErrorReply { + v := new(GetErrorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Error = int32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetError +// getErrorRequest writes a GetError request to a byte slice. +func getErrorRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 115 // 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(ContextTag)) + b += 4 + + return buf +} + +// GetFBConfigsCookie is a cookie used only for GetFBConfigs requests. +type GetFBConfigsCookie struct { + *xgb.Cookie +} + +// GetFBConfigs sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetFBConfigsCookie.Reply() +func GetFBConfigs(c *xgb.Conn, Screen uint32) GetFBConfigsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetFBConfigs' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getFBConfigsRequest(c, Screen), cookie) + return GetFBConfigsCookie{cookie} +} + +// GetFBConfigsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetFBConfigsUnchecked(c *xgb.Conn, Screen uint32) GetFBConfigsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetFBConfigs' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getFBConfigsRequest(c, Screen), cookie) + return GetFBConfigsCookie{cookie} +} + +// GetFBConfigsReply represents the data returned from a GetFBConfigs request. +type GetFBConfigsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumFbConfigs uint32 + NumProperties uint32 + // padding: 16 bytes + PropertyList []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a GetFBConfigs request. +func (cook GetFBConfigsCookie) Reply() (*GetFBConfigsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getFBConfigsReply(buf), nil +} + +// getFBConfigsReply reads a byte slice into a GetFBConfigsReply value. +func getFBConfigsReply(buf []byte) *GetFBConfigsReply { + v := new(GetFBConfigsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumFbConfigs = xgb.Get32(buf[b:]) + b += 4 + + v.NumProperties = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.PropertyList = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.PropertyList[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetFBConfigs +// getFBConfigsRequest writes a GetFBConfigs request to a byte slice. +func getFBConfigsRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 21 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// GetFloatvCookie is a cookie used only for GetFloatv requests. +type GetFloatvCookie struct { + *xgb.Cookie +} + +// GetFloatv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetFloatvCookie.Reply() +func GetFloatv(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetFloatvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetFloatv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getFloatvRequest(c, ContextTag, Pname), cookie) + return GetFloatvCookie{cookie} +} + +// GetFloatvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetFloatvUnchecked(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetFloatvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetFloatv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getFloatvRequest(c, ContextTag, Pname), cookie) + return GetFloatvCookie{cookie} +} + +// GetFloatvReply represents the data returned from a GetFloatv request. +type GetFloatvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetFloatv request. +func (cook GetFloatvCookie) Reply() (*GetFloatvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getFloatvReply(buf), nil +} + +// getFloatvReply reads a byte slice into a GetFloatvReply value. +func getFloatvReply(buf []byte) *GetFloatvReply { + v := new(GetFloatvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetFloatv +// getFloatvRequest writes a GetFloatv request to a byte slice. +func getFloatvRequest(c *xgb.Conn, ContextTag ContextTag, Pname uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 116 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetHistogramCookie is a cookie used only for GetHistogram requests. +type GetHistogramCookie struct { + *xgb.Cookie +} + +// GetHistogram sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetHistogramCookie.Reply() +func GetHistogram(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) GetHistogramCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogram' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getHistogramRequest(c, ContextTag, Target, Format, Type, SwapBytes, Reset), cookie) + return GetHistogramCookie{cookie} +} + +// GetHistogramUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetHistogramUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) GetHistogramCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogram' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getHistogramRequest(c, ContextTag, Target, Format, Type, SwapBytes, Reset), cookie) + return GetHistogramCookie{cookie} +} + +// GetHistogramReply represents the data returned from a GetHistogram request. +type GetHistogramReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + Width int32 + // padding: 12 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetHistogram request. +func (cook GetHistogramCookie) Reply() (*GetHistogramReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getHistogramReply(buf), nil +} + +// getHistogramReply reads a byte slice into a GetHistogramReply value. +func getHistogramReply(buf []byte) *GetHistogramReply { + v := new(GetHistogramReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.Width = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetHistogram +// getHistogramRequest writes a GetHistogram request to a byte slice. +func getHistogramRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 154 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Reset { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetHistogramParameterfvCookie is a cookie used only for GetHistogramParameterfv requests. +type GetHistogramParameterfvCookie struct { + *xgb.Cookie +} + +// GetHistogramParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetHistogramParameterfvCookie.Reply() +func GetHistogramParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetHistogramParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogramParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getHistogramParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetHistogramParameterfvCookie{cookie} +} + +// GetHistogramParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetHistogramParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetHistogramParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogramParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getHistogramParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetHistogramParameterfvCookie{cookie} +} + +// GetHistogramParameterfvReply represents the data returned from a GetHistogramParameterfv request. +type GetHistogramParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetHistogramParameterfv request. +func (cook GetHistogramParameterfvCookie) Reply() (*GetHistogramParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getHistogramParameterfvReply(buf), nil +} + +// getHistogramParameterfvReply reads a byte slice into a GetHistogramParameterfvReply value. +func getHistogramParameterfvReply(buf []byte) *GetHistogramParameterfvReply { + v := new(GetHistogramParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetHistogramParameterfv +// getHistogramParameterfvRequest writes a GetHistogramParameterfv request to a byte slice. +func getHistogramParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 155 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetHistogramParameterivCookie is a cookie used only for GetHistogramParameteriv requests. +type GetHistogramParameterivCookie struct { + *xgb.Cookie +} + +// GetHistogramParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetHistogramParameterivCookie.Reply() +func GetHistogramParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetHistogramParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogramParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getHistogramParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetHistogramParameterivCookie{cookie} +} + +// GetHistogramParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetHistogramParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetHistogramParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetHistogramParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getHistogramParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetHistogramParameterivCookie{cookie} +} + +// GetHistogramParameterivReply represents the data returned from a GetHistogramParameteriv request. +type GetHistogramParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetHistogramParameteriv request. +func (cook GetHistogramParameterivCookie) Reply() (*GetHistogramParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getHistogramParameterivReply(buf), nil +} + +// getHistogramParameterivReply reads a byte slice into a GetHistogramParameterivReply value. +func getHistogramParameterivReply(buf []byte) *GetHistogramParameterivReply { + v := new(GetHistogramParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetHistogramParameteriv +// getHistogramParameterivRequest writes a GetHistogramParameteriv request to a byte slice. +func getHistogramParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 156 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetIntegervCookie is a cookie used only for GetIntegerv requests. +type GetIntegervCookie struct { + *xgb.Cookie +} + +// GetIntegerv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetIntegervCookie.Reply() +func GetIntegerv(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetIntegervCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetIntegerv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getIntegervRequest(c, ContextTag, Pname), cookie) + return GetIntegervCookie{cookie} +} + +// GetIntegervUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetIntegervUnchecked(c *xgb.Conn, ContextTag ContextTag, Pname uint32) GetIntegervCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetIntegerv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getIntegervRequest(c, ContextTag, Pname), cookie) + return GetIntegervCookie{cookie} +} + +// GetIntegervReply represents the data returned from a GetIntegerv request. +type GetIntegervReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetIntegerv request. +func (cook GetIntegervCookie) Reply() (*GetIntegervReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getIntegervReply(buf), nil +} + +// getIntegervReply reads a byte slice into a GetIntegervReply value. +func getIntegervReply(buf []byte) *GetIntegervReply { + v := new(GetIntegervReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetIntegerv +// getIntegervRequest writes a GetIntegerv request to a byte slice. +func getIntegervRequest(c *xgb.Conn, ContextTag ContextTag, Pname uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 117 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetLightfvCookie is a cookie used only for GetLightfv requests. +type GetLightfvCookie struct { + *xgb.Cookie +} + +// GetLightfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetLightfvCookie.Reply() +func GetLightfv(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) GetLightfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetLightfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getLightfvRequest(c, ContextTag, Light, Pname), cookie) + return GetLightfvCookie{cookie} +} + +// GetLightfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetLightfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) GetLightfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetLightfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getLightfvRequest(c, ContextTag, Light, Pname), cookie) + return GetLightfvCookie{cookie} +} + +// GetLightfvReply represents the data returned from a GetLightfv request. +type GetLightfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetLightfv request. +func (cook GetLightfvCookie) Reply() (*GetLightfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getLightfvReply(buf), nil +} + +// getLightfvReply reads a byte slice into a GetLightfvReply value. +func getLightfvReply(buf []byte) *GetLightfvReply { + v := new(GetLightfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetLightfv +// getLightfvRequest writes a GetLightfv request to a byte slice. +func getLightfvRequest(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 118 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Light) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetLightivCookie is a cookie used only for GetLightiv requests. +type GetLightivCookie struct { + *xgb.Cookie +} + +// GetLightiv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetLightivCookie.Reply() +func GetLightiv(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) GetLightivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetLightiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getLightivRequest(c, ContextTag, Light, Pname), cookie) + return GetLightivCookie{cookie} +} + +// GetLightivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetLightivUnchecked(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) GetLightivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetLightiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getLightivRequest(c, ContextTag, Light, Pname), cookie) + return GetLightivCookie{cookie} +} + +// GetLightivReply represents the data returned from a GetLightiv request. +type GetLightivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetLightiv request. +func (cook GetLightivCookie) Reply() (*GetLightivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getLightivReply(buf), nil +} + +// getLightivReply reads a byte slice into a GetLightivReply value. +func getLightivReply(buf []byte) *GetLightivReply { + v := new(GetLightivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetLightiv +// getLightivRequest writes a GetLightiv request to a byte slice. +func getLightivRequest(c *xgb.Conn, ContextTag ContextTag, Light uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 119 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Light) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetMapdvCookie is a cookie used only for GetMapdv requests. +type GetMapdvCookie struct { + *xgb.Cookie +} + +// GetMapdv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMapdvCookie.Reply() +func GetMapdv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapdvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapdv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMapdvRequest(c, ContextTag, Target, Query), cookie) + return GetMapdvCookie{cookie} +} + +// GetMapdvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMapdvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapdvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapdv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMapdvRequest(c, ContextTag, Target, Query), cookie) + return GetMapdvCookie{cookie} +} + +// GetMapdvReply represents the data returned from a GetMapdv request. +type GetMapdvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float64 + // padding: 8 bytes + Data []Float64 // size: xgb.Pad((int(N) * 8)) +} + +// Reply blocks and returns the reply data for a GetMapdv request. +func (cook GetMapdvCookie) Reply() (*GetMapdvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMapdvReply(buf), nil +} + +// getMapdvReply reads a byte slice into a GetMapdvReply value. +func getMapdvReply(buf []byte) *GetMapdvReply { + v := new(GetMapdvReply) + b := 1 // skip reply determinant + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 1 // padding + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float64(xgb.Get64(buf[b:])) + b += 8 + + b += 8 // padding + + v.Data = make([]Float64, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float64(xgb.Get64(buf[b:])) + b += 8 + } + + return v +} + +// Write request to wire for GetMapdv +// getMapdvRequest writes a GetMapdv request to a byte slice. +func getMapdvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 120 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Query) + b += 4 + + return buf +} + +// GetMapfvCookie is a cookie used only for GetMapfv requests. +type GetMapfvCookie struct { + *xgb.Cookie +} + +// GetMapfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMapfvCookie.Reply() +func GetMapfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMapfvRequest(c, ContextTag, Target, Query), cookie) + return GetMapfvCookie{cookie} +} + +// GetMapfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMapfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMapfvRequest(c, ContextTag, Target, Query), cookie) + return GetMapfvCookie{cookie} +} + +// GetMapfvReply represents the data returned from a GetMapfv request. +type GetMapfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMapfv request. +func (cook GetMapfvCookie) Reply() (*GetMapfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMapfvReply(buf), nil +} + +// getMapfvReply reads a byte slice into a GetMapfvReply value. +func getMapfvReply(buf []byte) *GetMapfvReply { + v := new(GetMapfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMapfv +// getMapfvRequest writes a GetMapfv request to a byte slice. +func getMapfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 121 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Query) + b += 4 + + return buf +} + +// GetMapivCookie is a cookie used only for GetMapiv requests. +type GetMapivCookie struct { + *xgb.Cookie +} + +// GetMapiv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMapivCookie.Reply() +func GetMapiv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMapivRequest(c, ContextTag, Target, Query), cookie) + return GetMapivCookie{cookie} +} + +// GetMapivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMapivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) GetMapivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMapiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMapivRequest(c, ContextTag, Target, Query), cookie) + return GetMapivCookie{cookie} +} + +// GetMapivReply represents the data returned from a GetMapiv request. +type GetMapivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMapiv request. +func (cook GetMapivCookie) Reply() (*GetMapivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMapivReply(buf), nil +} + +// getMapivReply reads a byte slice into a GetMapivReply value. +func getMapivReply(buf []byte) *GetMapivReply { + v := new(GetMapivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMapiv +// getMapivRequest writes a GetMapiv request to a byte slice. +func getMapivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Query uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 122 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Query) + b += 4 + + return buf +} + +// GetMaterialfvCookie is a cookie used only for GetMaterialfv requests. +type GetMaterialfvCookie struct { + *xgb.Cookie +} + +// GetMaterialfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMaterialfvCookie.Reply() +func GetMaterialfv(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) GetMaterialfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMaterialfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMaterialfvRequest(c, ContextTag, Face, Pname), cookie) + return GetMaterialfvCookie{cookie} +} + +// GetMaterialfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMaterialfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) GetMaterialfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMaterialfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMaterialfvRequest(c, ContextTag, Face, Pname), cookie) + return GetMaterialfvCookie{cookie} +} + +// GetMaterialfvReply represents the data returned from a GetMaterialfv request. +type GetMaterialfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMaterialfv request. +func (cook GetMaterialfvCookie) Reply() (*GetMaterialfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMaterialfvReply(buf), nil +} + +// getMaterialfvReply reads a byte slice into a GetMaterialfvReply value. +func getMaterialfvReply(buf []byte) *GetMaterialfvReply { + v := new(GetMaterialfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMaterialfv +// getMaterialfvRequest writes a GetMaterialfv request to a byte slice. +func getMaterialfvRequest(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 123 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Face) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetMaterialivCookie is a cookie used only for GetMaterialiv requests. +type GetMaterialivCookie struct { + *xgb.Cookie +} + +// GetMaterialiv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMaterialivCookie.Reply() +func GetMaterialiv(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) GetMaterialivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMaterialiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMaterialivRequest(c, ContextTag, Face, Pname), cookie) + return GetMaterialivCookie{cookie} +} + +// GetMaterialivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMaterialivUnchecked(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) GetMaterialivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMaterialiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMaterialivRequest(c, ContextTag, Face, Pname), cookie) + return GetMaterialivCookie{cookie} +} + +// GetMaterialivReply represents the data returned from a GetMaterialiv request. +type GetMaterialivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMaterialiv request. +func (cook GetMaterialivCookie) Reply() (*GetMaterialivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMaterialivReply(buf), nil +} + +// getMaterialivReply reads a byte slice into a GetMaterialivReply value. +func getMaterialivReply(buf []byte) *GetMaterialivReply { + v := new(GetMaterialivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMaterialiv +// getMaterialivRequest writes a GetMaterialiv request to a byte slice. +func getMaterialivRequest(c *xgb.Conn, ContextTag ContextTag, Face uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 124 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Face) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetMinmaxCookie is a cookie used only for GetMinmax requests. +type GetMinmaxCookie struct { + *xgb.Cookie +} + +// GetMinmax sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMinmaxCookie.Reply() +func GetMinmax(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) GetMinmaxCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmax' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMinmaxRequest(c, ContextTag, Target, Format, Type, SwapBytes, Reset), cookie) + return GetMinmaxCookie{cookie} +} + +// GetMinmaxUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMinmaxUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) GetMinmaxCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmax' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMinmaxRequest(c, ContextTag, Target, Format, Type, SwapBytes, Reset), cookie) + return GetMinmaxCookie{cookie} +} + +// GetMinmaxReply represents the data returned from a GetMinmax request. +type GetMinmaxReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetMinmax request. +func (cook GetMinmaxCookie) Reply() (*GetMinmaxReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMinmaxReply(buf), nil +} + +// getMinmaxReply reads a byte slice into a GetMinmaxReply value. +func getMinmaxReply(buf []byte) *GetMinmaxReply { + v := new(GetMinmaxReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetMinmax +// getMinmaxRequest writes a GetMinmax request to a byte slice. +func getMinmaxRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool, Reset bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 157 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Reset { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetMinmaxParameterfvCookie is a cookie used only for GetMinmaxParameterfv requests. +type GetMinmaxParameterfvCookie struct { + *xgb.Cookie +} + +// GetMinmaxParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMinmaxParameterfvCookie.Reply() +func GetMinmaxParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetMinmaxParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmaxParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMinmaxParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetMinmaxParameterfvCookie{cookie} +} + +// GetMinmaxParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMinmaxParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetMinmaxParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmaxParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMinmaxParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetMinmaxParameterfvCookie{cookie} +} + +// GetMinmaxParameterfvReply represents the data returned from a GetMinmaxParameterfv request. +type GetMinmaxParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMinmaxParameterfv request. +func (cook GetMinmaxParameterfvCookie) Reply() (*GetMinmaxParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMinmaxParameterfvReply(buf), nil +} + +// getMinmaxParameterfvReply reads a byte slice into a GetMinmaxParameterfvReply value. +func getMinmaxParameterfvReply(buf []byte) *GetMinmaxParameterfvReply { + v := new(GetMinmaxParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMinmaxParameterfv +// getMinmaxParameterfvRequest writes a GetMinmaxParameterfv request to a byte slice. +func getMinmaxParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 158 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetMinmaxParameterivCookie is a cookie used only for GetMinmaxParameteriv requests. +type GetMinmaxParameterivCookie struct { + *xgb.Cookie +} + +// GetMinmaxParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMinmaxParameterivCookie.Reply() +func GetMinmaxParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetMinmaxParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmaxParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMinmaxParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetMinmaxParameterivCookie{cookie} +} + +// GetMinmaxParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMinmaxParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetMinmaxParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetMinmaxParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMinmaxParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetMinmaxParameterivCookie{cookie} +} + +// GetMinmaxParameterivReply represents the data returned from a GetMinmaxParameteriv request. +type GetMinmaxParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetMinmaxParameteriv request. +func (cook GetMinmaxParameterivCookie) Reply() (*GetMinmaxParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMinmaxParameterivReply(buf), nil +} + +// getMinmaxParameterivReply reads a byte slice into a GetMinmaxParameterivReply value. +func getMinmaxParameterivReply(buf []byte) *GetMinmaxParameterivReply { + v := new(GetMinmaxParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetMinmaxParameteriv +// getMinmaxParameterivRequest writes a GetMinmaxParameteriv request to a byte slice. +func getMinmaxParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 159 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetPixelMapfvCookie is a cookie used only for GetPixelMapfv requests. +type GetPixelMapfvCookie struct { + *xgb.Cookie +} + +// GetPixelMapfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPixelMapfvCookie.Reply() +func GetPixelMapfv(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPixelMapfvRequest(c, ContextTag, Map), cookie) + return GetPixelMapfvCookie{cookie} +} + +// GetPixelMapfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPixelMapfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPixelMapfvRequest(c, ContextTag, Map), cookie) + return GetPixelMapfvCookie{cookie} +} + +// GetPixelMapfvReply represents the data returned from a GetPixelMapfv request. +type GetPixelMapfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetPixelMapfv request. +func (cook GetPixelMapfvCookie) Reply() (*GetPixelMapfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPixelMapfvReply(buf), nil +} + +// getPixelMapfvReply reads a byte slice into a GetPixelMapfvReply value. +func getPixelMapfvReply(buf []byte) *GetPixelMapfvReply { + v := new(GetPixelMapfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetPixelMapfv +// getPixelMapfvRequest writes a GetPixelMapfv request to a byte slice. +func getPixelMapfvRequest(c *xgb.Conn, ContextTag ContextTag, Map uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 125 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Map) + b += 4 + + return buf +} + +// GetPixelMapuivCookie is a cookie used only for GetPixelMapuiv requests. +type GetPixelMapuivCookie struct { + *xgb.Cookie +} + +// GetPixelMapuiv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPixelMapuivCookie.Reply() +func GetPixelMapuiv(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapuivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapuiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPixelMapuivRequest(c, ContextTag, Map), cookie) + return GetPixelMapuivCookie{cookie} +} + +// GetPixelMapuivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPixelMapuivUnchecked(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapuivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapuiv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPixelMapuivRequest(c, ContextTag, Map), cookie) + return GetPixelMapuivCookie{cookie} +} + +// GetPixelMapuivReply represents the data returned from a GetPixelMapuiv request. +type GetPixelMapuivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum uint32 + // padding: 12 bytes + Data []uint32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetPixelMapuiv request. +func (cook GetPixelMapuivCookie) Reply() (*GetPixelMapuivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPixelMapuivReply(buf), nil +} + +// getPixelMapuivReply reads a byte slice into a GetPixelMapuivReply value. +func getPixelMapuivReply(buf []byte) *GetPixelMapuivReply { + v := new(GetPixelMapuivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]uint32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetPixelMapuiv +// getPixelMapuivRequest writes a GetPixelMapuiv request to a byte slice. +func getPixelMapuivRequest(c *xgb.Conn, ContextTag ContextTag, Map uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 126 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Map) + b += 4 + + return buf +} + +// GetPixelMapusvCookie is a cookie used only for GetPixelMapusv requests. +type GetPixelMapusvCookie struct { + *xgb.Cookie +} + +// GetPixelMapusv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPixelMapusvCookie.Reply() +func GetPixelMapusv(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapusvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapusv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPixelMapusvRequest(c, ContextTag, Map), cookie) + return GetPixelMapusvCookie{cookie} +} + +// GetPixelMapusvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPixelMapusvUnchecked(c *xgb.Conn, ContextTag ContextTag, Map uint32) GetPixelMapusvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPixelMapusv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPixelMapusvRequest(c, ContextTag, Map), cookie) + return GetPixelMapusvCookie{cookie} +} + +// GetPixelMapusvReply represents the data returned from a GetPixelMapusv request. +type GetPixelMapusvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum uint16 + // padding: 16 bytes + Data []uint16 // size: xgb.Pad((int(N) * 2)) +} + +// Reply blocks and returns the reply data for a GetPixelMapusv request. +func (cook GetPixelMapusvCookie) Reply() (*GetPixelMapusvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPixelMapusvReply(buf), nil +} + +// getPixelMapusvReply reads a byte slice into a GetPixelMapusvReply value. +func getPixelMapusvReply(buf []byte) *GetPixelMapusvReply { + v := new(GetPixelMapusvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = xgb.Get16(buf[b:]) + b += 2 + + b += 16 // padding + + v.Data = make([]uint16, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = xgb.Get16(buf[b:]) + b += 2 + } + + return v +} + +// Write request to wire for GetPixelMapusv +// getPixelMapusvRequest writes a GetPixelMapusv request to a byte slice. +func getPixelMapusvRequest(c *xgb.Conn, ContextTag ContextTag, Map uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 127 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Map) + b += 4 + + return buf +} + +// GetPolygonStippleCookie is a cookie used only for GetPolygonStipple requests. +type GetPolygonStippleCookie struct { + *xgb.Cookie +} + +// GetPolygonStipple sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPolygonStippleCookie.Reply() +func GetPolygonStipple(c *xgb.Conn, ContextTag ContextTag, LsbFirst bool) GetPolygonStippleCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPolygonStipple' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPolygonStippleRequest(c, ContextTag, LsbFirst), cookie) + return GetPolygonStippleCookie{cookie} +} + +// GetPolygonStippleUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPolygonStippleUnchecked(c *xgb.Conn, ContextTag ContextTag, LsbFirst bool) GetPolygonStippleCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetPolygonStipple' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPolygonStippleRequest(c, ContextTag, LsbFirst), cookie) + return GetPolygonStippleCookie{cookie} +} + +// GetPolygonStippleReply represents the data returned from a GetPolygonStipple request. +type GetPolygonStippleReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetPolygonStipple request. +func (cook GetPolygonStippleCookie) Reply() (*GetPolygonStippleReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPolygonStippleReply(buf), nil +} + +// getPolygonStippleReply reads a byte slice into a GetPolygonStippleReply value. +func getPolygonStippleReply(buf []byte) *GetPolygonStippleReply { + v := new(GetPolygonStippleReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetPolygonStipple +// getPolygonStippleRequest writes a GetPolygonStipple request to a byte slice. +func getPolygonStippleRequest(c *xgb.Conn, ContextTag ContextTag, LsbFirst bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 128 // 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(ContextTag)) + b += 4 + + if LsbFirst { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetQueryObjectivARBCookie is a cookie used only for GetQueryObjectivARB requests. +type GetQueryObjectivARBCookie struct { + *xgb.Cookie +} + +// GetQueryObjectivARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetQueryObjectivARBCookie.Reply() +func GetQueryObjectivARB(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) GetQueryObjectivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryObjectivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getQueryObjectivARBRequest(c, ContextTag, Id, Pname), cookie) + return GetQueryObjectivARBCookie{cookie} +} + +// GetQueryObjectivARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetQueryObjectivARBUnchecked(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) GetQueryObjectivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryObjectivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getQueryObjectivARBRequest(c, ContextTag, Id, Pname), cookie) + return GetQueryObjectivARBCookie{cookie} +} + +// GetQueryObjectivARBReply represents the data returned from a GetQueryObjectivARB request. +type GetQueryObjectivARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetQueryObjectivARB request. +func (cook GetQueryObjectivARBCookie) Reply() (*GetQueryObjectivARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getQueryObjectivARBReply(buf), nil +} + +// getQueryObjectivARBReply reads a byte slice into a GetQueryObjectivARBReply value. +func getQueryObjectivARBReply(buf []byte) *GetQueryObjectivARBReply { + v := new(GetQueryObjectivARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetQueryObjectivARB +// getQueryObjectivARBRequest writes a GetQueryObjectivARB request to a byte slice. +func getQueryObjectivARBRequest(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 165 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetQueryObjectuivARBCookie is a cookie used only for GetQueryObjectuivARB requests. +type GetQueryObjectuivARBCookie struct { + *xgb.Cookie +} + +// GetQueryObjectuivARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetQueryObjectuivARBCookie.Reply() +func GetQueryObjectuivARB(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) GetQueryObjectuivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryObjectuivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getQueryObjectuivARBRequest(c, ContextTag, Id, Pname), cookie) + return GetQueryObjectuivARBCookie{cookie} +} + +// GetQueryObjectuivARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetQueryObjectuivARBUnchecked(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) GetQueryObjectuivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryObjectuivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getQueryObjectuivARBRequest(c, ContextTag, Id, Pname), cookie) + return GetQueryObjectuivARBCookie{cookie} +} + +// GetQueryObjectuivARBReply represents the data returned from a GetQueryObjectuivARB request. +type GetQueryObjectuivARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum uint32 + // padding: 12 bytes + Data []uint32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetQueryObjectuivARB request. +func (cook GetQueryObjectuivARBCookie) Reply() (*GetQueryObjectuivARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getQueryObjectuivARBReply(buf), nil +} + +// getQueryObjectuivARBReply reads a byte slice into a GetQueryObjectuivARBReply value. +func getQueryObjectuivARBReply(buf []byte) *GetQueryObjectuivARBReply { + v := new(GetQueryObjectuivARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]uint32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetQueryObjectuivARB +// getQueryObjectuivARBRequest writes a GetQueryObjectuivARB request to a byte slice. +func getQueryObjectuivARBRequest(c *xgb.Conn, ContextTag ContextTag, Id uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 166 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetQueryivARBCookie is a cookie used only for GetQueryivARB requests. +type GetQueryivARBCookie struct { + *xgb.Cookie +} + +// GetQueryivARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetQueryivARBCookie.Reply() +func GetQueryivARB(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetQueryivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getQueryivARBRequest(c, ContextTag, Target, Pname), cookie) + return GetQueryivARBCookie{cookie} +} + +// GetQueryivARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetQueryivARBUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetQueryivARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetQueryivARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getQueryivARBRequest(c, ContextTag, Target, Pname), cookie) + return GetQueryivARBCookie{cookie} +} + +// GetQueryivARBReply represents the data returned from a GetQueryivARB request. +type GetQueryivARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetQueryivARB request. +func (cook GetQueryivARBCookie) Reply() (*GetQueryivARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getQueryivARBReply(buf), nil +} + +// getQueryivARBReply reads a byte slice into a GetQueryivARBReply value. +func getQueryivARBReply(buf []byte) *GetQueryivARBReply { + v := new(GetQueryivARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetQueryivARB +// getQueryivARBRequest writes a GetQueryivARB request to a byte slice. +func getQueryivARBRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 164 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetSeparableFilterCookie is a cookie used only for GetSeparableFilter requests. +type GetSeparableFilterCookie struct { + *xgb.Cookie +} + +// GetSeparableFilter sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSeparableFilterCookie.Reply() +func GetSeparableFilter(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetSeparableFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetSeparableFilter' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getSeparableFilterRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetSeparableFilterCookie{cookie} +} + +// GetSeparableFilterUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSeparableFilterUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) GetSeparableFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetSeparableFilter' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getSeparableFilterRequest(c, ContextTag, Target, Format, Type, SwapBytes), cookie) + return GetSeparableFilterCookie{cookie} +} + +// GetSeparableFilterReply represents the data returned from a GetSeparableFilter request. +type GetSeparableFilterReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + RowW int32 + ColH int32 + // padding: 8 bytes + RowsAndCols []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetSeparableFilter request. +func (cook GetSeparableFilterCookie) Reply() (*GetSeparableFilterReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSeparableFilterReply(buf), nil +} + +// getSeparableFilterReply reads a byte slice into a GetSeparableFilterReply value. +func getSeparableFilterReply(buf []byte) *GetSeparableFilterReply { + v := new(GetSeparableFilterReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.RowW = int32(xgb.Get32(buf[b:])) + b += 4 + + v.ColH = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 8 // padding + + v.RowsAndCols = make([]byte, (int(v.Length) * 4)) + copy(v.RowsAndCols[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetSeparableFilter +// getSeparableFilterRequest writes a GetSeparableFilter request to a byte slice. +func getSeparableFilterRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Format uint32, Type uint32, SwapBytes bool) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 153 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetStringCookie is a cookie used only for GetString requests. +type GetStringCookie struct { + *xgb.Cookie +} + +// GetString sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetStringCookie.Reply() +func GetString(c *xgb.Conn, ContextTag ContextTag, Name uint32) GetStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getStringRequest(c, ContextTag, Name), cookie) + return GetStringCookie{cookie} +} + +// GetStringUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetStringUnchecked(c *xgb.Conn, ContextTag ContextTag, Name uint32) GetStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getStringRequest(c, ContextTag, Name), cookie) + return GetStringCookie{cookie} +} + +// GetStringReply represents the data returned from a GetString request. +type GetStringReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + // padding: 16 bytes + String string // size: xgb.Pad((int(N) * 1)) +} + +// Reply blocks and returns the reply data for a GetString request. +func (cook GetStringCookie) Reply() (*GetStringReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getStringReply(buf), nil +} + +// getStringReply reads a byte slice into a GetStringReply value. +func getStringReply(buf []byte) *GetStringReply { + v := new(GetStringReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + { + byteString := make([]byte, v.N) + copy(byteString[:v.N], buf[b:]) + v.String = string(byteString) + b += int(v.N) + } + + return v +} + +// Write request to wire for GetString +// getStringRequest writes a GetString request to a byte slice. +func getStringRequest(c *xgb.Conn, ContextTag ContextTag, Name uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 129 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Name) + b += 4 + + return buf +} + +// GetTexEnvfvCookie is a cookie used only for GetTexEnvfv requests. +type GetTexEnvfvCookie struct { + *xgb.Cookie +} + +// GetTexEnvfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexEnvfvCookie.Reply() +func GetTexEnvfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexEnvfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexEnvfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexEnvfvRequest(c, ContextTag, Target, Pname), cookie) + return GetTexEnvfvCookie{cookie} +} + +// GetTexEnvfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexEnvfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexEnvfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexEnvfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexEnvfvRequest(c, ContextTag, Target, Pname), cookie) + return GetTexEnvfvCookie{cookie} +} + +// GetTexEnvfvReply represents the data returned from a GetTexEnvfv request. +type GetTexEnvfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexEnvfv request. +func (cook GetTexEnvfvCookie) Reply() (*GetTexEnvfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexEnvfvReply(buf), nil +} + +// getTexEnvfvReply reads a byte slice into a GetTexEnvfvReply value. +func getTexEnvfvReply(buf []byte) *GetTexEnvfvReply { + v := new(GetTexEnvfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexEnvfv +// getTexEnvfvRequest writes a GetTexEnvfv request to a byte slice. +func getTexEnvfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 130 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexEnvivCookie is a cookie used only for GetTexEnviv requests. +type GetTexEnvivCookie struct { + *xgb.Cookie +} + +// GetTexEnviv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexEnvivCookie.Reply() +func GetTexEnviv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexEnvivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexEnviv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexEnvivRequest(c, ContextTag, Target, Pname), cookie) + return GetTexEnvivCookie{cookie} +} + +// GetTexEnvivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexEnvivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexEnvivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexEnviv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexEnvivRequest(c, ContextTag, Target, Pname), cookie) + return GetTexEnvivCookie{cookie} +} + +// GetTexEnvivReply represents the data returned from a GetTexEnviv request. +type GetTexEnvivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexEnviv request. +func (cook GetTexEnvivCookie) Reply() (*GetTexEnvivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexEnvivReply(buf), nil +} + +// getTexEnvivReply reads a byte slice into a GetTexEnvivReply value. +func getTexEnvivReply(buf []byte) *GetTexEnvivReply { + v := new(GetTexEnvivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexEnviv +// getTexEnvivRequest writes a GetTexEnviv request to a byte slice. +func getTexEnvivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 131 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexGendvCookie is a cookie used only for GetTexGendv requests. +type GetTexGendvCookie struct { + *xgb.Cookie +} + +// GetTexGendv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexGendvCookie.Reply() +func GetTexGendv(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGendvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGendv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexGendvRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGendvCookie{cookie} +} + +// GetTexGendvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexGendvUnchecked(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGendvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGendv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexGendvRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGendvCookie{cookie} +} + +// GetTexGendvReply represents the data returned from a GetTexGendv request. +type GetTexGendvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float64 + // padding: 8 bytes + Data []Float64 // size: xgb.Pad((int(N) * 8)) +} + +// Reply blocks and returns the reply data for a GetTexGendv request. +func (cook GetTexGendvCookie) Reply() (*GetTexGendvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexGendvReply(buf), nil +} + +// getTexGendvReply reads a byte slice into a GetTexGendvReply value. +func getTexGendvReply(buf []byte) *GetTexGendvReply { + v := new(GetTexGendvReply) + b := 1 // skip reply determinant + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 1 // padding + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float64(xgb.Get64(buf[b:])) + b += 8 + + b += 8 // padding + + v.Data = make([]Float64, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float64(xgb.Get64(buf[b:])) + b += 8 + } + + return v +} + +// Write request to wire for GetTexGendv +// getTexGendvRequest writes a GetTexGendv request to a byte slice. +func getTexGendvRequest(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 132 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Coord) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexGenfvCookie is a cookie used only for GetTexGenfv requests. +type GetTexGenfvCookie struct { + *xgb.Cookie +} + +// GetTexGenfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexGenfvCookie.Reply() +func GetTexGenfv(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGenfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGenfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexGenfvRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGenfvCookie{cookie} +} + +// GetTexGenfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexGenfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGenfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGenfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexGenfvRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGenfvCookie{cookie} +} + +// GetTexGenfvReply represents the data returned from a GetTexGenfv request. +type GetTexGenfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexGenfv request. +func (cook GetTexGenfvCookie) Reply() (*GetTexGenfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexGenfvReply(buf), nil +} + +// getTexGenfvReply reads a byte slice into a GetTexGenfvReply value. +func getTexGenfvReply(buf []byte) *GetTexGenfvReply { + v := new(GetTexGenfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexGenfv +// getTexGenfvRequest writes a GetTexGenfv request to a byte slice. +func getTexGenfvRequest(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 133 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Coord) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexGenivCookie is a cookie used only for GetTexGeniv requests. +type GetTexGenivCookie struct { + *xgb.Cookie +} + +// GetTexGeniv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexGenivCookie.Reply() +func GetTexGeniv(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGenivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGeniv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexGenivRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGenivCookie{cookie} +} + +// GetTexGenivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexGenivUnchecked(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) GetTexGenivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexGeniv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexGenivRequest(c, ContextTag, Coord, Pname), cookie) + return GetTexGenivCookie{cookie} +} + +// GetTexGenivReply represents the data returned from a GetTexGeniv request. +type GetTexGenivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexGeniv request. +func (cook GetTexGenivCookie) Reply() (*GetTexGenivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexGenivReply(buf), nil +} + +// getTexGenivReply reads a byte slice into a GetTexGenivReply value. +func getTexGenivReply(buf []byte) *GetTexGenivReply { + v := new(GetTexGenivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexGeniv +// getTexGenivRequest writes a GetTexGeniv request to a byte slice. +func getTexGenivRequest(c *xgb.Conn, ContextTag ContextTag, Coord uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 134 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Coord) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexImageCookie is a cookie used only for GetTexImage requests. +type GetTexImageCookie struct { + *xgb.Cookie +} + +// GetTexImage sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexImageCookie.Reply() +func GetTexImage(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Format uint32, Type uint32, SwapBytes bool) GetTexImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexImage' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexImageRequest(c, ContextTag, Target, Level, Format, Type, SwapBytes), cookie) + return GetTexImageCookie{cookie} +} + +// GetTexImageUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexImageUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Format uint32, Type uint32, SwapBytes bool) GetTexImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexImage' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexImageRequest(c, ContextTag, Target, Level, Format, Type, SwapBytes), cookie) + return GetTexImageCookie{cookie} +} + +// GetTexImageReply represents the data returned from a GetTexImage request. +type GetTexImageReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 8 bytes + Width int32 + Height int32 + Depth int32 + // padding: 4 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetTexImage request. +func (cook GetTexImageCookie) Reply() (*GetTexImageReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexImageReply(buf), nil +} + +// getTexImageReply reads a byte slice into a GetTexImageReply value. +func getTexImageReply(buf []byte) *GetTexImageReply { + v := new(GetTexImageReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 8 // padding + + v.Width = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Height = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Depth = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 4 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetTexImage +// getTexImageRequest writes a GetTexImage request to a byte slice. +func getTexImageRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Format uint32, Type uint32, SwapBytes bool) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 135 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], uint32(Level)) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetTexLevelParameterfvCookie is a cookie used only for GetTexLevelParameterfv requests. +type GetTexLevelParameterfvCookie struct { + *xgb.Cookie +} + +// GetTexLevelParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexLevelParameterfvCookie.Reply() +func GetTexLevelParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) GetTexLevelParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexLevelParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexLevelParameterfvRequest(c, ContextTag, Target, Level, Pname), cookie) + return GetTexLevelParameterfvCookie{cookie} +} + +// GetTexLevelParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexLevelParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) GetTexLevelParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexLevelParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexLevelParameterfvRequest(c, ContextTag, Target, Level, Pname), cookie) + return GetTexLevelParameterfvCookie{cookie} +} + +// GetTexLevelParameterfvReply represents the data returned from a GetTexLevelParameterfv request. +type GetTexLevelParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexLevelParameterfv request. +func (cook GetTexLevelParameterfvCookie) Reply() (*GetTexLevelParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexLevelParameterfvReply(buf), nil +} + +// getTexLevelParameterfvReply reads a byte slice into a GetTexLevelParameterfvReply value. +func getTexLevelParameterfvReply(buf []byte) *GetTexLevelParameterfvReply { + v := new(GetTexLevelParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexLevelParameterfv +// getTexLevelParameterfvRequest writes a GetTexLevelParameterfv request to a byte slice. +func getTexLevelParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 138 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], uint32(Level)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexLevelParameterivCookie is a cookie used only for GetTexLevelParameteriv requests. +type GetTexLevelParameterivCookie struct { + *xgb.Cookie +} + +// GetTexLevelParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexLevelParameterivCookie.Reply() +func GetTexLevelParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) GetTexLevelParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexLevelParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexLevelParameterivRequest(c, ContextTag, Target, Level, Pname), cookie) + return GetTexLevelParameterivCookie{cookie} +} + +// GetTexLevelParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexLevelParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) GetTexLevelParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexLevelParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexLevelParameterivRequest(c, ContextTag, Target, Level, Pname), cookie) + return GetTexLevelParameterivCookie{cookie} +} + +// GetTexLevelParameterivReply represents the data returned from a GetTexLevelParameteriv request. +type GetTexLevelParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexLevelParameteriv request. +func (cook GetTexLevelParameterivCookie) Reply() (*GetTexLevelParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexLevelParameterivReply(buf), nil +} + +// getTexLevelParameterivReply reads a byte slice into a GetTexLevelParameterivReply value. +func getTexLevelParameterivReply(buf []byte) *GetTexLevelParameterivReply { + v := new(GetTexLevelParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexLevelParameteriv +// getTexLevelParameterivRequest writes a GetTexLevelParameteriv request to a byte slice. +func getTexLevelParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Level int32, Pname uint32) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 139 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], uint32(Level)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexParameterfvCookie is a cookie used only for GetTexParameterfv requests. +type GetTexParameterfvCookie struct { + *xgb.Cookie +} + +// GetTexParameterfv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexParameterfvCookie.Reply() +func GetTexParameterfv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetTexParameterfvCookie{cookie} +} + +// GetTexParameterfvUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexParameterfvUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexParameterfvCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexParameterfv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexParameterfvRequest(c, ContextTag, Target, Pname), cookie) + return GetTexParameterfvCookie{cookie} +} + +// GetTexParameterfvReply represents the data returned from a GetTexParameterfv request. +type GetTexParameterfvReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum Float32 + // padding: 12 bytes + Data []Float32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexParameterfv request. +func (cook GetTexParameterfvCookie) Reply() (*GetTexParameterfvReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexParameterfvReply(buf), nil +} + +// getTexParameterfvReply reads a byte slice into a GetTexParameterfvReply value. +func getTexParameterfvReply(buf []byte) *GetTexParameterfvReply { + v := new(GetTexParameterfvReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = Float32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]Float32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = Float32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexParameterfv +// getTexParameterfvRequest writes a GetTexParameterfv request to a byte slice. +func getTexParameterfvRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 136 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetTexParameterivCookie is a cookie used only for GetTexParameteriv requests. +type GetTexParameterivCookie struct { + *xgb.Cookie +} + +// GetTexParameteriv sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetTexParameterivCookie.Reply() +func GetTexParameteriv(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getTexParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetTexParameterivCookie{cookie} +} + +// GetTexParameterivUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetTexParameterivUnchecked(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) GetTexParameterivCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetTexParameteriv' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getTexParameterivRequest(c, ContextTag, Target, Pname), cookie) + return GetTexParameterivCookie{cookie} +} + +// GetTexParameterivReply represents the data returned from a GetTexParameteriv request. +type GetTexParameterivReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + Datum int32 + // padding: 12 bytes + Data []int32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a GetTexParameteriv request. +func (cook GetTexParameterivCookie) Reply() (*GetTexParameterivReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getTexParameterivReply(buf), nil +} + +// getTexParameterivReply reads a byte slice into a GetTexParameterivReply value. +func getTexParameterivReply(buf []byte) *GetTexParameterivReply { + v := new(GetTexParameterivReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.Datum = int32(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + v.Data = make([]int32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetTexParameteriv +// getTexParameterivRequest writes a GetTexParameteriv request to a byte slice. +func getTexParameterivRequest(c *xgb.Conn, ContextTag ContextTag, Target uint32, Pname uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 137 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Target) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + return buf +} + +// GetVisualConfigsCookie is a cookie used only for GetVisualConfigs requests. +type GetVisualConfigsCookie struct { + *xgb.Cookie +} + +// GetVisualConfigs sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetVisualConfigsCookie.Reply() +func GetVisualConfigs(c *xgb.Conn, Screen uint32) GetVisualConfigsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetVisualConfigs' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getVisualConfigsRequest(c, Screen), cookie) + return GetVisualConfigsCookie{cookie} +} + +// GetVisualConfigsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetVisualConfigsUnchecked(c *xgb.Conn, Screen uint32) GetVisualConfigsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'GetVisualConfigs' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getVisualConfigsRequest(c, Screen), cookie) + return GetVisualConfigsCookie{cookie} +} + +// GetVisualConfigsReply represents the data returned from a GetVisualConfigs request. +type GetVisualConfigsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumVisuals uint32 + NumProperties uint32 + // padding: 16 bytes + PropertyList []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a GetVisualConfigs request. +func (cook GetVisualConfigsCookie) Reply() (*GetVisualConfigsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getVisualConfigsReply(buf), nil +} + +// getVisualConfigsReply reads a byte slice into a GetVisualConfigsReply value. +func getVisualConfigsReply(buf []byte) *GetVisualConfigsReply { + v := new(GetVisualConfigsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumVisuals = xgb.Get32(buf[b:]) + b += 4 + + v.NumProperties = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.PropertyList = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.PropertyList[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetVisualConfigs +// getVisualConfigsRequest writes a GetVisualConfigs request to a byte slice. +func getVisualConfigsRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// IsDirectCookie is a cookie used only for IsDirect requests. +type IsDirectCookie struct { + *xgb.Cookie +} + +// IsDirect sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsDirectCookie.Reply() +func IsDirect(c *xgb.Conn, Context Context) IsDirectCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsDirect' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isDirectRequest(c, Context), cookie) + return IsDirectCookie{cookie} +} + +// IsDirectUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsDirectUnchecked(c *xgb.Conn, Context Context) IsDirectCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsDirect' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isDirectRequest(c, Context), cookie) + return IsDirectCookie{cookie} +} + +// IsDirectReply represents the data returned from a IsDirect request. +type IsDirectReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + IsDirect bool + // padding: 23 bytes +} + +// Reply blocks and returns the reply data for a IsDirect request. +func (cook IsDirectCookie) Reply() (*IsDirectReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isDirectReply(buf), nil +} + +// isDirectReply reads a byte slice into a IsDirectReply value. +func isDirectReply(buf []byte) *IsDirectReply { + v := new(IsDirectReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.IsDirect = true + } else { + v.IsDirect = false + } + b += 1 + + b += 23 // padding + + return v +} + +// Write request to wire for IsDirect +// isDirectRequest writes a IsDirect request to a byte slice. +func isDirectRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Context)) + b += 4 + + return buf +} + +// IsEnabledCookie is a cookie used only for IsEnabled requests. +type IsEnabledCookie struct { + *xgb.Cookie +} + +// IsEnabled sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsEnabledCookie.Reply() +func IsEnabled(c *xgb.Conn, ContextTag ContextTag, Capability uint32) IsEnabledCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsEnabled' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isEnabledRequest(c, ContextTag, Capability), cookie) + return IsEnabledCookie{cookie} +} + +// IsEnabledUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsEnabledUnchecked(c *xgb.Conn, ContextTag ContextTag, Capability uint32) IsEnabledCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsEnabled' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isEnabledRequest(c, ContextTag, Capability), cookie) + return IsEnabledCookie{cookie} +} + +// IsEnabledReply represents the data returned from a IsEnabled request. +type IsEnabledReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 +} + +// Reply blocks and returns the reply data for a IsEnabled request. +func (cook IsEnabledCookie) Reply() (*IsEnabledReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isEnabledReply(buf), nil +} + +// isEnabledReply reads a byte slice into a IsEnabledReply value. +func isEnabledReply(buf []byte) *IsEnabledReply { + v := new(IsEnabledReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for IsEnabled +// isEnabledRequest writes a IsEnabled request to a byte slice. +func isEnabledRequest(c *xgb.Conn, ContextTag ContextTag, Capability uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 140 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Capability) + b += 4 + + return buf +} + +// IsListCookie is a cookie used only for IsList requests. +type IsListCookie struct { + *xgb.Cookie +} + +// IsList sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsListCookie.Reply() +func IsList(c *xgb.Conn, ContextTag ContextTag, List uint32) IsListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isListRequest(c, ContextTag, List), cookie) + return IsListCookie{cookie} +} + +// IsListUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsListUnchecked(c *xgb.Conn, ContextTag ContextTag, List uint32) IsListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isListRequest(c, ContextTag, List), cookie) + return IsListCookie{cookie} +} + +// IsListReply represents the data returned from a IsList request. +type IsListReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 +} + +// Reply blocks and returns the reply data for a IsList request. +func (cook IsListCookie) Reply() (*IsListReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isListReply(buf), nil +} + +// isListReply reads a byte slice into a IsListReply value. +func isListReply(buf []byte) *IsListReply { + v := new(IsListReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for IsList +// isListRequest writes a IsList request to a byte slice. +func isListRequest(c *xgb.Conn, ContextTag ContextTag, List uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 141 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], List) + b += 4 + + return buf +} + +// IsQueryARBCookie is a cookie used only for IsQueryARB requests. +type IsQueryARBCookie struct { + *xgb.Cookie +} + +// IsQueryARB sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsQueryARBCookie.Reply() +func IsQueryARB(c *xgb.Conn, ContextTag ContextTag, Id uint32) IsQueryARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsQueryARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isQueryARBRequest(c, ContextTag, Id), cookie) + return IsQueryARBCookie{cookie} +} + +// IsQueryARBUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsQueryARBUnchecked(c *xgb.Conn, ContextTag ContextTag, Id uint32) IsQueryARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsQueryARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isQueryARBRequest(c, ContextTag, Id), cookie) + return IsQueryARBCookie{cookie} +} + +// IsQueryARBReply represents the data returned from a IsQueryARB request. +type IsQueryARBReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 +} + +// Reply blocks and returns the reply data for a IsQueryARB request. +func (cook IsQueryARBCookie) Reply() (*IsQueryARBReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isQueryARBReply(buf), nil +} + +// isQueryARBReply reads a byte slice into a IsQueryARBReply value. +func isQueryARBReply(buf []byte) *IsQueryARBReply { + v := new(IsQueryARBReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for IsQueryARB +// isQueryARBRequest writes a IsQueryARB request to a byte slice. +func isQueryARBRequest(c *xgb.Conn, ContextTag ContextTag, Id uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 163 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + return buf +} + +// IsTextureCookie is a cookie used only for IsTexture requests. +type IsTextureCookie struct { + *xgb.Cookie +} + +// IsTexture sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsTextureCookie.Reply() +func IsTexture(c *xgb.Conn, ContextTag ContextTag, Texture uint32) IsTextureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsTexture' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isTextureRequest(c, ContextTag, Texture), cookie) + return IsTextureCookie{cookie} +} + +// IsTextureUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsTextureUnchecked(c *xgb.Conn, ContextTag ContextTag, Texture uint32) IsTextureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsTexture' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isTextureRequest(c, ContextTag, Texture), cookie) + return IsTextureCookie{cookie} +} + +// IsTextureReply represents the data returned from a IsTexture request. +type IsTextureReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 +} + +// Reply blocks and returns the reply data for a IsTexture request. +func (cook IsTextureCookie) Reply() (*IsTextureReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isTextureReply(buf), nil +} + +// isTextureReply reads a byte slice into a IsTextureReply value. +func isTextureReply(buf []byte) *IsTextureReply { + v := new(IsTextureReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for IsTexture +// isTextureRequest writes a IsTexture request to a byte slice. +func isTextureRequest(c *xgb.Conn, ContextTag ContextTag, Texture uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 146 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Texture) + b += 4 + + return buf +} + +// MakeContextCurrentCookie is a cookie used only for MakeContextCurrent requests. +type MakeContextCurrentCookie struct { + *xgb.Cookie +} + +// MakeContextCurrent sends a checked request. +// If an error occurs, it will be returned with the reply by calling MakeContextCurrentCookie.Reply() +func MakeContextCurrent(c *xgb.Conn, OldContextTag ContextTag, Drawable Drawable, ReadDrawable Drawable, Context Context) MakeContextCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'MakeContextCurrent' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(makeContextCurrentRequest(c, OldContextTag, Drawable, ReadDrawable, Context), cookie) + return MakeContextCurrentCookie{cookie} +} + +// MakeContextCurrentUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func MakeContextCurrentUnchecked(c *xgb.Conn, OldContextTag ContextTag, Drawable Drawable, ReadDrawable Drawable, Context Context) MakeContextCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'MakeContextCurrent' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(makeContextCurrentRequest(c, OldContextTag, Drawable, ReadDrawable, Context), cookie) + return MakeContextCurrentCookie{cookie} +} + +// MakeContextCurrentReply represents the data returned from a MakeContextCurrent request. +type MakeContextCurrentReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextTag ContextTag + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a MakeContextCurrent request. +func (cook MakeContextCurrentCookie) Reply() (*MakeContextCurrentReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return makeContextCurrentReply(buf), nil +} + +// makeContextCurrentReply reads a byte slice into a MakeContextCurrentReply value. +func makeContextCurrentReply(buf []byte) *MakeContextCurrentReply { + v := new(MakeContextCurrentReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextTag = ContextTag(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for MakeContextCurrent +// makeContextCurrentRequest writes a MakeContextCurrent request to a byte slice. +func makeContextCurrentRequest(c *xgb.Conn, OldContextTag ContextTag, Drawable Drawable, ReadDrawable Drawable, Context Context) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 26 // 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(OldContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(ReadDrawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + return buf +} + +// MakeCurrentCookie is a cookie used only for MakeCurrent requests. +type MakeCurrentCookie struct { + *xgb.Cookie +} + +// MakeCurrent sends a checked request. +// If an error occurs, it will be returned with the reply by calling MakeCurrentCookie.Reply() +func MakeCurrent(c *xgb.Conn, Drawable Drawable, Context Context, OldContextTag ContextTag) MakeCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'MakeCurrent' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(makeCurrentRequest(c, Drawable, Context, OldContextTag), cookie) + return MakeCurrentCookie{cookie} +} + +// MakeCurrentUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func MakeCurrentUnchecked(c *xgb.Conn, Drawable Drawable, Context Context, OldContextTag ContextTag) MakeCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'MakeCurrent' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(makeCurrentRequest(c, Drawable, Context, OldContextTag), cookie) + return MakeCurrentCookie{cookie} +} + +// MakeCurrentReply represents the data returned from a MakeCurrent request. +type MakeCurrentReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextTag ContextTag + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a MakeCurrent request. +func (cook MakeCurrentCookie) Reply() (*MakeCurrentReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return makeCurrentReply(buf), nil +} + +// makeCurrentReply reads a byte slice into a MakeCurrentReply value. +func makeCurrentReply(buf []byte) *MakeCurrentReply { + v := new(MakeCurrentReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextTag = ContextTag(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for MakeCurrent +// makeCurrentRequest writes a MakeCurrent request to a byte slice. +func makeCurrentRequest(c *xgb.Conn, Drawable Drawable, Context Context, OldContextTag ContextTag) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + xgb.Put32(buf[b:], uint32(OldContextTag)) + b += 4 + + return buf +} + +// NewListCookie is a cookie used only for NewList requests. +type NewListCookie struct { + *xgb.Cookie +} + +// NewList sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func NewList(c *xgb.Conn, ContextTag ContextTag, List uint32, Mode uint32) NewListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'NewList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(newListRequest(c, ContextTag, List, Mode), cookie) + return NewListCookie{cookie} +} + +// NewListChecked sends a checked request. +// If an error occurs, it can be retrieved using NewListCookie.Check() +func NewListChecked(c *xgb.Conn, ContextTag ContextTag, List uint32, Mode uint32) NewListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'NewList' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(newListRequest(c, ContextTag, List, Mode), cookie) + return NewListCookie{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 NewListCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for NewList +// newListRequest writes a NewList request to a byte slice. +func newListRequest(c *xgb.Conn, ContextTag ContextTag, List uint32, Mode uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 101 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], List) + b += 4 + + xgb.Put32(buf[b:], Mode) + b += 4 + + return buf +} + +// PixelStorefCookie is a cookie used only for PixelStoref requests. +type PixelStorefCookie struct { + *xgb.Cookie +} + +// PixelStoref sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PixelStoref(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum Float32) PixelStorefCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'PixelStoref' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(pixelStorefRequest(c, ContextTag, Pname, Datum), cookie) + return PixelStorefCookie{cookie} +} + +// PixelStorefChecked sends a checked request. +// If an error occurs, it can be retrieved using PixelStorefCookie.Check() +func PixelStorefChecked(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum Float32) PixelStorefCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'PixelStoref' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(pixelStorefRequest(c, ContextTag, Pname, Datum), cookie) + return PixelStorefCookie{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 PixelStorefCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PixelStoref +// pixelStorefRequest writes a PixelStoref request to a byte slice. +func pixelStorefRequest(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum Float32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 109 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + xgb.Put32(buf[b:], uint32(Datum)) + b += 4 + + return buf +} + +// PixelStoreiCookie is a cookie used only for PixelStorei requests. +type PixelStoreiCookie struct { + *xgb.Cookie +} + +// PixelStorei sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PixelStorei(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum int32) PixelStoreiCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'PixelStorei' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(pixelStoreiRequest(c, ContextTag, Pname, Datum), cookie) + return PixelStoreiCookie{cookie} +} + +// PixelStoreiChecked sends a checked request. +// If an error occurs, it can be retrieved using PixelStoreiCookie.Check() +func PixelStoreiChecked(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum int32) PixelStoreiCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'PixelStorei' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(pixelStoreiRequest(c, ContextTag, Pname, Datum), cookie) + return PixelStoreiCookie{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 PixelStoreiCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PixelStorei +// pixelStoreiRequest writes a PixelStorei request to a byte slice. +func pixelStoreiRequest(c *xgb.Conn, ContextTag ContextTag, Pname uint32, Datum int32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 110 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Pname) + b += 4 + + xgb.Put32(buf[b:], uint32(Datum)) + b += 4 + + return buf +} + +// QueryContextCookie is a cookie used only for QueryContext requests. +type QueryContextCookie struct { + *xgb.Cookie +} + +// QueryContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryContextCookie.Reply() +func QueryContext(c *xgb.Conn, Context Context) QueryContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryContextRequest(c, Context), cookie) + return QueryContextCookie{cookie} +} + +// QueryContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryContextUnchecked(c *xgb.Conn, Context Context) QueryContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryContext' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryContextRequest(c, Context), cookie) + return QueryContextCookie{cookie} +} + +// QueryContextReply represents the data returned from a QueryContext request. +type QueryContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAttribs uint32 + // padding: 20 bytes + Attribs []uint32 // size: xgb.Pad(((int(NumAttribs) * 2) * 4)) +} + +// Reply blocks and returns the reply data for a QueryContext request. +func (cook QueryContextCookie) Reply() (*QueryContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryContextReply(buf), nil +} + +// queryContextReply reads a byte slice into a QueryContextReply value. +func queryContextReply(buf []byte) *QueryContextReply { + v := new(QueryContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAttribs = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Attribs = make([]uint32, (int(v.NumAttribs) * 2)) + for i := 0; i < int((int(v.NumAttribs) * 2)); i++ { + v.Attribs[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for QueryContext +// queryContextRequest writes a QueryContext request to a byte slice. +func queryContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 25 // 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(Context)) + b += 4 + + return buf +} + +// QueryExtensionsStringCookie is a cookie used only for QueryExtensionsString requests. +type QueryExtensionsStringCookie struct { + *xgb.Cookie +} + +// QueryExtensionsString sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryExtensionsStringCookie.Reply() +func QueryExtensionsString(c *xgb.Conn, Screen uint32) QueryExtensionsStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryExtensionsString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryExtensionsStringRequest(c, Screen), cookie) + return QueryExtensionsStringCookie{cookie} +} + +// QueryExtensionsStringUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryExtensionsStringUnchecked(c *xgb.Conn, Screen uint32) QueryExtensionsStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryExtensionsString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryExtensionsStringRequest(c, Screen), cookie) + return QueryExtensionsStringCookie{cookie} +} + +// QueryExtensionsStringReply represents the data returned from a QueryExtensionsString request. +type QueryExtensionsStringReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + N uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryExtensionsString request. +func (cook QueryExtensionsStringCookie) Reply() (*QueryExtensionsStringReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryExtensionsStringReply(buf), nil +} + +// queryExtensionsStringReply reads a byte slice into a QueryExtensionsStringReply value. +func queryExtensionsStringReply(buf []byte) *QueryExtensionsStringReply { + v := new(QueryExtensionsStringReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.N = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryExtensionsString +// queryExtensionsStringRequest writes a QueryExtensionsString request to a byte slice. +func queryExtensionsStringRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// QueryServerStringCookie is a cookie used only for QueryServerString requests. +type QueryServerStringCookie struct { + *xgb.Cookie +} + +// QueryServerString sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryServerStringCookie.Reply() +func QueryServerString(c *xgb.Conn, Screen uint32, Name uint32) QueryServerStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryServerString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryServerStringRequest(c, Screen, Name), cookie) + return QueryServerStringCookie{cookie} +} + +// QueryServerStringUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryServerStringUnchecked(c *xgb.Conn, Screen uint32, Name uint32) QueryServerStringCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryServerString' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryServerStringRequest(c, Screen, Name), cookie) + return QueryServerStringCookie{cookie} +} + +// QueryServerStringReply represents the data returned from a QueryServerString request. +type QueryServerStringReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 4 bytes + StrLen uint32 + // padding: 16 bytes + String string // size: xgb.Pad((int(StrLen) * 1)) +} + +// Reply blocks and returns the reply data for a QueryServerString request. +func (cook QueryServerStringCookie) Reply() (*QueryServerStringReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryServerStringReply(buf), nil +} + +// queryServerStringReply reads a byte slice into a QueryServerStringReply value. +func queryServerStringReply(buf []byte) *QueryServerStringReply { + v := new(QueryServerStringReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 4 // padding + + v.StrLen = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + { + byteString := make([]byte, v.StrLen) + copy(byteString[:v.StrLen], buf[b:]) + v.String = string(byteString) + b += int(v.StrLen) + } + + return v +} + +// Write request to wire for QueryServerString +// queryServerStringRequest writes a QueryServerString request to a byte slice. +func queryServerStringRequest(c *xgb.Conn, Screen uint32, Name uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Name) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + return buf +} + +// ReadPixelsCookie is a cookie used only for ReadPixels requests. +type ReadPixelsCookie struct { + *xgb.Cookie +} + +// ReadPixels sends a checked request. +// If an error occurs, it will be returned with the reply by calling ReadPixelsCookie.Reply() +func ReadPixels(c *xgb.Conn, ContextTag ContextTag, X int32, Y int32, Width int32, Height int32, Format uint32, Type uint32, SwapBytes bool, LsbFirst bool) ReadPixelsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ReadPixels' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(readPixelsRequest(c, ContextTag, X, Y, Width, Height, Format, Type, SwapBytes, LsbFirst), cookie) + return ReadPixelsCookie{cookie} +} + +// ReadPixelsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ReadPixelsUnchecked(c *xgb.Conn, ContextTag ContextTag, X int32, Y int32, Width int32, Height int32, Format uint32, Type uint32, SwapBytes bool, LsbFirst bool) ReadPixelsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'ReadPixels' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(readPixelsRequest(c, ContextTag, X, Y, Width, Height, Format, Type, SwapBytes, LsbFirst), cookie) + return ReadPixelsCookie{cookie} +} + +// ReadPixelsReply represents the data returned from a ReadPixels request. +type ReadPixelsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a ReadPixels request. +func (cook ReadPixelsCookie) Reply() (*ReadPixelsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return readPixelsReply(buf), nil +} + +// readPixelsReply reads a byte slice into a ReadPixelsReply value. +func readPixelsReply(buf []byte) *ReadPixelsReply { + v := new(ReadPixelsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for ReadPixels +// readPixelsRequest writes a ReadPixels request to a byte slice. +func readPixelsRequest(c *xgb.Conn, ContextTag ContextTag, X int32, Y int32, Width int32, Height int32, Format uint32, Type uint32, SwapBytes bool, LsbFirst bool) []byte { + size := 36 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 111 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(X)) + b += 4 + + xgb.Put32(buf[b:], uint32(Y)) + b += 4 + + xgb.Put32(buf[b:], uint32(Width)) + b += 4 + + xgb.Put32(buf[b:], uint32(Height)) + b += 4 + + xgb.Put32(buf[b:], Format) + b += 4 + + xgb.Put32(buf[b:], Type) + b += 4 + + if SwapBytes { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if LsbFirst { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// RenderCookie is a cookie used only for Render requests. +type RenderCookie struct { + *xgb.Cookie +} + +// Render sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Render(c *xgb.Conn, ContextTag ContextTag, Data []byte) RenderCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Render' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(renderRequest(c, ContextTag, Data), cookie) + return RenderCookie{cookie} +} + +// RenderChecked sends a checked request. +// If an error occurs, it can be retrieved using RenderCookie.Check() +func RenderChecked(c *xgb.Conn, ContextTag ContextTag, Data []byte) RenderCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'Render' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(renderRequest(c, ContextTag, Data), cookie) + return RenderCookie{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 RenderCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Render +// renderRequest writes a Render request to a byte slice. +func renderRequest(c *xgb.Conn, ContextTag ContextTag, Data []byte) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + 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(ContextTag)) + b += 4 + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// RenderLargeCookie is a cookie used only for RenderLarge requests. +type RenderLargeCookie struct { + *xgb.Cookie +} + +// RenderLarge sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RenderLarge(c *xgb.Conn, ContextTag ContextTag, RequestNum uint16, RequestTotal uint16, DataLen uint32, Data []byte) RenderLargeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'RenderLarge' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(renderLargeRequest(c, ContextTag, RequestNum, RequestTotal, DataLen, Data), cookie) + return RenderLargeCookie{cookie} +} + +// RenderLargeChecked sends a checked request. +// If an error occurs, it can be retrieved using RenderLargeCookie.Check() +func RenderLargeChecked(c *xgb.Conn, ContextTag ContextTag, RequestNum uint16, RequestTotal uint16, DataLen uint32, Data []byte) RenderLargeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'RenderLarge' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(renderLargeRequest(c, ContextTag, RequestNum, RequestTotal, DataLen, Data), cookie) + return RenderLargeCookie{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 RenderLargeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RenderLarge +// renderLargeRequest writes a RenderLarge request to a byte slice. +func renderLargeRequest(c *xgb.Conn, ContextTag ContextTag, RequestNum uint16, RequestTotal uint16, DataLen uint32, Data []byte) []byte { + size := xgb.Pad((16 + xgb.Pad((int(DataLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(ContextTag)) + b += 4 + + xgb.Put16(buf[b:], RequestNum) + b += 2 + + xgb.Put16(buf[b:], RequestTotal) + b += 2 + + xgb.Put32(buf[b:], DataLen) + b += 4 + + copy(buf[b:], Data[:DataLen]) + b += int(DataLen) + + return buf +} + +// RenderModeCookie is a cookie used only for RenderMode requests. +type RenderModeCookie struct { + *xgb.Cookie +} + +// RenderMode sends a checked request. +// If an error occurs, it will be returned with the reply by calling RenderModeCookie.Reply() +func RenderMode(c *xgb.Conn, ContextTag ContextTag, Mode uint32) RenderModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'RenderMode' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(renderModeRequest(c, ContextTag, Mode), cookie) + return RenderModeCookie{cookie} +} + +// RenderModeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RenderModeUnchecked(c *xgb.Conn, ContextTag ContextTag, Mode uint32) RenderModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'RenderMode' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(renderModeRequest(c, ContextTag, Mode), cookie) + return RenderModeCookie{cookie} +} + +// RenderModeReply represents the data returned from a RenderMode request. +type RenderModeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal uint32 + N uint32 + NewMode uint32 + // padding: 12 bytes + Data []uint32 // size: xgb.Pad((int(N) * 4)) +} + +// Reply blocks and returns the reply data for a RenderMode request. +func (cook RenderModeCookie) Reply() (*RenderModeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return renderModeReply(buf), nil +} + +// renderModeReply reads a byte slice into a RenderModeReply value. +func renderModeReply(buf []byte) *RenderModeReply { + v := new(RenderModeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RetVal = xgb.Get32(buf[b:]) + b += 4 + + v.N = xgb.Get32(buf[b:]) + b += 4 + + v.NewMode = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]uint32, v.N) + for i := 0; i < int(v.N); i++ { + v.Data[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for RenderMode +// renderModeRequest writes a RenderMode request to a byte slice. +func renderModeRequest(c *xgb.Conn, ContextTag ContextTag, Mode uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 107 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Mode) + b += 4 + + return buf +} + +// SelectBufferCookie is a cookie used only for SelectBuffer requests. +type SelectBufferCookie struct { + *xgb.Cookie +} + +// SelectBuffer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectBuffer(c *xgb.Conn, ContextTag ContextTag, Size int32) SelectBufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SelectBuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectBufferRequest(c, ContextTag, Size), cookie) + return SelectBufferCookie{cookie} +} + +// SelectBufferChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectBufferCookie.Check() +func SelectBufferChecked(c *xgb.Conn, ContextTag ContextTag, Size int32) SelectBufferCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SelectBuffer' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectBufferRequest(c, ContextTag, Size), cookie) + return SelectBufferCookie{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 SelectBufferCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectBuffer +// selectBufferRequest writes a SelectBuffer request to a byte slice. +func selectBufferRequest(c *xgb.Conn, ContextTag ContextTag, Size int32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 106 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Size)) + b += 4 + + return buf +} + +// SetClientInfo2ARBCookie is a cookie used only for SetClientInfo2ARB requests. +type SetClientInfo2ARBCookie struct { + *xgb.Cookie +} + +// SetClientInfo2ARB sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetClientInfo2ARB(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) SetClientInfo2ARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SetClientInfo2ARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setClientInfo2ARBRequest(c, MajorVersion, MinorVersion, NumVersions, GlStrLen, GlxStrLen, GlVersions, GlExtensionString, GlxExtensionString), cookie) + return SetClientInfo2ARBCookie{cookie} +} + +// SetClientInfo2ARBChecked sends a checked request. +// If an error occurs, it can be retrieved using SetClientInfo2ARBCookie.Check() +func SetClientInfo2ARBChecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) SetClientInfo2ARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SetClientInfo2ARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setClientInfo2ARBRequest(c, MajorVersion, MinorVersion, NumVersions, GlStrLen, GlxStrLen, GlVersions, GlExtensionString, GlxExtensionString), cookie) + return SetClientInfo2ARBCookie{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 SetClientInfo2ARBCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetClientInfo2ARB +// setClientInfo2ARBRequest writes a SetClientInfo2ARB request to a byte slice. +func setClientInfo2ARBRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) []byte { + size := xgb.Pad((((24 + xgb.Pad(((int(NumVersions) * 3) * 4))) + xgb.Pad((int(GlStrLen) * 1))) + xgb.Pad((int(GlxStrLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 35 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + xgb.Put32(buf[b:], NumVersions) + b += 4 + + xgb.Put32(buf[b:], GlStrLen) + b += 4 + + xgb.Put32(buf[b:], GlxStrLen) + b += 4 + + for i := 0; i < int((int(NumVersions) * 3)); i++ { + xgb.Put32(buf[b:], GlVersions[i]) + b += 4 + } + + copy(buf[b:], GlExtensionString[:GlStrLen]) + b += int(GlStrLen) + + copy(buf[b:], GlxExtensionString[:GlxStrLen]) + b += int(GlxStrLen) + + return buf +} + +// SetClientInfoARBCookie is a cookie used only for SetClientInfoARB requests. +type SetClientInfoARBCookie struct { + *xgb.Cookie +} + +// SetClientInfoARB sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetClientInfoARB(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) SetClientInfoARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SetClientInfoARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setClientInfoARBRequest(c, MajorVersion, MinorVersion, NumVersions, GlStrLen, GlxStrLen, GlVersions, GlExtensionString, GlxExtensionString), cookie) + return SetClientInfoARBCookie{cookie} +} + +// SetClientInfoARBChecked sends a checked request. +// If an error occurs, it can be retrieved using SetClientInfoARBCookie.Check() +func SetClientInfoARBChecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) SetClientInfoARBCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SetClientInfoARB' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setClientInfoARBRequest(c, MajorVersion, MinorVersion, NumVersions, GlStrLen, GlxStrLen, GlVersions, GlExtensionString, GlxExtensionString), cookie) + return SetClientInfoARBCookie{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 SetClientInfoARBCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetClientInfoARB +// setClientInfoARBRequest writes a SetClientInfoARB request to a byte slice. +func setClientInfoARBRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32, NumVersions uint32, GlStrLen uint32, GlxStrLen uint32, GlVersions []uint32, GlExtensionString string, GlxExtensionString string) []byte { + size := xgb.Pad((((24 + xgb.Pad(((int(NumVersions) * 2) * 4))) + xgb.Pad((int(GlStrLen) * 1))) + xgb.Pad((int(GlxStrLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 33 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + xgb.Put32(buf[b:], NumVersions) + b += 4 + + xgb.Put32(buf[b:], GlStrLen) + b += 4 + + xgb.Put32(buf[b:], GlxStrLen) + b += 4 + + for i := 0; i < int((int(NumVersions) * 2)); i++ { + xgb.Put32(buf[b:], GlVersions[i]) + b += 4 + } + + copy(buf[b:], GlExtensionString[:GlStrLen]) + b += int(GlStrLen) + + copy(buf[b:], GlxExtensionString[:GlxStrLen]) + b += int(GlxStrLen) + + return buf +} + +// SwapBuffersCookie is a cookie used only for SwapBuffers requests. +type SwapBuffersCookie struct { + *xgb.Cookie +} + +// SwapBuffers sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SwapBuffers(c *xgb.Conn, ContextTag ContextTag, Drawable Drawable) SwapBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(swapBuffersRequest(c, ContextTag, Drawable), cookie) + return SwapBuffersCookie{cookie} +} + +// SwapBuffersChecked sends a checked request. +// If an error occurs, it can be retrieved using SwapBuffersCookie.Check() +func SwapBuffersChecked(c *xgb.Conn, ContextTag ContextTag, Drawable Drawable) SwapBuffersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(swapBuffersRequest(c, ContextTag, Drawable), cookie) + return SwapBuffersCookie{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 SwapBuffersCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SwapBuffers +// swapBuffersRequest writes a SwapBuffers request to a byte slice. +func swapBuffersRequest(c *xgb.Conn, ContextTag ContextTag, Drawable Drawable) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + return buf +} + +// UseXFontCookie is a cookie used only for UseXFont requests. +type UseXFontCookie struct { + *xgb.Cookie +} + +// UseXFont sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UseXFont(c *xgb.Conn, ContextTag ContextTag, Font xproto.Font, First uint32, Count uint32, ListBase uint32) UseXFontCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'UseXFont' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(useXFontRequest(c, ContextTag, Font, First, Count, ListBase), cookie) + return UseXFontCookie{cookie} +} + +// UseXFontChecked sends a checked request. +// If an error occurs, it can be retrieved using UseXFontCookie.Check() +func UseXFontChecked(c *xgb.Conn, ContextTag ContextTag, Font xproto.Font, First uint32, Count uint32, ListBase uint32) UseXFontCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'UseXFont' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(useXFontRequest(c, ContextTag, Font, First, Count, ListBase), cookie) + return UseXFontCookie{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 UseXFontCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UseXFont +// useXFontRequest writes a UseXFont request to a byte slice. +func useXFontRequest(c *xgb.Conn, ContextTag ContextTag, Font xproto.Font, First uint32, Count uint32, ListBase uint32) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], uint32(Font)) + b += 4 + + xgb.Put32(buf[b:], First) + b += 4 + + xgb.Put32(buf[b:], Count) + b += 4 + + xgb.Put32(buf[b:], ListBase) + b += 4 + + return buf +} + +// VendorPrivateCookie is a cookie used only for VendorPrivate requests. +type VendorPrivateCookie struct { + *xgb.Cookie +} + +// VendorPrivate sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func VendorPrivate(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) VendorPrivateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'VendorPrivate' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(vendorPrivateRequest(c, VendorCode, ContextTag, Data), cookie) + return VendorPrivateCookie{cookie} +} + +// VendorPrivateChecked sends a checked request. +// If an error occurs, it can be retrieved using VendorPrivateCookie.Check() +func VendorPrivateChecked(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) VendorPrivateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'VendorPrivate' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(vendorPrivateRequest(c, VendorCode, ContextTag, Data), cookie) + return VendorPrivateCookie{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 VendorPrivateCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for VendorPrivate +// vendorPrivateRequest writes a VendorPrivate request to a byte slice. +func vendorPrivateRequest(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], VendorCode) + b += 4 + + xgb.Put32(buf[b:], uint32(ContextTag)) + b += 4 + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// VendorPrivateWithReplyCookie is a cookie used only for VendorPrivateWithReply requests. +type VendorPrivateWithReplyCookie struct { + *xgb.Cookie +} + +// VendorPrivateWithReply sends a checked request. +// If an error occurs, it will be returned with the reply by calling VendorPrivateWithReplyCookie.Reply() +func VendorPrivateWithReply(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) VendorPrivateWithReplyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'VendorPrivateWithReply' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(vendorPrivateWithReplyRequest(c, VendorCode, ContextTag, Data), cookie) + return VendorPrivateWithReplyCookie{cookie} +} + +// VendorPrivateWithReplyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func VendorPrivateWithReplyUnchecked(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) VendorPrivateWithReplyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'VendorPrivateWithReply' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(vendorPrivateWithReplyRequest(c, VendorCode, ContextTag, Data), cookie) + return VendorPrivateWithReplyCookie{cookie} +} + +// VendorPrivateWithReplyReply represents the data returned from a VendorPrivateWithReply request. +type VendorPrivateWithReplyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Retval uint32 + Data1 []byte // size: 24 + Data2 []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a VendorPrivateWithReply request. +func (cook VendorPrivateWithReplyCookie) Reply() (*VendorPrivateWithReplyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return vendorPrivateWithReplyReply(buf), nil +} + +// vendorPrivateWithReplyReply reads a byte slice into a VendorPrivateWithReplyReply value. +func vendorPrivateWithReplyReply(buf []byte) *VendorPrivateWithReplyReply { + v := new(VendorPrivateWithReplyReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Retval = xgb.Get32(buf[b:]) + b += 4 + + v.Data1 = make([]byte, 24) + copy(v.Data1[:24], buf[b:]) + b += int(24) + + v.Data2 = make([]byte, (int(v.Length) * 4)) + copy(v.Data2[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for VendorPrivateWithReply +// vendorPrivateWithReplyRequest writes a VendorPrivateWithReply request to a byte slice. +func vendorPrivateWithReplyRequest(c *xgb.Conn, VendorCode uint32, ContextTag ContextTag, Data []byte) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], VendorCode) + b += 4 + + xgb.Put32(buf[b:], uint32(ContextTag)) + b += 4 + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// WaitGLCookie is a cookie used only for WaitGL requests. +type WaitGLCookie struct { + *xgb.Cookie +} + +// WaitGL sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func WaitGL(c *xgb.Conn, ContextTag ContextTag) WaitGLCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'WaitGL' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(waitGLRequest(c, ContextTag), cookie) + return WaitGLCookie{cookie} +} + +// WaitGLChecked sends a checked request. +// If an error occurs, it can be retrieved using WaitGLCookie.Check() +func WaitGLChecked(c *xgb.Conn, ContextTag ContextTag) WaitGLCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'WaitGL' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(waitGLRequest(c, ContextTag), cookie) + return WaitGLCookie{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 WaitGLCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for WaitGL +// waitGLRequest writes a WaitGL request to a byte slice. +func waitGLRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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(ContextTag)) + b += 4 + + return buf +} + +// WaitXCookie is a cookie used only for WaitX requests. +type WaitXCookie struct { + *xgb.Cookie +} + +// WaitX sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func WaitX(c *xgb.Conn, ContextTag ContextTag) WaitXCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'WaitX' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(waitXRequest(c, ContextTag), cookie) + return WaitXCookie{cookie} +} + +// WaitXChecked sends a checked request. +// If an error occurs, it can be retrieved using WaitXCookie.Check() +func WaitXChecked(c *xgb.Conn, ContextTag ContextTag) WaitXCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'WaitX' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(waitXRequest(c, ContextTag), cookie) + return WaitXCookie{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 WaitXCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for WaitX +// waitXRequest writes a WaitX request to a byte slice. +func waitXRequest(c *xgb.Conn, ContextTag ContextTag) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // 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(ContextTag)) + b += 4 + + return buf +} diff --git a/nexgb/help.go b/nexgb/help.go new file mode 100644 index 0000000..f692442 --- /dev/null +++ b/nexgb/help.go @@ -0,0 +1,105 @@ +package xgb + +/* +help.go is meant to contain a rough hodge podge of functions that are mainly +used in the auto generated code. Indeed, several functions here are simple +wrappers so that the sub-packages don't need to be smart about which stdlib +packages to import. + +Also, the 'Get..' and 'Put..' functions are used through the core xgb package +too. (xgbutil uses them too.) +*/ + +import ( + "fmt" + "strings" +) + +// StringsJoin is an alias to strings.Join. It allows us to avoid having to +// import 'strings' in each of the generated Go files. +func StringsJoin(ss []string, sep string) string { + return strings.Join(ss, sep) +} + +// Sprintf is so we don't need to import 'fmt' in the generated Go files. +func Sprintf(format string, v ...interface{}) string { + return fmt.Sprintf(format, v...) +} + +// Errorf is just a wrapper for fmt.Errorf. Exists for the same reason +// that 'stringsJoin' and 'sprintf' exists. +func Errorf(format string, v ...interface{}) error { + return fmt.Errorf(format, v...) +} + +// Pad a length to align on 4 bytes. +func Pad(n int) int { + return (n + 3) & ^3 +} + +// PopCount counts the number of bits set in a value list mask. +func PopCount(mask0 int) int { + mask := uint32(mask0) + n := 0 + for i := uint32(0); i < 32; i++ { + if mask&(1<<i) != 0 { + n++ + } + } + return n +} + +// Put16 takes a 16 bit integer and copies it into a byte slice. +func Put16(buf []byte, v uint16) { + buf[0] = byte(v) + buf[1] = byte(v >> 8) +} + +// Put32 takes a 32 bit integer and copies it into a byte slice. +func Put32(buf []byte, v uint32) { + buf[0] = byte(v) + buf[1] = byte(v >> 8) + buf[2] = byte(v >> 16) + buf[3] = byte(v >> 24) +} + +// Put64 takes a 64 bit integer and copies it into a byte slice. +func Put64(buf []byte, v uint64) { + buf[0] = byte(v) + buf[1] = byte(v >> 8) + buf[2] = byte(v >> 16) + buf[3] = byte(v >> 24) + buf[4] = byte(v >> 32) + buf[5] = byte(v >> 40) + buf[6] = byte(v >> 48) + buf[7] = byte(v >> 56) +} + +// Get16 constructs a 16 bit integer from the beginning of a byte slice. +func Get16(buf []byte) uint16 { + v := uint16(buf[0]) + v |= uint16(buf[1]) << 8 + return v +} + +// Get32 constructs a 32 bit integer from the beginning of a byte slice. +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 +} + +// Get64 constructs a 64 bit integer from the beginning of a byte slice. +func Get64(buf []byte) uint64 { + v := uint64(buf[0]) + v |= uint64(buf[1]) << 8 + v |= uint64(buf[2]) << 16 + v |= uint64(buf[3]) << 24 + v |= uint64(buf[4]) << 32 + v |= uint64(buf[5]) << 40 + v |= uint64(buf[6]) << 48 + v |= uint64(buf[7]) << 56 + return v +} diff --git a/nexgb/randr/randr.go b/nexgb/randr/randr.go new file mode 100644 index 0000000..d280e95 --- /dev/null +++ b/nexgb/randr/randr.go @@ -0,0 +1,6267 @@ +// Package randr is the X client API for the RANDR extension. +package randr + +// This file is automatically generated from randr.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/render" + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the RANDR extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 5, "RANDR").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named RANDR could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["RANDR"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["RANDR"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["RANDR"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["RANDR"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["RANDR"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadCrtc is the error number for a BadBadCrtc. +const BadBadCrtc = 1 + +type BadCrtcError struct { + Sequence uint16 + NiceName string +} + +// BadCrtcErrorNew constructs a BadCrtcError value that implements xgb.Error from a byte slice. +func BadCrtcErrorNew(buf []byte) xgb.Error { + v := BadCrtcError{} + v.NiceName = "BadCrtc" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadCrtc error. +// This is mostly used internally. +func (err BadCrtcError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadCrtc error. If no bad value exists, 0 is returned. +func (err BadCrtcError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadCrtc error. + +func (err BadCrtcError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadCrtc {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RANDR"][1] = BadCrtcErrorNew +} + +// BadBadMode is the error number for a BadBadMode. +const BadBadMode = 2 + +type BadModeError struct { + Sequence uint16 + NiceName string +} + +// BadModeErrorNew constructs a BadModeError value that implements xgb.Error from a byte slice. +func BadModeErrorNew(buf []byte) xgb.Error { + v := BadModeError{} + v.NiceName = "BadMode" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadMode error. +// This is mostly used internally. +func (err BadModeError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadMode error. If no bad value exists, 0 is returned. +func (err BadModeError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadMode error. + +func (err BadModeError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadMode {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RANDR"][2] = BadModeErrorNew +} + +// BadBadOutput is the error number for a BadBadOutput. +const BadBadOutput = 0 + +type BadOutputError struct { + Sequence uint16 + NiceName string +} + +// BadOutputErrorNew constructs a BadOutputError value that implements xgb.Error from a byte slice. +func BadOutputErrorNew(buf []byte) xgb.Error { + v := BadOutputError{} + v.NiceName = "BadOutput" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadOutput error. +// This is mostly used internally. +func (err BadOutputError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadOutput error. If no bad value exists, 0 is returned. +func (err BadOutputError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadOutput error. + +func (err BadOutputError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadOutput {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RANDR"][0] = BadOutputErrorNew +} + +// BadBadProvider is the error number for a BadBadProvider. +const BadBadProvider = 3 + +type BadProviderError struct { + Sequence uint16 + NiceName string +} + +// BadProviderErrorNew constructs a BadProviderError value that implements xgb.Error from a byte slice. +func BadProviderErrorNew(buf []byte) xgb.Error { + v := BadProviderError{} + v.NiceName = "BadProvider" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadProvider error. +// This is mostly used internally. +func (err BadProviderError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadProvider error. If no bad value exists, 0 is returned. +func (err BadProviderError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadProvider error. + +func (err BadProviderError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadProvider {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RANDR"][3] = BadProviderErrorNew +} + +const ( + ConnectionConnected = 0 + ConnectionDisconnected = 1 + ConnectionUnknown = 2 +) + +type Crtc uint32 + +func NewCrtcId(c *xgb.Conn) (Crtc, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Crtc(id), nil +} + +type CrtcChange struct { + Timestamp xproto.Timestamp + Window xproto.Window + Crtc Crtc + Mode Mode + Rotation uint16 + // padding: 2 bytes + X int16 + Y int16 + Width uint16 + Height uint16 +} + +// CrtcChangeRead reads a byte slice into a CrtcChange value. +func CrtcChangeRead(buf []byte, v *CrtcChange) int { + b := 0 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Crtc = Crtc(xgb.Get32(buf[b:])) + b += 4 + + v.Mode = Mode(xgb.Get32(buf[b:])) + b += 4 + + v.Rotation = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// CrtcChangeReadList reads a byte slice into a list of CrtcChange values. +func CrtcChangeReadList(buf []byte, dest []CrtcChange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = CrtcChange{} + b += CrtcChangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a CrtcChange value to a byte slice. +func (v CrtcChange) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Crtc)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Mode)) + b += 4 + + xgb.Put16(buf[b:], v.Rotation) + b += 2 + + b += 2 // padding + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + return buf[:b] +} + +// CrtcChangeListBytes writes a list of CrtcChange values to a byte slice. +func CrtcChangeListBytes(buf []byte, list []CrtcChange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Mode uint32 + +func NewModeId(c *xgb.Conn) (Mode, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Mode(id), nil +} + +const ( + ModeFlagHsyncPositive = 1 + ModeFlagHsyncNegative = 2 + ModeFlagVsyncPositive = 4 + ModeFlagVsyncNegative = 8 + ModeFlagInterlace = 16 + ModeFlagDoubleScan = 32 + ModeFlagCsync = 64 + ModeFlagCsyncPositive = 128 + ModeFlagCsyncNegative = 256 + ModeFlagHskewPresent = 512 + ModeFlagBcast = 1024 + ModeFlagPixelMultiplex = 2048 + ModeFlagDoubleClock = 4096 + ModeFlagHalveClock = 8192 +) + +type ModeInfo struct { + Id uint32 + Width uint16 + Height uint16 + DotClock uint32 + HsyncStart uint16 + HsyncEnd uint16 + Htotal uint16 + Hskew uint16 + VsyncStart uint16 + VsyncEnd uint16 + Vtotal uint16 + NameLen uint16 + ModeFlags uint32 +} + +// ModeInfoRead reads a byte slice into a ModeInfo value. +func ModeInfoRead(buf []byte, v *ModeInfo) int { + b := 0 + + v.Id = xgb.Get32(buf[b:]) + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.DotClock = xgb.Get32(buf[b:]) + b += 4 + + v.HsyncStart = xgb.Get16(buf[b:]) + b += 2 + + v.HsyncEnd = xgb.Get16(buf[b:]) + b += 2 + + v.Htotal = xgb.Get16(buf[b:]) + b += 2 + + v.Hskew = xgb.Get16(buf[b:]) + b += 2 + + v.VsyncStart = xgb.Get16(buf[b:]) + b += 2 + + v.VsyncEnd = xgb.Get16(buf[b:]) + b += 2 + + v.Vtotal = xgb.Get16(buf[b:]) + b += 2 + + v.NameLen = xgb.Get16(buf[b:]) + b += 2 + + v.ModeFlags = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ModeInfoReadList reads a byte slice into a list of ModeInfo values. +func ModeInfoReadList(buf []byte, dest []ModeInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ModeInfo{} + b += ModeInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ModeInfo value to a byte slice. +func (v ModeInfo) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + xgb.Put32(buf[b:], v.Id) + b += 4 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put32(buf[b:], v.DotClock) + b += 4 + + xgb.Put16(buf[b:], v.HsyncStart) + b += 2 + + xgb.Put16(buf[b:], v.HsyncEnd) + b += 2 + + xgb.Put16(buf[b:], v.Htotal) + b += 2 + + xgb.Put16(buf[b:], v.Hskew) + b += 2 + + xgb.Put16(buf[b:], v.VsyncStart) + b += 2 + + xgb.Put16(buf[b:], v.VsyncEnd) + b += 2 + + xgb.Put16(buf[b:], v.Vtotal) + b += 2 + + xgb.Put16(buf[b:], v.NameLen) + b += 2 + + xgb.Put32(buf[b:], v.ModeFlags) + b += 4 + + return buf[:b] +} + +// ModeInfoListBytes writes a list of ModeInfo values to a byte slice. +func ModeInfoListBytes(buf []byte, list []ModeInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type MonitorInfo struct { + Name xproto.Atom + Primary bool + Automatic bool + NOutput uint16 + X int16 + Y int16 + Width uint16 + Height uint16 + WidthInMillimeters uint32 + HeightInMillimeters uint32 + Outputs []Output // size: xgb.Pad((int(NOutput) * 4)) +} + +// MonitorInfoRead reads a byte slice into a MonitorInfo value. +func MonitorInfoRead(buf []byte, v *MonitorInfo) int { + b := 0 + + v.Name = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.Primary = true + } else { + v.Primary = false + } + b += 1 + + if buf[b] == 1 { + v.Automatic = true + } else { + v.Automatic = false + } + b += 1 + + v.NOutput = xgb.Get16(buf[b:]) + b += 2 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.WidthInMillimeters = xgb.Get32(buf[b:]) + b += 4 + + v.HeightInMillimeters = xgb.Get32(buf[b:]) + b += 4 + + v.Outputs = make([]Output, v.NOutput) + for i := 0; i < int(v.NOutput); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + return b +} + +// MonitorInfoReadList reads a byte slice into a list of MonitorInfo values. +func MonitorInfoReadList(buf []byte, dest []MonitorInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = MonitorInfo{} + b += MonitorInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a MonitorInfo value to a byte slice. +func (v MonitorInfo) Bytes() []byte { + buf := make([]byte, (24 + xgb.Pad((int(v.NOutput) * 4)))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Name)) + b += 4 + + if v.Primary { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if v.Automatic { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], v.NOutput) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put32(buf[b:], v.WidthInMillimeters) + b += 4 + + xgb.Put32(buf[b:], v.HeightInMillimeters) + b += 4 + + for i := 0; i < int(v.NOutput); i++ { + xgb.Put32(buf[b:], uint32(v.Outputs[i])) + b += 4 + } + + return buf[:b] +} + +// MonitorInfoListBytes writes a list of MonitorInfo values to a byte slice. +func MonitorInfoListBytes(buf []byte, list []MonitorInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// MonitorInfoListSize computes the size (bytes) of a list of MonitorInfo values. +func MonitorInfoListSize(list []MonitorInfo) int { + size := 0 + for _, item := range list { + size += (24 + xgb.Pad((int(item.NOutput) * 4))) + } + return size +} + +const ( + NotifyCrtcChange = 0 + NotifyOutputChange = 1 + NotifyOutputProperty = 2 + NotifyProviderChange = 3 + NotifyProviderProperty = 4 + NotifyResourceChange = 5 +) + +// Notify is the event number for a NotifyEvent. +const Notify = 1 + +type NotifyEvent struct { + Sequence uint16 + SubCode byte + U NotifyDataUnion +} + +// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. +func NotifyEventNew(buf []byte) xgb.Event { + v := NotifyEvent{} + b := 1 // don't read event number + + v.SubCode = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.U = NotifyDataUnion{} + b += NotifyDataUnionRead(buf[b:], &v.U) + + return v +} + +// Bytes writes a NotifyEvent value to a byte slice. +func (v NotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + buf[b] = v.SubCode + b += 1 + + b += 2 // skip sequence number + + { + unionBytes := v.U.Bytes() + copy(buf[b:], unionBytes) + b += len(unionBytes) + } + + return buf +} + +// SequenceId returns the sequence id attached to the Notify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NotifyEvent. +func (v NotifyEvent) String() string { + fieldVals := make([]string, 0, 2) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("SubCode: %d", v.SubCode)) + return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["RANDR"][1] = NotifyEventNew +} + +// NotifyDataUnion is a represention of the NotifyDataUnion union type. +// Note that to *create* a Union, you should *never* create +// this struct directly (unless you know what you're doing). +// Instead use one of the following constructors for 'NotifyDataUnion': +// NotifyDataUnionCcNew(Cc CrtcChange) NotifyDataUnion +// NotifyDataUnionOcNew(Oc OutputChange) NotifyDataUnion +// NotifyDataUnionOpNew(Op OutputProperty) NotifyDataUnion +// NotifyDataUnionPcNew(Pc ProviderChange) NotifyDataUnion +// NotifyDataUnionPpNew(Pp ProviderProperty) NotifyDataUnion +// NotifyDataUnionRcNew(Rc ResourceChange) NotifyDataUnion +type NotifyDataUnion struct { + Cc CrtcChange + Oc OutputChange + Op OutputProperty + Pc ProviderChange + Pp ProviderProperty + Rc ResourceChange +} + +// NotifyDataUnionCcNew constructs a new NotifyDataUnion union type with the Cc field. +func NotifyDataUnionCcNew(Cc CrtcChange) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Cc.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionOcNew constructs a new NotifyDataUnion union type with the Oc field. +func NotifyDataUnionOcNew(Oc OutputChange) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Oc.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionOpNew constructs a new NotifyDataUnion union type with the Op field. +func NotifyDataUnionOpNew(Op OutputProperty) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Op.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionPcNew constructs a new NotifyDataUnion union type with the Pc field. +func NotifyDataUnionPcNew(Pc ProviderChange) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Pc.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionPpNew constructs a new NotifyDataUnion union type with the Pp field. +func NotifyDataUnionPpNew(Pp ProviderProperty) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Pp.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionRcNew constructs a new NotifyDataUnion union type with the Rc field. +func NotifyDataUnionRcNew(Rc ResourceChange) NotifyDataUnion { + var b int + buf := make([]byte, 28) + + { + structBytes := Rc.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + // Create the Union type + v := NotifyDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // always read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // always read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // always read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // always read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // always read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return v +} + +// NotifyDataUnionRead reads a byte slice into a NotifyDataUnion value. +func NotifyDataUnionRead(buf []byte, v *NotifyDataUnion) int { + var b int + + b = 0 // re-read the same bytes + v.Cc = CrtcChange{} + b += CrtcChangeRead(buf[b:], &v.Cc) + + b = 0 // re-read the same bytes + v.Oc = OutputChange{} + b += OutputChangeRead(buf[b:], &v.Oc) + + b = 0 // re-read the same bytes + v.Op = OutputProperty{} + b += OutputPropertyRead(buf[b:], &v.Op) + + b = 0 // re-read the same bytes + v.Pc = ProviderChange{} + b += ProviderChangeRead(buf[b:], &v.Pc) + + b = 0 // re-read the same bytes + v.Pp = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &v.Pp) + + b = 0 // re-read the same bytes + v.Rc = ResourceChange{} + b += ResourceChangeRead(buf[b:], &v.Rc) + + return 28 +} + +// NotifyDataUnionReadList reads a byte slice into a list of NotifyDataUnion values. +func NotifyDataUnionReadList(buf []byte, dest []NotifyDataUnion) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = NotifyDataUnion{} + b += NotifyDataUnionRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a NotifyDataUnion value to a byte slice. +// Each field in a union must contain the same data. +// So simply pick the first field and write that to the wire. +func (v NotifyDataUnion) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + { + structBytes := v.Cc.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return buf +} + +// NotifyDataUnionListBytes writes a list of NotifyDataUnion values to a byte slice. +func NotifyDataUnionListBytes(buf []byte, list []NotifyDataUnion) int { + b := 0 + var unionBytes []byte + for _, item := range list { + unionBytes = item.Bytes() + copy(buf[b:], unionBytes) + b += xgb.Pad(len(unionBytes)) + } + return b +} + +const ( + NotifyMaskScreenChange = 1 + NotifyMaskCrtcChange = 2 + NotifyMaskOutputChange = 4 + NotifyMaskOutputProperty = 8 + NotifyMaskProviderChange = 16 + NotifyMaskProviderProperty = 32 + NotifyMaskResourceChange = 64 +) + +type Output uint32 + +func NewOutputId(c *xgb.Conn) (Output, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Output(id), nil +} + +type OutputChange struct { + Timestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + Window xproto.Window + Output Output + Crtc Crtc + Mode Mode + Rotation uint16 + Connection byte + SubpixelOrder byte +} + +// OutputChangeRead reads a byte slice into a OutputChange value. +func OutputChangeRead(buf []byte, v *OutputChange) int { + b := 0 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Output = Output(xgb.Get32(buf[b:])) + b += 4 + + v.Crtc = Crtc(xgb.Get32(buf[b:])) + b += 4 + + v.Mode = Mode(xgb.Get32(buf[b:])) + b += 4 + + v.Rotation = xgb.Get16(buf[b:]) + b += 2 + + v.Connection = buf[b] + b += 1 + + v.SubpixelOrder = buf[b] + b += 1 + + return b +} + +// OutputChangeReadList reads a byte slice into a list of OutputChange values. +func OutputChangeReadList(buf []byte, dest []OutputChange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = OutputChange{} + b += OutputChangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a OutputChange value to a byte slice. +func (v OutputChange) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.ConfigTimestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Crtc)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Mode)) + b += 4 + + xgb.Put16(buf[b:], v.Rotation) + b += 2 + + buf[b] = v.Connection + b += 1 + + buf[b] = v.SubpixelOrder + b += 1 + + return buf[:b] +} + +// OutputChangeListBytes writes a list of OutputChange values to a byte slice. +func OutputChangeListBytes(buf []byte, list []OutputChange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type OutputProperty struct { + Window xproto.Window + Output Output + Atom xproto.Atom + Timestamp xproto.Timestamp + Status byte + // padding: 11 bytes +} + +// OutputPropertyRead reads a byte slice into a OutputProperty value. +func OutputPropertyRead(buf []byte, v *OutputProperty) int { + b := 0 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Output = Output(xgb.Get32(buf[b:])) + b += 4 + + v.Atom = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Status = buf[b] + b += 1 + + b += 11 // padding + + return b +} + +// OutputPropertyReadList reads a byte slice into a list of OutputProperty values. +func OutputPropertyReadList(buf []byte, dest []OutputProperty) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = OutputProperty{} + b += OutputPropertyRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a OutputProperty value to a byte slice. +func (v OutputProperty) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Atom)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + buf[b] = v.Status + b += 1 + + b += 11 // padding + + return buf[:b] +} + +// OutputPropertyListBytes writes a list of OutputProperty values to a byte slice. +func OutputPropertyListBytes(buf []byte, list []OutputProperty) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Provider uint32 + +func NewProviderId(c *xgb.Conn) (Provider, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Provider(id), nil +} + +const ( + ProviderCapabilitySourceOutput = 1 + ProviderCapabilitySinkOutput = 2 + ProviderCapabilitySourceOffload = 4 + ProviderCapabilitySinkOffload = 8 +) + +type ProviderChange struct { + Timestamp xproto.Timestamp + Window xproto.Window + Provider Provider + // padding: 16 bytes +} + +// ProviderChangeRead reads a byte slice into a ProviderChange value. +func ProviderChangeRead(buf []byte, v *ProviderChange) int { + b := 0 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Provider = Provider(xgb.Get32(buf[b:])) + b += 4 + + b += 16 // padding + + return b +} + +// ProviderChangeReadList reads a byte slice into a list of ProviderChange values. +func ProviderChangeReadList(buf []byte, dest []ProviderChange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ProviderChange{} + b += ProviderChangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ProviderChange value to a byte slice. +func (v ProviderChange) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Provider)) + b += 4 + + b += 16 // padding + + return buf[:b] +} + +// ProviderChangeListBytes writes a list of ProviderChange values to a byte slice. +func ProviderChangeListBytes(buf []byte, list []ProviderChange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type ProviderProperty struct { + Window xproto.Window + Provider Provider + Atom xproto.Atom + Timestamp xproto.Timestamp + State byte + // padding: 11 bytes +} + +// ProviderPropertyRead reads a byte slice into a ProviderProperty value. +func ProviderPropertyRead(buf []byte, v *ProviderProperty) int { + b := 0 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Provider = Provider(xgb.Get32(buf[b:])) + b += 4 + + v.Atom = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.State = buf[b] + b += 1 + + b += 11 // padding + + return b +} + +// ProviderPropertyReadList reads a byte slice into a list of ProviderProperty values. +func ProviderPropertyReadList(buf []byte, dest []ProviderProperty) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ProviderProperty{} + b += ProviderPropertyRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ProviderProperty value to a byte slice. +func (v ProviderProperty) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Atom)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + buf[b] = v.State + b += 1 + + b += 11 // padding + + return buf[:b] +} + +// ProviderPropertyListBytes writes a list of ProviderProperty values to a byte slice. +func ProviderPropertyListBytes(buf []byte, list []ProviderProperty) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type RefreshRates struct { + NRates uint16 + Rates []uint16 // size: xgb.Pad((int(NRates) * 2)) +} + +// RefreshRatesRead reads a byte slice into a RefreshRates value. +func RefreshRatesRead(buf []byte, v *RefreshRates) int { + b := 0 + + v.NRates = xgb.Get16(buf[b:]) + b += 2 + + v.Rates = make([]uint16, v.NRates) + for i := 0; i < int(v.NRates); i++ { + v.Rates[i] = xgb.Get16(buf[b:]) + b += 2 + } + + return b +} + +// RefreshRatesReadList reads a byte slice into a list of RefreshRates values. +func RefreshRatesReadList(buf []byte, dest []RefreshRates) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = RefreshRates{} + b += RefreshRatesRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a RefreshRates value to a byte slice. +func (v RefreshRates) Bytes() []byte { + buf := make([]byte, (2 + xgb.Pad((int(v.NRates) * 2)))) + b := 0 + + xgb.Put16(buf[b:], v.NRates) + b += 2 + + for i := 0; i < int(v.NRates); i++ { + xgb.Put16(buf[b:], v.Rates[i]) + b += 2 + } + + return buf[:b] +} + +// RefreshRatesListBytes writes a list of RefreshRates values to a byte slice. +func RefreshRatesListBytes(buf []byte, list []RefreshRates) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// RefreshRatesListSize computes the size (bytes) of a list of RefreshRates values. +func RefreshRatesListSize(list []RefreshRates) int { + size := 0 + for _, item := range list { + size += (2 + xgb.Pad((int(item.NRates) * 2))) + } + return size +} + +type ResourceChange struct { + Timestamp xproto.Timestamp + Window xproto.Window + // padding: 20 bytes +} + +// ResourceChangeRead reads a byte slice into a ResourceChange value. +func ResourceChangeRead(buf []byte, v *ResourceChange) int { + b := 0 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return b +} + +// ResourceChangeReadList reads a byte slice into a list of ResourceChange values. +func ResourceChangeReadList(buf []byte, dest []ResourceChange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ResourceChange{} + b += ResourceChangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ResourceChange value to a byte slice. +func (v ResourceChange) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + b += 20 // padding + + return buf[:b] +} + +// ResourceChangeListBytes writes a list of ResourceChange values to a byte slice. +func ResourceChangeListBytes(buf []byte, list []ResourceChange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + RotationRotate0 = 1 + RotationRotate90 = 2 + RotationRotate180 = 4 + RotationRotate270 = 8 + RotationReflectX = 16 + RotationReflectY = 32 +) + +// ScreenChangeNotify is the event number for a ScreenChangeNotifyEvent. +const ScreenChangeNotify = 0 + +type ScreenChangeNotifyEvent struct { + Sequence uint16 + Rotation byte + Timestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + Root xproto.Window + RequestWindow xproto.Window + SizeID uint16 + SubpixelOrder uint16 + Width uint16 + Height uint16 + Mwidth uint16 + Mheight uint16 +} + +// ScreenChangeNotifyEventNew constructs a ScreenChangeNotifyEvent value that implements xgb.Event from a byte slice. +func ScreenChangeNotifyEventNew(buf []byte) xgb.Event { + v := ScreenChangeNotifyEvent{} + b := 1 // don't read event number + + v.Rotation = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.RequestWindow = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.SizeID = xgb.Get16(buf[b:]) + b += 2 + + v.SubpixelOrder = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Mwidth = xgb.Get16(buf[b:]) + b += 2 + + v.Mheight = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Bytes writes a ScreenChangeNotifyEvent value to a byte slice. +func (v ScreenChangeNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.Rotation + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.ConfigTimestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.RequestWindow)) + b += 4 + + xgb.Put16(buf[b:], v.SizeID) + b += 2 + + xgb.Put16(buf[b:], v.SubpixelOrder) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.Mwidth) + b += 2 + + xgb.Put16(buf[b:], v.Mheight) + b += 2 + + return buf +} + +// SequenceId returns the sequence id attached to the ScreenChangeNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ScreenChangeNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ScreenChangeNotifyEvent. +func (v ScreenChangeNotifyEvent) String() string { + fieldVals := make([]string, 0, 11) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Rotation: %d", v.Rotation)) + fieldVals = append(fieldVals, xgb.Sprintf("Timestamp: %d", v.Timestamp)) + fieldVals = append(fieldVals, xgb.Sprintf("ConfigTimestamp: %d", v.ConfigTimestamp)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("RequestWindow: %d", v.RequestWindow)) + fieldVals = append(fieldVals, xgb.Sprintf("SizeID: %d", v.SizeID)) + fieldVals = append(fieldVals, xgb.Sprintf("SubpixelOrder: %d", v.SubpixelOrder)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("Mwidth: %d", v.Mwidth)) + fieldVals = append(fieldVals, xgb.Sprintf("Mheight: %d", v.Mheight)) + return "ScreenChangeNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["RANDR"][0] = ScreenChangeNotifyEventNew +} + +type ScreenSize struct { + Width uint16 + Height uint16 + Mwidth uint16 + Mheight uint16 +} + +// ScreenSizeRead reads a byte slice into a ScreenSize value. +func ScreenSizeRead(buf []byte, v *ScreenSize) int { + b := 0 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Mwidth = xgb.Get16(buf[b:]) + b += 2 + + v.Mheight = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// ScreenSizeReadList reads a byte slice into a list of ScreenSize values. +func ScreenSizeReadList(buf []byte, dest []ScreenSize) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ScreenSize{} + b += ScreenSizeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ScreenSize value to a byte slice. +func (v ScreenSize) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.Mwidth) + b += 2 + + xgb.Put16(buf[b:], v.Mheight) + b += 2 + + return buf[:b] +} + +// ScreenSizeListBytes writes a list of ScreenSize values to a byte slice. +func ScreenSizeListBytes(buf []byte, list []ScreenSize) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + SetConfigSuccess = 0 + SetConfigInvalidConfigTime = 1 + SetConfigInvalidTime = 2 + SetConfigFailed = 3 +) + +const ( + TransformUnit = 1 + TransformScaleUp = 2 + TransformScaleDown = 4 + TransformProjective = 8 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AddOutputModeCookie is a cookie used only for AddOutputMode requests. +type AddOutputModeCookie struct { + *xgb.Cookie +} + +// AddOutputMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AddOutputMode(c *xgb.Conn, Output Output, Mode Mode) AddOutputModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'AddOutputMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(addOutputModeRequest(c, Output, Mode), cookie) + return AddOutputModeCookie{cookie} +} + +// AddOutputModeChecked sends a checked request. +// If an error occurs, it can be retrieved using AddOutputModeCookie.Check() +func AddOutputModeChecked(c *xgb.Conn, Output Output, Mode Mode) AddOutputModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'AddOutputMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(addOutputModeRequest(c, Output, Mode), cookie) + return AddOutputModeCookie{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 AddOutputModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AddOutputMode +// addOutputModeRequest writes a AddOutputMode request to a byte slice. +func addOutputModeRequest(c *xgb.Conn, Output Output, Mode Mode) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Mode)) + b += 4 + + return buf +} + +// ChangeOutputPropertyCookie is a cookie used only for ChangeOutputProperty requests. +type ChangeOutputPropertyCookie struct { + *xgb.Cookie +} + +// ChangeOutputProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeOutputProperty(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumUnits uint32, Data []byte) ChangeOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ChangeOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeOutputPropertyRequest(c, Output, Property, Type, Format, Mode, NumUnits, Data), cookie) + return ChangeOutputPropertyCookie{cookie} +} + +// ChangeOutputPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeOutputPropertyCookie.Check() +func ChangeOutputPropertyChecked(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumUnits uint32, Data []byte) ChangeOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ChangeOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeOutputPropertyRequest(c, Output, Property, Type, Format, Mode, NumUnits, Data), cookie) + return ChangeOutputPropertyCookie{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 ChangeOutputPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeOutputProperty +// changeOutputPropertyRequest writes a ChangeOutputProperty request to a byte slice. +func changeOutputPropertyRequest(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumUnits uint32, Data []byte) []byte { + size := xgb.Pad((24 + xgb.Pad((((int(NumUnits) * int(Format)) / 8) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + buf[b] = Format + b += 1 + + buf[b] = Mode + b += 1 + + b += 2 // padding + + xgb.Put32(buf[b:], NumUnits) + b += 4 + + copy(buf[b:], Data[:((int(NumUnits)*int(Format))/8)]) + b += int(((int(NumUnits) * int(Format)) / 8)) + + return buf +} + +// ChangeProviderPropertyCookie is a cookie used only for ChangeProviderProperty requests. +type ChangeProviderPropertyCookie struct { + *xgb.Cookie +} + +// ChangeProviderProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeProviderProperty(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumItems uint32, Data []byte) ChangeProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ChangeProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeProviderPropertyRequest(c, Provider, Property, Type, Format, Mode, NumItems, Data), cookie) + return ChangeProviderPropertyCookie{cookie} +} + +// ChangeProviderPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeProviderPropertyCookie.Check() +func ChangeProviderPropertyChecked(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumItems uint32, Data []byte) ChangeProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ChangeProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeProviderPropertyRequest(c, Provider, Property, Type, Format, Mode, NumItems, Data), cookie) + return ChangeProviderPropertyCookie{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 ChangeProviderPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeProviderProperty +// changeProviderPropertyRequest writes a ChangeProviderProperty request to a byte slice. +func changeProviderPropertyRequest(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, Format byte, Mode byte, NumItems uint32, Data []byte) []byte { + size := xgb.Pad((24 + xgb.Pad(((int(NumItems) * (int(Format) / 8)) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 39 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + buf[b] = Format + b += 1 + + buf[b] = Mode + b += 1 + + b += 2 // padding + + xgb.Put32(buf[b:], NumItems) + b += 4 + + copy(buf[b:], Data[:(int(NumItems)*(int(Format)/8))]) + b += int((int(NumItems) * (int(Format) / 8))) + + return buf +} + +// ConfigureOutputPropertyCookie is a cookie used only for ConfigureOutputProperty requests. +type ConfigureOutputPropertyCookie struct { + *xgb.Cookie +} + +// ConfigureOutputProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ConfigureOutputProperty(c *xgb.Conn, Output Output, Property xproto.Atom, Pending bool, Range bool, Values []int32) ConfigureOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ConfigureOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(configureOutputPropertyRequest(c, Output, Property, Pending, Range, Values), cookie) + return ConfigureOutputPropertyCookie{cookie} +} + +// ConfigureOutputPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using ConfigureOutputPropertyCookie.Check() +func ConfigureOutputPropertyChecked(c *xgb.Conn, Output Output, Property xproto.Atom, Pending bool, Range bool, Values []int32) ConfigureOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ConfigureOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(configureOutputPropertyRequest(c, Output, Property, Pending, Range, Values), cookie) + return ConfigureOutputPropertyCookie{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 ConfigureOutputPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ConfigureOutputProperty +// configureOutputPropertyRequest writes a ConfigureOutputProperty request to a byte slice. +func configureOutputPropertyRequest(c *xgb.Conn, Output Output, Property xproto.Atom, Pending bool, Range bool, Values []int32) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Values) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + if Pending { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Range { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 2 // padding + + for i := 0; i < int(len(Values)); i++ { + xgb.Put32(buf[b:], uint32(Values[i])) + b += 4 + } + + return buf +} + +// ConfigureProviderPropertyCookie is a cookie used only for ConfigureProviderProperty requests. +type ConfigureProviderPropertyCookie struct { + *xgb.Cookie +} + +// ConfigureProviderProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ConfigureProviderProperty(c *xgb.Conn, Provider Provider, Property xproto.Atom, Pending bool, Range bool, Values []int32) ConfigureProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ConfigureProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(configureProviderPropertyRequest(c, Provider, Property, Pending, Range, Values), cookie) + return ConfigureProviderPropertyCookie{cookie} +} + +// ConfigureProviderPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using ConfigureProviderPropertyCookie.Check() +func ConfigureProviderPropertyChecked(c *xgb.Conn, Provider Provider, Property xproto.Atom, Pending bool, Range bool, Values []int32) ConfigureProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ConfigureProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(configureProviderPropertyRequest(c, Provider, Property, Pending, Range, Values), cookie) + return ConfigureProviderPropertyCookie{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 ConfigureProviderPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ConfigureProviderProperty +// configureProviderPropertyRequest writes a ConfigureProviderProperty request to a byte slice. +func configureProviderPropertyRequest(c *xgb.Conn, Provider Provider, Property xproto.Atom, Pending bool, Range bool, Values []int32) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Values) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 38 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + if Pending { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Range { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 2 // padding + + for i := 0; i < int(len(Values)); i++ { + xgb.Put32(buf[b:], uint32(Values[i])) + b += 4 + } + + return buf +} + +// CreateModeCookie is a cookie used only for CreateMode requests. +type CreateModeCookie struct { + *xgb.Cookie +} + +// CreateMode sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateModeCookie.Reply() +func CreateMode(c *xgb.Conn, Window xproto.Window, ModeInfo ModeInfo, Name string) CreateModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'CreateMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createModeRequest(c, Window, ModeInfo, Name), cookie) + return CreateModeCookie{cookie} +} + +// CreateModeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateModeUnchecked(c *xgb.Conn, Window xproto.Window, ModeInfo ModeInfo, Name string) CreateModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'CreateMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createModeRequest(c, Window, ModeInfo, Name), cookie) + return CreateModeCookie{cookie} +} + +// CreateModeReply represents the data returned from a CreateMode request. +type CreateModeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Mode Mode + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a CreateMode request. +func (cook CreateModeCookie) Reply() (*CreateModeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createModeReply(buf), nil +} + +// createModeReply reads a byte slice into a CreateModeReply value. +func createModeReply(buf []byte) *CreateModeReply { + v := new(CreateModeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Mode = Mode(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for CreateMode +// createModeRequest writes a CreateMode request to a byte slice. +func createModeRequest(c *xgb.Conn, Window xproto.Window, ModeInfo ModeInfo, Name string) []byte { + size := xgb.Pad((40 + xgb.Pad((len(Name) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // 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 + + { + structBytes := ModeInfo.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + copy(buf[b:], Name[:len(Name)]) + b += int(len(Name)) + + return buf +} + +// DeleteMonitorCookie is a cookie used only for DeleteMonitor requests. +type DeleteMonitorCookie struct { + *xgb.Cookie +} + +// DeleteMonitor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteMonitor(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) DeleteMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteMonitorRequest(c, Window, Name), cookie) + return DeleteMonitorCookie{cookie} +} + +// DeleteMonitorChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteMonitorCookie.Check() +func DeleteMonitorChecked(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) DeleteMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteMonitorRequest(c, Window, Name), cookie) + return DeleteMonitorCookie{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 DeleteMonitorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteMonitor +// deleteMonitorRequest writes a DeleteMonitor request to a byte slice. +func deleteMonitorRequest(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 44 // 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(Name)) + b += 4 + + return buf +} + +// DeleteOutputModeCookie is a cookie used only for DeleteOutputMode requests. +type DeleteOutputModeCookie struct { + *xgb.Cookie +} + +// DeleteOutputMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteOutputMode(c *xgb.Conn, Output Output, Mode Mode) DeleteOutputModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteOutputMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteOutputModeRequest(c, Output, Mode), cookie) + return DeleteOutputModeCookie{cookie} +} + +// DeleteOutputModeChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteOutputModeCookie.Check() +func DeleteOutputModeChecked(c *xgb.Conn, Output Output, Mode Mode) DeleteOutputModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteOutputMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteOutputModeRequest(c, Output, Mode), cookie) + return DeleteOutputModeCookie{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 DeleteOutputModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteOutputMode +// deleteOutputModeRequest writes a DeleteOutputMode request to a byte slice. +func deleteOutputModeRequest(c *xgb.Conn, Output Output, Mode Mode) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Mode)) + b += 4 + + return buf +} + +// DeleteOutputPropertyCookie is a cookie used only for DeleteOutputProperty requests. +type DeleteOutputPropertyCookie struct { + *xgb.Cookie +} + +// DeleteOutputProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteOutputProperty(c *xgb.Conn, Output Output, Property xproto.Atom) DeleteOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteOutputPropertyRequest(c, Output, Property), cookie) + return DeleteOutputPropertyCookie{cookie} +} + +// DeleteOutputPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteOutputPropertyCookie.Check() +func DeleteOutputPropertyChecked(c *xgb.Conn, Output Output, Property xproto.Atom) DeleteOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteOutputPropertyRequest(c, Output, Property), cookie) + return DeleteOutputPropertyCookie{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 DeleteOutputPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteOutputProperty +// deleteOutputPropertyRequest writes a DeleteOutputProperty request to a byte slice. +func deleteOutputPropertyRequest(c *xgb.Conn, Output Output, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + return buf +} + +// DeleteProviderPropertyCookie is a cookie used only for DeleteProviderProperty requests. +type DeleteProviderPropertyCookie struct { + *xgb.Cookie +} + +// DeleteProviderProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteProviderProperty(c *xgb.Conn, Provider Provider, Property xproto.Atom) DeleteProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteProviderPropertyRequest(c, Provider, Property), cookie) + return DeleteProviderPropertyCookie{cookie} +} + +// DeleteProviderPropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteProviderPropertyCookie.Check() +func DeleteProviderPropertyChecked(c *xgb.Conn, Provider Provider, Property xproto.Atom) DeleteProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteProviderPropertyRequest(c, Provider, Property), cookie) + return DeleteProviderPropertyCookie{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 DeleteProviderPropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteProviderProperty +// deleteProviderPropertyRequest writes a DeleteProviderProperty request to a byte slice. +func deleteProviderPropertyRequest(c *xgb.Conn, Provider Provider, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 40 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + return buf +} + +// DestroyModeCookie is a cookie used only for DestroyMode requests. +type DestroyModeCookie struct { + *xgb.Cookie +} + +// DestroyMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyMode(c *xgb.Conn, Mode Mode) DestroyModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DestroyMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyModeRequest(c, Mode), cookie) + return DestroyModeCookie{cookie} +} + +// DestroyModeChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyModeCookie.Check() +func DestroyModeChecked(c *xgb.Conn, Mode Mode) DestroyModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DestroyMode' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyModeRequest(c, Mode), cookie) + return DestroyModeCookie{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 DestroyModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyMode +// destroyModeRequest writes a DestroyMode request to a byte slice. +func destroyModeRequest(c *xgb.Conn, Mode Mode) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // 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(Mode)) + b += 4 + + return buf +} + +// GetCrtcGammaCookie is a cookie used only for GetCrtcGamma requests. +type GetCrtcGammaCookie struct { + *xgb.Cookie +} + +// GetCrtcGamma sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCrtcGammaCookie.Reply() +func GetCrtcGamma(c *xgb.Conn, Crtc Crtc) GetCrtcGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcGamma' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCrtcGammaRequest(c, Crtc), cookie) + return GetCrtcGammaCookie{cookie} +} + +// GetCrtcGammaUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCrtcGammaUnchecked(c *xgb.Conn, Crtc Crtc) GetCrtcGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcGamma' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCrtcGammaRequest(c, Crtc), cookie) + return GetCrtcGammaCookie{cookie} +} + +// GetCrtcGammaReply represents the data returned from a GetCrtcGamma request. +type GetCrtcGammaReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Size uint16 + // padding: 22 bytes + Red []uint16 // size: xgb.Pad((int(Size) * 2)) + Green []uint16 // size: xgb.Pad((int(Size) * 2)) + Blue []uint16 // size: xgb.Pad((int(Size) * 2)) +} + +// Reply blocks and returns the reply data for a GetCrtcGamma request. +func (cook GetCrtcGammaCookie) Reply() (*GetCrtcGammaReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCrtcGammaReply(buf), nil +} + +// getCrtcGammaReply reads a byte slice into a GetCrtcGammaReply value. +func getCrtcGammaReply(buf []byte) *GetCrtcGammaReply { + v := new(GetCrtcGammaReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Size = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Red = make([]uint16, v.Size) + for i := 0; i < int(v.Size); i++ { + v.Red[i] = xgb.Get16(buf[b:]) + b += 2 + } + + v.Green = make([]uint16, v.Size) + for i := 0; i < int(v.Size); i++ { + v.Green[i] = xgb.Get16(buf[b:]) + b += 2 + } + + v.Blue = make([]uint16, v.Size) + for i := 0; i < int(v.Size); i++ { + v.Blue[i] = xgb.Get16(buf[b:]) + b += 2 + } + + return v +} + +// Write request to wire for GetCrtcGamma +// getCrtcGammaRequest writes a GetCrtcGamma request to a byte slice. +func getCrtcGammaRequest(c *xgb.Conn, Crtc Crtc) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 23 // 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(Crtc)) + b += 4 + + return buf +} + +// GetCrtcGammaSizeCookie is a cookie used only for GetCrtcGammaSize requests. +type GetCrtcGammaSizeCookie struct { + *xgb.Cookie +} + +// GetCrtcGammaSize sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCrtcGammaSizeCookie.Reply() +func GetCrtcGammaSize(c *xgb.Conn, Crtc Crtc) GetCrtcGammaSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcGammaSize' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCrtcGammaSizeRequest(c, Crtc), cookie) + return GetCrtcGammaSizeCookie{cookie} +} + +// GetCrtcGammaSizeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCrtcGammaSizeUnchecked(c *xgb.Conn, Crtc Crtc) GetCrtcGammaSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcGammaSize' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCrtcGammaSizeRequest(c, Crtc), cookie) + return GetCrtcGammaSizeCookie{cookie} +} + +// GetCrtcGammaSizeReply represents the data returned from a GetCrtcGammaSize request. +type GetCrtcGammaSizeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Size uint16 + // padding: 22 bytes +} + +// Reply blocks and returns the reply data for a GetCrtcGammaSize request. +func (cook GetCrtcGammaSizeCookie) Reply() (*GetCrtcGammaSizeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCrtcGammaSizeReply(buf), nil +} + +// getCrtcGammaSizeReply reads a byte slice into a GetCrtcGammaSizeReply value. +func getCrtcGammaSizeReply(buf []byte) *GetCrtcGammaSizeReply { + v := new(GetCrtcGammaSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Size = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + return v +} + +// Write request to wire for GetCrtcGammaSize +// getCrtcGammaSizeRequest writes a GetCrtcGammaSize request to a byte slice. +func getCrtcGammaSizeRequest(c *xgb.Conn, Crtc Crtc) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // 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(Crtc)) + b += 4 + + return buf +} + +// GetCrtcInfoCookie is a cookie used only for GetCrtcInfo requests. +type GetCrtcInfoCookie struct { + *xgb.Cookie +} + +// GetCrtcInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCrtcInfoCookie.Reply() +func GetCrtcInfo(c *xgb.Conn, Crtc Crtc, ConfigTimestamp xproto.Timestamp) GetCrtcInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCrtcInfoRequest(c, Crtc, ConfigTimestamp), cookie) + return GetCrtcInfoCookie{cookie} +} + +// GetCrtcInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCrtcInfoUnchecked(c *xgb.Conn, Crtc Crtc, ConfigTimestamp xproto.Timestamp) GetCrtcInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCrtcInfoRequest(c, Crtc, ConfigTimestamp), cookie) + return GetCrtcInfoCookie{cookie} +} + +// GetCrtcInfoReply represents the data returned from a GetCrtcInfo request. +type GetCrtcInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp + X int16 + Y int16 + Width uint16 + Height uint16 + Mode Mode + Rotation uint16 + Rotations uint16 + NumOutputs uint16 + NumPossibleOutputs uint16 + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + Possible []Output // size: xgb.Pad((int(NumPossibleOutputs) * 4)) +} + +// Reply blocks and returns the reply data for a GetCrtcInfo request. +func (cook GetCrtcInfoCookie) Reply() (*GetCrtcInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCrtcInfoReply(buf), nil +} + +// getCrtcInfoReply reads a byte slice into a GetCrtcInfoReply value. +func getCrtcInfoReply(buf []byte) *GetCrtcInfoReply { + v := new(GetCrtcInfoReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Mode = Mode(xgb.Get32(buf[b:])) + b += 4 + + v.Rotation = xgb.Get16(buf[b:]) + b += 2 + + v.Rotations = xgb.Get16(buf[b:]) + b += 2 + + v.NumOutputs = xgb.Get16(buf[b:]) + b += 2 + + v.NumPossibleOutputs = xgb.Get16(buf[b:]) + b += 2 + + v.Outputs = make([]Output, v.NumOutputs) + for i := 0; i < int(v.NumOutputs); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + v.Possible = make([]Output, v.NumPossibleOutputs) + for i := 0; i < int(v.NumPossibleOutputs); i++ { + v.Possible[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetCrtcInfo +// getCrtcInfoRequest writes a GetCrtcInfo request to a byte slice. +func getCrtcInfoRequest(c *xgb.Conn, Crtc Crtc, ConfigTimestamp xproto.Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // 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(Crtc)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + return buf +} + +// GetCrtcTransformCookie is a cookie used only for GetCrtcTransform requests. +type GetCrtcTransformCookie struct { + *xgb.Cookie +} + +// GetCrtcTransform sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCrtcTransformCookie.Reply() +func GetCrtcTransform(c *xgb.Conn, Crtc Crtc) GetCrtcTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcTransform' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCrtcTransformRequest(c, Crtc), cookie) + return GetCrtcTransformCookie{cookie} +} + +// GetCrtcTransformUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCrtcTransformUnchecked(c *xgb.Conn, Crtc Crtc) GetCrtcTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetCrtcTransform' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCrtcTransformRequest(c, Crtc), cookie) + return GetCrtcTransformCookie{cookie} +} + +// GetCrtcTransformReply represents the data returned from a GetCrtcTransform request. +type GetCrtcTransformReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PendingTransform render.Transform + HasTransforms bool + // padding: 3 bytes + CurrentTransform render.Transform + // padding: 4 bytes + PendingLen uint16 + PendingNparams uint16 + CurrentLen uint16 + CurrentNparams uint16 + PendingFilterName string // size: xgb.Pad((int(PendingLen) * 1)) + // alignment gap to multiple of 4 + PendingParams []render.Fixed // size: xgb.Pad((int(PendingNparams) * 4)) + CurrentFilterName string // size: xgb.Pad((int(CurrentLen) * 1)) + // alignment gap to multiple of 4 + CurrentParams []render.Fixed // size: xgb.Pad((int(CurrentNparams) * 4)) +} + +// Reply blocks and returns the reply data for a GetCrtcTransform request. +func (cook GetCrtcTransformCookie) Reply() (*GetCrtcTransformReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCrtcTransformReply(buf), nil +} + +// getCrtcTransformReply reads a byte slice into a GetCrtcTransformReply value. +func getCrtcTransformReply(buf []byte) *GetCrtcTransformReply { + v := new(GetCrtcTransformReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PendingTransform = render.Transform{} + b += render.TransformRead(buf[b:], &v.PendingTransform) + + if buf[b] == 1 { + v.HasTransforms = true + } else { + v.HasTransforms = false + } + b += 1 + + b += 3 // padding + + v.CurrentTransform = render.Transform{} + b += render.TransformRead(buf[b:], &v.CurrentTransform) + + b += 4 // padding + + v.PendingLen = xgb.Get16(buf[b:]) + b += 2 + + v.PendingNparams = xgb.Get16(buf[b:]) + b += 2 + + v.CurrentLen = xgb.Get16(buf[b:]) + b += 2 + + v.CurrentNparams = xgb.Get16(buf[b:]) + b += 2 + + { + byteString := make([]byte, v.PendingLen) + copy(byteString[:v.PendingLen], buf[b:]) + v.PendingFilterName = string(byteString) + b += int(v.PendingLen) + } + + b = (b + 3) & ^3 // alignment gap + + v.PendingParams = make([]render.Fixed, v.PendingNparams) + for i := 0; i < int(v.PendingNparams); i++ { + v.PendingParams[i] = render.Fixed(xgb.Get32(buf[b:])) + b += 4 + } + + { + byteString := make([]byte, v.CurrentLen) + copy(byteString[:v.CurrentLen], buf[b:]) + v.CurrentFilterName = string(byteString) + b += int(v.CurrentLen) + } + + b = (b + 3) & ^3 // alignment gap + + v.CurrentParams = make([]render.Fixed, v.CurrentNparams) + for i := 0; i < int(v.CurrentNparams); i++ { + v.CurrentParams[i] = render.Fixed(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetCrtcTransform +// getCrtcTransformRequest writes a GetCrtcTransform request to a byte slice. +func getCrtcTransformRequest(c *xgb.Conn, Crtc Crtc) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 27 // 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(Crtc)) + b += 4 + + return buf +} + +// GetMonitorsCookie is a cookie used only for GetMonitors requests. +type GetMonitorsCookie struct { + *xgb.Cookie +} + +// GetMonitors sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMonitorsCookie.Reply() +func GetMonitors(c *xgb.Conn, Window xproto.Window, GetActive bool) GetMonitorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetMonitors' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMonitorsRequest(c, Window, GetActive), cookie) + return GetMonitorsCookie{cookie} +} + +// GetMonitorsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMonitorsUnchecked(c *xgb.Conn, Window xproto.Window, GetActive bool) GetMonitorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetMonitors' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMonitorsRequest(c, Window, GetActive), cookie) + return GetMonitorsCookie{cookie} +} + +// GetMonitorsReply represents the data returned from a GetMonitors request. +type GetMonitorsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timestamp xproto.Timestamp + NMonitors uint32 + NOutputs uint32 + // padding: 12 bytes + Monitors []MonitorInfo // size: MonitorInfoListSize(Monitors) +} + +// Reply blocks and returns the reply data for a GetMonitors request. +func (cook GetMonitorsCookie) Reply() (*GetMonitorsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMonitorsReply(buf), nil +} + +// getMonitorsReply reads a byte slice into a GetMonitorsReply value. +func getMonitorsReply(buf []byte) *GetMonitorsReply { + v := new(GetMonitorsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NMonitors = xgb.Get32(buf[b:]) + b += 4 + + v.NOutputs = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Monitors = make([]MonitorInfo, v.NMonitors) + b += MonitorInfoReadList(buf[b:], v.Monitors) + + return v +} + +// Write request to wire for GetMonitors +// getMonitorsRequest writes a GetMonitors request to a byte slice. +func getMonitorsRequest(c *xgb.Conn, Window xproto.Window, GetActive bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 42 // 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 + + if GetActive { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// GetOutputInfoCookie is a cookie used only for GetOutputInfo requests. +type GetOutputInfoCookie struct { + *xgb.Cookie +} + +// GetOutputInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetOutputInfoCookie.Reply() +func GetOutputInfo(c *xgb.Conn, Output Output, ConfigTimestamp xproto.Timestamp) GetOutputInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getOutputInfoRequest(c, Output, ConfigTimestamp), cookie) + return GetOutputInfoCookie{cookie} +} + +// GetOutputInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetOutputInfoUnchecked(c *xgb.Conn, Output Output, ConfigTimestamp xproto.Timestamp) GetOutputInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getOutputInfoRequest(c, Output, ConfigTimestamp), cookie) + return GetOutputInfoCookie{cookie} +} + +// GetOutputInfoReply represents the data returned from a GetOutputInfo request. +type GetOutputInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp + Crtc Crtc + MmWidth uint32 + MmHeight uint32 + Connection byte + SubpixelOrder byte + NumCrtcs uint16 + NumModes uint16 + NumPreferred uint16 + NumClones uint16 + NameLen uint16 + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Modes []Mode // size: xgb.Pad((int(NumModes) * 4)) + Clones []Output // size: xgb.Pad((int(NumClones) * 4)) + Name []byte // size: xgb.Pad((int(NameLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetOutputInfo request. +func (cook GetOutputInfoCookie) Reply() (*GetOutputInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getOutputInfoReply(buf), nil +} + +// getOutputInfoReply reads a byte slice into a GetOutputInfoReply value. +func getOutputInfoReply(buf []byte) *GetOutputInfoReply { + v := new(GetOutputInfoReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Crtc = Crtc(xgb.Get32(buf[b:])) + b += 4 + + v.MmWidth = xgb.Get32(buf[b:]) + b += 4 + + v.MmHeight = xgb.Get32(buf[b:]) + b += 4 + + v.Connection = buf[b] + b += 1 + + v.SubpixelOrder = buf[b] + b += 1 + + v.NumCrtcs = xgb.Get16(buf[b:]) + b += 2 + + v.NumModes = xgb.Get16(buf[b:]) + b += 2 + + v.NumPreferred = xgb.Get16(buf[b:]) + b += 2 + + v.NumClones = xgb.Get16(buf[b:]) + b += 2 + + v.NameLen = xgb.Get16(buf[b:]) + b += 2 + + v.Crtcs = make([]Crtc, v.NumCrtcs) + for i := 0; i < int(v.NumCrtcs); i++ { + v.Crtcs[i] = Crtc(xgb.Get32(buf[b:])) + b += 4 + } + + v.Modes = make([]Mode, v.NumModes) + for i := 0; i < int(v.NumModes); i++ { + v.Modes[i] = Mode(xgb.Get32(buf[b:])) + b += 4 + } + + v.Clones = make([]Output, v.NumClones) + for i := 0; i < int(v.NumClones); i++ { + v.Clones[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + v.Name = make([]byte, v.NameLen) + copy(v.Name[:v.NameLen], buf[b:]) + b += int(v.NameLen) + + return v +} + +// Write request to wire for GetOutputInfo +// getOutputInfoRequest writes a GetOutputInfo request to a byte slice. +func getOutputInfoRequest(c *xgb.Conn, Output Output, ConfigTimestamp xproto.Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + return buf +} + +// GetOutputPrimaryCookie is a cookie used only for GetOutputPrimary requests. +type GetOutputPrimaryCookie struct { + *xgb.Cookie +} + +// GetOutputPrimary sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetOutputPrimaryCookie.Reply() +func GetOutputPrimary(c *xgb.Conn, Window xproto.Window) GetOutputPrimaryCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputPrimary' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getOutputPrimaryRequest(c, Window), cookie) + return GetOutputPrimaryCookie{cookie} +} + +// GetOutputPrimaryUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetOutputPrimaryUnchecked(c *xgb.Conn, Window xproto.Window) GetOutputPrimaryCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputPrimary' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getOutputPrimaryRequest(c, Window), cookie) + return GetOutputPrimaryCookie{cookie} +} + +// GetOutputPrimaryReply represents the data returned from a GetOutputPrimary request. +type GetOutputPrimaryReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Output Output +} + +// Reply blocks and returns the reply data for a GetOutputPrimary request. +func (cook GetOutputPrimaryCookie) Reply() (*GetOutputPrimaryReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getOutputPrimaryReply(buf), nil +} + +// getOutputPrimaryReply reads a byte slice into a GetOutputPrimaryReply value. +func getOutputPrimaryReply(buf []byte) *GetOutputPrimaryReply { + v := new(GetOutputPrimaryReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Output = Output(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetOutputPrimary +// getOutputPrimaryRequest writes a GetOutputPrimary request to a byte slice. +func getOutputPrimaryRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 31 // 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 + + return buf +} + +// GetOutputPropertyCookie is a cookie used only for GetOutputProperty requests. +type GetOutputPropertyCookie struct { + *xgb.Cookie +} + +// GetOutputProperty sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetOutputPropertyCookie.Reply() +func GetOutputProperty(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) GetOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getOutputPropertyRequest(c, Output, Property, Type, LongOffset, LongLength, Delete, Pending), cookie) + return GetOutputPropertyCookie{cookie} +} + +// GetOutputPropertyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetOutputPropertyUnchecked(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) GetOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getOutputPropertyRequest(c, Output, Property, Type, LongOffset, LongLength, Delete, Pending), cookie) + return GetOutputPropertyCookie{cookie} +} + +// GetOutputPropertyReply represents the data returned from a GetOutputProperty request. +type GetOutputPropertyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Format byte + Type xproto.Atom + BytesAfter uint32 + NumItems uint32 + // padding: 12 bytes + Data []byte // size: xgb.Pad(((int(NumItems) * (int(Format) / 8)) * 1)) +} + +// Reply blocks and returns the reply data for a GetOutputProperty request. +func (cook GetOutputPropertyCookie) Reply() (*GetOutputPropertyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getOutputPropertyReply(buf), nil +} + +// getOutputPropertyReply reads a byte slice into a GetOutputPropertyReply value. +func getOutputPropertyReply(buf []byte) *GetOutputPropertyReply { + v := new(GetOutputPropertyReply) + b := 1 // skip reply determinant + + v.Format = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Type = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.BytesAfter = xgb.Get32(buf[b:]) + b += 4 + + v.NumItems = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, (int(v.NumItems) * (int(v.Format) / 8))) + copy(v.Data[:(int(v.NumItems)*(int(v.Format)/8))], buf[b:]) + b += int((int(v.NumItems) * (int(v.Format) / 8))) + + return v +} + +// Write request to wire for GetOutputProperty +// getOutputPropertyRequest writes a GetOutputProperty request to a byte slice. +func getOutputPropertyRequest(c *xgb.Conn, Output Output, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + xgb.Put32(buf[b:], LongOffset) + b += 4 + + xgb.Put32(buf[b:], LongLength) + b += 4 + + if Delete { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Pending { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 2 // padding + + return buf +} + +// GetPanningCookie is a cookie used only for GetPanning requests. +type GetPanningCookie struct { + *xgb.Cookie +} + +// GetPanning sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPanningCookie.Reply() +func GetPanning(c *xgb.Conn, Crtc Crtc) GetPanningCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetPanning' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPanningRequest(c, Crtc), cookie) + return GetPanningCookie{cookie} +} + +// GetPanningUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPanningUnchecked(c *xgb.Conn, Crtc Crtc) GetPanningCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetPanning' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPanningRequest(c, Crtc), cookie) + return GetPanningCookie{cookie} +} + +// GetPanningReply represents the data returned from a GetPanning request. +type GetPanningReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp + Left uint16 + Top uint16 + Width uint16 + Height uint16 + TrackLeft uint16 + TrackTop uint16 + TrackWidth uint16 + TrackHeight uint16 + BorderLeft int16 + BorderTop int16 + BorderRight int16 + BorderBottom int16 +} + +// Reply blocks and returns the reply data for a GetPanning request. +func (cook GetPanningCookie) Reply() (*GetPanningReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPanningReply(buf), nil +} + +// getPanningReply reads a byte slice into a GetPanningReply value. +func getPanningReply(buf []byte) *GetPanningReply { + v := new(GetPanningReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Left = xgb.Get16(buf[b:]) + b += 2 + + v.Top = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.TrackLeft = xgb.Get16(buf[b:]) + b += 2 + + v.TrackTop = xgb.Get16(buf[b:]) + b += 2 + + v.TrackWidth = xgb.Get16(buf[b:]) + b += 2 + + v.TrackHeight = xgb.Get16(buf[b:]) + b += 2 + + v.BorderLeft = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BorderTop = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BorderRight = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BorderBottom = int16(xgb.Get16(buf[b:])) + b += 2 + + return v +} + +// Write request to wire for GetPanning +// getPanningRequest writes a GetPanning request to a byte slice. +func getPanningRequest(c *xgb.Conn, Crtc Crtc) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 28 // 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(Crtc)) + b += 4 + + return buf +} + +// GetProviderInfoCookie is a cookie used only for GetProviderInfo requests. +type GetProviderInfoCookie struct { + *xgb.Cookie +} + +// GetProviderInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetProviderInfoCookie.Reply() +func GetProviderInfo(c *xgb.Conn, Provider Provider, ConfigTimestamp xproto.Timestamp) GetProviderInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviderInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getProviderInfoRequest(c, Provider, ConfigTimestamp), cookie) + return GetProviderInfoCookie{cookie} +} + +// GetProviderInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetProviderInfoUnchecked(c *xgb.Conn, Provider Provider, ConfigTimestamp xproto.Timestamp) GetProviderInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviderInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getProviderInfoRequest(c, Provider, ConfigTimestamp), cookie) + return GetProviderInfoCookie{cookie} +} + +// GetProviderInfoReply represents the data returned from a GetProviderInfo request. +type GetProviderInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp + Capabilities uint32 + NumCrtcs uint16 + NumOutputs uint16 + NumAssociatedProviders uint16 + NameLen uint16 + // padding: 8 bytes + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + AssociatedProviders []Provider // size: xgb.Pad((int(NumAssociatedProviders) * 4)) + AssociatedCapability []uint32 // size: xgb.Pad((int(NumAssociatedProviders) * 4)) + Name string // size: xgb.Pad((int(NameLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetProviderInfo request. +func (cook GetProviderInfoCookie) Reply() (*GetProviderInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getProviderInfoReply(buf), nil +} + +// getProviderInfoReply reads a byte slice into a GetProviderInfoReply value. +func getProviderInfoReply(buf []byte) *GetProviderInfoReply { + v := new(GetProviderInfoReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Capabilities = xgb.Get32(buf[b:]) + b += 4 + + v.NumCrtcs = xgb.Get16(buf[b:]) + b += 2 + + v.NumOutputs = xgb.Get16(buf[b:]) + b += 2 + + v.NumAssociatedProviders = xgb.Get16(buf[b:]) + b += 2 + + v.NameLen = xgb.Get16(buf[b:]) + b += 2 + + b += 8 // padding + + v.Crtcs = make([]Crtc, v.NumCrtcs) + for i := 0; i < int(v.NumCrtcs); i++ { + v.Crtcs[i] = Crtc(xgb.Get32(buf[b:])) + b += 4 + } + + v.Outputs = make([]Output, v.NumOutputs) + for i := 0; i < int(v.NumOutputs); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + v.AssociatedProviders = make([]Provider, v.NumAssociatedProviders) + for i := 0; i < int(v.NumAssociatedProviders); i++ { + v.AssociatedProviders[i] = Provider(xgb.Get32(buf[b:])) + b += 4 + } + + v.AssociatedCapability = make([]uint32, v.NumAssociatedProviders) + for i := 0; i < int(v.NumAssociatedProviders); i++ { + v.AssociatedCapability[i] = xgb.Get32(buf[b:]) + b += 4 + } + + { + byteString := make([]byte, v.NameLen) + copy(byteString[:v.NameLen], buf[b:]) + v.Name = string(byteString) + b += int(v.NameLen) + } + + return v +} + +// Write request to wire for GetProviderInfo +// getProviderInfoRequest writes a GetProviderInfo request to a byte slice. +func getProviderInfoRequest(c *xgb.Conn, Provider Provider, ConfigTimestamp xproto.Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 33 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + return buf +} + +// GetProviderPropertyCookie is a cookie used only for GetProviderProperty requests. +type GetProviderPropertyCookie struct { + *xgb.Cookie +} + +// GetProviderProperty sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetProviderPropertyCookie.Reply() +func GetProviderProperty(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) GetProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getProviderPropertyRequest(c, Provider, Property, Type, LongOffset, LongLength, Delete, Pending), cookie) + return GetProviderPropertyCookie{cookie} +} + +// GetProviderPropertyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetProviderPropertyUnchecked(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) GetProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getProviderPropertyRequest(c, Provider, Property, Type, LongOffset, LongLength, Delete, Pending), cookie) + return GetProviderPropertyCookie{cookie} +} + +// GetProviderPropertyReply represents the data returned from a GetProviderProperty request. +type GetProviderPropertyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Format byte + Type xproto.Atom + BytesAfter uint32 + NumItems uint32 + // padding: 12 bytes + Data []byte // size: xgb.Pad(((int(NumItems) * (int(Format) / 8)) * 1)) +} + +// Reply blocks and returns the reply data for a GetProviderProperty request. +func (cook GetProviderPropertyCookie) Reply() (*GetProviderPropertyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getProviderPropertyReply(buf), nil +} + +// getProviderPropertyReply reads a byte slice into a GetProviderPropertyReply value. +func getProviderPropertyReply(buf []byte) *GetProviderPropertyReply { + v := new(GetProviderPropertyReply) + b := 1 // skip reply determinant + + v.Format = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Type = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.BytesAfter = xgb.Get32(buf[b:]) + b += 4 + + v.NumItems = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, (int(v.NumItems) * (int(v.Format) / 8))) + copy(v.Data[:(int(v.NumItems)*(int(v.Format)/8))], buf[b:]) + b += int((int(v.NumItems) * (int(v.Format) / 8))) + + return v +} + +// Write request to wire for GetProviderProperty +// getProviderPropertyRequest writes a GetProviderProperty request to a byte slice. +func getProviderPropertyRequest(c *xgb.Conn, Provider Provider, Property xproto.Atom, Type xproto.Atom, LongOffset uint32, LongLength uint32, Delete bool, Pending bool) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 41 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + xgb.Put32(buf[b:], LongOffset) + b += 4 + + xgb.Put32(buf[b:], LongLength) + b += 4 + + if Delete { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if Pending { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 2 // padding + + return buf +} + +// GetProvidersCookie is a cookie used only for GetProviders requests. +type GetProvidersCookie struct { + *xgb.Cookie +} + +// GetProviders sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetProvidersCookie.Reply() +func GetProviders(c *xgb.Conn, Window xproto.Window) GetProvidersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviders' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getProvidersRequest(c, Window), cookie) + return GetProvidersCookie{cookie} +} + +// GetProvidersUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetProvidersUnchecked(c *xgb.Conn, Window xproto.Window) GetProvidersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetProviders' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getProvidersRequest(c, Window), cookie) + return GetProvidersCookie{cookie} +} + +// GetProvidersReply represents the data returned from a GetProviders request. +type GetProvidersReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timestamp xproto.Timestamp + NumProviders uint16 + // padding: 18 bytes + Providers []Provider // size: xgb.Pad((int(NumProviders) * 4)) +} + +// Reply blocks and returns the reply data for a GetProviders request. +func (cook GetProvidersCookie) Reply() (*GetProvidersReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getProvidersReply(buf), nil +} + +// getProvidersReply reads a byte slice into a GetProvidersReply value. +func getProvidersReply(buf []byte) *GetProvidersReply { + v := new(GetProvidersReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NumProviders = xgb.Get16(buf[b:]) + b += 2 + + b += 18 // padding + + v.Providers = make([]Provider, v.NumProviders) + for i := 0; i < int(v.NumProviders); i++ { + v.Providers[i] = Provider(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetProviders +// getProvidersRequest writes a GetProviders request to a byte slice. +func getProvidersRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 32 // 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 + + return buf +} + +// GetScreenInfoCookie is a cookie used only for GetScreenInfo requests. +type GetScreenInfoCookie struct { + *xgb.Cookie +} + +// GetScreenInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenInfoCookie.Reply() +func GetScreenInfo(c *xgb.Conn, Window xproto.Window) GetScreenInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenInfoRequest(c, Window), cookie) + return GetScreenInfoCookie{cookie} +} + +// GetScreenInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenInfoUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenInfo' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenInfoRequest(c, Window), cookie) + return GetScreenInfoCookie{cookie} +} + +// GetScreenInfoReply represents the data returned from a GetScreenInfo request. +type GetScreenInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Rotations byte + Root xproto.Window + Timestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + NSizes uint16 + SizeID uint16 + Rotation uint16 + Rate uint16 + NInfo uint16 + // padding: 2 bytes + Sizes []ScreenSize // size: xgb.Pad((int(NSizes) * 8)) + Rates []RefreshRates // size: RefreshRatesListSize(Rates) +} + +// Reply blocks and returns the reply data for a GetScreenInfo request. +func (cook GetScreenInfoCookie) Reply() (*GetScreenInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenInfoReply(buf), nil +} + +// getScreenInfoReply reads a byte slice into a GetScreenInfoReply value. +func getScreenInfoReply(buf []byte) *GetScreenInfoReply { + v := new(GetScreenInfoReply) + b := 1 // skip reply determinant + + v.Rotations = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Root = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NSizes = xgb.Get16(buf[b:]) + b += 2 + + v.SizeID = xgb.Get16(buf[b:]) + b += 2 + + v.Rotation = xgb.Get16(buf[b:]) + b += 2 + + v.Rate = xgb.Get16(buf[b:]) + b += 2 + + v.NInfo = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Sizes = make([]ScreenSize, v.NSizes) + b += ScreenSizeReadList(buf[b:], v.Sizes) + + v.Rates = make([]RefreshRates, (int(v.NInfo) - int(v.NSizes))) + b += RefreshRatesReadList(buf[b:], v.Rates) + + return v +} + +// Write request to wire for GetScreenInfo +// getScreenInfoRequest writes a GetScreenInfo request to a byte slice. +func getScreenInfoRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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 + + return buf +} + +// GetScreenResourcesCookie is a cookie used only for GetScreenResources requests. +type GetScreenResourcesCookie struct { + *xgb.Cookie +} + +// GetScreenResources sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenResourcesCookie.Reply() +func GetScreenResources(c *xgb.Conn, Window xproto.Window) GetScreenResourcesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenResources' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenResourcesRequest(c, Window), cookie) + return GetScreenResourcesCookie{cookie} +} + +// GetScreenResourcesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenResourcesUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenResourcesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenResources' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenResourcesRequest(c, Window), cookie) + return GetScreenResourcesCookie{cookie} +} + +// GetScreenResourcesReply represents the data returned from a GetScreenResources request. +type GetScreenResourcesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + NumCrtcs uint16 + NumOutputs uint16 + NumModes uint16 + NamesLen uint16 + // padding: 8 bytes + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) + Names []byte // size: xgb.Pad((int(NamesLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetScreenResources request. +func (cook GetScreenResourcesCookie) Reply() (*GetScreenResourcesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenResourcesReply(buf), nil +} + +// getScreenResourcesReply reads a byte slice into a GetScreenResourcesReply value. +func getScreenResourcesReply(buf []byte) *GetScreenResourcesReply { + v := new(GetScreenResourcesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NumCrtcs = xgb.Get16(buf[b:]) + b += 2 + + v.NumOutputs = xgb.Get16(buf[b:]) + b += 2 + + v.NumModes = xgb.Get16(buf[b:]) + b += 2 + + v.NamesLen = xgb.Get16(buf[b:]) + b += 2 + + b += 8 // padding + + v.Crtcs = make([]Crtc, v.NumCrtcs) + for i := 0; i < int(v.NumCrtcs); i++ { + v.Crtcs[i] = Crtc(xgb.Get32(buf[b:])) + b += 4 + } + + v.Outputs = make([]Output, v.NumOutputs) + for i := 0; i < int(v.NumOutputs); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + v.Modes = make([]ModeInfo, v.NumModes) + b += ModeInfoReadList(buf[b:], v.Modes) + + v.Names = make([]byte, v.NamesLen) + copy(v.Names[:v.NamesLen], buf[b:]) + b += int(v.NamesLen) + + return v +} + +// Write request to wire for GetScreenResources +// getScreenResourcesRequest writes a GetScreenResources request to a byte slice. +func getScreenResourcesRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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 + + return buf +} + +// GetScreenResourcesCurrentCookie is a cookie used only for GetScreenResourcesCurrent requests. +type GetScreenResourcesCurrentCookie struct { + *xgb.Cookie +} + +// GetScreenResourcesCurrent sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenResourcesCurrentCookie.Reply() +func GetScreenResourcesCurrent(c *xgb.Conn, Window xproto.Window) GetScreenResourcesCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenResourcesCurrent' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenResourcesCurrentRequest(c, Window), cookie) + return GetScreenResourcesCurrentCookie{cookie} +} + +// GetScreenResourcesCurrentUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenResourcesCurrentUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenResourcesCurrentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenResourcesCurrent' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenResourcesCurrentRequest(c, Window), cookie) + return GetScreenResourcesCurrentCookie{cookie} +} + +// GetScreenResourcesCurrentReply represents the data returned from a GetScreenResourcesCurrent request. +type GetScreenResourcesCurrentReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + NumCrtcs uint16 + NumOutputs uint16 + NumModes uint16 + NamesLen uint16 + // padding: 8 bytes + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) + Names []byte // size: xgb.Pad((int(NamesLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetScreenResourcesCurrent request. +func (cook GetScreenResourcesCurrentCookie) Reply() (*GetScreenResourcesCurrentReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenResourcesCurrentReply(buf), nil +} + +// getScreenResourcesCurrentReply reads a byte slice into a GetScreenResourcesCurrentReply value. +func getScreenResourcesCurrentReply(buf []byte) *GetScreenResourcesCurrentReply { + v := new(GetScreenResourcesCurrentReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NumCrtcs = xgb.Get16(buf[b:]) + b += 2 + + v.NumOutputs = xgb.Get16(buf[b:]) + b += 2 + + v.NumModes = xgb.Get16(buf[b:]) + b += 2 + + v.NamesLen = xgb.Get16(buf[b:]) + b += 2 + + b += 8 // padding + + v.Crtcs = make([]Crtc, v.NumCrtcs) + for i := 0; i < int(v.NumCrtcs); i++ { + v.Crtcs[i] = Crtc(xgb.Get32(buf[b:])) + b += 4 + } + + v.Outputs = make([]Output, v.NumOutputs) + for i := 0; i < int(v.NumOutputs); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + v.Modes = make([]ModeInfo, v.NumModes) + b += ModeInfoReadList(buf[b:], v.Modes) + + v.Names = make([]byte, v.NamesLen) + copy(v.Names[:v.NamesLen], buf[b:]) + b += int(v.NamesLen) + + return v +} + +// Write request to wire for GetScreenResourcesCurrent +// getScreenResourcesCurrentRequest writes a GetScreenResourcesCurrent request to a byte slice. +func getScreenResourcesCurrentRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 25 // 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 + + return buf +} + +// GetScreenSizeRangeCookie is a cookie used only for GetScreenSizeRange requests. +type GetScreenSizeRangeCookie struct { + *xgb.Cookie +} + +// GetScreenSizeRange sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenSizeRangeCookie.Reply() +func GetScreenSizeRange(c *xgb.Conn, Window xproto.Window) GetScreenSizeRangeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenSizeRange' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenSizeRangeRequest(c, Window), cookie) + return GetScreenSizeRangeCookie{cookie} +} + +// GetScreenSizeRangeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenSizeRangeUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenSizeRangeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetScreenSizeRange' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenSizeRangeRequest(c, Window), cookie) + return GetScreenSizeRangeCookie{cookie} +} + +// GetScreenSizeRangeReply represents the data returned from a GetScreenSizeRange request. +type GetScreenSizeRangeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MinWidth uint16 + MinHeight uint16 + MaxWidth uint16 + MaxHeight uint16 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a GetScreenSizeRange request. +func (cook GetScreenSizeRangeCookie) Reply() (*GetScreenSizeRangeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenSizeRangeReply(buf), nil +} + +// getScreenSizeRangeReply reads a byte slice into a GetScreenSizeRangeReply value. +func getScreenSizeRangeReply(buf []byte) *GetScreenSizeRangeReply { + v := new(GetScreenSizeRangeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MinWidth = xgb.Get16(buf[b:]) + b += 2 + + v.MinHeight = xgb.Get16(buf[b:]) + b += 2 + + v.MaxWidth = xgb.Get16(buf[b:]) + b += 2 + + v.MaxHeight = xgb.Get16(buf[b:]) + b += 2 + + b += 16 // padding + + return v +} + +// Write request to wire for GetScreenSizeRange +// getScreenSizeRangeRequest writes a GetScreenSizeRange request to a byte slice. +func getScreenSizeRangeRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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 + + return buf +} + +// ListOutputPropertiesCookie is a cookie used only for ListOutputProperties requests. +type ListOutputPropertiesCookie struct { + *xgb.Cookie +} + +// ListOutputProperties sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListOutputPropertiesCookie.Reply() +func ListOutputProperties(c *xgb.Conn, Output Output) ListOutputPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ListOutputProperties' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listOutputPropertiesRequest(c, Output), cookie) + return ListOutputPropertiesCookie{cookie} +} + +// ListOutputPropertiesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListOutputPropertiesUnchecked(c *xgb.Conn, Output Output) ListOutputPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ListOutputProperties' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listOutputPropertiesRequest(c, Output), cookie) + return ListOutputPropertiesCookie{cookie} +} + +// ListOutputPropertiesReply represents the data returned from a ListOutputProperties request. +type ListOutputPropertiesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAtoms uint16 + // padding: 22 bytes + Atoms []xproto.Atom // size: xgb.Pad((int(NumAtoms) * 4)) +} + +// Reply blocks and returns the reply data for a ListOutputProperties request. +func (cook ListOutputPropertiesCookie) Reply() (*ListOutputPropertiesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listOutputPropertiesReply(buf), nil +} + +// listOutputPropertiesReply reads a byte slice into a ListOutputPropertiesReply value. +func listOutputPropertiesReply(buf []byte) *ListOutputPropertiesReply { + v := new(ListOutputPropertiesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAtoms = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Atoms = make([]xproto.Atom, v.NumAtoms) + for i := 0; i < int(v.NumAtoms); i++ { + v.Atoms[i] = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for ListOutputProperties +// listOutputPropertiesRequest writes a ListOutputProperties request to a byte slice. +func listOutputPropertiesRequest(c *xgb.Conn, Output Output) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // 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(Output)) + b += 4 + + return buf +} + +// ListProviderPropertiesCookie is a cookie used only for ListProviderProperties requests. +type ListProviderPropertiesCookie struct { + *xgb.Cookie +} + +// ListProviderProperties sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListProviderPropertiesCookie.Reply() +func ListProviderProperties(c *xgb.Conn, Provider Provider) ListProviderPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ListProviderProperties' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listProviderPropertiesRequest(c, Provider), cookie) + return ListProviderPropertiesCookie{cookie} +} + +// ListProviderPropertiesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListProviderPropertiesUnchecked(c *xgb.Conn, Provider Provider) ListProviderPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'ListProviderProperties' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listProviderPropertiesRequest(c, Provider), cookie) + return ListProviderPropertiesCookie{cookie} +} + +// ListProviderPropertiesReply represents the data returned from a ListProviderProperties request. +type ListProviderPropertiesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAtoms uint16 + // padding: 22 bytes + Atoms []xproto.Atom // size: xgb.Pad((int(NumAtoms) * 4)) +} + +// Reply blocks and returns the reply data for a ListProviderProperties request. +func (cook ListProviderPropertiesCookie) Reply() (*ListProviderPropertiesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listProviderPropertiesReply(buf), nil +} + +// listProviderPropertiesReply reads a byte slice into a ListProviderPropertiesReply value. +func listProviderPropertiesReply(buf []byte) *ListProviderPropertiesReply { + v := new(ListProviderPropertiesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAtoms = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Atoms = make([]xproto.Atom, v.NumAtoms) + for i := 0; i < int(v.NumAtoms); i++ { + v.Atoms[i] = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for ListProviderProperties +// listProviderPropertiesRequest writes a ListProviderProperties request to a byte slice. +func listProviderPropertiesRequest(c *xgb.Conn, Provider Provider) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 36 // 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(Provider)) + b += 4 + + return buf +} + +// QueryOutputPropertyCookie is a cookie used only for QueryOutputProperty requests. +type QueryOutputPropertyCookie struct { + *xgb.Cookie +} + +// QueryOutputProperty sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryOutputPropertyCookie.Reply() +func QueryOutputProperty(c *xgb.Conn, Output Output, Property xproto.Atom) QueryOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryOutputPropertyRequest(c, Output, Property), cookie) + return QueryOutputPropertyCookie{cookie} +} + +// QueryOutputPropertyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryOutputPropertyUnchecked(c *xgb.Conn, Output Output, Property xproto.Atom) QueryOutputPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryOutputProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryOutputPropertyRequest(c, Output, Property), cookie) + return QueryOutputPropertyCookie{cookie} +} + +// QueryOutputPropertyReply represents the data returned from a QueryOutputProperty request. +type QueryOutputPropertyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Pending bool + Range bool + Immutable bool + // padding: 21 bytes + ValidValues []int32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a QueryOutputProperty request. +func (cook QueryOutputPropertyCookie) Reply() (*QueryOutputPropertyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryOutputPropertyReply(buf), nil +} + +// queryOutputPropertyReply reads a byte slice into a QueryOutputPropertyReply value. +func queryOutputPropertyReply(buf []byte) *QueryOutputPropertyReply { + v := new(QueryOutputPropertyReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.Pending = true + } else { + v.Pending = false + } + b += 1 + + if buf[b] == 1 { + v.Range = true + } else { + v.Range = false + } + b += 1 + + if buf[b] == 1 { + v.Immutable = true + } else { + v.Immutable = false + } + b += 1 + + b += 21 // padding + + v.ValidValues = make([]int32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.ValidValues[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for QueryOutputProperty +// queryOutputPropertyRequest writes a QueryOutputProperty request to a byte slice. +func queryOutputPropertyRequest(c *xgb.Conn, Output Output, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(Output)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + return buf +} + +// QueryProviderPropertyCookie is a cookie used only for QueryProviderProperty requests. +type QueryProviderPropertyCookie struct { + *xgb.Cookie +} + +// QueryProviderProperty sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryProviderPropertyCookie.Reply() +func QueryProviderProperty(c *xgb.Conn, Provider Provider, Property xproto.Atom) QueryProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryProviderPropertyRequest(c, Provider, Property), cookie) + return QueryProviderPropertyCookie{cookie} +} + +// QueryProviderPropertyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryProviderPropertyUnchecked(c *xgb.Conn, Provider Provider, Property xproto.Atom) QueryProviderPropertyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryProviderProperty' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryProviderPropertyRequest(c, Provider, Property), cookie) + return QueryProviderPropertyCookie{cookie} +} + +// QueryProviderPropertyReply represents the data returned from a QueryProviderProperty request. +type QueryProviderPropertyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Pending bool + Range bool + Immutable bool + // padding: 21 bytes + ValidValues []int32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a QueryProviderProperty request. +func (cook QueryProviderPropertyCookie) Reply() (*QueryProviderPropertyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryProviderPropertyReply(buf), nil +} + +// queryProviderPropertyReply reads a byte slice into a QueryProviderPropertyReply value. +func queryProviderPropertyReply(buf []byte) *QueryProviderPropertyReply { + v := new(QueryProviderPropertyReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.Pending = true + } else { + v.Pending = false + } + b += 1 + + if buf[b] == 1 { + v.Range = true + } else { + v.Range = false + } + b += 1 + + if buf[b] == 1 { + v.Immutable = true + } else { + v.Immutable = false + } + b += 1 + + b += 21 // padding + + v.ValidValues = make([]int32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.ValidValues[i] = int32(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for QueryProviderProperty +// queryProviderPropertyRequest writes a QueryProviderProperty request to a byte slice. +func queryProviderPropertyRequest(c *xgb.Conn, Provider Provider, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 37 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], MajorVersion) + b += 4 + + xgb.Put32(buf[b:], MinorVersion) + b += 4 + + return buf +} + +// SelectInputCookie is a cookie used only for SelectInput requests. +type SelectInputCookie struct { + *xgb.Cookie +} + +// SelectInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectInput(c *xgb.Conn, Window xproto.Window, Enable uint16) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectInputRequest(c, Window, Enable), cookie) + return SelectInputCookie{cookie} +} + +// SelectInputChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectInputCookie.Check() +func SelectInputChecked(c *xgb.Conn, Window xproto.Window, Enable uint16) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectInputRequest(c, Window, Enable), cookie) + return SelectInputCookie{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 SelectInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectInput +// selectInputRequest writes a SelectInput request to a byte slice. +func selectInputRequest(c *xgb.Conn, Window xproto.Window, Enable uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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.Put16(buf[b:], Enable) + b += 2 + + b += 2 // padding + + return buf +} + +// SetCrtcConfigCookie is a cookie used only for SetCrtcConfig requests. +type SetCrtcConfigCookie struct { + *xgb.Cookie +} + +// SetCrtcConfig sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetCrtcConfigCookie.Reply() +func SetCrtcConfig(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, X int16, Y int16, Mode Mode, Rotation uint16, Outputs []Output) SetCrtcConfigCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcConfig' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(setCrtcConfigRequest(c, Crtc, Timestamp, ConfigTimestamp, X, Y, Mode, Rotation, Outputs), cookie) + return SetCrtcConfigCookie{cookie} +} + +// SetCrtcConfigUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetCrtcConfigUnchecked(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, X int16, Y int16, Mode Mode, Rotation uint16, Outputs []Output) SetCrtcConfigCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcConfig' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(setCrtcConfigRequest(c, Crtc, Timestamp, ConfigTimestamp, X, Y, Mode, Rotation, Outputs), cookie) + return SetCrtcConfigCookie{cookie} +} + +// SetCrtcConfigReply represents the data returned from a SetCrtcConfig request. +type SetCrtcConfigReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a SetCrtcConfig request. +func (cook SetCrtcConfigCookie) Reply() (*SetCrtcConfigReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return setCrtcConfigReply(buf), nil +} + +// setCrtcConfigReply reads a byte slice into a SetCrtcConfigReply value. +func setCrtcConfigReply(buf []byte) *SetCrtcConfigReply { + v := new(SetCrtcConfigReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for SetCrtcConfig +// setCrtcConfigRequest writes a SetCrtcConfig request to a byte slice. +func setCrtcConfigRequest(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, X int16, Y int16, Mode Mode, Rotation uint16, Outputs []Output) []byte { + size := xgb.Pad((28 + xgb.Pad((len(Outputs) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 21 // 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(Crtc)) + b += 4 + + xgb.Put32(buf[b:], uint32(Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put32(buf[b:], uint32(Mode)) + b += 4 + + xgb.Put16(buf[b:], Rotation) + b += 2 + + b += 2 // padding + + for i := 0; i < int(len(Outputs)); i++ { + xgb.Put32(buf[b:], uint32(Outputs[i])) + b += 4 + } + + return buf +} + +// SetCrtcGammaCookie is a cookie used only for SetCrtcGamma requests. +type SetCrtcGammaCookie struct { + *xgb.Cookie +} + +// SetCrtcGamma sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetCrtcGamma(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Green []uint16, Blue []uint16) SetCrtcGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcGamma' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setCrtcGammaRequest(c, Crtc, Size, Red, Green, Blue), cookie) + return SetCrtcGammaCookie{cookie} +} + +// SetCrtcGammaChecked sends a checked request. +// If an error occurs, it can be retrieved using SetCrtcGammaCookie.Check() +func SetCrtcGammaChecked(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Green []uint16, Blue []uint16) SetCrtcGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcGamma' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setCrtcGammaRequest(c, Crtc, Size, Red, Green, Blue), cookie) + return SetCrtcGammaCookie{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 SetCrtcGammaCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetCrtcGamma +// setCrtcGammaRequest writes a SetCrtcGamma request to a byte slice. +func setCrtcGammaRequest(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Green []uint16, Blue []uint16) []byte { + size := xgb.Pad((((12 + xgb.Pad((int(Size) * 2))) + xgb.Pad((int(Size) * 2))) + xgb.Pad((int(Size) * 2)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 24 // 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(Crtc)) + b += 4 + + xgb.Put16(buf[b:], Size) + b += 2 + + b += 2 // padding + + for i := 0; i < int(Size); i++ { + xgb.Put16(buf[b:], Red[i]) + b += 2 + } + + for i := 0; i < int(Size); i++ { + xgb.Put16(buf[b:], Green[i]) + b += 2 + } + + for i := 0; i < int(Size); i++ { + xgb.Put16(buf[b:], Blue[i]) + b += 2 + } + + return buf +} + +// SetCrtcTransformCookie is a cookie used only for SetCrtcTransform requests. +type SetCrtcTransformCookie struct { + *xgb.Cookie +} + +// SetCrtcTransform sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetCrtcTransform(c *xgb.Conn, Crtc Crtc, Transform render.Transform, FilterLen uint16, FilterName string, FilterParams []render.Fixed) SetCrtcTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcTransform' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setCrtcTransformRequest(c, Crtc, Transform, FilterLen, FilterName, FilterParams), cookie) + return SetCrtcTransformCookie{cookie} +} + +// SetCrtcTransformChecked sends a checked request. +// If an error occurs, it can be retrieved using SetCrtcTransformCookie.Check() +func SetCrtcTransformChecked(c *xgb.Conn, Crtc Crtc, Transform render.Transform, FilterLen uint16, FilterName string, FilterParams []render.Fixed) SetCrtcTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetCrtcTransform' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setCrtcTransformRequest(c, Crtc, Transform, FilterLen, FilterName, FilterParams), cookie) + return SetCrtcTransformCookie{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 SetCrtcTransformCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetCrtcTransform +// setCrtcTransformRequest writes a SetCrtcTransform request to a byte slice. +func setCrtcTransformRequest(c *xgb.Conn, Crtc Crtc, Transform render.Transform, FilterLen uint16, FilterName string, FilterParams []render.Fixed) []byte { + size := xgb.Pad((((48 + xgb.Pad((int(FilterLen) * 1))) + 4) + xgb.Pad((len(FilterParams) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 26 // request opcode + b += 1 + + blen := b + b += 2 + + xgb.Put32(buf[b:], uint32(Crtc)) + b += 4 + + { + structBytes := Transform.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put16(buf[b:], FilterLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], FilterName[:FilterLen]) + b += int(FilterLen) + + b = (b + 3) & ^3 // alignment gap + + for i := 0; i < int(len(FilterParams)); i++ { + xgb.Put32(buf[b:], uint32(FilterParams[i])) + b += 4 + } + + b = xgb.Pad(b) + xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units + return buf[:b] +} + +// SetMonitorCookie is a cookie used only for SetMonitor requests. +type SetMonitorCookie struct { + *xgb.Cookie +} + +// SetMonitor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetMonitor(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) SetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setMonitorRequest(c, Window, Monitorinfo), cookie) + return SetMonitorCookie{cookie} +} + +// SetMonitorChecked sends a checked request. +// If an error occurs, it can be retrieved using SetMonitorCookie.Check() +func SetMonitorChecked(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) SetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setMonitorRequest(c, Window, Monitorinfo), cookie) + return SetMonitorCookie{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 SetMonitorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetMonitor +// setMonitorRequest writes a SetMonitor request to a byte slice. +func setMonitorRequest(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) []byte { + size := xgb.Pad((8 + (24 + xgb.Pad((int(Monitorinfo.NOutput) * 4))))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 43 // 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 + + { + structBytes := Monitorinfo.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf +} + +// SetOutputPrimaryCookie is a cookie used only for SetOutputPrimary requests. +type SetOutputPrimaryCookie struct { + *xgb.Cookie +} + +// SetOutputPrimary sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetOutputPrimary(c *xgb.Conn, Window xproto.Window, Output Output) SetOutputPrimaryCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetOutputPrimary' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setOutputPrimaryRequest(c, Window, Output), cookie) + return SetOutputPrimaryCookie{cookie} +} + +// SetOutputPrimaryChecked sends a checked request. +// If an error occurs, it can be retrieved using SetOutputPrimaryCookie.Check() +func SetOutputPrimaryChecked(c *xgb.Conn, Window xproto.Window, Output Output) SetOutputPrimaryCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetOutputPrimary' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setOutputPrimaryRequest(c, Window, Output), cookie) + return SetOutputPrimaryCookie{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 SetOutputPrimaryCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetOutputPrimary +// setOutputPrimaryRequest writes a SetOutputPrimary request to a byte slice. +func setOutputPrimaryRequest(c *xgb.Conn, Window xproto.Window, Output Output) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 30 // 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(Output)) + b += 4 + + return buf +} + +// SetPanningCookie is a cookie used only for SetPanning requests. +type SetPanningCookie struct { + *xgb.Cookie +} + +// SetPanning sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetPanningCookie.Reply() +func SetPanning(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, Left uint16, Top uint16, Width uint16, Height uint16, TrackLeft uint16, TrackTop uint16, TrackWidth uint16, TrackHeight uint16, BorderLeft int16, BorderTop int16, BorderRight int16, BorderBottom int16) SetPanningCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetPanning' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(setPanningRequest(c, Crtc, Timestamp, Left, Top, Width, Height, TrackLeft, TrackTop, TrackWidth, TrackHeight, BorderLeft, BorderTop, BorderRight, BorderBottom), cookie) + return SetPanningCookie{cookie} +} + +// SetPanningUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPanningUnchecked(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, Left uint16, Top uint16, Width uint16, Height uint16, TrackLeft uint16, TrackTop uint16, TrackWidth uint16, TrackHeight uint16, BorderLeft int16, BorderTop int16, BorderRight int16, BorderBottom int16) SetPanningCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetPanning' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(setPanningRequest(c, Crtc, Timestamp, Left, Top, Width, Height, TrackLeft, TrackTop, TrackWidth, TrackHeight, BorderLeft, BorderTop, BorderRight, BorderBottom), cookie) + return SetPanningCookie{cookie} +} + +// SetPanningReply represents the data returned from a SetPanning request. +type SetPanningReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + Timestamp xproto.Timestamp +} + +// Reply blocks and returns the reply data for a SetPanning request. +func (cook SetPanningCookie) Reply() (*SetPanningReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return setPanningReply(buf), nil +} + +// setPanningReply reads a byte slice into a SetPanningReply value. +func setPanningReply(buf []byte) *SetPanningReply { + v := new(SetPanningReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for SetPanning +// setPanningRequest writes a SetPanning request to a byte slice. +func setPanningRequest(c *xgb.Conn, Crtc Crtc, Timestamp xproto.Timestamp, Left uint16, Top uint16, Width uint16, Height uint16, TrackLeft uint16, TrackTop uint16, TrackWidth uint16, TrackHeight uint16, BorderLeft int16, BorderTop int16, BorderRight int16, BorderBottom int16) []byte { + size := 36 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 29 // 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(Crtc)) + b += 4 + + xgb.Put32(buf[b:], uint32(Timestamp)) + b += 4 + + xgb.Put16(buf[b:], Left) + b += 2 + + xgb.Put16(buf[b:], Top) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put16(buf[b:], TrackLeft) + b += 2 + + xgb.Put16(buf[b:], TrackTop) + b += 2 + + xgb.Put16(buf[b:], TrackWidth) + b += 2 + + xgb.Put16(buf[b:], TrackHeight) + b += 2 + + xgb.Put16(buf[b:], uint16(BorderLeft)) + b += 2 + + xgb.Put16(buf[b:], uint16(BorderTop)) + b += 2 + + xgb.Put16(buf[b:], uint16(BorderRight)) + b += 2 + + xgb.Put16(buf[b:], uint16(BorderBottom)) + b += 2 + + return buf +} + +// SetProviderOffloadSinkCookie is a cookie used only for SetProviderOffloadSink requests. +type SetProviderOffloadSinkCookie struct { + *xgb.Cookie +} + +// SetProviderOffloadSink sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetProviderOffloadSink(c *xgb.Conn, Provider Provider, SinkProvider Provider, ConfigTimestamp xproto.Timestamp) SetProviderOffloadSinkCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetProviderOffloadSink' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setProviderOffloadSinkRequest(c, Provider, SinkProvider, ConfigTimestamp), cookie) + return SetProviderOffloadSinkCookie{cookie} +} + +// SetProviderOffloadSinkChecked sends a checked request. +// If an error occurs, it can be retrieved using SetProviderOffloadSinkCookie.Check() +func SetProviderOffloadSinkChecked(c *xgb.Conn, Provider Provider, SinkProvider Provider, ConfigTimestamp xproto.Timestamp) SetProviderOffloadSinkCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetProviderOffloadSink' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setProviderOffloadSinkRequest(c, Provider, SinkProvider, ConfigTimestamp), cookie) + return SetProviderOffloadSinkCookie{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 SetProviderOffloadSinkCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetProviderOffloadSink +// setProviderOffloadSinkRequest writes a SetProviderOffloadSink request to a byte slice. +func setProviderOffloadSinkRequest(c *xgb.Conn, Provider Provider, SinkProvider Provider, ConfigTimestamp xproto.Timestamp) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 34 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(SinkProvider)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + return buf +} + +// SetProviderOutputSourceCookie is a cookie used only for SetProviderOutputSource requests. +type SetProviderOutputSourceCookie struct { + *xgb.Cookie +} + +// SetProviderOutputSource sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetProviderOutputSource(c *xgb.Conn, Provider Provider, SourceProvider Provider, ConfigTimestamp xproto.Timestamp) SetProviderOutputSourceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetProviderOutputSource' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setProviderOutputSourceRequest(c, Provider, SourceProvider, ConfigTimestamp), cookie) + return SetProviderOutputSourceCookie{cookie} +} + +// SetProviderOutputSourceChecked sends a checked request. +// If an error occurs, it can be retrieved using SetProviderOutputSourceCookie.Check() +func SetProviderOutputSourceChecked(c *xgb.Conn, Provider Provider, SourceProvider Provider, ConfigTimestamp xproto.Timestamp) SetProviderOutputSourceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetProviderOutputSource' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setProviderOutputSourceRequest(c, Provider, SourceProvider, ConfigTimestamp), cookie) + return SetProviderOutputSourceCookie{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 SetProviderOutputSourceCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetProviderOutputSource +// setProviderOutputSourceRequest writes a SetProviderOutputSource request to a byte slice. +func setProviderOutputSourceRequest(c *xgb.Conn, Provider Provider, SourceProvider Provider, ConfigTimestamp xproto.Timestamp) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 35 // 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(Provider)) + b += 4 + + xgb.Put32(buf[b:], uint32(SourceProvider)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + return buf +} + +// SetScreenConfigCookie is a cookie used only for SetScreenConfig requests. +type SetScreenConfigCookie struct { + *xgb.Cookie +} + +// SetScreenConfig sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetScreenConfigCookie.Reply() +func SetScreenConfig(c *xgb.Conn, Window xproto.Window, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, SizeID uint16, Rotation uint16, Rate uint16) SetScreenConfigCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetScreenConfig' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(setScreenConfigRequest(c, Window, Timestamp, ConfigTimestamp, SizeID, Rotation, Rate), cookie) + return SetScreenConfigCookie{cookie} +} + +// SetScreenConfigUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetScreenConfigUnchecked(c *xgb.Conn, Window xproto.Window, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, SizeID uint16, Rotation uint16, Rate uint16) SetScreenConfigCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetScreenConfig' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(setScreenConfigRequest(c, Window, Timestamp, ConfigTimestamp, SizeID, Rotation, Rate), cookie) + return SetScreenConfigCookie{cookie} +} + +// SetScreenConfigReply represents the data returned from a SetScreenConfig request. +type SetScreenConfigReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte + NewTimestamp xproto.Timestamp + ConfigTimestamp xproto.Timestamp + Root xproto.Window + SubpixelOrder uint16 + // padding: 10 bytes +} + +// Reply blocks and returns the reply data for a SetScreenConfig request. +func (cook SetScreenConfigCookie) Reply() (*SetScreenConfigReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return setScreenConfigReply(buf), nil +} + +// setScreenConfigReply reads a byte slice into a SetScreenConfigReply value. +func setScreenConfigReply(buf []byte) *SetScreenConfigReply { + v := new(SetScreenConfigReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NewTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.ConfigTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.SubpixelOrder = xgb.Get16(buf[b:]) + b += 2 + + b += 10 // padding + + return v +} + +// Write request to wire for SetScreenConfig +// setScreenConfigRequest writes a SetScreenConfig request to a byte slice. +func setScreenConfigRequest(c *xgb.Conn, Window xproto.Window, Timestamp xproto.Timestamp, ConfigTimestamp xproto.Timestamp, SizeID uint16, Rotation uint16, Rate uint16) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(ConfigTimestamp)) + b += 4 + + xgb.Put16(buf[b:], SizeID) + b += 2 + + xgb.Put16(buf[b:], Rotation) + b += 2 + + xgb.Put16(buf[b:], Rate) + b += 2 + + b += 2 // padding + + return buf +} + +// SetScreenSizeCookie is a cookie used only for SetScreenSize requests. +type SetScreenSizeCookie struct { + *xgb.Cookie +} + +// SetScreenSize sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetScreenSize(c *xgb.Conn, Window xproto.Window, Width uint16, Height uint16, MmWidth uint32, MmHeight uint32) SetScreenSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetScreenSize' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setScreenSizeRequest(c, Window, Width, Height, MmWidth, MmHeight), cookie) + return SetScreenSizeCookie{cookie} +} + +// SetScreenSizeChecked sends a checked request. +// If an error occurs, it can be retrieved using SetScreenSizeCookie.Check() +func SetScreenSizeChecked(c *xgb.Conn, Window xproto.Window, Width uint16, Height uint16, MmWidth uint32, MmHeight uint32) SetScreenSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetScreenSize' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setScreenSizeRequest(c, Window, Width, Height, MmWidth, MmHeight), cookie) + return SetScreenSizeCookie{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 SetScreenSizeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetScreenSize +// setScreenSizeRequest writes a SetScreenSize request to a byte slice. +func setScreenSizeRequest(c *xgb.Conn, Window xproto.Window, Width uint16, Height uint16, MmWidth uint32, MmHeight uint32) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put32(buf[b:], MmWidth) + b += 4 + + xgb.Put32(buf[b:], MmHeight) + b += 4 + + return buf +} diff --git a/nexgb/record/record.go b/nexgb/record/record.go new file mode 100644 index 0000000..1cb022b --- /dev/null +++ b/nexgb/record/record.go @@ -0,0 +1,1204 @@ +// Package record is the X client API for the RECORD extension. +package record + +// This file is automatically generated from record.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the RECORD extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "RECORD").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named RECORD could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["RECORD"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["RECORD"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["RECORD"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["RECORD"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadContext is the error number for a BadBadContext. +const BadBadContext = 0 + +type BadContextError struct { + Sequence uint16 + NiceName string + InvalidRecord uint32 +} + +// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. +func BadContextErrorNew(buf []byte) xgb.Error { + v := BadContextError{} + v.NiceName = "BadContext" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.InvalidRecord = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadContext error. +// This is mostly used internally. +func (err BadContextError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. +func (err BadContextError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadContext error. + +func (err BadContextError) Error() string { + fieldVals := make([]string, 0, 1) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("InvalidRecord: %d", err.InvalidRecord)) + return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RECORD"][0] = BadContextErrorNew +} + +type ClientInfo struct { + ClientResource ClientSpec + NumRanges uint32 + Ranges []Range // size: xgb.Pad((int(NumRanges) * 24)) +} + +// ClientInfoRead reads a byte slice into a ClientInfo value. +func ClientInfoRead(buf []byte, v *ClientInfo) int { + b := 0 + + v.ClientResource = ClientSpec(xgb.Get32(buf[b:])) + b += 4 + + v.NumRanges = xgb.Get32(buf[b:]) + b += 4 + + v.Ranges = make([]Range, v.NumRanges) + b += RangeReadList(buf[b:], v.Ranges) + + return b +} + +// ClientInfoReadList reads a byte slice into a list of ClientInfo values. +func ClientInfoReadList(buf []byte, dest []ClientInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ClientInfo{} + b += ClientInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ClientInfo value to a byte slice. +func (v ClientInfo) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumRanges) * 24)))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.ClientResource)) + b += 4 + + xgb.Put32(buf[b:], v.NumRanges) + b += 4 + + b += RangeListBytes(buf[b:], v.Ranges) + + return buf[:b] +} + +// ClientInfoListBytes writes a list of ClientInfo values to a byte slice. +func ClientInfoListBytes(buf []byte, list []ClientInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ClientInfoListSize computes the size (bytes) of a list of ClientInfo values. +func ClientInfoListSize(list []ClientInfo) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumRanges) * 24))) + } + return size +} + +type ClientSpec uint32 + +type Context uint32 + +func NewContextId(c *xgb.Conn) (Context, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Context(id), nil +} + +const ( + CsCurrentClients = 1 + CsFutureClients = 2 + CsAllClients = 3 +) + +type ElementHeader byte + +type ExtRange struct { + Major Range8 + Minor Range16 +} + +// ExtRangeRead reads a byte slice into a ExtRange value. +func ExtRangeRead(buf []byte, v *ExtRange) int { + b := 0 + + v.Major = Range8{} + b += Range8Read(buf[b:], &v.Major) + + v.Minor = Range16{} + b += Range16Read(buf[b:], &v.Minor) + + return b +} + +// ExtRangeReadList reads a byte slice into a list of ExtRange values. +func ExtRangeReadList(buf []byte, dest []ExtRange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ExtRange{} + b += ExtRangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ExtRange value to a byte slice. +func (v ExtRange) Bytes() []byte { + buf := make([]byte, 6) + b := 0 + + { + structBytes := v.Major.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.Minor.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf[:b] +} + +// ExtRangeListBytes writes a list of ExtRange values to a byte slice. +func ExtRangeListBytes(buf []byte, list []ExtRange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + HTypeFromServerTime = 1 + HTypeFromClientTime = 2 + HTypeFromClientSequence = 4 +) + +type Range struct { + CoreRequests Range8 + CoreReplies Range8 + ExtRequests ExtRange + ExtReplies ExtRange + DeliveredEvents Range8 + DeviceEvents Range8 + Errors Range8 + ClientStarted bool + ClientDied bool +} + +// RangeRead reads a byte slice into a Range value. +func RangeRead(buf []byte, v *Range) int { + b := 0 + + v.CoreRequests = Range8{} + b += Range8Read(buf[b:], &v.CoreRequests) + + v.CoreReplies = Range8{} + b += Range8Read(buf[b:], &v.CoreReplies) + + v.ExtRequests = ExtRange{} + b += ExtRangeRead(buf[b:], &v.ExtRequests) + + v.ExtReplies = ExtRange{} + b += ExtRangeRead(buf[b:], &v.ExtReplies) + + v.DeliveredEvents = Range8{} + b += Range8Read(buf[b:], &v.DeliveredEvents) + + v.DeviceEvents = Range8{} + b += Range8Read(buf[b:], &v.DeviceEvents) + + v.Errors = Range8{} + b += Range8Read(buf[b:], &v.Errors) + + if buf[b] == 1 { + v.ClientStarted = true + } else { + v.ClientStarted = false + } + b += 1 + + if buf[b] == 1 { + v.ClientDied = true + } else { + v.ClientDied = false + } + b += 1 + + return b +} + +// RangeReadList reads a byte slice into a list of Range values. +func RangeReadList(buf []byte, dest []Range) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range{} + b += RangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Range value to a byte slice. +func (v Range) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + { + structBytes := v.CoreRequests.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.CoreReplies.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.ExtRequests.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.ExtReplies.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.DeliveredEvents.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.DeviceEvents.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.Errors.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + if v.ClientStarted { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if v.ClientDied { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf[:b] +} + +// RangeListBytes writes a list of Range values to a byte slice. +func RangeListBytes(buf []byte, list []Range) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Range16 struct { + First uint16 + Last uint16 +} + +// Range16Read reads a byte slice into a Range16 value. +func Range16Read(buf []byte, v *Range16) int { + b := 0 + + v.First = xgb.Get16(buf[b:]) + b += 2 + + v.Last = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// Range16ReadList reads a byte slice into a list of Range16 values. +func Range16ReadList(buf []byte, dest []Range16) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range16{} + b += Range16Read(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Range16 value to a byte slice. +func (v Range16) Bytes() []byte { + buf := make([]byte, 4) + b := 0 + + xgb.Put16(buf[b:], v.First) + b += 2 + + xgb.Put16(buf[b:], v.Last) + b += 2 + + return buf[:b] +} + +// Range16ListBytes writes a list of Range16 values to a byte slice. +func Range16ListBytes(buf []byte, list []Range16) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Range8 struct { + First byte + Last byte +} + +// Range8Read reads a byte slice into a Range8 value. +func Range8Read(buf []byte, v *Range8) int { + b := 0 + + v.First = buf[b] + b += 1 + + v.Last = buf[b] + b += 1 + + return b +} + +// Range8ReadList reads a byte slice into a list of Range8 values. +func Range8ReadList(buf []byte, dest []Range8) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range8{} + b += Range8Read(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Range8 value to a byte slice. +func (v Range8) Bytes() []byte { + buf := make([]byte, 2) + b := 0 + + buf[b] = v.First + b += 1 + + buf[b] = v.Last + b += 1 + + return buf[:b] +} + +// Range8ListBytes writes a list of Range8 values to a byte slice. +func Range8ListBytes(buf []byte, list []Range8) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CreateContextCookie is a cookie used only for CreateContext requests. +type CreateContextCookie struct { + *xgb.Cookie +} + +// CreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateContextCookie.Check() +func CreateContextChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return CreateContextCookie{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 CreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. +func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + 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(Context)) + b += 4 + + buf[b] = byte(ElementHeader) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + xgb.Put32(buf[b:], NumRanges) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + + b += RangeListBytes(buf[b:], Ranges) + + return buf +} + +// DisableContextCookie is a cookie used only for DisableContext requests. +type DisableContextCookie struct { + *xgb.Cookie +} + +// DisableContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{cookie} +} + +// DisableContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DisableContextCookie.Check() +func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{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 DisableContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DisableContext +// disableContextRequest writes a DisableContext request to a byte slice. +func disableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Context)) + b += 4 + + return buf +} + +// EnableContextCookie is a cookie used only for EnableContext requests. +type EnableContextCookie struct { + *xgb.Cookie +} + +// EnableContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() +func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +// EnableContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +// EnableContextReply represents the data returned from a EnableContext request. +type EnableContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Category byte + ElementHeader ElementHeader + ClientSwapped bool + // padding: 2 bytes + XidBase uint32 + ServerTime uint32 + RecSequenceNum uint32 + // padding: 8 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a EnableContext request. +func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return enableContextReply(buf), nil +} + +// enableContextReply reads a byte slice into a EnableContextReply value. +func enableContextReply(buf []byte) *EnableContextReply { + v := new(EnableContextReply) + b := 1 // skip reply determinant + + v.Category = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ElementHeader = ElementHeader(buf[b]) + b += 1 + + if buf[b] == 1 { + v.ClientSwapped = true + } else { + v.ClientSwapped = false + } + b += 1 + + b += 2 // padding + + v.XidBase = xgb.Get32(buf[b:]) + b += 4 + + v.ServerTime = xgb.Get32(buf[b:]) + b += 4 + + v.RecSequenceNum = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for EnableContext +// enableContextRequest writes a EnableContext request to a byte slice. +func enableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Context)) + b += 4 + + return buf +} + +// FreeContextCookie is a cookie used only for FreeContext requests. +type FreeContextCookie struct { + *xgb.Cookie +} + +// FreeContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{cookie} +} + +// FreeContextChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeContextCookie.Check() +func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{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 FreeContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeContext +// freeContextRequest writes a FreeContext request to a byte slice. +func freeContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Context)) + b += 4 + + return buf +} + +// GetContextCookie is a cookie used only for GetContext requests. +type GetContextCookie struct { + *xgb.Cookie +} + +// GetContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetContextCookie.Reply() +func GetContext(c *xgb.Conn, Context Context) GetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getContextRequest(c, Context), cookie) + return GetContextCookie{cookie} +} + +// GetContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetContextUnchecked(c *xgb.Conn, Context Context) GetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getContextRequest(c, Context), cookie) + return GetContextCookie{cookie} +} + +// GetContextReply represents the data returned from a GetContext request. +type GetContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Enabled bool + ElementHeader ElementHeader + // padding: 3 bytes + NumInterceptedClients uint32 + // padding: 16 bytes + InterceptedClients []ClientInfo // size: ClientInfoListSize(InterceptedClients) +} + +// Reply blocks and returns the reply data for a GetContext request. +func (cook GetContextCookie) Reply() (*GetContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getContextReply(buf), nil +} + +// getContextReply reads a byte slice into a GetContextReply value. +func getContextReply(buf []byte) *GetContextReply { + v := new(GetContextReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.Enabled = true + } else { + v.Enabled = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ElementHeader = ElementHeader(buf[b]) + b += 1 + + b += 3 // padding + + v.NumInterceptedClients = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.InterceptedClients = make([]ClientInfo, v.NumInterceptedClients) + b += ClientInfoReadList(buf[b:], v.InterceptedClients) + + return v +} + +// Write request to wire for GetContext +// getContextRequest writes a GetContext request to a byte slice. +func getContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Context)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], MajorVersion) + b += 2 + + xgb.Put16(buf[b:], MinorVersion) + b += 2 + + return buf +} + +// RegisterClientsCookie is a cookie used only for RegisterClients requests. +type RegisterClientsCookie struct { + *xgb.Cookie +} + +// RegisterClients sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{cookie} +} + +// RegisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using RegisterClientsCookie.Check() +func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{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 RegisterClientsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RegisterClients +// registerClientsRequest writes a RegisterClients request to a byte slice. +func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + buf[b] = byte(ElementHeader) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + xgb.Put32(buf[b:], NumRanges) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + + b += RangeListBytes(buf[b:], Ranges) + + return buf +} + +// UnregisterClientsCookie is a cookie used only for UnregisterClients requests. +type UnregisterClientsCookie struct { + *xgb.Cookie +} + +// UnregisterClients sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{cookie} +} + +// UnregisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() +func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{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 UnregisterClientsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnregisterClients +// unregisterClientsRequest writes a UnregisterClients request to a byte slice. +func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + + return buf +} diff --git a/nexgb/render/render.go b/nexgb/render/render.go new file mode 100644 index 0000000..01ea481 --- /dev/null +++ b/nexgb/render/render.go @@ -0,0 +1,4029 @@ +// Package render is the X client API for the RENDER extension. +package render + +// This file is automatically generated from render.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the RENDER extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "RENDER").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named RENDER could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["RENDER"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["RENDER"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["RENDER"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["RENDER"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["RENDER"] = make(map[int]xgb.NewErrorFun) +} + +type Animcursorelt struct { + Cursor xproto.Cursor + Delay uint32 +} + +// AnimcursoreltRead reads a byte slice into a Animcursorelt value. +func AnimcursoreltRead(buf []byte, v *Animcursorelt) int { + b := 0 + + v.Cursor = xproto.Cursor(xgb.Get32(buf[b:])) + b += 4 + + v.Delay = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// AnimcursoreltReadList reads a byte slice into a list of Animcursorelt values. +func AnimcursoreltReadList(buf []byte, dest []Animcursorelt) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Animcursorelt{} + b += AnimcursoreltRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Animcursorelt value to a byte slice. +func (v Animcursorelt) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Cursor)) + b += 4 + + xgb.Put32(buf[b:], v.Delay) + b += 4 + + return buf[:b] +} + +// AnimcursoreltListBytes writes a list of Animcursorelt values to a byte slice. +func AnimcursoreltListBytes(buf []byte, list []Animcursorelt) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Color struct { + Red uint16 + Green uint16 + Blue uint16 + Alpha uint16 +} + +// ColorRead reads a byte slice into a Color value. +func ColorRead(buf []byte, v *Color) int { + b := 0 + + v.Red = xgb.Get16(buf[b:]) + b += 2 + + v.Green = xgb.Get16(buf[b:]) + b += 2 + + v.Blue = xgb.Get16(buf[b:]) + b += 2 + + v.Alpha = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// ColorReadList reads a byte slice into a list of Color values. +func ColorReadList(buf []byte, dest []Color) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Color{} + b += ColorRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Color value to a byte slice. +func (v Color) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], v.Red) + b += 2 + + xgb.Put16(buf[b:], v.Green) + b += 2 + + xgb.Put16(buf[b:], v.Blue) + b += 2 + + xgb.Put16(buf[b:], v.Alpha) + b += 2 + + return buf[:b] +} + +// ColorListBytes writes a list of Color values to a byte slice. +func ColorListBytes(buf []byte, list []Color) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + CpRepeat = 1 + CpAlphaMap = 2 + CpAlphaXOrigin = 4 + CpAlphaYOrigin = 8 + CpClipXOrigin = 16 + CpClipYOrigin = 32 + CpClipMask = 64 + CpGraphicsExposure = 128 + CpSubwindowMode = 256 + CpPolyEdge = 512 + CpPolyMode = 1024 + CpDither = 2048 + CpComponentAlpha = 4096 +) + +type Directformat struct { + RedShift uint16 + RedMask uint16 + GreenShift uint16 + GreenMask uint16 + BlueShift uint16 + BlueMask uint16 + AlphaShift uint16 + AlphaMask uint16 +} + +// DirectformatRead reads a byte slice into a Directformat value. +func DirectformatRead(buf []byte, v *Directformat) int { + b := 0 + + v.RedShift = xgb.Get16(buf[b:]) + b += 2 + + v.RedMask = xgb.Get16(buf[b:]) + b += 2 + + v.GreenShift = xgb.Get16(buf[b:]) + b += 2 + + v.GreenMask = xgb.Get16(buf[b:]) + b += 2 + + v.BlueShift = xgb.Get16(buf[b:]) + b += 2 + + v.BlueMask = xgb.Get16(buf[b:]) + b += 2 + + v.AlphaShift = xgb.Get16(buf[b:]) + b += 2 + + v.AlphaMask = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// DirectformatReadList reads a byte slice into a list of Directformat values. +func DirectformatReadList(buf []byte, dest []Directformat) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Directformat{} + b += DirectformatRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Directformat value to a byte slice. +func (v Directformat) Bytes() []byte { + buf := make([]byte, 16) + b := 0 + + xgb.Put16(buf[b:], v.RedShift) + b += 2 + + xgb.Put16(buf[b:], v.RedMask) + b += 2 + + xgb.Put16(buf[b:], v.GreenShift) + b += 2 + + xgb.Put16(buf[b:], v.GreenMask) + b += 2 + + xgb.Put16(buf[b:], v.BlueShift) + b += 2 + + xgb.Put16(buf[b:], v.BlueMask) + b += 2 + + xgb.Put16(buf[b:], v.AlphaShift) + b += 2 + + xgb.Put16(buf[b:], v.AlphaMask) + b += 2 + + return buf[:b] +} + +// DirectformatListBytes writes a list of Directformat values to a byte slice. +func DirectformatListBytes(buf []byte, list []Directformat) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Fixed int32 + +type Glyph uint32 + +// BadGlyph is the error number for a BadGlyph. +const BadGlyph = 4 + +type GlyphError struct { + Sequence uint16 + NiceName string +} + +// GlyphErrorNew constructs a GlyphError value that implements xgb.Error from a byte slice. +func GlyphErrorNew(buf []byte) xgb.Error { + v := GlyphError{} + v.NiceName = "Glyph" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadGlyph error. +// This is mostly used internally. +func (err GlyphError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadGlyph error. If no bad value exists, 0 is returned. +func (err GlyphError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadGlyph error. + +func (err GlyphError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadGlyph {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RENDER"][4] = GlyphErrorNew +} + +// BadGlyphSet is the error number for a BadGlyphSet. +const BadGlyphSet = 3 + +type GlyphSetError struct { + Sequence uint16 + NiceName string +} + +// GlyphSetErrorNew constructs a GlyphSetError value that implements xgb.Error from a byte slice. +func GlyphSetErrorNew(buf []byte) xgb.Error { + v := GlyphSetError{} + v.NiceName = "GlyphSet" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadGlyphSet error. +// This is mostly used internally. +func (err GlyphSetError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadGlyphSet error. If no bad value exists, 0 is returned. +func (err GlyphSetError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadGlyphSet error. + +func (err GlyphSetError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadGlyphSet {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RENDER"][3] = GlyphSetErrorNew +} + +type Glyphinfo struct { + Width uint16 + Height uint16 + X int16 + Y int16 + XOff int16 + YOff int16 +} + +// GlyphinfoRead reads a byte slice into a Glyphinfo value. +func GlyphinfoRead(buf []byte, v *Glyphinfo) int { + b := 0 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.XOff = int16(xgb.Get16(buf[b:])) + b += 2 + + v.YOff = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// GlyphinfoReadList reads a byte slice into a list of Glyphinfo values. +func GlyphinfoReadList(buf []byte, dest []Glyphinfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Glyphinfo{} + b += GlyphinfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Glyphinfo value to a byte slice. +func (v Glyphinfo) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.XOff)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.YOff)) + b += 2 + + return buf[:b] +} + +// GlyphinfoListBytes writes a list of Glyphinfo values to a byte slice. +func GlyphinfoListBytes(buf []byte, list []Glyphinfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Glyphset uint32 + +func NewGlyphsetId(c *xgb.Conn) (Glyphset, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Glyphset(id), nil +} + +type Indexvalue struct { + Pixel uint32 + Red uint16 + Green uint16 + Blue uint16 + Alpha uint16 +} + +// IndexvalueRead reads a byte slice into a Indexvalue value. +func IndexvalueRead(buf []byte, v *Indexvalue) int { + b := 0 + + v.Pixel = xgb.Get32(buf[b:]) + b += 4 + + v.Red = xgb.Get16(buf[b:]) + b += 2 + + v.Green = xgb.Get16(buf[b:]) + b += 2 + + v.Blue = xgb.Get16(buf[b:]) + b += 2 + + v.Alpha = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// IndexvalueReadList reads a byte slice into a list of Indexvalue values. +func IndexvalueReadList(buf []byte, dest []Indexvalue) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Indexvalue{} + b += IndexvalueRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Indexvalue value to a byte slice. +func (v Indexvalue) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put32(buf[b:], v.Pixel) + b += 4 + + xgb.Put16(buf[b:], v.Red) + b += 2 + + xgb.Put16(buf[b:], v.Green) + b += 2 + + xgb.Put16(buf[b:], v.Blue) + b += 2 + + xgb.Put16(buf[b:], v.Alpha) + b += 2 + + return buf[:b] +} + +// IndexvalueListBytes writes a list of Indexvalue values to a byte slice. +func IndexvalueListBytes(buf []byte, list []Indexvalue) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Linefix struct { + P1 Pointfix + P2 Pointfix +} + +// LinefixRead reads a byte slice into a Linefix value. +func LinefixRead(buf []byte, v *Linefix) int { + b := 0 + + v.P1 = Pointfix{} + b += PointfixRead(buf[b:], &v.P1) + + v.P2 = Pointfix{} + b += PointfixRead(buf[b:], &v.P2) + + return b +} + +// LinefixReadList reads a byte slice into a list of Linefix values. +func LinefixReadList(buf []byte, dest []Linefix) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Linefix{} + b += LinefixRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Linefix value to a byte slice. +func (v Linefix) Bytes() []byte { + buf := make([]byte, 16) + b := 0 + + { + structBytes := v.P1.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.P2.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf[:b] +} + +// LinefixListBytes writes a list of Linefix values to a byte slice. +func LinefixListBytes(buf []byte, list []Linefix) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// BadPictFormat is the error number for a BadPictFormat. +const BadPictFormat = 0 + +type PictFormatError struct { + Sequence uint16 + NiceName string +} + +// PictFormatErrorNew constructs a PictFormatError value that implements xgb.Error from a byte slice. +func PictFormatErrorNew(buf []byte) xgb.Error { + v := PictFormatError{} + v.NiceName = "PictFormat" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadPictFormat error. +// This is mostly used internally. +func (err PictFormatError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadPictFormat error. If no bad value exists, 0 is returned. +func (err PictFormatError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadPictFormat error. + +func (err PictFormatError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadPictFormat {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RENDER"][0] = PictFormatErrorNew +} + +// BadPictOp is the error number for a BadPictOp. +const BadPictOp = 2 + +type PictOpError struct { + Sequence uint16 + NiceName string +} + +// PictOpErrorNew constructs a PictOpError value that implements xgb.Error from a byte slice. +func PictOpErrorNew(buf []byte) xgb.Error { + v := PictOpError{} + v.NiceName = "PictOp" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadPictOp error. +// This is mostly used internally. +func (err PictOpError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadPictOp error. If no bad value exists, 0 is returned. +func (err PictOpError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadPictOp error. + +func (err PictOpError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadPictOp {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RENDER"][2] = PictOpErrorNew +} + +const ( + PictOpClear = 0 + PictOpSrc = 1 + PictOpDst = 2 + PictOpOver = 3 + PictOpOverReverse = 4 + PictOpIn = 5 + PictOpInReverse = 6 + PictOpOut = 7 + PictOpOutReverse = 8 + PictOpAtop = 9 + PictOpAtopReverse = 10 + PictOpXor = 11 + PictOpAdd = 12 + PictOpSaturate = 13 + PictOpDisjointClear = 16 + PictOpDisjointSrc = 17 + PictOpDisjointDst = 18 + PictOpDisjointOver = 19 + PictOpDisjointOverReverse = 20 + PictOpDisjointIn = 21 + PictOpDisjointInReverse = 22 + PictOpDisjointOut = 23 + PictOpDisjointOutReverse = 24 + PictOpDisjointAtop = 25 + PictOpDisjointAtopReverse = 26 + PictOpDisjointXor = 27 + PictOpConjointClear = 32 + PictOpConjointSrc = 33 + PictOpConjointDst = 34 + PictOpConjointOver = 35 + PictOpConjointOverReverse = 36 + PictOpConjointIn = 37 + PictOpConjointInReverse = 38 + PictOpConjointOut = 39 + PictOpConjointOutReverse = 40 + PictOpConjointAtop = 41 + PictOpConjointAtopReverse = 42 + PictOpConjointXor = 43 + PictOpMultiply = 48 + PictOpScreen = 49 + PictOpOverlay = 50 + PictOpDarken = 51 + PictOpLighten = 52 + PictOpColorDodge = 53 + PictOpColorBurn = 54 + PictOpHardLight = 55 + PictOpSoftLight = 56 + PictOpDifference = 57 + PictOpExclusion = 58 + PictOpHSLHue = 59 + PictOpHSLSaturation = 60 + PictOpHSLColor = 61 + PictOpHSLLuminosity = 62 +) + +const ( + PictTypeIndexed = 0 + PictTypeDirect = 1 +) + +type Pictdepth struct { + Depth byte + // padding: 1 bytes + NumVisuals uint16 + // padding: 4 bytes + Visuals []Pictvisual // size: xgb.Pad((int(NumVisuals) * 8)) +} + +// PictdepthRead reads a byte slice into a Pictdepth value. +func PictdepthRead(buf []byte, v *Pictdepth) int { + b := 0 + + v.Depth = buf[b] + b += 1 + + b += 1 // padding + + v.NumVisuals = xgb.Get16(buf[b:]) + b += 2 + + b += 4 // padding + + v.Visuals = make([]Pictvisual, v.NumVisuals) + b += PictvisualReadList(buf[b:], v.Visuals) + + return b +} + +// PictdepthReadList reads a byte slice into a list of Pictdepth values. +func PictdepthReadList(buf []byte, dest []Pictdepth) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Pictdepth{} + b += PictdepthRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Pictdepth value to a byte slice. +func (v Pictdepth) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumVisuals) * 8)))) + b := 0 + + buf[b] = v.Depth + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], v.NumVisuals) + b += 2 + + b += 4 // padding + + b += PictvisualListBytes(buf[b:], v.Visuals) + + return buf[:b] +} + +// PictdepthListBytes writes a list of Pictdepth values to a byte slice. +func PictdepthListBytes(buf []byte, list []Pictdepth) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// PictdepthListSize computes the size (bytes) of a list of Pictdepth values. +func PictdepthListSize(list []Pictdepth) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumVisuals) * 8))) + } + return size +} + +type Pictformat uint32 + +func NewPictformatId(c *xgb.Conn) (Pictformat, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Pictformat(id), nil +} + +type Pictforminfo struct { + Id Pictformat + Type byte + Depth byte + // padding: 2 bytes + Direct Directformat + Colormap xproto.Colormap +} + +// PictforminfoRead reads a byte slice into a Pictforminfo value. +func PictforminfoRead(buf []byte, v *Pictforminfo) int { + b := 0 + + v.Id = Pictformat(xgb.Get32(buf[b:])) + b += 4 + + v.Type = buf[b] + b += 1 + + v.Depth = buf[b] + b += 1 + + b += 2 // padding + + v.Direct = Directformat{} + b += DirectformatRead(buf[b:], &v.Direct) + + v.Colormap = xproto.Colormap(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// PictforminfoReadList reads a byte slice into a list of Pictforminfo values. +func PictforminfoReadList(buf []byte, dest []Pictforminfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Pictforminfo{} + b += PictforminfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Pictforminfo value to a byte slice. +func (v Pictforminfo) Bytes() []byte { + buf := make([]byte, 28) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Id)) + b += 4 + + buf[b] = v.Type + b += 1 + + buf[b] = v.Depth + b += 1 + + b += 2 // padding + + { + structBytes := v.Direct.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], uint32(v.Colormap)) + b += 4 + + return buf[:b] +} + +// PictforminfoListBytes writes a list of Pictforminfo values to a byte slice. +func PictforminfoListBytes(buf []byte, list []Pictforminfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Pictscreen struct { + NumDepths uint32 + Fallback Pictformat + Depths []Pictdepth // size: PictdepthListSize(Depths) +} + +// PictscreenRead reads a byte slice into a Pictscreen value. +func PictscreenRead(buf []byte, v *Pictscreen) int { + b := 0 + + v.NumDepths = xgb.Get32(buf[b:]) + b += 4 + + v.Fallback = Pictformat(xgb.Get32(buf[b:])) + b += 4 + + v.Depths = make([]Pictdepth, v.NumDepths) + b += PictdepthReadList(buf[b:], v.Depths) + + return b +} + +// PictscreenReadList reads a byte slice into a list of Pictscreen values. +func PictscreenReadList(buf []byte, dest []Pictscreen) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Pictscreen{} + b += PictscreenRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Pictscreen value to a byte slice. +func (v Pictscreen) Bytes() []byte { + buf := make([]byte, (8 + PictdepthListSize(v.Depths))) + b := 0 + + xgb.Put32(buf[b:], v.NumDepths) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Fallback)) + b += 4 + + b += PictdepthListBytes(buf[b:], v.Depths) + + return buf[:b] +} + +// PictscreenListBytes writes a list of Pictscreen values to a byte slice. +func PictscreenListBytes(buf []byte, list []Pictscreen) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// PictscreenListSize computes the size (bytes) of a list of Pictscreen values. +func PictscreenListSize(list []Pictscreen) int { + size := 0 + for _, item := range list { + size += (8 + PictdepthListSize(item.Depths)) + } + return size +} + +type Picture uint32 + +func NewPictureId(c *xgb.Conn) (Picture, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Picture(id), nil +} + +// BadPicture is the error number for a BadPicture. +const BadPicture = 1 + +type PictureError struct { + Sequence uint16 + NiceName string +} + +// PictureErrorNew constructs a PictureError value that implements xgb.Error from a byte slice. +func PictureErrorNew(buf []byte) xgb.Error { + v := PictureError{} + v.NiceName = "Picture" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadPicture error. +// This is mostly used internally. +func (err PictureError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadPicture error. If no bad value exists, 0 is returned. +func (err PictureError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadPicture error. + +func (err PictureError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadPicture {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RENDER"][1] = PictureErrorNew +} + +const ( + PictureNone = 0 +) + +type Pictvisual struct { + Visual xproto.Visualid + Format Pictformat +} + +// PictvisualRead reads a byte slice into a Pictvisual value. +func PictvisualRead(buf []byte, v *Pictvisual) int { + b := 0 + + v.Visual = xproto.Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.Format = Pictformat(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// PictvisualReadList reads a byte slice into a list of Pictvisual values. +func PictvisualReadList(buf []byte, dest []Pictvisual) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Pictvisual{} + b += PictvisualRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Pictvisual value to a byte slice. +func (v Pictvisual) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Visual)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Format)) + b += 4 + + return buf[:b] +} + +// PictvisualListBytes writes a list of Pictvisual values to a byte slice. +func PictvisualListBytes(buf []byte, list []Pictvisual) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Pointfix struct { + X Fixed + Y Fixed +} + +// PointfixRead reads a byte slice into a Pointfix value. +func PointfixRead(buf []byte, v *Pointfix) int { + b := 0 + + v.X = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Y = Fixed(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// PointfixReadList reads a byte slice into a list of Pointfix values. +func PointfixReadList(buf []byte, dest []Pointfix) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Pointfix{} + b += PointfixRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Pointfix value to a byte slice. +func (v Pointfix) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.X)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Y)) + b += 4 + + return buf[:b] +} + +// PointfixListBytes writes a list of Pointfix values to a byte slice. +func PointfixListBytes(buf []byte, list []Pointfix) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + PolyEdgeSharp = 0 + PolyEdgeSmooth = 1 +) + +const ( + PolyModePrecise = 0 + PolyModeImprecise = 1 +) + +const ( + RepeatNone = 0 + RepeatNormal = 1 + RepeatPad = 2 + RepeatReflect = 3 +) + +type Spanfix struct { + L Fixed + R Fixed + Y Fixed +} + +// SpanfixRead reads a byte slice into a Spanfix value. +func SpanfixRead(buf []byte, v *Spanfix) int { + b := 0 + + v.L = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.R = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Y = Fixed(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// SpanfixReadList reads a byte slice into a list of Spanfix values. +func SpanfixReadList(buf []byte, dest []Spanfix) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Spanfix{} + b += SpanfixRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Spanfix value to a byte slice. +func (v Spanfix) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put32(buf[b:], uint32(v.L)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.R)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Y)) + b += 4 + + return buf[:b] +} + +// SpanfixListBytes writes a list of Spanfix values to a byte slice. +func SpanfixListBytes(buf []byte, list []Spanfix) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + SubPixelUnknown = 0 + SubPixelHorizontalRGB = 1 + SubPixelHorizontalBGR = 2 + SubPixelVerticalRGB = 3 + SubPixelVerticalBGR = 4 + SubPixelNone = 5 +) + +type Transform struct { + Matrix11 Fixed + Matrix12 Fixed + Matrix13 Fixed + Matrix21 Fixed + Matrix22 Fixed + Matrix23 Fixed + Matrix31 Fixed + Matrix32 Fixed + Matrix33 Fixed +} + +// TransformRead reads a byte slice into a Transform value. +func TransformRead(buf []byte, v *Transform) int { + b := 0 + + v.Matrix11 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix12 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix13 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix21 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix22 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix23 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix31 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix32 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Matrix33 = Fixed(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// TransformReadList reads a byte slice into a list of Transform values. +func TransformReadList(buf []byte, dest []Transform) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Transform{} + b += TransformRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Transform value to a byte slice. +func (v Transform) Bytes() []byte { + buf := make([]byte, 36) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Matrix11)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix12)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix13)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix21)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix22)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix23)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix31)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix32)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Matrix33)) + b += 4 + + return buf[:b] +} + +// TransformListBytes writes a list of Transform values to a byte slice. +func TransformListBytes(buf []byte, list []Transform) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Trap struct { + Top Spanfix + Bot Spanfix +} + +// TrapRead reads a byte slice into a Trap value. +func TrapRead(buf []byte, v *Trap) int { + b := 0 + + v.Top = Spanfix{} + b += SpanfixRead(buf[b:], &v.Top) + + v.Bot = Spanfix{} + b += SpanfixRead(buf[b:], &v.Bot) + + return b +} + +// TrapReadList reads a byte slice into a list of Trap values. +func TrapReadList(buf []byte, dest []Trap) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Trap{} + b += TrapRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Trap value to a byte slice. +func (v Trap) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + { + structBytes := v.Top.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.Bot.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf[:b] +} + +// TrapListBytes writes a list of Trap values to a byte slice. +func TrapListBytes(buf []byte, list []Trap) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Trapezoid struct { + Top Fixed + Bottom Fixed + Left Linefix + Right Linefix +} + +// TrapezoidRead reads a byte slice into a Trapezoid value. +func TrapezoidRead(buf []byte, v *Trapezoid) int { + b := 0 + + v.Top = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Bottom = Fixed(xgb.Get32(buf[b:])) + b += 4 + + v.Left = Linefix{} + b += LinefixRead(buf[b:], &v.Left) + + v.Right = Linefix{} + b += LinefixRead(buf[b:], &v.Right) + + return b +} + +// TrapezoidReadList reads a byte slice into a list of Trapezoid values. +func TrapezoidReadList(buf []byte, dest []Trapezoid) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Trapezoid{} + b += TrapezoidRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Trapezoid value to a byte slice. +func (v Trapezoid) Bytes() []byte { + buf := make([]byte, 40) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Top)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Bottom)) + b += 4 + + { + structBytes := v.Left.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.Right.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf[:b] +} + +// TrapezoidListBytes writes a list of Trapezoid values to a byte slice. +func TrapezoidListBytes(buf []byte, list []Trapezoid) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Triangle struct { + P1 Pointfix + P2 Pointfix + P3 Pointfix +} + +// TriangleRead reads a byte slice into a Triangle value. +func TriangleRead(buf []byte, v *Triangle) int { + b := 0 + + v.P1 = Pointfix{} + b += PointfixRead(buf[b:], &v.P1) + + v.P2 = Pointfix{} + b += PointfixRead(buf[b:], &v.P2) + + v.P3 = Pointfix{} + b += PointfixRead(buf[b:], &v.P3) + + return b +} + +// TriangleReadList reads a byte slice into a list of Triangle values. +func TriangleReadList(buf []byte, dest []Triangle) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Triangle{} + b += TriangleRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Triangle value to a byte slice. +func (v Triangle) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + { + structBytes := v.P1.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.P2.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := v.P3.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf[:b] +} + +// TriangleListBytes writes a list of Triangle values to a byte slice. +func TriangleListBytes(buf []byte, list []Triangle) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AddGlyphsCookie is a cookie used only for AddGlyphs requests. +type AddGlyphsCookie struct { + *xgb.Cookie +} + +// AddGlyphs sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AddGlyphs(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids []uint32, Glyphs []Glyphinfo, Data []byte) AddGlyphsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'AddGlyphs' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(addGlyphsRequest(c, Glyphset, GlyphsLen, Glyphids, Glyphs, Data), cookie) + return AddGlyphsCookie{cookie} +} + +// AddGlyphsChecked sends a checked request. +// If an error occurs, it can be retrieved using AddGlyphsCookie.Check() +func AddGlyphsChecked(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids []uint32, Glyphs []Glyphinfo, Data []byte) AddGlyphsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'AddGlyphs' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(addGlyphsRequest(c, Glyphset, GlyphsLen, Glyphids, Glyphs, Data), cookie) + return AddGlyphsCookie{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 AddGlyphsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AddGlyphs +// addGlyphsRequest writes a AddGlyphs request to a byte slice. +func addGlyphsRequest(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids []uint32, Glyphs []Glyphinfo, Data []byte) []byte { + size := xgb.Pad((((12 + xgb.Pad((int(GlyphsLen) * 4))) + xgb.Pad((int(GlyphsLen) * 12))) + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // 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(Glyphset)) + b += 4 + + xgb.Put32(buf[b:], GlyphsLen) + b += 4 + + for i := 0; i < int(GlyphsLen); i++ { + xgb.Put32(buf[b:], Glyphids[i]) + b += 4 + } + + b += GlyphinfoListBytes(buf[b:], Glyphs) + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// AddTrapsCookie is a cookie used only for AddTraps requests. +type AddTrapsCookie struct { + *xgb.Cookie +} + +// AddTraps sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AddTraps(c *xgb.Conn, Picture Picture, XOff int16, YOff int16, Traps []Trap) AddTrapsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'AddTraps' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(addTrapsRequest(c, Picture, XOff, YOff, Traps), cookie) + return AddTrapsCookie{cookie} +} + +// AddTrapsChecked sends a checked request. +// If an error occurs, it can be retrieved using AddTrapsCookie.Check() +func AddTrapsChecked(c *xgb.Conn, Picture Picture, XOff int16, YOff int16, Traps []Trap) AddTrapsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'AddTraps' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(addTrapsRequest(c, Picture, XOff, YOff, Traps), cookie) + return AddTrapsCookie{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 AddTrapsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AddTraps +// addTrapsRequest writes a AddTraps request to a byte slice. +func addTrapsRequest(c *xgb.Conn, Picture Picture, XOff int16, YOff int16, Traps []Trap) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Traps) * 24)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 32 // 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(Picture)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOff)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOff)) + b += 2 + + b += TrapListBytes(buf[b:], Traps) + + return buf +} + +// ChangePictureCookie is a cookie used only for ChangePicture requests. +type ChangePictureCookie struct { + *xgb.Cookie +} + +// ChangePicture sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangePicture(c *xgb.Conn, Picture Picture, ValueMask uint32, ValueList []uint32) ChangePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'ChangePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changePictureRequest(c, Picture, ValueMask, ValueList), cookie) + return ChangePictureCookie{cookie} +} + +// ChangePictureChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangePictureCookie.Check() +func ChangePictureChecked(c *xgb.Conn, Picture Picture, ValueMask uint32, ValueList []uint32) ChangePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'ChangePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changePictureRequest(c, Picture, ValueMask, ValueList), cookie) + return ChangePictureCookie{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 ChangePictureCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangePicture +// changePictureRequest writes a ChangePicture request to a byte slice. +func changePictureRequest(c *xgb.Conn, Picture Picture, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Picture)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// CompositeCookie is a cookie used only for Composite requests. +type CompositeCookie struct { + *xgb.Cookie +} + +// Composite sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Composite(c *xgb.Conn, Op byte, Src Picture, Mask Picture, Dst Picture, SrcX int16, SrcY int16, MaskX int16, MaskY int16, DstX int16, DstY int16, Width uint16, Height uint16) CompositeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Composite' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(compositeRequest(c, Op, Src, Mask, Dst, SrcX, SrcY, MaskX, MaskY, DstX, DstY, Width, Height), cookie) + return CompositeCookie{cookie} +} + +// CompositeChecked sends a checked request. +// If an error occurs, it can be retrieved using CompositeCookie.Check() +func CompositeChecked(c *xgb.Conn, Op byte, Src Picture, Mask Picture, Dst Picture, SrcX int16, SrcY int16, MaskX int16, MaskY int16, DstX int16, DstY int16, Width uint16, Height uint16) CompositeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Composite' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(compositeRequest(c, Op, Src, Mask, Dst, SrcX, SrcY, MaskX, MaskY, DstX, DstY, Width, Height), cookie) + return CompositeCookie{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 CompositeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Composite +// compositeRequest writes a Composite request to a byte slice. +func compositeRequest(c *xgb.Conn, Op byte, Src Picture, Mask Picture, Dst Picture, SrcX int16, SrcY int16, MaskX int16, MaskY int16, DstX int16, DstY int16, Width uint16, Height uint16) []byte { + size := 36 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Mask)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], uint16(MaskX)) + b += 2 + + xgb.Put16(buf[b:], uint16(MaskY)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// CompositeGlyphs16Cookie is a cookie used only for CompositeGlyphs16 requests. +type CompositeGlyphs16Cookie struct { + *xgb.Cookie +} + +// CompositeGlyphs16 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CompositeGlyphs16(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs16Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs16' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(compositeGlyphs16Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs16Cookie{cookie} +} + +// CompositeGlyphs16Checked sends a checked request. +// If an error occurs, it can be retrieved using CompositeGlyphs16Cookie.Check() +func CompositeGlyphs16Checked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs16Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs16' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(compositeGlyphs16Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs16Cookie{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 CompositeGlyphs16Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CompositeGlyphs16 +// compositeGlyphs16Request writes a CompositeGlyphs16 request to a byte slice. +func compositeGlyphs16Request(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) []byte { + size := xgb.Pad((28 + xgb.Pad((len(Glyphcmds) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 24 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put32(buf[b:], uint32(Glyphset)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + copy(buf[b:], Glyphcmds[:len(Glyphcmds)]) + b += int(len(Glyphcmds)) + + return buf +} + +// CompositeGlyphs32Cookie is a cookie used only for CompositeGlyphs32 requests. +type CompositeGlyphs32Cookie struct { + *xgb.Cookie +} + +// CompositeGlyphs32 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CompositeGlyphs32(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs32Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs32' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(compositeGlyphs32Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs32Cookie{cookie} +} + +// CompositeGlyphs32Checked sends a checked request. +// If an error occurs, it can be retrieved using CompositeGlyphs32Cookie.Check() +func CompositeGlyphs32Checked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs32Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs32' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(compositeGlyphs32Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs32Cookie{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 CompositeGlyphs32Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CompositeGlyphs32 +// compositeGlyphs32Request writes a CompositeGlyphs32 request to a byte slice. +func compositeGlyphs32Request(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) []byte { + size := xgb.Pad((28 + xgb.Pad((len(Glyphcmds) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 25 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put32(buf[b:], uint32(Glyphset)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + copy(buf[b:], Glyphcmds[:len(Glyphcmds)]) + b += int(len(Glyphcmds)) + + return buf +} + +// CompositeGlyphs8Cookie is a cookie used only for CompositeGlyphs8 requests. +type CompositeGlyphs8Cookie struct { + *xgb.Cookie +} + +// CompositeGlyphs8 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CompositeGlyphs8(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs8Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs8' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(compositeGlyphs8Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs8Cookie{cookie} +} + +// CompositeGlyphs8Checked sends a checked request. +// If an error occurs, it can be retrieved using CompositeGlyphs8Cookie.Check() +func CompositeGlyphs8Checked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) CompositeGlyphs8Cookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CompositeGlyphs8' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(compositeGlyphs8Request(c, Op, Src, Dst, MaskFormat, Glyphset, SrcX, SrcY, Glyphcmds), cookie) + return CompositeGlyphs8Cookie{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 CompositeGlyphs8Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CompositeGlyphs8 +// compositeGlyphs8Request writes a CompositeGlyphs8 request to a byte slice. +func compositeGlyphs8Request(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, Glyphset Glyphset, SrcX int16, SrcY int16, Glyphcmds []byte) []byte { + size := xgb.Pad((28 + xgb.Pad((len(Glyphcmds) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 23 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put32(buf[b:], uint32(Glyphset)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + copy(buf[b:], Glyphcmds[:len(Glyphcmds)]) + b += int(len(Glyphcmds)) + + return buf +} + +// CreateAnimCursorCookie is a cookie used only for CreateAnimCursor requests. +type CreateAnimCursorCookie struct { + *xgb.Cookie +} + +// CreateAnimCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateAnimCursor(c *xgb.Conn, Cid xproto.Cursor, Cursors []Animcursorelt) CreateAnimCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateAnimCursor' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createAnimCursorRequest(c, Cid, Cursors), cookie) + return CreateAnimCursorCookie{cookie} +} + +// CreateAnimCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateAnimCursorCookie.Check() +func CreateAnimCursorChecked(c *xgb.Conn, Cid xproto.Cursor, Cursors []Animcursorelt) CreateAnimCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateAnimCursor' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createAnimCursorRequest(c, Cid, Cursors), cookie) + return CreateAnimCursorCookie{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 CreateAnimCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateAnimCursor +// createAnimCursorRequest writes a CreateAnimCursor request to a byte slice. +func createAnimCursorRequest(c *xgb.Conn, Cid xproto.Cursor, Cursors []Animcursorelt) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Cursors) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 31 // 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(Cid)) + b += 4 + + b += AnimcursoreltListBytes(buf[b:], Cursors) + + return buf +} + +// CreateConicalGradientCookie is a cookie used only for CreateConicalGradient requests. +type CreateConicalGradientCookie struct { + *xgb.Cookie +} + +// CreateConicalGradient sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateConicalGradient(c *xgb.Conn, Picture Picture, Center Pointfix, Angle Fixed, NumStops uint32, Stops []Fixed, Colors []Color) CreateConicalGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateConicalGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createConicalGradientRequest(c, Picture, Center, Angle, NumStops, Stops, Colors), cookie) + return CreateConicalGradientCookie{cookie} +} + +// CreateConicalGradientChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateConicalGradientCookie.Check() +func CreateConicalGradientChecked(c *xgb.Conn, Picture Picture, Center Pointfix, Angle Fixed, NumStops uint32, Stops []Fixed, Colors []Color) CreateConicalGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateConicalGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createConicalGradientRequest(c, Picture, Center, Angle, NumStops, Stops, Colors), cookie) + return CreateConicalGradientCookie{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 CreateConicalGradientCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateConicalGradient +// createConicalGradientRequest writes a CreateConicalGradient request to a byte slice. +func createConicalGradientRequest(c *xgb.Conn, Picture Picture, Center Pointfix, Angle Fixed, NumStops uint32, Stops []Fixed, Colors []Color) []byte { + size := xgb.Pad(((24 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 36 // 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(Picture)) + b += 4 + + { + structBytes := Center.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], uint32(Angle)) + b += 4 + + xgb.Put32(buf[b:], NumStops) + b += 4 + + for i := 0; i < int(NumStops); i++ { + xgb.Put32(buf[b:], uint32(Stops[i])) + b += 4 + } + + b += ColorListBytes(buf[b:], Colors) + + return buf +} + +// CreateCursorCookie is a cookie used only for CreateCursor requests. +type CreateCursorCookie struct { + *xgb.Cookie +} + +// CreateCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateCursor(c *xgb.Conn, Cid xproto.Cursor, Source Picture, X uint16, Y uint16) CreateCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateCursor' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createCursorRequest(c, Cid, Source, X, Y), cookie) + return CreateCursorCookie{cookie} +} + +// CreateCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateCursorCookie.Check() +func CreateCursorChecked(c *xgb.Conn, Cid xproto.Cursor, Source Picture, X uint16, Y uint16) CreateCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateCursor' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createCursorRequest(c, Cid, Source, X, Y), cookie) + return CreateCursorCookie{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 CreateCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateCursor +// createCursorRequest writes a CreateCursor request to a byte slice. +func createCursorRequest(c *xgb.Conn, Cid xproto.Cursor, Source Picture, X uint16, Y uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 27 // 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(Cid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Source)) + b += 4 + + xgb.Put16(buf[b:], X) + b += 2 + + xgb.Put16(buf[b:], Y) + b += 2 + + return buf +} + +// CreateGlyphSetCookie is a cookie used only for CreateGlyphSet requests. +type CreateGlyphSetCookie struct { + *xgb.Cookie +} + +// CreateGlyphSet sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateGlyphSet(c *xgb.Conn, Gsid Glyphset, Format Pictformat) CreateGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createGlyphSetRequest(c, Gsid, Format), cookie) + return CreateGlyphSetCookie{cookie} +} + +// CreateGlyphSetChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateGlyphSetCookie.Check() +func CreateGlyphSetChecked(c *xgb.Conn, Gsid Glyphset, Format Pictformat) CreateGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createGlyphSetRequest(c, Gsid, Format), cookie) + return CreateGlyphSetCookie{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 CreateGlyphSetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateGlyphSet +// createGlyphSetRequest writes a CreateGlyphSet request to a byte slice. +func createGlyphSetRequest(c *xgb.Conn, Gsid Glyphset, Format Pictformat) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // 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(Gsid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Format)) + b += 4 + + return buf +} + +// CreateLinearGradientCookie is a cookie used only for CreateLinearGradient requests. +type CreateLinearGradientCookie struct { + *xgb.Cookie +} + +// CreateLinearGradient sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateLinearGradient(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 Pointfix, NumStops uint32, Stops []Fixed, Colors []Color) CreateLinearGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateLinearGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createLinearGradientRequest(c, Picture, P1, P2, NumStops, Stops, Colors), cookie) + return CreateLinearGradientCookie{cookie} +} + +// CreateLinearGradientChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateLinearGradientCookie.Check() +func CreateLinearGradientChecked(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 Pointfix, NumStops uint32, Stops []Fixed, Colors []Color) CreateLinearGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateLinearGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createLinearGradientRequest(c, Picture, P1, P2, NumStops, Stops, Colors), cookie) + return CreateLinearGradientCookie{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 CreateLinearGradientCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateLinearGradient +// createLinearGradientRequest writes a CreateLinearGradient request to a byte slice. +func createLinearGradientRequest(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 Pointfix, NumStops uint32, Stops []Fixed, Colors []Color) []byte { + size := xgb.Pad(((28 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 34 // 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(Picture)) + b += 4 + + { + structBytes := P1.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := P2.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], NumStops) + b += 4 + + for i := 0; i < int(NumStops); i++ { + xgb.Put32(buf[b:], uint32(Stops[i])) + b += 4 + } + + b += ColorListBytes(buf[b:], Colors) + + return buf +} + +// CreatePictureCookie is a cookie used only for CreatePicture requests. +type CreatePictureCookie struct { + *xgb.Cookie +} + +// CreatePicture sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePicture(c *xgb.Conn, Pid Picture, Drawable xproto.Drawable, Format Pictformat, ValueMask uint32, ValueList []uint32) CreatePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreatePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createPictureRequest(c, Pid, Drawable, Format, ValueMask, ValueList), cookie) + return CreatePictureCookie{cookie} +} + +// CreatePictureChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePictureCookie.Check() +func CreatePictureChecked(c *xgb.Conn, Pid Picture, Drawable xproto.Drawable, Format Pictformat, ValueMask uint32, ValueList []uint32) CreatePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreatePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createPictureRequest(c, Pid, Drawable, Format, ValueMask, ValueList), cookie) + return CreatePictureCookie{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 CreatePictureCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePicture +// createPictureRequest writes a CreatePicture request to a byte slice. +func createPictureRequest(c *xgb.Conn, Pid Picture, Drawable xproto.Drawable, Format Pictformat, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((20 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Pid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Format)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// CreateRadialGradientCookie is a cookie used only for CreateRadialGradient requests. +type CreateRadialGradientCookie struct { + *xgb.Cookie +} + +// CreateRadialGradient sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRadialGradient(c *xgb.Conn, Picture Picture, Inner Pointfix, Outer Pointfix, InnerRadius Fixed, OuterRadius Fixed, NumStops uint32, Stops []Fixed, Colors []Color) CreateRadialGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateRadialGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRadialGradientRequest(c, Picture, Inner, Outer, InnerRadius, OuterRadius, NumStops, Stops, Colors), cookie) + return CreateRadialGradientCookie{cookie} +} + +// CreateRadialGradientChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRadialGradientCookie.Check() +func CreateRadialGradientChecked(c *xgb.Conn, Picture Picture, Inner Pointfix, Outer Pointfix, InnerRadius Fixed, OuterRadius Fixed, NumStops uint32, Stops []Fixed, Colors []Color) CreateRadialGradientCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateRadialGradient' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRadialGradientRequest(c, Picture, Inner, Outer, InnerRadius, OuterRadius, NumStops, Stops, Colors), cookie) + return CreateRadialGradientCookie{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 CreateRadialGradientCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRadialGradient +// createRadialGradientRequest writes a CreateRadialGradient request to a byte slice. +func createRadialGradientRequest(c *xgb.Conn, Picture Picture, Inner Pointfix, Outer Pointfix, InnerRadius Fixed, OuterRadius Fixed, NumStops uint32, Stops []Fixed, Colors []Color) []byte { + size := xgb.Pad(((36 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 35 // 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(Picture)) + b += 4 + + { + structBytes := Inner.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + { + structBytes := Outer.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], uint32(InnerRadius)) + b += 4 + + xgb.Put32(buf[b:], uint32(OuterRadius)) + b += 4 + + xgb.Put32(buf[b:], NumStops) + b += 4 + + for i := 0; i < int(NumStops); i++ { + xgb.Put32(buf[b:], uint32(Stops[i])) + b += 4 + } + + b += ColorListBytes(buf[b:], Colors) + + return buf +} + +// CreateSolidFillCookie is a cookie used only for CreateSolidFill requests. +type CreateSolidFillCookie struct { + *xgb.Cookie +} + +// CreateSolidFill sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateSolidFill(c *xgb.Conn, Picture Picture, Color Color) CreateSolidFillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateSolidFill' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createSolidFillRequest(c, Picture, Color), cookie) + return CreateSolidFillCookie{cookie} +} + +// CreateSolidFillChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateSolidFillCookie.Check() +func CreateSolidFillChecked(c *xgb.Conn, Picture Picture, Color Color) CreateSolidFillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'CreateSolidFill' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createSolidFillRequest(c, Picture, Color), cookie) + return CreateSolidFillCookie{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 CreateSolidFillCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateSolidFill +// createSolidFillRequest writes a CreateSolidFill request to a byte slice. +func createSolidFillRequest(c *xgb.Conn, Picture Picture, Color Color) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 33 // 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(Picture)) + b += 4 + + { + structBytes := Color.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf +} + +// FillRectanglesCookie is a cookie used only for FillRectangles requests. +type FillRectanglesCookie struct { + *xgb.Cookie +} + +// FillRectangles sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FillRectangles(c *xgb.Conn, Op byte, Dst Picture, Color Color, Rects []xproto.Rectangle) FillRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FillRectangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(fillRectanglesRequest(c, Op, Dst, Color, Rects), cookie) + return FillRectanglesCookie{cookie} +} + +// FillRectanglesChecked sends a checked request. +// If an error occurs, it can be retrieved using FillRectanglesCookie.Check() +func FillRectanglesChecked(c *xgb.Conn, Op byte, Dst Picture, Color Color, Rects []xproto.Rectangle) FillRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FillRectangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(fillRectanglesRequest(c, Op, Dst, Color, Rects), cookie) + return FillRectanglesCookie{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 FillRectanglesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FillRectangles +// fillRectanglesRequest writes a FillRectangles request to a byte slice. +func fillRectanglesRequest(c *xgb.Conn, Op byte, Dst Picture, Color Color, Rects []xproto.Rectangle) []byte { + size := xgb.Pad((20 + xgb.Pad((len(Rects) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 26 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + { + structBytes := Color.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + b += xproto.RectangleListBytes(buf[b:], Rects) + + return buf +} + +// FreeGlyphSetCookie is a cookie used only for FreeGlyphSet requests. +type FreeGlyphSetCookie struct { + *xgb.Cookie +} + +// FreeGlyphSet sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeGlyphSet(c *xgb.Conn, Glyphset Glyphset) FreeGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreeGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(freeGlyphSetRequest(c, Glyphset), cookie) + return FreeGlyphSetCookie{cookie} +} + +// FreeGlyphSetChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeGlyphSetCookie.Check() +func FreeGlyphSetChecked(c *xgb.Conn, Glyphset Glyphset) FreeGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreeGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(freeGlyphSetRequest(c, Glyphset), cookie) + return FreeGlyphSetCookie{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 FreeGlyphSetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeGlyphSet +// freeGlyphSetRequest writes a FreeGlyphSet request to a byte slice. +func freeGlyphSetRequest(c *xgb.Conn, Glyphset Glyphset) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Glyphset)) + b += 4 + + return buf +} + +// FreeGlyphsCookie is a cookie used only for FreeGlyphs requests. +type FreeGlyphsCookie struct { + *xgb.Cookie +} + +// FreeGlyphs sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeGlyphs(c *xgb.Conn, Glyphset Glyphset, Glyphs []Glyph) FreeGlyphsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreeGlyphs' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(freeGlyphsRequest(c, Glyphset, Glyphs), cookie) + return FreeGlyphsCookie{cookie} +} + +// FreeGlyphsChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeGlyphsCookie.Check() +func FreeGlyphsChecked(c *xgb.Conn, Glyphset Glyphset, Glyphs []Glyph) FreeGlyphsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreeGlyphs' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(freeGlyphsRequest(c, Glyphset, Glyphs), cookie) + return FreeGlyphsCookie{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 FreeGlyphsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeGlyphs +// freeGlyphsRequest writes a FreeGlyphs request to a byte slice. +func freeGlyphsRequest(c *xgb.Conn, Glyphset Glyphset, Glyphs []Glyph) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Glyphs) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // 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(Glyphset)) + b += 4 + + for i := 0; i < int(len(Glyphs)); i++ { + xgb.Put32(buf[b:], uint32(Glyphs[i])) + b += 4 + } + + return buf +} + +// FreePictureCookie is a cookie used only for FreePicture requests. +type FreePictureCookie struct { + *xgb.Cookie +} + +// FreePicture sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreePicture(c *xgb.Conn, Picture Picture) FreePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(freePictureRequest(c, Picture), cookie) + return FreePictureCookie{cookie} +} + +// FreePictureChecked sends a checked request. +// If an error occurs, it can be retrieved using FreePictureCookie.Check() +func FreePictureChecked(c *xgb.Conn, Picture Picture) FreePictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'FreePicture' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(freePictureRequest(c, Picture), cookie) + return FreePictureCookie{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 FreePictureCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreePicture +// freePictureRequest writes a FreePicture request to a byte slice. +func freePictureRequest(c *xgb.Conn, Picture Picture) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Picture)) + b += 4 + + return buf +} + +// QueryFiltersCookie is a cookie used only for QueryFilters requests. +type QueryFiltersCookie struct { + *xgb.Cookie +} + +// QueryFilters sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryFiltersCookie.Reply() +func QueryFilters(c *xgb.Conn, Drawable xproto.Drawable) QueryFiltersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryFilters' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryFiltersRequest(c, Drawable), cookie) + return QueryFiltersCookie{cookie} +} + +// QueryFiltersUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryFiltersUnchecked(c *xgb.Conn, Drawable xproto.Drawable) QueryFiltersCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryFilters' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryFiltersRequest(c, Drawable), cookie) + return QueryFiltersCookie{cookie} +} + +// QueryFiltersReply represents the data returned from a QueryFilters request. +type QueryFiltersReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAliases uint32 + NumFilters uint32 + // padding: 16 bytes + Aliases []uint16 // size: xgb.Pad((int(NumAliases) * 2)) + Filters []xproto.Str // size: xproto.StrListSize(Filters) +} + +// Reply blocks and returns the reply data for a QueryFilters request. +func (cook QueryFiltersCookie) Reply() (*QueryFiltersReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryFiltersReply(buf), nil +} + +// queryFiltersReply reads a byte slice into a QueryFiltersReply value. +func queryFiltersReply(buf []byte) *QueryFiltersReply { + v := new(QueryFiltersReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAliases = xgb.Get32(buf[b:]) + b += 4 + + v.NumFilters = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.Aliases = make([]uint16, v.NumAliases) + for i := 0; i < int(v.NumAliases); i++ { + v.Aliases[i] = xgb.Get16(buf[b:]) + b += 2 + } + + v.Filters = make([]xproto.Str, v.NumFilters) + b += xproto.StrReadList(buf[b:], v.Filters) + + return v +} + +// Write request to wire for QueryFilters +// queryFiltersRequest writes a QueryFilters request to a byte slice. +func queryFiltersRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 29 // 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(Drawable)) + b += 4 + + return buf +} + +// QueryPictFormatsCookie is a cookie used only for QueryPictFormats requests. +type QueryPictFormatsCookie struct { + *xgb.Cookie +} + +// QueryPictFormats sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryPictFormatsCookie.Reply() +func QueryPictFormats(c *xgb.Conn) QueryPictFormatsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryPictFormats' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryPictFormatsRequest(c), cookie) + return QueryPictFormatsCookie{cookie} +} + +// QueryPictFormatsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryPictFormatsUnchecked(c *xgb.Conn) QueryPictFormatsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryPictFormats' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryPictFormatsRequest(c), cookie) + return QueryPictFormatsCookie{cookie} +} + +// QueryPictFormatsReply represents the data returned from a QueryPictFormats request. +type QueryPictFormatsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumFormats uint32 + NumScreens uint32 + NumDepths uint32 + NumVisuals uint32 + NumSubpixel uint32 + // padding: 4 bytes + Formats []Pictforminfo // size: xgb.Pad((int(NumFormats) * 28)) + Screens []Pictscreen // size: PictscreenListSize(Screens) + Subpixels []uint32 // size: xgb.Pad((int(NumSubpixel) * 4)) +} + +// Reply blocks and returns the reply data for a QueryPictFormats request. +func (cook QueryPictFormatsCookie) Reply() (*QueryPictFormatsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryPictFormatsReply(buf), nil +} + +// queryPictFormatsReply reads a byte slice into a QueryPictFormatsReply value. +func queryPictFormatsReply(buf []byte) *QueryPictFormatsReply { + v := new(QueryPictFormatsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumFormats = xgb.Get32(buf[b:]) + b += 4 + + v.NumScreens = xgb.Get32(buf[b:]) + b += 4 + + v.NumDepths = xgb.Get32(buf[b:]) + b += 4 + + v.NumVisuals = xgb.Get32(buf[b:]) + b += 4 + + v.NumSubpixel = xgb.Get32(buf[b:]) + b += 4 + + b += 4 // padding + + v.Formats = make([]Pictforminfo, v.NumFormats) + b += PictforminfoReadList(buf[b:], v.Formats) + + v.Screens = make([]Pictscreen, v.NumScreens) + b += PictscreenReadList(buf[b:], v.Screens) + + v.Subpixels = make([]uint32, v.NumSubpixel) + for i := 0; i < int(v.NumSubpixel); i++ { + v.Subpixels[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for QueryPictFormats +// queryPictFormatsRequest writes a QueryPictFormats request to a byte slice. +func queryPictFormatsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// QueryPictIndexValuesCookie is a cookie used only for QueryPictIndexValues requests. +type QueryPictIndexValuesCookie struct { + *xgb.Cookie +} + +// QueryPictIndexValues sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryPictIndexValuesCookie.Reply() +func QueryPictIndexValues(c *xgb.Conn, Format Pictformat) QueryPictIndexValuesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryPictIndexValues' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryPictIndexValuesRequest(c, Format), cookie) + return QueryPictIndexValuesCookie{cookie} +} + +// QueryPictIndexValuesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryPictIndexValuesUnchecked(c *xgb.Conn, Format Pictformat) QueryPictIndexValuesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryPictIndexValues' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryPictIndexValuesRequest(c, Format), cookie) + return QueryPictIndexValuesCookie{cookie} +} + +// QueryPictIndexValuesReply represents the data returned from a QueryPictIndexValues request. +type QueryPictIndexValuesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumValues uint32 + // padding: 20 bytes + Values []Indexvalue // size: xgb.Pad((int(NumValues) * 12)) +} + +// Reply blocks and returns the reply data for a QueryPictIndexValues request. +func (cook QueryPictIndexValuesCookie) Reply() (*QueryPictIndexValuesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryPictIndexValuesReply(buf), nil +} + +// queryPictIndexValuesReply reads a byte slice into a QueryPictIndexValuesReply value. +func queryPictIndexValuesReply(buf []byte) *QueryPictIndexValuesReply { + v := new(QueryPictIndexValuesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumValues = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Values = make([]Indexvalue, v.NumValues) + b += IndexvalueReadList(buf[b:], v.Values) + + return v +} + +// Write request to wire for QueryPictIndexValues +// queryPictIndexValuesRequest writes a QueryPictIndexValues request to a byte slice. +func queryPictIndexValuesRequest(c *xgb.Conn, Format Pictformat) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Format)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], ClientMajorVersion) + b += 4 + + xgb.Put32(buf[b:], ClientMinorVersion) + b += 4 + + return buf +} + +// ReferenceGlyphSetCookie is a cookie used only for ReferenceGlyphSet requests. +type ReferenceGlyphSetCookie struct { + *xgb.Cookie +} + +// ReferenceGlyphSet sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ReferenceGlyphSet(c *xgb.Conn, Gsid Glyphset, Existing Glyphset) ReferenceGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'ReferenceGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(referenceGlyphSetRequest(c, Gsid, Existing), cookie) + return ReferenceGlyphSetCookie{cookie} +} + +// ReferenceGlyphSetChecked sends a checked request. +// If an error occurs, it can be retrieved using ReferenceGlyphSetCookie.Check() +func ReferenceGlyphSetChecked(c *xgb.Conn, Gsid Glyphset, Existing Glyphset) ReferenceGlyphSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'ReferenceGlyphSet' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(referenceGlyphSetRequest(c, Gsid, Existing), cookie) + return ReferenceGlyphSetCookie{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 ReferenceGlyphSetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ReferenceGlyphSet +// referenceGlyphSetRequest writes a ReferenceGlyphSet request to a byte slice. +func referenceGlyphSetRequest(c *xgb.Conn, Gsid Glyphset, Existing Glyphset) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // 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(Gsid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Existing)) + b += 4 + + return buf +} + +// SetPictureClipRectanglesCookie is a cookie used only for SetPictureClipRectangles requests. +type SetPictureClipRectanglesCookie struct { + *xgb.Cookie +} + +// SetPictureClipRectangles sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPictureClipRectangles(c *xgb.Conn, Picture Picture, ClipXOrigin int16, ClipYOrigin int16, Rectangles []xproto.Rectangle) SetPictureClipRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureClipRectangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPictureClipRectanglesRequest(c, Picture, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetPictureClipRectanglesCookie{cookie} +} + +// SetPictureClipRectanglesChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPictureClipRectanglesCookie.Check() +func SetPictureClipRectanglesChecked(c *xgb.Conn, Picture Picture, ClipXOrigin int16, ClipYOrigin int16, Rectangles []xproto.Rectangle) SetPictureClipRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureClipRectangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPictureClipRectanglesRequest(c, Picture, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetPictureClipRectanglesCookie{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 SetPictureClipRectanglesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPictureClipRectangles +// setPictureClipRectanglesRequest writes a SetPictureClipRectangles request to a byte slice. +func setPictureClipRectanglesRequest(c *xgb.Conn, Picture Picture, ClipXOrigin int16, ClipYOrigin int16, Rectangles []xproto.Rectangle) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Picture)) + b += 4 + + xgb.Put16(buf[b:], uint16(ClipXOrigin)) + b += 2 + + xgb.Put16(buf[b:], uint16(ClipYOrigin)) + b += 2 + + b += xproto.RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// SetPictureFilterCookie is a cookie used only for SetPictureFilter requests. +type SetPictureFilterCookie struct { + *xgb.Cookie +} + +// SetPictureFilter sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPictureFilter(c *xgb.Conn, Picture Picture, FilterLen uint16, Filter string, Values []Fixed) SetPictureFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureFilter' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPictureFilterRequest(c, Picture, FilterLen, Filter, Values), cookie) + return SetPictureFilterCookie{cookie} +} + +// SetPictureFilterChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPictureFilterCookie.Check() +func SetPictureFilterChecked(c *xgb.Conn, Picture Picture, FilterLen uint16, Filter string, Values []Fixed) SetPictureFilterCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureFilter' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPictureFilterRequest(c, Picture, FilterLen, Filter, Values), cookie) + return SetPictureFilterCookie{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 SetPictureFilterCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPictureFilter +// setPictureFilterRequest writes a SetPictureFilter request to a byte slice. +func setPictureFilterRequest(c *xgb.Conn, Picture Picture, FilterLen uint16, Filter string, Values []Fixed) []byte { + size := xgb.Pad((((12 + xgb.Pad((int(FilterLen) * 1))) + 4) + xgb.Pad((len(Values) * 4)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 30 // request opcode + b += 1 + + blen := b + b += 2 + + xgb.Put32(buf[b:], uint32(Picture)) + b += 4 + + xgb.Put16(buf[b:], FilterLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Filter[:FilterLen]) + b += int(FilterLen) + + b = (b + 3) & ^3 // alignment gap + + for i := 0; i < int(len(Values)); i++ { + xgb.Put32(buf[b:], uint32(Values[i])) + b += 4 + } + + b = xgb.Pad(b) + xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units + return buf[:b] +} + +// SetPictureTransformCookie is a cookie used only for SetPictureTransform requests. +type SetPictureTransformCookie struct { + *xgb.Cookie +} + +// SetPictureTransform sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPictureTransform(c *xgb.Conn, Picture Picture, Transform Transform) SetPictureTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureTransform' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPictureTransformRequest(c, Picture, Transform), cookie) + return SetPictureTransformCookie{cookie} +} + +// SetPictureTransformChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPictureTransformCookie.Check() +func SetPictureTransformChecked(c *xgb.Conn, Picture Picture, Transform Transform) SetPictureTransformCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'SetPictureTransform' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPictureTransformRequest(c, Picture, Transform), cookie) + return SetPictureTransformCookie{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 SetPictureTransformCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPictureTransform +// setPictureTransformRequest writes a SetPictureTransform request to a byte slice. +func setPictureTransformRequest(c *xgb.Conn, Picture Picture, Transform Transform) []byte { + size := 44 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 28 // 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(Picture)) + b += 4 + + { + structBytes := Transform.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf +} + +// TrapezoidsCookie is a cookie used only for Trapezoids requests. +type TrapezoidsCookie struct { + *xgb.Cookie +} + +// Trapezoids sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Trapezoids(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Traps []Trapezoid) TrapezoidsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Trapezoids' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(trapezoidsRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Traps), cookie) + return TrapezoidsCookie{cookie} +} + +// TrapezoidsChecked sends a checked request. +// If an error occurs, it can be retrieved using TrapezoidsCookie.Check() +func TrapezoidsChecked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Traps []Trapezoid) TrapezoidsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Trapezoids' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(trapezoidsRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Traps), cookie) + return TrapezoidsCookie{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 TrapezoidsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Trapezoids +// trapezoidsRequest writes a Trapezoids request to a byte slice. +func trapezoidsRequest(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Traps []Trapezoid) []byte { + size := xgb.Pad((24 + xgb.Pad((len(Traps) * 40)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + b += TrapezoidListBytes(buf[b:], Traps) + + return buf +} + +// TriFanCookie is a cookie used only for TriFan requests. +type TriFanCookie struct { + *xgb.Cookie +} + +// TriFan sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func TriFan(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) TriFanCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'TriFan' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(triFanRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Points), cookie) + return TriFanCookie{cookie} +} + +// TriFanChecked sends a checked request. +// If an error occurs, it can be retrieved using TriFanCookie.Check() +func TriFanChecked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) TriFanCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'TriFan' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(triFanRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Points), cookie) + return TriFanCookie{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 TriFanCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for TriFan +// triFanRequest writes a TriFan request to a byte slice. +func triFanRequest(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) []byte { + size := xgb.Pad((24 + xgb.Pad((len(Points) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + b += PointfixListBytes(buf[b:], Points) + + return buf +} + +// TriStripCookie is a cookie used only for TriStrip requests. +type TriStripCookie struct { + *xgb.Cookie +} + +// TriStrip sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func TriStrip(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) TriStripCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'TriStrip' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(triStripRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Points), cookie) + return TriStripCookie{cookie} +} + +// TriStripChecked sends a checked request. +// If an error occurs, it can be retrieved using TriStripCookie.Check() +func TriStripChecked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) TriStripCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'TriStrip' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(triStripRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Points), cookie) + return TriStripCookie{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 TriStripCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for TriStrip +// triStripRequest writes a TriStrip request to a byte slice. +func triStripRequest(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Points []Pointfix) []byte { + size := xgb.Pad((24 + xgb.Pad((len(Points) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + b += PointfixListBytes(buf[b:], Points) + + return buf +} + +// TrianglesCookie is a cookie used only for Triangles requests. +type TrianglesCookie struct { + *xgb.Cookie +} + +// Triangles sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Triangles(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Triangles []Triangle) TrianglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Triangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(trianglesRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Triangles), cookie) + return TrianglesCookie{cookie} +} + +// TrianglesChecked sends a checked request. +// If an error occurs, it can be retrieved using TrianglesCookie.Check() +func TrianglesChecked(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Triangles []Triangle) TrianglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RENDER"]; !ok { + panic("Cannot issue request 'Triangles' using the uninitialized extension 'RENDER'. render.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(trianglesRequest(c, Op, Src, Dst, MaskFormat, SrcX, SrcY, Triangles), cookie) + return TrianglesCookie{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 TrianglesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Triangles +// trianglesRequest writes a Triangles request to a byte slice. +func trianglesRequest(c *xgb.Conn, Op byte, Src Picture, Dst Picture, MaskFormat Pictformat, SrcX int16, SrcY int16, Triangles []Triangle) []byte { + size := xgb.Pad((24 + xgb.Pad((len(Triangles) * 24)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RENDER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Op + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Src)) + b += 4 + + xgb.Put32(buf[b:], uint32(Dst)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFormat)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + b += TriangleListBytes(buf[b:], Triangles) + + return buf +} diff --git a/nexgb/res/res.go b/nexgb/res/res.go new file mode 100644 index 0000000..0ad0389 --- /dev/null +++ b/nexgb/res/res.go @@ -0,0 +1,1110 @@ +// Package res is the X client API for the X-Resource extension. +package res + +// This file is automatically generated from res.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the X-Resource extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 10, "X-Resource").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named X-Resource could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["X-Resource"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["X-Resource"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["X-Resource"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["X-Resource"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["X-Resource"] = make(map[int]xgb.NewErrorFun) +} + +type Client struct { + ResourceBase uint32 + ResourceMask uint32 +} + +// ClientRead reads a byte slice into a Client value. +func ClientRead(buf []byte, v *Client) int { + b := 0 + + v.ResourceBase = xgb.Get32(buf[b:]) + b += 4 + + v.ResourceMask = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ClientReadList reads a byte slice into a list of Client values. +func ClientReadList(buf []byte, dest []Client) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Client{} + b += ClientRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Client value to a byte slice. +func (v Client) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], v.ResourceBase) + b += 4 + + xgb.Put32(buf[b:], v.ResourceMask) + b += 4 + + return buf[:b] +} + +// ClientListBytes writes a list of Client values to a byte slice. +func ClientListBytes(buf []byte, list []Client) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + ClientIdMaskClientXID = 1 + ClientIdMaskLocalClientPID = 2 +) + +type ClientIdSpec struct { + Client uint32 + Mask uint32 +} + +// ClientIdSpecRead reads a byte slice into a ClientIdSpec value. +func ClientIdSpecRead(buf []byte, v *ClientIdSpec) int { + b := 0 + + v.Client = xgb.Get32(buf[b:]) + b += 4 + + v.Mask = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ClientIdSpecReadList reads a byte slice into a list of ClientIdSpec values. +func ClientIdSpecReadList(buf []byte, dest []ClientIdSpec) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ClientIdSpec{} + b += ClientIdSpecRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ClientIdSpec value to a byte slice. +func (v ClientIdSpec) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], v.Client) + b += 4 + + xgb.Put32(buf[b:], v.Mask) + b += 4 + + return buf[:b] +} + +// ClientIdSpecListBytes writes a list of ClientIdSpec values to a byte slice. +func ClientIdSpecListBytes(buf []byte, list []ClientIdSpec) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type ClientIdValue struct { + Spec ClientIdSpec + Length uint32 + Value []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// ClientIdValueRead reads a byte slice into a ClientIdValue value. +func ClientIdValueRead(buf []byte, v *ClientIdValue) int { + b := 0 + + v.Spec = ClientIdSpec{} + b += ClientIdSpecRead(buf[b:], &v.Spec) + + v.Length = xgb.Get32(buf[b:]) + b += 4 + + v.Value = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.Value[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return b +} + +// ClientIdValueReadList reads a byte slice into a list of ClientIdValue values. +func ClientIdValueReadList(buf []byte, dest []ClientIdValue) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ClientIdValue{} + b += ClientIdValueRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ClientIdValue value to a byte slice. +func (v ClientIdValue) Bytes() []byte { + buf := make([]byte, (12 + xgb.Pad((int(v.Length) * 4)))) + b := 0 + + { + structBytes := v.Spec.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], v.Length) + b += 4 + + for i := 0; i < int(v.Length); i++ { + xgb.Put32(buf[b:], v.Value[i]) + b += 4 + } + + return buf[:b] +} + +// ClientIdValueListBytes writes a list of ClientIdValue values to a byte slice. +func ClientIdValueListBytes(buf []byte, list []ClientIdValue) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ClientIdValueListSize computes the size (bytes) of a list of ClientIdValue values. +func ClientIdValueListSize(list []ClientIdValue) int { + size := 0 + for _, item := range list { + size += (12 + xgb.Pad((int(item.Length) * 4))) + } + return size +} + +type ResourceIdSpec struct { + Resource uint32 + Type uint32 +} + +// ResourceIdSpecRead reads a byte slice into a ResourceIdSpec value. +func ResourceIdSpecRead(buf []byte, v *ResourceIdSpec) int { + b := 0 + + v.Resource = xgb.Get32(buf[b:]) + b += 4 + + v.Type = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ResourceIdSpecReadList reads a byte slice into a list of ResourceIdSpec values. +func ResourceIdSpecReadList(buf []byte, dest []ResourceIdSpec) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ResourceIdSpec{} + b += ResourceIdSpecRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ResourceIdSpec value to a byte slice. +func (v ResourceIdSpec) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], v.Resource) + b += 4 + + xgb.Put32(buf[b:], v.Type) + b += 4 + + return buf[:b] +} + +// ResourceIdSpecListBytes writes a list of ResourceIdSpec values to a byte slice. +func ResourceIdSpecListBytes(buf []byte, list []ResourceIdSpec) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type ResourceSizeSpec struct { + Spec ResourceIdSpec + Bytes_ uint32 + RefCount uint32 + UseCount uint32 +} + +// ResourceSizeSpecRead reads a byte slice into a ResourceSizeSpec value. +func ResourceSizeSpecRead(buf []byte, v *ResourceSizeSpec) int { + b := 0 + + v.Spec = ResourceIdSpec{} + b += ResourceIdSpecRead(buf[b:], &v.Spec) + + v.Bytes_ = xgb.Get32(buf[b:]) + b += 4 + + v.RefCount = xgb.Get32(buf[b:]) + b += 4 + + v.UseCount = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ResourceSizeSpecReadList reads a byte slice into a list of ResourceSizeSpec values. +func ResourceSizeSpecReadList(buf []byte, dest []ResourceSizeSpec) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ResourceSizeSpec{} + b += ResourceSizeSpecRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ResourceSizeSpec value to a byte slice. +func (v ResourceSizeSpec) Bytes() []byte { + buf := make([]byte, 20) + b := 0 + + { + structBytes := v.Spec.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], v.Bytes_) + b += 4 + + xgb.Put32(buf[b:], v.RefCount) + b += 4 + + xgb.Put32(buf[b:], v.UseCount) + b += 4 + + return buf[:b] +} + +// ResourceSizeSpecListBytes writes a list of ResourceSizeSpec values to a byte slice. +func ResourceSizeSpecListBytes(buf []byte, list []ResourceSizeSpec) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type ResourceSizeValue struct { + Size ResourceSizeSpec + NumCrossReferences uint32 + CrossReferences []ResourceSizeSpec // size: xgb.Pad((int(NumCrossReferences) * 20)) +} + +// ResourceSizeValueRead reads a byte slice into a ResourceSizeValue value. +func ResourceSizeValueRead(buf []byte, v *ResourceSizeValue) int { + b := 0 + + v.Size = ResourceSizeSpec{} + b += ResourceSizeSpecRead(buf[b:], &v.Size) + + v.NumCrossReferences = xgb.Get32(buf[b:]) + b += 4 + + v.CrossReferences = make([]ResourceSizeSpec, v.NumCrossReferences) + b += ResourceSizeSpecReadList(buf[b:], v.CrossReferences) + + return b +} + +// ResourceSizeValueReadList reads a byte slice into a list of ResourceSizeValue values. +func ResourceSizeValueReadList(buf []byte, dest []ResourceSizeValue) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ResourceSizeValue{} + b += ResourceSizeValueRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ResourceSizeValue value to a byte slice. +func (v ResourceSizeValue) Bytes() []byte { + buf := make([]byte, (24 + xgb.Pad((int(v.NumCrossReferences) * 20)))) + b := 0 + + { + structBytes := v.Size.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], v.NumCrossReferences) + b += 4 + + b += ResourceSizeSpecListBytes(buf[b:], v.CrossReferences) + + return buf[:b] +} + +// ResourceSizeValueListBytes writes a list of ResourceSizeValue values to a byte slice. +func ResourceSizeValueListBytes(buf []byte, list []ResourceSizeValue) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ResourceSizeValueListSize computes the size (bytes) of a list of ResourceSizeValue values. +func ResourceSizeValueListSize(list []ResourceSizeValue) int { + size := 0 + for _, item := range list { + size += (24 + xgb.Pad((int(item.NumCrossReferences) * 20))) + } + return size +} + +type Type struct { + ResourceType xproto.Atom + Count uint32 +} + +// TypeRead reads a byte slice into a Type value. +func TypeRead(buf []byte, v *Type) int { + b := 0 + + v.ResourceType = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Count = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// TypeReadList reads a byte slice into a list of Type values. +func TypeReadList(buf []byte, dest []Type) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Type{} + b += TypeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Type value to a byte slice. +func (v Type) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.ResourceType)) + b += 4 + + xgb.Put32(buf[b:], v.Count) + b += 4 + + return buf[:b] +} + +// TypeListBytes writes a list of Type values to a byte slice. +func TypeListBytes(buf []byte, list []Type) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// QueryClientIdsCookie is a cookie used only for QueryClientIds requests. +type QueryClientIdsCookie struct { + *xgb.Cookie +} + +// QueryClientIds sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryClientIdsCookie.Reply() +func QueryClientIds(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) QueryClientIdsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientIds' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryClientIdsRequest(c, NumSpecs, Specs), cookie) + return QueryClientIdsCookie{cookie} +} + +// QueryClientIdsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryClientIdsUnchecked(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) QueryClientIdsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientIds' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryClientIdsRequest(c, NumSpecs, Specs), cookie) + return QueryClientIdsCookie{cookie} +} + +// QueryClientIdsReply represents the data returned from a QueryClientIds request. +type QueryClientIdsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumIds uint32 + // padding: 20 bytes + Ids []ClientIdValue // size: ClientIdValueListSize(Ids) +} + +// Reply blocks and returns the reply data for a QueryClientIds request. +func (cook QueryClientIdsCookie) Reply() (*QueryClientIdsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryClientIdsReply(buf), nil +} + +// queryClientIdsReply reads a byte slice into a QueryClientIdsReply value. +func queryClientIdsReply(buf []byte) *QueryClientIdsReply { + v := new(QueryClientIdsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumIds = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Ids = make([]ClientIdValue, v.NumIds) + b += ClientIdValueReadList(buf[b:], v.Ids) + + return v +} + +// Write request to wire for QueryClientIds +// queryClientIdsRequest writes a QueryClientIds request to a byte slice. +func queryClientIdsRequest(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) []byte { + size := xgb.Pad((8 + xgb.Pad((int(NumSpecs) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], NumSpecs) + b += 4 + + b += ClientIdSpecListBytes(buf[b:], Specs) + + return buf +} + +// QueryClientPixmapBytesCookie is a cookie used only for QueryClientPixmapBytes requests. +type QueryClientPixmapBytesCookie struct { + *xgb.Cookie +} + +// QueryClientPixmapBytes sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryClientPixmapBytesCookie.Reply() +func QueryClientPixmapBytes(c *xgb.Conn, Xid uint32) QueryClientPixmapBytesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientPixmapBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryClientPixmapBytesRequest(c, Xid), cookie) + return QueryClientPixmapBytesCookie{cookie} +} + +// QueryClientPixmapBytesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryClientPixmapBytesUnchecked(c *xgb.Conn, Xid uint32) QueryClientPixmapBytesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientPixmapBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryClientPixmapBytesRequest(c, Xid), cookie) + return QueryClientPixmapBytesCookie{cookie} +} + +// QueryClientPixmapBytesReply represents the data returned from a QueryClientPixmapBytes request. +type QueryClientPixmapBytesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Bytes_ uint32 + BytesOverflow uint32 +} + +// Reply blocks and returns the reply data for a QueryClientPixmapBytes request. +func (cook QueryClientPixmapBytesCookie) Reply() (*QueryClientPixmapBytesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryClientPixmapBytesReply(buf), nil +} + +// queryClientPixmapBytesReply reads a byte slice into a QueryClientPixmapBytesReply value. +func queryClientPixmapBytesReply(buf []byte) *QueryClientPixmapBytesReply { + v := new(QueryClientPixmapBytesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Bytes_ = xgb.Get32(buf[b:]) + b += 4 + + v.BytesOverflow = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for QueryClientPixmapBytes +// queryClientPixmapBytesRequest writes a QueryClientPixmapBytes request to a byte slice. +func queryClientPixmapBytesRequest(c *xgb.Conn, Xid uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Xid) + b += 4 + + return buf +} + +// QueryClientResourcesCookie is a cookie used only for QueryClientResources requests. +type QueryClientResourcesCookie struct { + *xgb.Cookie +} + +// QueryClientResources sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryClientResourcesCookie.Reply() +func QueryClientResources(c *xgb.Conn, Xid uint32) QueryClientResourcesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientResources' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryClientResourcesRequest(c, Xid), cookie) + return QueryClientResourcesCookie{cookie} +} + +// QueryClientResourcesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryClientResourcesUnchecked(c *xgb.Conn, Xid uint32) QueryClientResourcesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClientResources' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryClientResourcesRequest(c, Xid), cookie) + return QueryClientResourcesCookie{cookie} +} + +// QueryClientResourcesReply represents the data returned from a QueryClientResources request. +type QueryClientResourcesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumTypes uint32 + // padding: 20 bytes + Types []Type // size: xgb.Pad((int(NumTypes) * 8)) +} + +// Reply blocks and returns the reply data for a QueryClientResources request. +func (cook QueryClientResourcesCookie) Reply() (*QueryClientResourcesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryClientResourcesReply(buf), nil +} + +// queryClientResourcesReply reads a byte slice into a QueryClientResourcesReply value. +func queryClientResourcesReply(buf []byte) *QueryClientResourcesReply { + v := new(QueryClientResourcesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumTypes = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Types = make([]Type, v.NumTypes) + b += TypeReadList(buf[b:], v.Types) + + return v +} + +// Write request to wire for QueryClientResources +// queryClientResourcesRequest writes a QueryClientResources request to a byte slice. +func queryClientResourcesRequest(c *xgb.Conn, Xid uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Xid) + b += 4 + + return buf +} + +// QueryClientsCookie is a cookie used only for QueryClients requests. +type QueryClientsCookie struct { + *xgb.Cookie +} + +// QueryClients sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryClientsCookie.Reply() +func QueryClients(c *xgb.Conn) QueryClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClients' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryClientsRequest(c), cookie) + return QueryClientsCookie{cookie} +} + +// QueryClientsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryClientsUnchecked(c *xgb.Conn) QueryClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryClients' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryClientsRequest(c), cookie) + return QueryClientsCookie{cookie} +} + +// QueryClientsReply represents the data returned from a QueryClients request. +type QueryClientsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumClients uint32 + // padding: 20 bytes + Clients []Client // size: xgb.Pad((int(NumClients) * 8)) +} + +// Reply blocks and returns the reply data for a QueryClients request. +func (cook QueryClientsCookie) Reply() (*QueryClientsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryClientsReply(buf), nil +} + +// queryClientsReply reads a byte slice into a QueryClientsReply value. +func queryClientsReply(buf []byte) *QueryClientsReply { + v := new(QueryClientsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumClients = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Clients = make([]Client, v.NumClients) + b += ClientReadList(buf[b:], v.Clients) + + return v +} + +// Write request to wire for QueryClients +// queryClientsRequest writes a QueryClients request to a byte slice. +func queryClientsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// QueryResourceBytesCookie is a cookie used only for QueryResourceBytes requests. +type QueryResourceBytesCookie struct { + *xgb.Cookie +} + +// QueryResourceBytes sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryResourceBytesCookie.Reply() +func QueryResourceBytes(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) QueryResourceBytesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryResourceBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryResourceBytesRequest(c, Client, NumSpecs, Specs), cookie) + return QueryResourceBytesCookie{cookie} +} + +// QueryResourceBytesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryResourceBytesUnchecked(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) QueryResourceBytesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryResourceBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryResourceBytesRequest(c, Client, NumSpecs, Specs), cookie) + return QueryResourceBytesCookie{cookie} +} + +// QueryResourceBytesReply represents the data returned from a QueryResourceBytes request. +type QueryResourceBytesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumSizes uint32 + // padding: 20 bytes + Sizes []ResourceSizeValue // size: ResourceSizeValueListSize(Sizes) +} + +// Reply blocks and returns the reply data for a QueryResourceBytes request. +func (cook QueryResourceBytesCookie) Reply() (*QueryResourceBytesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryResourceBytesReply(buf), nil +} + +// queryResourceBytesReply reads a byte slice into a QueryResourceBytesReply value. +func queryResourceBytesReply(buf []byte) *QueryResourceBytesReply { + v := new(QueryResourceBytesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumSizes = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Sizes = make([]ResourceSizeValue, v.NumSizes) + b += ResourceSizeValueReadList(buf[b:], v.Sizes) + + return v +} + +// Write request to wire for QueryResourceBytes +// queryResourceBytesRequest writes a QueryResourceBytes request to a byte slice. +func queryResourceBytesRequest(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumSpecs) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Client) + b += 4 + + xgb.Put32(buf[b:], NumSpecs) + b += 4 + + b += ResourceIdSpecListBytes(buf[b:], Specs) + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["X-Resource"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ServerMajor uint16 + ServerMinor uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajor = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinor = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajor byte, ClientMinor byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["X-Resource"] + c.ExtLock.RUnlock() + 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] = ClientMajor + b += 1 + + buf[b] = ClientMinor + b += 1 + + return buf +} diff --git a/nexgb/screensaver/screensaver.go b/nexgb/screensaver/screensaver.go new file mode 100644 index 0000000..0e9511f --- /dev/null +++ b/nexgb/screensaver/screensaver.go @@ -0,0 +1,696 @@ +// Package screensaver is the X client API for the MIT-SCREEN-SAVER extension. +package screensaver + +// This file is automatically generated from screensaver.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the MIT-SCREEN-SAVER extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 16, "MIT-SCREEN-SAVER").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named MIT-SCREEN-SAVER could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["MIT-SCREEN-SAVER"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["MIT-SCREEN-SAVER"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["MIT-SCREEN-SAVER"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["MIT-SCREEN-SAVER"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["MIT-SCREEN-SAVER"] = make(map[int]xgb.NewErrorFun) +} + +const ( + EventNotifyMask = 1 + EventCycleMask = 2 +) + +const ( + KindBlanked = 0 + KindInternal = 1 + KindExternal = 2 +) + +// Notify is the event number for a NotifyEvent. +const Notify = 0 + +type NotifyEvent struct { + Sequence uint16 + State byte + Time xproto.Timestamp + Root xproto.Window + Window xproto.Window + Kind byte + Forced bool + // padding: 14 bytes +} + +// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. +func NotifyEventNew(buf []byte) xgb.Event { + v := NotifyEvent{} + b := 1 // don't read event number + + v.State = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Kind = buf[b] + b += 1 + + if buf[b] == 1 { + v.Forced = true + } else { + v.Forced = false + } + b += 1 + + b += 14 // padding + + return v +} + +// Bytes writes a NotifyEvent value to a byte slice. +func (v NotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.State + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + buf[b] = v.Kind + b += 1 + + if v.Forced { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 14 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the Notify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NotifyEvent. +func (v NotifyEvent) String() string { + fieldVals := make([]string, 0, 7) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Kind: %d", v.Kind)) + fieldVals = append(fieldVals, xgb.Sprintf("Forced: %t", v.Forced)) + return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["MIT-SCREEN-SAVER"][0] = NotifyEventNew +} + +const ( + StateOff = 0 + StateOn = 1 + StateCycle = 2 + StateDisabled = 3 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// QueryInfoCookie is a cookie used only for QueryInfo requests. +type QueryInfoCookie struct { + *xgb.Cookie +} + +// QueryInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryInfoCookie.Reply() +func QueryInfo(c *xgb.Conn, Drawable xproto.Drawable) QueryInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'QueryInfo' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryInfoRequest(c, Drawable), cookie) + return QueryInfoCookie{cookie} +} + +// QueryInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryInfoUnchecked(c *xgb.Conn, Drawable xproto.Drawable) QueryInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'QueryInfo' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryInfoRequest(c, Drawable), cookie) + return QueryInfoCookie{cookie} +} + +// QueryInfoReply represents the data returned from a QueryInfo request. +type QueryInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + State byte + SaverWindow xproto.Window + MsUntilServer uint32 + MsSinceUserInput uint32 + EventMask uint32 + Kind byte + // padding: 7 bytes +} + +// Reply blocks and returns the reply data for a QueryInfo request. +func (cook QueryInfoCookie) Reply() (*QueryInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryInfoReply(buf), nil +} + +// queryInfoReply reads a byte slice into a QueryInfoReply value. +func queryInfoReply(buf []byte) *QueryInfoReply { + v := new(QueryInfoReply) + b := 1 // skip reply determinant + + v.State = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.SaverWindow = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.MsUntilServer = xgb.Get32(buf[b:]) + b += 4 + + v.MsSinceUserInput = xgb.Get32(buf[b:]) + b += 4 + + v.EventMask = xgb.Get32(buf[b:]) + b += 4 + + v.Kind = buf[b] + b += 1 + + b += 7 // padding + + return v +} + +// Write request to wire for QueryInfo +// queryInfoRequest writes a QueryInfo request to a byte slice. +func queryInfoRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + 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(Drawable)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion byte, ClientMinorVersion byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion byte, ClientMinorVersion byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ServerMajorVersion uint16 + ServerMinorVersion uint16 + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + b += 20 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion byte, ClientMinorVersion byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + 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] = ClientMajorVersion + b += 1 + + buf[b] = ClientMinorVersion + b += 1 + + b += 2 // padding + + return buf +} + +// SelectInputCookie is a cookie used only for SelectInput requests. +type SelectInputCookie struct { + *xgb.Cookie +} + +// SelectInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectInput(c *xgb.Conn, Drawable xproto.Drawable, EventMask uint32) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectInputRequest(c, Drawable, EventMask), cookie) + return SelectInputCookie{cookie} +} + +// SelectInputChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectInputCookie.Check() +func SelectInputChecked(c *xgb.Conn, Drawable xproto.Drawable, EventMask uint32) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectInputRequest(c, Drawable, EventMask), cookie) + return SelectInputCookie{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 SelectInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectInput +// selectInputRequest writes a SelectInput request to a byte slice. +func selectInputRequest(c *xgb.Conn, Drawable xproto.Drawable, EventMask uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + return buf +} + +// SetAttributesCookie is a cookie used only for SetAttributes requests. +type SetAttributesCookie struct { + *xgb.Cookie +} + +// SetAttributes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetAttributes(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class byte, Depth byte, Visual xproto.Visualid, ValueMask uint32, ValueList []uint32) SetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'SetAttributes' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setAttributesRequest(c, Drawable, X, Y, Width, Height, BorderWidth, Class, Depth, Visual, ValueMask, ValueList), cookie) + return SetAttributesCookie{cookie} +} + +// SetAttributesChecked sends a checked request. +// If an error occurs, it can be retrieved using SetAttributesCookie.Check() +func SetAttributesChecked(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class byte, Depth byte, Visual xproto.Visualid, ValueMask uint32, ValueList []uint32) SetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'SetAttributes' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setAttributesRequest(c, Drawable, X, Y, Width, Height, BorderWidth, Class, Depth, Visual, ValueMask, ValueList), cookie) + return SetAttributesCookie{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 SetAttributesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetAttributes +// setAttributesRequest writes a SetAttributes request to a byte slice. +func setAttributesRequest(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class byte, Depth byte, Visual xproto.Visualid, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((28 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put16(buf[b:], BorderWidth) + b += 2 + + buf[b] = Class + b += 1 + + buf[b] = Depth + b += 1 + + xgb.Put32(buf[b:], uint32(Visual)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// SuspendCookie is a cookie used only for Suspend requests. +type SuspendCookie struct { + *xgb.Cookie +} + +// Suspend sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Suspend(c *xgb.Conn, Suspend bool) SuspendCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'Suspend' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(suspendRequest(c, Suspend), cookie) + return SuspendCookie{cookie} +} + +// SuspendChecked sends a checked request. +// If an error occurs, it can be retrieved using SuspendCookie.Check() +func SuspendChecked(c *xgb.Conn, Suspend bool) SuspendCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'Suspend' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(suspendRequest(c, Suspend), cookie) + return SuspendCookie{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 SuspendCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Suspend +// suspendRequest writes a Suspend request to a byte slice. +func suspendRequest(c *xgb.Conn, Suspend bool) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + if Suspend { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// UnsetAttributesCookie is a cookie used only for UnsetAttributes requests. +type UnsetAttributesCookie struct { + *xgb.Cookie +} + +// UnsetAttributes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnsetAttributes(c *xgb.Conn, Drawable xproto.Drawable) UnsetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'UnsetAttributes' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(unsetAttributesRequest(c, Drawable), cookie) + return UnsetAttributesCookie{cookie} +} + +// UnsetAttributesChecked sends a checked request. +// If an error occurs, it can be retrieved using UnsetAttributesCookie.Check() +func UnsetAttributesChecked(c *xgb.Conn, Drawable xproto.Drawable) UnsetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SCREEN-SAVER"]; !ok { + panic("Cannot issue request 'UnsetAttributes' using the uninitialized extension 'MIT-SCREEN-SAVER'. screensaver.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(unsetAttributesRequest(c, Drawable), cookie) + return UnsetAttributesCookie{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 UnsetAttributesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnsetAttributes +// unsetAttributesRequest writes a UnsetAttributes request to a byte slice. +func unsetAttributesRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SCREEN-SAVER"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Drawable)) + b += 4 + + return buf +} diff --git a/nexgb/shape/shape.go b/nexgb/shape/shape.go new file mode 100644 index 0000000..7069f7e --- /dev/null +++ b/nexgb/shape/shape.go @@ -0,0 +1,1025 @@ +// Package shape is the X client API for the SHAPE extension. +package shape + +// This file is automatically generated from shape.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the SHAPE extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 5, "SHAPE").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named SHAPE could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["SHAPE"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["SHAPE"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["SHAPE"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["SHAPE"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["SHAPE"] = make(map[int]xgb.NewErrorFun) +} + +type Kind byte + +// Notify is the event number for a NotifyEvent. +const Notify = 0 + +type NotifyEvent struct { + Sequence uint16 + ShapeKind Kind + AffectedWindow xproto.Window + ExtentsX int16 + ExtentsY int16 + ExtentsWidth uint16 + ExtentsHeight uint16 + ServerTime xproto.Timestamp + Shaped bool + // padding: 11 bytes +} + +// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. +func NotifyEventNew(buf []byte) xgb.Event { + v := NotifyEvent{} + b := 1 // don't read event number + + v.ShapeKind = Kind(buf[b]) + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.AffectedWindow = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.ExtentsX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.ExtentsY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.ExtentsWidth = xgb.Get16(buf[b:]) + b += 2 + + v.ExtentsHeight = xgb.Get16(buf[b:]) + b += 2 + + v.ServerTime = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.Shaped = true + } else { + v.Shaped = false + } + b += 1 + + b += 11 // padding + + return v +} + +// Bytes writes a NotifyEvent value to a byte slice. +func (v NotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = byte(v.ShapeKind) + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.AffectedWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.ExtentsX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.ExtentsY)) + b += 2 + + xgb.Put16(buf[b:], v.ExtentsWidth) + b += 2 + + xgb.Put16(buf[b:], v.ExtentsHeight) + b += 2 + + xgb.Put32(buf[b:], uint32(v.ServerTime)) + b += 4 + + if v.Shaped { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 11 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the Notify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NotifyEvent. +func (v NotifyEvent) String() string { + fieldVals := make([]string, 0, 9) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("ShapeKind: %d", v.ShapeKind)) + fieldVals = append(fieldVals, xgb.Sprintf("AffectedWindow: %d", v.AffectedWindow)) + fieldVals = append(fieldVals, xgb.Sprintf("ExtentsX: %d", v.ExtentsX)) + fieldVals = append(fieldVals, xgb.Sprintf("ExtentsY: %d", v.ExtentsY)) + fieldVals = append(fieldVals, xgb.Sprintf("ExtentsWidth: %d", v.ExtentsWidth)) + fieldVals = append(fieldVals, xgb.Sprintf("ExtentsHeight: %d", v.ExtentsHeight)) + fieldVals = append(fieldVals, xgb.Sprintf("ServerTime: %d", v.ServerTime)) + fieldVals = append(fieldVals, xgb.Sprintf("Shaped: %t", v.Shaped)) + return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["SHAPE"][0] = NotifyEventNew +} + +type Op byte + +const ( + SkBounding = 0 + SkClip = 1 + SkInput = 2 +) + +const ( + SoSet = 0 + SoUnion = 1 + SoIntersect = 2 + SoSubtract = 3 + SoInvert = 4 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CombineCookie is a cookie used only for Combine requests. +type CombineCookie struct { + *xgb.Cookie +} + +// Combine sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Combine(c *xgb.Conn, Operation Op, DestinationKind Kind, SourceKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceWindow xproto.Window) CombineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Combine' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(combineRequest(c, Operation, DestinationKind, SourceKind, DestinationWindow, XOffset, YOffset, SourceWindow), cookie) + return CombineCookie{cookie} +} + +// CombineChecked sends a checked request. +// If an error occurs, it can be retrieved using CombineCookie.Check() +func CombineChecked(c *xgb.Conn, Operation Op, DestinationKind Kind, SourceKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceWindow xproto.Window) CombineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Combine' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(combineRequest(c, Operation, DestinationKind, SourceKind, DestinationWindow, XOffset, YOffset, SourceWindow), cookie) + return CombineCookie{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 CombineCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Combine +// combineRequest writes a Combine request to a byte slice. +func combineRequest(c *xgb.Conn, Operation Op, DestinationKind Kind, SourceKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceWindow xproto.Window) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + 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 + + buf[b] = byte(Operation) + b += 1 + + buf[b] = byte(DestinationKind) + b += 1 + + buf[b] = byte(SourceKind) + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(DestinationWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOffset)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOffset)) + b += 2 + + xgb.Put32(buf[b:], uint32(SourceWindow)) + b += 4 + + return buf +} + +// GetRectanglesCookie is a cookie used only for GetRectangles requests. +type GetRectanglesCookie struct { + *xgb.Cookie +} + +// GetRectangles sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetRectanglesCookie.Reply() +func GetRectangles(c *xgb.Conn, Window xproto.Window, SourceKind Kind) GetRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'GetRectangles' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getRectanglesRequest(c, Window, SourceKind), cookie) + return GetRectanglesCookie{cookie} +} + +// GetRectanglesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetRectanglesUnchecked(c *xgb.Conn, Window xproto.Window, SourceKind Kind) GetRectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'GetRectangles' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getRectanglesRequest(c, Window, SourceKind), cookie) + return GetRectanglesCookie{cookie} +} + +// GetRectanglesReply represents the data returned from a GetRectangles request. +type GetRectanglesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Ordering byte + RectanglesLen uint32 + // padding: 20 bytes + Rectangles []xproto.Rectangle // size: xgb.Pad((int(RectanglesLen) * 8)) +} + +// Reply blocks and returns the reply data for a GetRectangles request. +func (cook GetRectanglesCookie) Reply() (*GetRectanglesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getRectanglesReply(buf), nil +} + +// getRectanglesReply reads a byte slice into a GetRectanglesReply value. +func getRectanglesReply(buf []byte) *GetRectanglesReply { + v := new(GetRectanglesReply) + b := 1 // skip reply determinant + + v.Ordering = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.RectanglesLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Rectangles = make([]xproto.Rectangle, v.RectanglesLen) + b += xproto.RectangleReadList(buf[b:], v.Rectangles) + + return v +} + +// Write request to wire for GetRectangles +// getRectanglesRequest writes a GetRectangles request to a byte slice. +func getRectanglesRequest(c *xgb.Conn, Window xproto.Window, SourceKind Kind) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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 + + buf[b] = byte(SourceKind) + b += 1 + + b += 3 // padding + + return buf +} + +// InputSelectedCookie is a cookie used only for InputSelected requests. +type InputSelectedCookie struct { + *xgb.Cookie +} + +// InputSelected sends a checked request. +// If an error occurs, it will be returned with the reply by calling InputSelectedCookie.Reply() +func InputSelected(c *xgb.Conn, DestinationWindow xproto.Window) InputSelectedCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'InputSelected' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(inputSelectedRequest(c, DestinationWindow), cookie) + return InputSelectedCookie{cookie} +} + +// InputSelectedUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func InputSelectedUnchecked(c *xgb.Conn, DestinationWindow xproto.Window) InputSelectedCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'InputSelected' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(inputSelectedRequest(c, DestinationWindow), cookie) + return InputSelectedCookie{cookie} +} + +// InputSelectedReply represents the data returned from a InputSelected request. +type InputSelectedReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Enabled bool +} + +// Reply blocks and returns the reply data for a InputSelected request. +func (cook InputSelectedCookie) Reply() (*InputSelectedReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return inputSelectedReply(buf), nil +} + +// inputSelectedReply reads a byte slice into a InputSelectedReply value. +func inputSelectedReply(buf []byte) *InputSelectedReply { + v := new(InputSelectedReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.Enabled = true + } else { + v.Enabled = 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 InputSelected +// inputSelectedRequest writes a InputSelected request to a byte slice. +func inputSelectedRequest(c *xgb.Conn, DestinationWindow xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(DestinationWindow)) + b += 4 + + return buf +} + +// MaskCookie is a cookie used only for Mask requests. +type MaskCookie struct { + *xgb.Cookie +} + +// Mask sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Mask(c *xgb.Conn, Operation Op, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceBitmap xproto.Pixmap) MaskCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Mask' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(maskRequest(c, Operation, DestinationKind, DestinationWindow, XOffset, YOffset, SourceBitmap), cookie) + return MaskCookie{cookie} +} + +// MaskChecked sends a checked request. +// If an error occurs, it can be retrieved using MaskCookie.Check() +func MaskChecked(c *xgb.Conn, Operation Op, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceBitmap xproto.Pixmap) MaskCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Mask' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(maskRequest(c, Operation, DestinationKind, DestinationWindow, XOffset, YOffset, SourceBitmap), cookie) + return MaskCookie{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 MaskCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Mask +// maskRequest writes a Mask request to a byte slice. +func maskRequest(c *xgb.Conn, Operation Op, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16, SourceBitmap xproto.Pixmap) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + 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] = byte(Operation) + b += 1 + + buf[b] = byte(DestinationKind) + b += 1 + + b += 2 // padding + + xgb.Put32(buf[b:], uint32(DestinationWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOffset)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOffset)) + b += 2 + + xgb.Put32(buf[b:], uint32(SourceBitmap)) + b += 4 + + return buf +} + +// OffsetCookie is a cookie used only for Offset requests. +type OffsetCookie struct { + *xgb.Cookie +} + +// Offset sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Offset(c *xgb.Conn, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16) OffsetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Offset' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(offsetRequest(c, DestinationKind, DestinationWindow, XOffset, YOffset), cookie) + return OffsetCookie{cookie} +} + +// OffsetChecked sends a checked request. +// If an error occurs, it can be retrieved using OffsetCookie.Check() +func OffsetChecked(c *xgb.Conn, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16) OffsetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Offset' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(offsetRequest(c, DestinationKind, DestinationWindow, XOffset, YOffset), cookie) + return OffsetCookie{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 OffsetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Offset +// offsetRequest writes a Offset request to a byte slice. +func offsetRequest(c *xgb.Conn, DestinationKind Kind, DestinationWindow xproto.Window, XOffset int16, YOffset int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = byte(DestinationKind) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(DestinationWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOffset)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOffset)) + b += 2 + + return buf +} + +// QueryExtentsCookie is a cookie used only for QueryExtents requests. +type QueryExtentsCookie struct { + *xgb.Cookie +} + +// QueryExtents sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryExtentsCookie.Reply() +func QueryExtents(c *xgb.Conn, DestinationWindow xproto.Window) QueryExtentsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'QueryExtents' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryExtentsRequest(c, DestinationWindow), cookie) + return QueryExtentsCookie{cookie} +} + +// QueryExtentsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryExtentsUnchecked(c *xgb.Conn, DestinationWindow xproto.Window) QueryExtentsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'QueryExtents' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryExtentsRequest(c, DestinationWindow), cookie) + return QueryExtentsCookie{cookie} +} + +// QueryExtentsReply represents the data returned from a QueryExtents request. +type QueryExtentsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + BoundingShaped bool + ClipShaped bool + // padding: 2 bytes + BoundingShapeExtentsX int16 + BoundingShapeExtentsY int16 + BoundingShapeExtentsWidth uint16 + BoundingShapeExtentsHeight uint16 + ClipShapeExtentsX int16 + ClipShapeExtentsY int16 + ClipShapeExtentsWidth uint16 + ClipShapeExtentsHeight uint16 +} + +// Reply blocks and returns the reply data for a QueryExtents request. +func (cook QueryExtentsCookie) Reply() (*QueryExtentsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryExtentsReply(buf), nil +} + +// queryExtentsReply reads a byte slice into a QueryExtentsReply value. +func queryExtentsReply(buf []byte) *QueryExtentsReply { + v := new(QueryExtentsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.BoundingShaped = true + } else { + v.BoundingShaped = false + } + b += 1 + + if buf[b] == 1 { + v.ClipShaped = true + } else { + v.ClipShaped = false + } + b += 1 + + b += 2 // padding + + v.BoundingShapeExtentsX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BoundingShapeExtentsY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BoundingShapeExtentsWidth = xgb.Get16(buf[b:]) + b += 2 + + v.BoundingShapeExtentsHeight = xgb.Get16(buf[b:]) + b += 2 + + v.ClipShapeExtentsX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.ClipShapeExtentsY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.ClipShapeExtentsWidth = xgb.Get16(buf[b:]) + b += 2 + + v.ClipShapeExtentsHeight = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryExtents +// queryExtentsRequest writes a QueryExtents request to a byte slice. +func queryExtentsRequest(c *xgb.Conn, DestinationWindow xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(DestinationWindow)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// RectanglesCookie is a cookie used only for Rectangles requests. +type RectanglesCookie struct { + *xgb.Cookie +} + +// Rectangles sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Rectangles(c *xgb.Conn, Operation Op, DestinationKind Kind, Ordering byte, DestinationWindow xproto.Window, XOffset int16, YOffset int16, Rectangles []xproto.Rectangle) RectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Rectangles' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(rectanglesRequest(c, Operation, DestinationKind, Ordering, DestinationWindow, XOffset, YOffset, Rectangles), cookie) + return RectanglesCookie{cookie} +} + +// RectanglesChecked sends a checked request. +// If an error occurs, it can be retrieved using RectanglesCookie.Check() +func RectanglesChecked(c *xgb.Conn, Operation Op, DestinationKind Kind, Ordering byte, DestinationWindow xproto.Window, XOffset int16, YOffset int16, Rectangles []xproto.Rectangle) RectanglesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'Rectangles' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(rectanglesRequest(c, Operation, DestinationKind, Ordering, DestinationWindow, XOffset, YOffset, Rectangles), cookie) + return RectanglesCookie{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 RectanglesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Rectangles +// rectanglesRequest writes a Rectangles request to a byte slice. +func rectanglesRequest(c *xgb.Conn, Operation Op, DestinationKind Kind, Ordering byte, DestinationWindow xproto.Window, XOffset int16, YOffset int16, Rectangles []xproto.Rectangle) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + 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 + + buf[b] = byte(Operation) + b += 1 + + buf[b] = byte(DestinationKind) + b += 1 + + buf[b] = Ordering + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(DestinationWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOffset)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOffset)) + b += 2 + + b += xproto.RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// SelectInputCookie is a cookie used only for SelectInput requests. +type SelectInputCookie struct { + *xgb.Cookie +} + +// SelectInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectInput(c *xgb.Conn, DestinationWindow xproto.Window, Enable bool) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectInputRequest(c, DestinationWindow, Enable), cookie) + return SelectInputCookie{cookie} +} + +// SelectInputChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectInputCookie.Check() +func SelectInputChecked(c *xgb.Conn, DestinationWindow xproto.Window, Enable bool) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SHAPE"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'SHAPE'. shape.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectInputRequest(c, DestinationWindow, Enable), cookie) + return SelectInputCookie{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 SelectInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectInput +// selectInputRequest writes a SelectInput request to a byte slice. +func selectInputRequest(c *xgb.Conn, DestinationWindow xproto.Window, Enable bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SHAPE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(DestinationWindow)) + b += 4 + + if Enable { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} diff --git a/nexgb/shm/shm.go b/nexgb/shm/shm.go new file mode 100644 index 0000000..b310c34 --- /dev/null +++ b/nexgb/shm/shm.go @@ -0,0 +1,945 @@ +// Package shm is the X client API for the MIT-SHM extension. +package shm + +// This file is automatically generated from shm.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the MIT-SHM extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 7, "MIT-SHM").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named MIT-SHM could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["MIT-SHM"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["MIT-SHM"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["MIT-SHM"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["MIT-SHM"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["MIT-SHM"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadSeg is the error number for a BadBadSeg. +const BadBadSeg = 0 + +type BadSegError xproto.ValueError + +// BadSegErrorNew constructs a BadSegError value that implements xgb.Error from a byte slice. +func BadSegErrorNew(buf []byte) xgb.Error { + v := BadSegError(xproto.ValueErrorNew(buf).(xproto.ValueError)) + v.NiceName = "BadSeg" + return v +} + +// SequenceId returns the sequence id attached to the BadBadSeg error. +// This is mostly used internally. +func (err BadSegError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadSeg error. If no bad value exists, 0 is returned. +func (err BadSegError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadSeg error. +func (err BadSegError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadBadSeg {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["MIT-SHM"][0] = BadSegErrorNew +} + +// Completion is the event number for a CompletionEvent. +const Completion = 0 + +type CompletionEvent struct { + Sequence uint16 + // padding: 1 bytes + Drawable xproto.Drawable + MinorEvent uint16 + MajorEvent byte + // padding: 1 bytes + Shmseg Seg + Offset uint32 +} + +// CompletionEventNew constructs a CompletionEvent value that implements xgb.Event from a byte slice. +func CompletionEventNew(buf []byte) xgb.Event { + v := CompletionEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.MinorEvent = xgb.Get16(buf[b:]) + b += 2 + + v.MajorEvent = buf[b] + b += 1 + + b += 1 // padding + + v.Shmseg = Seg(xgb.Get32(buf[b:])) + b += 4 + + v.Offset = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Bytes writes a CompletionEvent value to a byte slice. +func (v CompletionEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put16(buf[b:], v.MinorEvent) + b += 2 + + buf[b] = v.MajorEvent + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(v.Shmseg)) + b += 4 + + xgb.Put32(buf[b:], v.Offset) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the Completion event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v CompletionEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of CompletionEvent. +func (v CompletionEvent) String() string { + fieldVals := make([]string, 0, 7) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorEvent: %d", v.MinorEvent)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorEvent: %d", v.MajorEvent)) + fieldVals = append(fieldVals, xgb.Sprintf("Shmseg: %d", v.Shmseg)) + fieldVals = append(fieldVals, xgb.Sprintf("Offset: %d", v.Offset)) + return "Completion {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["MIT-SHM"][0] = CompletionEventNew +} + +type Seg uint32 + +func NewSegId(c *xgb.Conn) (Seg, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Seg(id), nil +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AttachCookie is a cookie used only for Attach requests. +type AttachCookie struct { + *xgb.Cookie +} + +// Attach sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Attach(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'Attach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie) + return AttachCookie{cookie} +} + +// AttachChecked sends a checked request. +// If an error occurs, it can be retrieved using AttachCookie.Check() +func AttachChecked(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'Attach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie) + return AttachCookie{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 AttachCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Attach +// attachRequest writes a Attach request to a byte slice. +func attachRequest(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + 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(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Shmid) + b += 4 + + if ReadOnly { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// AttachFdCookie is a cookie used only for AttachFd requests. +type AttachFdCookie struct { + *xgb.Cookie +} + +// AttachFd sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AttachFd(c *xgb.Conn, Shmseg Seg, ReadOnly bool) AttachFdCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'AttachFd' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(attachFdRequest(c, Shmseg, ReadOnly), cookie) + return AttachFdCookie{cookie} +} + +// AttachFdChecked sends a checked request. +// If an error occurs, it can be retrieved using AttachFdCookie.Check() +func AttachFdChecked(c *xgb.Conn, Shmseg Seg, ReadOnly bool) AttachFdCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'AttachFd' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(attachFdRequest(c, Shmseg, ReadOnly), cookie) + return AttachFdCookie{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 AttachFdCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AttachFd +// attachFdRequest writes a AttachFd request to a byte slice. +func attachFdRequest(c *xgb.Conn, Shmseg Seg, ReadOnly bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Shmseg)) + b += 4 + + if ReadOnly { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// CreatePixmapCookie is a cookie used only for CreatePixmap requests. +type CreatePixmapCookie struct { + *xgb.Cookie +} + +// CreatePixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePixmap(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) CreatePixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie) + return CreatePixmapCookie{cookie} +} + +// CreatePixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePixmapCookie.Check() +func CreatePixmapChecked(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) CreatePixmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie) + return CreatePixmapCookie{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 CreatePixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePixmap +// createPixmapRequest writes a CreatePixmap request to a byte slice. +func createPixmapRequest(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Pid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + buf[b] = Depth + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Offset) + b += 4 + + return buf +} + +// CreateSegmentCookie is a cookie used only for CreateSegment requests. +type CreateSegmentCookie struct { + *xgb.Cookie +} + +// CreateSegment sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateSegmentCookie.Reply() +func CreateSegment(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) CreateSegmentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'CreateSegment' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createSegmentRequest(c, Shmseg, Size, ReadOnly), cookie) + return CreateSegmentCookie{cookie} +} + +// CreateSegmentUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateSegmentUnchecked(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) CreateSegmentCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'CreateSegment' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createSegmentRequest(c, Shmseg, Size, ReadOnly), cookie) + return CreateSegmentCookie{cookie} +} + +// CreateSegmentReply represents the data returned from a CreateSegment request. +type CreateSegmentReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Nfd byte + // padding: 24 bytes +} + +// Reply blocks and returns the reply data for a CreateSegment request. +func (cook CreateSegmentCookie) Reply() (*CreateSegmentReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createSegmentReply(buf), nil +} + +// createSegmentReply reads a byte slice into a CreateSegmentReply value. +func createSegmentReply(buf []byte) *CreateSegmentReply { + v := new(CreateSegmentReply) + b := 1 // skip reply determinant + + v.Nfd = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + return v +} + +// Write request to wire for CreateSegment +// createSegmentRequest writes a CreateSegment request to a byte slice. +func createSegmentRequest(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Size) + b += 4 + + if ReadOnly { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// DetachCookie is a cookie used only for Detach requests. +type DetachCookie struct { + *xgb.Cookie +} + +// Detach sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Detach(c *xgb.Conn, Shmseg Seg) DetachCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(detachRequest(c, Shmseg), cookie) + return DetachCookie{cookie} +} + +// DetachChecked sends a checked request. +// If an error occurs, it can be retrieved using DetachCookie.Check() +func DetachChecked(c *xgb.Conn, Shmseg Seg) DetachCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(detachRequest(c, Shmseg), cookie) + return DetachCookie{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 DetachCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Detach +// detachRequest writes a Detach request to a byte slice. +func detachRequest(c *xgb.Conn, Shmseg Seg) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Shmseg)) + b += 4 + + return buf +} + +// GetImageCookie is a cookie used only for GetImage requests. +type GetImageCookie struct { + *xgb.Cookie +} + +// GetImage sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetImageCookie.Reply() +func GetImage(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) GetImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'GetImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie) + return GetImageCookie{cookie} +} + +// GetImageUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetImageUnchecked(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) GetImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'GetImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie) + return GetImageCookie{cookie} +} + +// GetImageReply represents the data returned from a GetImage request. +type GetImageReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Depth byte + Visual xproto.Visualid + Size uint32 +} + +// Reply blocks and returns the reply data for a GetImage request. +func (cook GetImageCookie) Reply() (*GetImageReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getImageReply(buf), nil +} + +// getImageReply reads a byte slice into a GetImageReply value. +func getImageReply(buf []byte) *GetImageReply { + v := new(GetImageReply) + b := 1 // skip reply determinant + + v.Depth = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Visual = xproto.Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.Size = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GetImage +// getImageRequest writes a GetImage request to a byte slice. +func getImageRequest(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Drawable)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put32(buf[b:], PlaneMask) + b += 4 + + buf[b] = Format + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], uint32(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Offset) + b += 4 + + return buf +} + +// PutImageCookie is a cookie used only for PutImage requests. +type PutImageCookie struct { + *xgb.Cookie +} + +// PutImage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PutImage(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) PutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie) + return PutImageCookie{cookie} +} + +// PutImageChecked sends a checked request. +// If an error occurs, it can be retrieved using PutImageCookie.Check() +func PutImageChecked(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) PutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie) + return PutImageCookie{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 PutImageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PutImage +// putImageRequest writes a PutImage request to a byte slice. +func putImageRequest(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) []byte { + size := 40 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], TotalWidth) + b += 2 + + xgb.Put16(buf[b:], TotalHeight) + b += 2 + + xgb.Put16(buf[b:], SrcX) + b += 2 + + xgb.Put16(buf[b:], SrcY) + b += 2 + + xgb.Put16(buf[b:], SrcWidth) + b += 2 + + xgb.Put16(buf[b:], SrcHeight) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + buf[b] = Depth + b += 1 + + buf[b] = Format + b += 1 + + buf[b] = SendEvent + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Offset) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["MIT-SHM"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + SharedPixmaps bool + MajorVersion uint16 + MinorVersion uint16 + Uid uint16 + Gid uint16 + PixmapFormat byte + // padding: 15 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.SharedPixmaps = true + } else { + v.SharedPixmaps = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.Uid = xgb.Get16(buf[b:]) + b += 2 + + v.Gid = xgb.Get16(buf[b:]) + b += 2 + + v.PixmapFormat = buf[b] + b += 1 + + b += 15 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["MIT-SHM"] + c.ExtLock.RUnlock() + 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 + + return buf +} diff --git a/nexgb/sync.go b/nexgb/sync.go new file mode 100644 index 0000000..59d0de1 --- /dev/null +++ b/nexgb/sync.go @@ -0,0 +1,29 @@ +package xgb + +// Sync sends a round trip request and waits for the response. +// This forces all pending cookies to be dealt with. +// You actually shouldn't need to use this like you might with Xlib. Namely, +// buffers are automatically flushed using Go's channels and round trip requests +// are forced where appropriate automatically. +func (c *Conn) Sync() { + cookie := c.NewCookie(true, true) + c.NewRequest(c.getInputFocusRequest(), cookie) + cookie.Reply() // wait for the buffer to clear +} + +// getInputFocusRequest writes the raw bytes to a buffer. +// It is duplicated from xproto/xproto.go. +func (c *Conn) getInputFocusRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 43 // request opcode + b += 1 + + b += 1 // padding + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} diff --git a/nexgb/xcmisc/xcmisc.go b/nexgb/xcmisc/xcmisc.go new file mode 100644 index 0000000..1778057 --- /dev/null +++ b/nexgb/xcmisc/xcmisc.go @@ -0,0 +1,361 @@ +// Package xcmisc is the X client API for the XC-MISC extension. +package xcmisc + +// This file is automatically generated from xc_misc.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XC-MISC extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 7, "XC-MISC").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XC-MISC could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XC-MISC"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XC-MISC"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XC-MISC"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XC-MISC"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XC-MISC"] = make(map[int]xgb.NewErrorFun) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// 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, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), 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, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), 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 + // padding: 1 bytes + ServerMajorVersion uint16 + ServerMinorVersion 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 + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinorVersion = 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, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XC-MISC"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], ClientMajorVersion) + b += 2 + + xgb.Put16(buf[b:], ClientMinorVersion) + b += 2 + + return buf +} + +// GetXIDListCookie is a cookie used only for GetXIDList requests. +type GetXIDListCookie struct { + *xgb.Cookie +} + +// GetXIDList sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetXIDListCookie.Reply() +func GetXIDList(c *xgb.Conn, Count uint32) GetXIDListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetXIDList' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getXIDListRequest(c, Count), cookie) + return GetXIDListCookie{cookie} +} + +// GetXIDListUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetXIDListUnchecked(c *xgb.Conn, Count uint32) GetXIDListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetXIDList' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getXIDListRequest(c, Count), cookie) + return GetXIDListCookie{cookie} +} + +// GetXIDListReply represents the data returned from a GetXIDList request. +type GetXIDListReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + IdsLen uint32 + // padding: 20 bytes + Ids []uint32 // size: xgb.Pad((int(IdsLen) * 4)) +} + +// Reply blocks and returns the reply data for a GetXIDList request. +func (cook GetXIDListCookie) Reply() (*GetXIDListReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getXIDListReply(buf), nil +} + +// getXIDListReply reads a byte slice into a GetXIDListReply value. +func getXIDListReply(buf []byte) *GetXIDListReply { + v := new(GetXIDListReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.IdsLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Ids = make([]uint32, v.IdsLen) + for i := 0; i < int(v.IdsLen); i++ { + v.Ids[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetXIDList +// getXIDListRequest writes a GetXIDList request to a byte slice. +func getXIDListRequest(c *xgb.Conn, Count uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XC-MISC"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Count) + b += 4 + + return buf +} + +// GetXIDRangeCookie is a cookie used only for GetXIDRange requests. +type GetXIDRangeCookie struct { + *xgb.Cookie +} + +// GetXIDRange sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetXIDRangeCookie.Reply() +func GetXIDRange(c *xgb.Conn) GetXIDRangeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetXIDRange' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getXIDRangeRequest(c), cookie) + return GetXIDRangeCookie{cookie} +} + +// GetXIDRangeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetXIDRangeUnchecked(c *xgb.Conn) GetXIDRangeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XC-MISC"]; !ok { + panic("Cannot issue request 'GetXIDRange' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getXIDRangeRequest(c), cookie) + return GetXIDRangeCookie{cookie} +} + +// GetXIDRangeReply represents the data returned from a GetXIDRange request. +type GetXIDRangeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + StartId uint32 + Count uint32 +} + +// Reply blocks and returns the reply data for a GetXIDRange request. +func (cook GetXIDRangeCookie) Reply() (*GetXIDRangeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getXIDRangeReply(buf), nil +} + +// getXIDRangeReply reads a byte slice into a GetXIDRangeReply value. +func getXIDRangeReply(buf []byte) *GetXIDRangeReply { + v := new(GetXIDRangeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.StartId = xgb.Get32(buf[b:]) + b += 4 + + v.Count = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GetXIDRange +// getXIDRangeRequest writes a GetXIDRange request to a byte slice. +func getXIDRangeRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XC-MISC"] + c.ExtLock.RUnlock() + 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 + + return buf +} diff --git a/nexgb/xevie/xevie.go b/nexgb/xevie/xevie.go new file mode 100644 index 0000000..180312b --- /dev/null +++ b/nexgb/xevie/xevie.go @@ -0,0 +1,595 @@ +// Package xevie is the X client API for the XEVIE extension. +package xevie + +// This file is automatically generated from xevie.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XEVIE extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 5, "XEVIE").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XEVIE could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XEVIE"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XEVIE"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XEVIE"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XEVIE"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XEVIE"] = make(map[int]xgb.NewErrorFun) +} + +const ( + DatatypeUnmodified = 0 + DatatypeModified = 1 +) + +type Event struct { + // padding: 32 bytes +} + +// EventRead reads a byte slice into a Event value. +func EventRead(buf []byte, v *Event) int { + b := 0 + + b += 32 // padding + + return b +} + +// EventReadList reads a byte slice into a list of Event values. +func EventReadList(buf []byte, dest []Event) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Event{} + b += EventRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Event value to a byte slice. +func (v Event) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + b += 32 // padding + + return buf[:b] +} + +// EventListBytes writes a list of Event values to a byte slice. +func EventListBytes(buf []byte, list []Event) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// EndCookie is a cookie used only for End requests. +type EndCookie struct { + *xgb.Cookie +} + +// End sends a checked request. +// If an error occurs, it will be returned with the reply by calling EndCookie.Reply() +func End(c *xgb.Conn, Cmap uint32) EndCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'End' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(endRequest(c, Cmap), cookie) + return EndCookie{cookie} +} + +// EndUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func EndUnchecked(c *xgb.Conn, Cmap uint32) EndCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'End' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(endRequest(c, Cmap), cookie) + return EndCookie{cookie} +} + +// EndReply represents the data returned from a End request. +type EndReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes +} + +// Reply blocks and returns the reply data for a End request. +func (cook EndCookie) Reply() (*EndReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return endReply(buf), nil +} + +// endReply reads a byte slice into a EndReply value. +func endReply(buf []byte) *EndReply { + v := new(EndReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + return v +} + +// Write request to wire for End +// endRequest writes a End request to a byte slice. +func endRequest(c *xgb.Conn, Cmap uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XEVIE"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Cmap) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ServerMajorVersion uint16 + ServerMinorVersion uint16 + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + b += 20 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XEVIE"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], ClientMajorVersion) + b += 2 + + xgb.Put16(buf[b:], ClientMinorVersion) + b += 2 + + return buf +} + +// SelectInputCookie is a cookie used only for SelectInput requests. +type SelectInputCookie struct { + *xgb.Cookie +} + +// SelectInput sends a checked request. +// If an error occurs, it will be returned with the reply by calling SelectInputCookie.Reply() +func SelectInput(c *xgb.Conn, EventMask uint32) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(selectInputRequest(c, EventMask), cookie) + return SelectInputCookie{cookie} +} + +// SelectInputUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectInputUnchecked(c *xgb.Conn, EventMask uint32) SelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'SelectInput' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(selectInputRequest(c, EventMask), cookie) + return SelectInputCookie{cookie} +} + +// SelectInputReply represents the data returned from a SelectInput request. +type SelectInputReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes +} + +// Reply blocks and returns the reply data for a SelectInput request. +func (cook SelectInputCookie) Reply() (*SelectInputReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return selectInputReply(buf), nil +} + +// selectInputReply reads a byte slice into a SelectInputReply value. +func selectInputReply(buf []byte) *SelectInputReply { + v := new(SelectInputReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + return v +} + +// Write request to wire for SelectInput +// selectInputRequest writes a SelectInput request to a byte slice. +func selectInputRequest(c *xgb.Conn, EventMask uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XEVIE"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + return buf +} + +// SendCookie is a cookie used only for Send requests. +type SendCookie struct { + *xgb.Cookie +} + +// Send sends a checked request. +// If an error occurs, it will be returned with the reply by calling SendCookie.Reply() +func Send(c *xgb.Conn, Event Event, DataType uint32) SendCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'Send' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(sendRequest(c, Event, DataType), cookie) + return SendCookie{cookie} +} + +// SendUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SendUnchecked(c *xgb.Conn, Event Event, DataType uint32) SendCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'Send' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(sendRequest(c, Event, DataType), cookie) + return SendCookie{cookie} +} + +// SendReply represents the data returned from a Send request. +type SendReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes +} + +// Reply blocks and returns the reply data for a Send request. +func (cook SendCookie) Reply() (*SendReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return sendReply(buf), nil +} + +// sendReply reads a byte slice into a SendReply value. +func sendReply(buf []byte) *SendReply { + v := new(SendReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + return v +} + +// Write request to wire for Send +// sendRequest writes a Send request to a byte slice. +func sendRequest(c *xgb.Conn, Event Event, DataType uint32) []byte { + size := 104 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XEVIE"] + c.ExtLock.RUnlock() + 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 + + { + structBytes := Event.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], DataType) + b += 4 + + b += 64 // padding + + return buf +} + +// StartCookie is a cookie used only for Start requests. +type StartCookie struct { + *xgb.Cookie +} + +// Start sends a checked request. +// If an error occurs, it will be returned with the reply by calling StartCookie.Reply() +func Start(c *xgb.Conn, Screen uint32) StartCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'Start' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(startRequest(c, Screen), cookie) + return StartCookie{cookie} +} + +// StartUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func StartUnchecked(c *xgb.Conn, Screen uint32) StartCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XEVIE"]; !ok { + panic("Cannot issue request 'Start' using the uninitialized extension 'XEVIE'. xevie.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(startRequest(c, Screen), cookie) + return StartCookie{cookie} +} + +// StartReply represents the data returned from a Start request. +type StartReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes +} + +// Reply blocks and returns the reply data for a Start request. +func (cook StartCookie) Reply() (*StartReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return startReply(buf), nil +} + +// startReply reads a byte slice into a StartReply value. +func startReply(buf []byte) *StartReply { + v := new(StartReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + return v +} + +// Write request to wire for Start +// startRequest writes a Start request to a byte slice. +func startRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XEVIE"] + c.ExtLock.RUnlock() + 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:], Screen) + b += 4 + + return buf +} diff --git a/nexgb/xf86dri/xf86dri.go b/nexgb/xf86dri/xf86dri.go new file mode 100644 index 0000000..06f49a0 --- /dev/null +++ b/nexgb/xf86dri/xf86dri.go @@ -0,0 +1,1301 @@ +// Package xf86dri is the X client API for the XFree86-DRI extension. +package xf86dri + +// This file is automatically generated from xf86dri.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XFree86-DRI extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 11, "XFree86-DRI").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XFree86-DRI could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XFree86-DRI"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XFree86-DRI"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XFree86-DRI"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XFree86-DRI"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XFree86-DRI"] = make(map[int]xgb.NewErrorFun) +} + +type DrmClipRect struct { + X1 int16 + Y1 int16 + X2 int16 + X3 int16 +} + +// DrmClipRectRead reads a byte slice into a DrmClipRect value. +func DrmClipRectRead(buf []byte, v *DrmClipRect) int { + b := 0 + + v.X1 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y1 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.X2 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.X3 = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// DrmClipRectReadList reads a byte slice into a list of DrmClipRect values. +func DrmClipRectReadList(buf []byte, dest []DrmClipRect) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = DrmClipRect{} + b += DrmClipRectRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a DrmClipRect value to a byte slice. +func (v DrmClipRect) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], uint16(v.X1)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y1)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X2)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X3)) + b += 2 + + return buf[:b] +} + +// DrmClipRectListBytes writes a list of DrmClipRect values to a byte slice. +func DrmClipRectListBytes(buf []byte, list []DrmClipRect) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AuthConnectionCookie is a cookie used only for AuthConnection requests. +type AuthConnectionCookie struct { + *xgb.Cookie +} + +// AuthConnection sends a checked request. +// If an error occurs, it will be returned with the reply by calling AuthConnectionCookie.Reply() +func AuthConnection(c *xgb.Conn, Screen uint32, Magic uint32) AuthConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'AuthConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(authConnectionRequest(c, Screen, Magic), cookie) + return AuthConnectionCookie{cookie} +} + +// AuthConnectionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AuthConnectionUnchecked(c *xgb.Conn, Screen uint32, Magic uint32) AuthConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'AuthConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(authConnectionRequest(c, Screen, Magic), cookie) + return AuthConnectionCookie{cookie} +} + +// AuthConnectionReply represents the data returned from a AuthConnection request. +type AuthConnectionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Authenticated uint32 +} + +// Reply blocks and returns the reply data for a AuthConnection request. +func (cook AuthConnectionCookie) Reply() (*AuthConnectionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return authConnectionReply(buf), nil +} + +// authConnectionReply reads a byte slice into a AuthConnectionReply value. +func authConnectionReply(buf []byte) *AuthConnectionReply { + v := new(AuthConnectionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Authenticated = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for AuthConnection +// authConnectionRequest writes a AuthConnection request to a byte slice. +func authConnectionRequest(c *xgb.Conn, Screen uint32, Magic uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Magic) + b += 4 + + return buf +} + +// CloseConnectionCookie is a cookie used only for CloseConnection requests. +type CloseConnectionCookie struct { + *xgb.Cookie +} + +// CloseConnection sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CloseConnection(c *xgb.Conn, Screen uint32) CloseConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CloseConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(closeConnectionRequest(c, Screen), cookie) + return CloseConnectionCookie{cookie} +} + +// CloseConnectionChecked sends a checked request. +// If an error occurs, it can be retrieved using CloseConnectionCookie.Check() +func CloseConnectionChecked(c *xgb.Conn, Screen uint32) CloseConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CloseConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(closeConnectionRequest(c, Screen), cookie) + return CloseConnectionCookie{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 CloseConnectionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CloseConnection +// closeConnectionRequest writes a CloseConnection request to a byte slice. +func closeConnectionRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// CreateContextCookie is a cookie used only for CreateContext requests. +type CreateContextCookie struct { + *xgb.Cookie +} + +// CreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateContextCookie.Reply() +func CreateContext(c *xgb.Conn, Screen uint32, Visual uint32, Context uint32) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createContextRequest(c, Screen, Visual, Context), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContextUnchecked(c *xgb.Conn, Screen uint32, Visual uint32, Context uint32) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createContextRequest(c, Screen, Visual, Context), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextReply represents the data returned from a CreateContext request. +type CreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + HwContext uint32 +} + +// Reply blocks and returns the reply data for a CreateContext request. +func (cook CreateContextCookie) Reply() (*CreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createContextReply(buf), nil +} + +// createContextReply reads a byte slice into a CreateContextReply value. +func createContextReply(buf []byte) *CreateContextReply { + v := new(CreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.HwContext = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. +func createContextRequest(c *xgb.Conn, Screen uint32, Visual uint32, Context uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Visual) + b += 4 + + xgb.Put32(buf[b:], Context) + b += 4 + + return buf +} + +// CreateDrawableCookie is a cookie used only for CreateDrawable requests. +type CreateDrawableCookie struct { + *xgb.Cookie +} + +// CreateDrawable sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateDrawableCookie.Reply() +func CreateDrawable(c *xgb.Conn, Screen uint32, Drawable uint32) CreateDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createDrawableRequest(c, Screen, Drawable), cookie) + return CreateDrawableCookie{cookie} +} + +// CreateDrawableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateDrawableUnchecked(c *xgb.Conn, Screen uint32, Drawable uint32) CreateDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createDrawableRequest(c, Screen, Drawable), cookie) + return CreateDrawableCookie{cookie} +} + +// CreateDrawableReply represents the data returned from a CreateDrawable request. +type CreateDrawableReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + HwDrawableHandle uint32 +} + +// Reply blocks and returns the reply data for a CreateDrawable request. +func (cook CreateDrawableCookie) Reply() (*CreateDrawableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createDrawableReply(buf), nil +} + +// createDrawableReply reads a byte slice into a CreateDrawableReply value. +func createDrawableReply(buf []byte) *CreateDrawableReply { + v := new(CreateDrawableReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.HwDrawableHandle = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for CreateDrawable +// createDrawableRequest writes a CreateDrawable request to a byte slice. +func createDrawableRequest(c *xgb.Conn, Screen uint32, Drawable uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Drawable) + b += 4 + + return buf +} + +// DestroyContextCookie is a cookie used only for DestroyContext requests. +type DestroyContextCookie struct { + *xgb.Cookie +} + +// DestroyContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyContext(c *xgb.Conn, Screen uint32, Context uint32) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyContextRequest(c, Screen, Context), cookie) + return DestroyContextCookie{cookie} +} + +// DestroyContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyContextCookie.Check() +func DestroyContextChecked(c *xgb.Conn, Screen uint32, Context uint32) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyContextRequest(c, Screen, Context), cookie) + return DestroyContextCookie{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 DestroyContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyContext +// destroyContextRequest writes a DestroyContext request to a byte slice. +func destroyContextRequest(c *xgb.Conn, Screen uint32, Context uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Context) + b += 4 + + return buf +} + +// DestroyDrawableCookie is a cookie used only for DestroyDrawable requests. +type DestroyDrawableCookie struct { + *xgb.Cookie +} + +// DestroyDrawable sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyDrawable(c *xgb.Conn, Screen uint32, Drawable uint32) DestroyDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyDrawableRequest(c, Screen, Drawable), cookie) + return DestroyDrawableCookie{cookie} +} + +// DestroyDrawableChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyDrawableCookie.Check() +func DestroyDrawableChecked(c *xgb.Conn, Screen uint32, Drawable uint32) DestroyDrawableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyDrawableRequest(c, Screen, Drawable), cookie) + return DestroyDrawableCookie{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 DestroyDrawableCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyDrawable +// destroyDrawableRequest writes a DestroyDrawable request to a byte slice. +func destroyDrawableRequest(c *xgb.Conn, Screen uint32, Drawable uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Drawable) + b += 4 + + return buf +} + +// GetClientDriverNameCookie is a cookie used only for GetClientDriverName requests. +type GetClientDriverNameCookie struct { + *xgb.Cookie +} + +// GetClientDriverName sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetClientDriverNameCookie.Reply() +func GetClientDriverName(c *xgb.Conn, Screen uint32) GetClientDriverNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetClientDriverName' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getClientDriverNameRequest(c, Screen), cookie) + return GetClientDriverNameCookie{cookie} +} + +// GetClientDriverNameUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetClientDriverNameUnchecked(c *xgb.Conn, Screen uint32) GetClientDriverNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetClientDriverName' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getClientDriverNameRequest(c, Screen), cookie) + return GetClientDriverNameCookie{cookie} +} + +// GetClientDriverNameReply represents the data returned from a GetClientDriverName request. +type GetClientDriverNameReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ClientDriverMajorVersion uint32 + ClientDriverMinorVersion uint32 + ClientDriverPatchVersion uint32 + ClientDriverNameLen uint32 + // padding: 8 bytes + ClientDriverName string // size: xgb.Pad((int(ClientDriverNameLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetClientDriverName request. +func (cook GetClientDriverNameCookie) Reply() (*GetClientDriverNameReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getClientDriverNameReply(buf), nil +} + +// getClientDriverNameReply reads a byte slice into a GetClientDriverNameReply value. +func getClientDriverNameReply(buf []byte) *GetClientDriverNameReply { + v := new(GetClientDriverNameReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ClientDriverMajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.ClientDriverMinorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.ClientDriverPatchVersion = xgb.Get32(buf[b:]) + b += 4 + + v.ClientDriverNameLen = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + { + byteString := make([]byte, v.ClientDriverNameLen) + copy(byteString[:v.ClientDriverNameLen], buf[b:]) + v.ClientDriverName = string(byteString) + b += int(v.ClientDriverNameLen) + } + + return v +} + +// Write request to wire for GetClientDriverName +// getClientDriverNameRequest writes a GetClientDriverName request to a byte slice. +func getClientDriverNameRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// GetDeviceInfoCookie is a cookie used only for GetDeviceInfo requests. +type GetDeviceInfoCookie struct { + *xgb.Cookie +} + +// GetDeviceInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceInfoCookie.Reply() +func GetDeviceInfo(c *xgb.Conn, Screen uint32) GetDeviceInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetDeviceInfo' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDeviceInfoRequest(c, Screen), cookie) + return GetDeviceInfoCookie{cookie} +} + +// GetDeviceInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDeviceInfoUnchecked(c *xgb.Conn, Screen uint32) GetDeviceInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetDeviceInfo' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDeviceInfoRequest(c, Screen), cookie) + return GetDeviceInfoCookie{cookie} +} + +// GetDeviceInfoReply represents the data returned from a GetDeviceInfo request. +type GetDeviceInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + FramebufferHandleLow uint32 + FramebufferHandleHigh uint32 + FramebufferOriginOffset uint32 + FramebufferSize uint32 + FramebufferStride uint32 + DevicePrivateSize uint32 + DevicePrivate []uint32 // size: xgb.Pad((int(DevicePrivateSize) * 4)) +} + +// Reply blocks and returns the reply data for a GetDeviceInfo request. +func (cook GetDeviceInfoCookie) Reply() (*GetDeviceInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDeviceInfoReply(buf), nil +} + +// getDeviceInfoReply reads a byte slice into a GetDeviceInfoReply value. +func getDeviceInfoReply(buf []byte) *GetDeviceInfoReply { + v := new(GetDeviceInfoReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.FramebufferHandleLow = xgb.Get32(buf[b:]) + b += 4 + + v.FramebufferHandleHigh = xgb.Get32(buf[b:]) + b += 4 + + v.FramebufferOriginOffset = xgb.Get32(buf[b:]) + b += 4 + + v.FramebufferSize = xgb.Get32(buf[b:]) + b += 4 + + v.FramebufferStride = xgb.Get32(buf[b:]) + b += 4 + + v.DevicePrivateSize = xgb.Get32(buf[b:]) + b += 4 + + v.DevicePrivate = make([]uint32, v.DevicePrivateSize) + for i := 0; i < int(v.DevicePrivateSize); i++ { + v.DevicePrivate[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetDeviceInfo +// getDeviceInfoRequest writes a GetDeviceInfo request to a byte slice. +func getDeviceInfoRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// GetDrawableInfoCookie is a cookie used only for GetDrawableInfo requests. +type GetDrawableInfoCookie struct { + *xgb.Cookie +} + +// GetDrawableInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDrawableInfoCookie.Reply() +func GetDrawableInfo(c *xgb.Conn, Screen uint32, Drawable uint32) GetDrawableInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetDrawableInfo' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDrawableInfoRequest(c, Screen, Drawable), cookie) + return GetDrawableInfoCookie{cookie} +} + +// GetDrawableInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDrawableInfoUnchecked(c *xgb.Conn, Screen uint32, Drawable uint32) GetDrawableInfoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'GetDrawableInfo' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDrawableInfoRequest(c, Screen, Drawable), cookie) + return GetDrawableInfoCookie{cookie} +} + +// GetDrawableInfoReply represents the data returned from a GetDrawableInfo request. +type GetDrawableInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + DrawableTableIndex uint32 + DrawableTableStamp uint32 + DrawableOriginX int16 + DrawableOriginY int16 + DrawableSizeW int16 + DrawableSizeH int16 + NumClipRects uint32 + BackX int16 + BackY int16 + NumBackClipRects uint32 + ClipRects []DrmClipRect // size: xgb.Pad((int(NumClipRects) * 8)) + BackClipRects []DrmClipRect // size: xgb.Pad((int(NumBackClipRects) * 8)) +} + +// Reply blocks and returns the reply data for a GetDrawableInfo request. +func (cook GetDrawableInfoCookie) Reply() (*GetDrawableInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDrawableInfoReply(buf), nil +} + +// getDrawableInfoReply reads a byte slice into a GetDrawableInfoReply value. +func getDrawableInfoReply(buf []byte) *GetDrawableInfoReply { + v := new(GetDrawableInfoReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.DrawableTableIndex = xgb.Get32(buf[b:]) + b += 4 + + v.DrawableTableStamp = xgb.Get32(buf[b:]) + b += 4 + + v.DrawableOriginX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.DrawableOriginY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.DrawableSizeW = int16(xgb.Get16(buf[b:])) + b += 2 + + v.DrawableSizeH = int16(xgb.Get16(buf[b:])) + b += 2 + + v.NumClipRects = xgb.Get32(buf[b:]) + b += 4 + + v.BackX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.BackY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.NumBackClipRects = xgb.Get32(buf[b:]) + b += 4 + + v.ClipRects = make([]DrmClipRect, v.NumClipRects) + b += DrmClipRectReadList(buf[b:], v.ClipRects) + + v.BackClipRects = make([]DrmClipRect, v.NumBackClipRects) + b += DrmClipRectReadList(buf[b:], v.BackClipRects) + + return v +} + +// Write request to wire for GetDrawableInfo +// getDrawableInfoRequest writes a GetDrawableInfo request to a byte slice. +func getDrawableInfoRequest(c *xgb.Conn, Screen uint32, Drawable uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], Drawable) + b += 4 + + return buf +} + +// OpenConnectionCookie is a cookie used only for OpenConnection requests. +type OpenConnectionCookie struct { + *xgb.Cookie +} + +// OpenConnection sends a checked request. +// If an error occurs, it will be returned with the reply by calling OpenConnectionCookie.Reply() +func OpenConnection(c *xgb.Conn, Screen uint32) OpenConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'OpenConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(openConnectionRequest(c, Screen), cookie) + return OpenConnectionCookie{cookie} +} + +// OpenConnectionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func OpenConnectionUnchecked(c *xgb.Conn, Screen uint32) OpenConnectionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'OpenConnection' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(openConnectionRequest(c, Screen), cookie) + return OpenConnectionCookie{cookie} +} + +// OpenConnectionReply represents the data returned from a OpenConnection request. +type OpenConnectionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + SareaHandleLow uint32 + SareaHandleHigh uint32 + BusIdLen uint32 + // padding: 12 bytes + BusId string // size: xgb.Pad((int(BusIdLen) * 1)) +} + +// Reply blocks and returns the reply data for a OpenConnection request. +func (cook OpenConnectionCookie) Reply() (*OpenConnectionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return openConnectionReply(buf), nil +} + +// openConnectionReply reads a byte slice into a OpenConnectionReply value. +func openConnectionReply(buf []byte) *OpenConnectionReply { + v := new(OpenConnectionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.SareaHandleLow = xgb.Get32(buf[b:]) + b += 4 + + v.SareaHandleHigh = xgb.Get32(buf[b:]) + b += 4 + + v.BusIdLen = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + { + byteString := make([]byte, v.BusIdLen) + copy(byteString[:v.BusIdLen], buf[b:]) + v.BusId = string(byteString) + b += int(v.BusIdLen) + } + + return v +} + +// Write request to wire for OpenConnection +// openConnectionRequest writes a OpenConnection request to a byte slice. +func openConnectionRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// QueryDirectRenderingCapableCookie is a cookie used only for QueryDirectRenderingCapable requests. +type QueryDirectRenderingCapableCookie struct { + *xgb.Cookie +} + +// QueryDirectRenderingCapable sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryDirectRenderingCapableCookie.Reply() +func QueryDirectRenderingCapable(c *xgb.Conn, Screen uint32) QueryDirectRenderingCapableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'QueryDirectRenderingCapable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryDirectRenderingCapableRequest(c, Screen), cookie) + return QueryDirectRenderingCapableCookie{cookie} +} + +// QueryDirectRenderingCapableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryDirectRenderingCapableUnchecked(c *xgb.Conn, Screen uint32) QueryDirectRenderingCapableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'QueryDirectRenderingCapable' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryDirectRenderingCapableRequest(c, Screen), cookie) + return QueryDirectRenderingCapableCookie{cookie} +} + +// QueryDirectRenderingCapableReply represents the data returned from a QueryDirectRenderingCapable request. +type QueryDirectRenderingCapableReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + IsCapable bool +} + +// Reply blocks and returns the reply data for a QueryDirectRenderingCapable request. +func (cook QueryDirectRenderingCapableCookie) Reply() (*QueryDirectRenderingCapableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryDirectRenderingCapableReply(buf), nil +} + +// queryDirectRenderingCapableReply reads a byte slice into a QueryDirectRenderingCapableReply value. +func queryDirectRenderingCapableReply(buf []byte) *QueryDirectRenderingCapableReply { + v := new(QueryDirectRenderingCapableReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.IsCapable = true + } else { + v.IsCapable = false + } + b += 1 + + return v +} + +// Write request to wire for QueryDirectRenderingCapable +// queryDirectRenderingCapableRequest writes a QueryDirectRenderingCapable request to a byte slice. +func queryDirectRenderingCapableRequest(c *xgb.Conn, Screen uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + 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:], Screen) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-DRI"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFree86-DRI'. xf86dri.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + DriMajorVersion uint16 + DriMinorVersion uint16 + DriMinorPatch uint32 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.DriMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.DriMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.DriMinorPatch = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-DRI"] + c.ExtLock.RUnlock() + 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 + + return buf +} diff --git a/nexgb/xf86vidmode/xf86vidmode.go b/nexgb/xf86vidmode/xf86vidmode.go new file mode 100644 index 0000000..22e236f --- /dev/null +++ b/nexgb/xf86vidmode/xf86vidmode.go @@ -0,0 +1,2688 @@ +// Package xf86vidmode is the X client API for the XFree86-VidModeExtension extension. +package xf86vidmode + +// This file is automatically generated from xf86vidmode.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XFree86-VidModeExtension extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 24, "XFree86-VidModeExtension").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XFree86-VidModeExtension could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XFree86-VidModeExtension"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XFree86-VidModeExtension"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XFree86-VidModeExtension"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XFree86-VidModeExtension"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadClock is the error number for a BadBadClock. +const BadBadClock = 0 + +type BadClockError struct { + Sequence uint16 + NiceName string +} + +// BadClockErrorNew constructs a BadClockError value that implements xgb.Error from a byte slice. +func BadClockErrorNew(buf []byte) xgb.Error { + v := BadClockError{} + v.NiceName = "BadClock" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadClock error. +// This is mostly used internally. +func (err BadClockError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadClock error. If no bad value exists, 0 is returned. +func (err BadClockError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadClock error. + +func (err BadClockError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadClock {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][0] = BadClockErrorNew +} + +// BadBadHTimings is the error number for a BadBadHTimings. +const BadBadHTimings = 1 + +type BadHTimingsError struct { + Sequence uint16 + NiceName string +} + +// BadHTimingsErrorNew constructs a BadHTimingsError value that implements xgb.Error from a byte slice. +func BadHTimingsErrorNew(buf []byte) xgb.Error { + v := BadHTimingsError{} + v.NiceName = "BadHTimings" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadHTimings error. +// This is mostly used internally. +func (err BadHTimingsError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadHTimings error. If no bad value exists, 0 is returned. +func (err BadHTimingsError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadHTimings error. + +func (err BadHTimingsError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadHTimings {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][1] = BadHTimingsErrorNew +} + +// BadBadVTimings is the error number for a BadBadVTimings. +const BadBadVTimings = 2 + +type BadVTimingsError struct { + Sequence uint16 + NiceName string +} + +// BadVTimingsErrorNew constructs a BadVTimingsError value that implements xgb.Error from a byte slice. +func BadVTimingsErrorNew(buf []byte) xgb.Error { + v := BadVTimingsError{} + v.NiceName = "BadVTimings" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadVTimings error. +// This is mostly used internally. +func (err BadVTimingsError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadVTimings error. If no bad value exists, 0 is returned. +func (err BadVTimingsError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadVTimings error. + +func (err BadVTimingsError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadVTimings {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][2] = BadVTimingsErrorNew +} + +// BadClientNotLocal is the error number for a BadClientNotLocal. +const BadClientNotLocal = 5 + +type ClientNotLocalError struct { + Sequence uint16 + NiceName string +} + +// ClientNotLocalErrorNew constructs a ClientNotLocalError value that implements xgb.Error from a byte slice. +func ClientNotLocalErrorNew(buf []byte) xgb.Error { + v := ClientNotLocalError{} + v.NiceName = "ClientNotLocal" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadClientNotLocal error. +// This is mostly used internally. +func (err ClientNotLocalError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadClientNotLocal error. If no bad value exists, 0 is returned. +func (err ClientNotLocalError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadClientNotLocal error. + +func (err ClientNotLocalError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadClientNotLocal {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][5] = ClientNotLocalErrorNew +} + +const ( + ClockFlagProgramable = 1 +) + +type Dotclock uint32 + +// BadExtensionDisabled is the error number for a BadExtensionDisabled. +const BadExtensionDisabled = 4 + +type ExtensionDisabledError struct { + Sequence uint16 + NiceName string +} + +// ExtensionDisabledErrorNew constructs a ExtensionDisabledError value that implements xgb.Error from a byte slice. +func ExtensionDisabledErrorNew(buf []byte) xgb.Error { + v := ExtensionDisabledError{} + v.NiceName = "ExtensionDisabled" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadExtensionDisabled error. +// This is mostly used internally. +func (err ExtensionDisabledError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadExtensionDisabled error. If no bad value exists, 0 is returned. +func (err ExtensionDisabledError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadExtensionDisabled error. + +func (err ExtensionDisabledError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadExtensionDisabled {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][4] = ExtensionDisabledErrorNew +} + +const ( + ModeFlagPositiveHsync = 1 + ModeFlagNegativeHsync = 2 + ModeFlagPositiveVsync = 4 + ModeFlagNegativeVsync = 8 + ModeFlagInterlace = 16 + ModeFlagCompositeSync = 32 + ModeFlagPositiveCsync = 64 + ModeFlagNegativeCsync = 128 + ModeFlagHSkew = 256 + ModeFlagBroadcast = 512 + ModeFlagPixmux = 1024 + ModeFlagDoubleClock = 2048 + ModeFlagHalfClock = 4096 +) + +type ModeInfo struct { + Dotclock Dotclock + Hdisplay uint16 + Hsyncstart uint16 + Hsyncend uint16 + Htotal uint16 + Hskew uint32 + Vdisplay uint16 + Vsyncstart uint16 + Vsyncend uint16 + Vtotal uint16 + // padding: 4 bytes + Flags uint32 + // padding: 12 bytes + Privsize uint32 +} + +// ModeInfoRead reads a byte slice into a ModeInfo value. +func ModeInfoRead(buf []byte, v *ModeInfo) int { + b := 0 + + v.Dotclock = Dotclock(xgb.Get32(buf[b:])) + b += 4 + + v.Hdisplay = xgb.Get16(buf[b:]) + b += 2 + + v.Hsyncstart = xgb.Get16(buf[b:]) + b += 2 + + v.Hsyncend = xgb.Get16(buf[b:]) + b += 2 + + v.Htotal = xgb.Get16(buf[b:]) + b += 2 + + v.Hskew = xgb.Get32(buf[b:]) + b += 4 + + v.Vdisplay = xgb.Get16(buf[b:]) + b += 2 + + v.Vsyncstart = xgb.Get16(buf[b:]) + b += 2 + + v.Vsyncend = xgb.Get16(buf[b:]) + b += 2 + + v.Vtotal = xgb.Get16(buf[b:]) + b += 2 + + b += 4 // padding + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Privsize = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// ModeInfoReadList reads a byte slice into a list of ModeInfo values. +func ModeInfoReadList(buf []byte, dest []ModeInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ModeInfo{} + b += ModeInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ModeInfo value to a byte slice. +func (v ModeInfo) Bytes() []byte { + buf := make([]byte, 48) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Dotclock)) + b += 4 + + xgb.Put16(buf[b:], v.Hdisplay) + b += 2 + + xgb.Put16(buf[b:], v.Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], v.Hsyncend) + b += 2 + + xgb.Put16(buf[b:], v.Htotal) + b += 2 + + xgb.Put32(buf[b:], v.Hskew) + b += 4 + + xgb.Put16(buf[b:], v.Vdisplay) + b += 2 + + xgb.Put16(buf[b:], v.Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], v.Vsyncend) + b += 2 + + xgb.Put16(buf[b:], v.Vtotal) + b += 2 + + b += 4 // padding + + xgb.Put32(buf[b:], v.Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], v.Privsize) + b += 4 + + return buf[:b] +} + +// ModeInfoListBytes writes a list of ModeInfo values to a byte slice. +func ModeInfoListBytes(buf []byte, list []ModeInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// BadModeUnsuitable is the error number for a BadModeUnsuitable. +const BadModeUnsuitable = 3 + +type ModeUnsuitableError struct { + Sequence uint16 + NiceName string +} + +// ModeUnsuitableErrorNew constructs a ModeUnsuitableError value that implements xgb.Error from a byte slice. +func ModeUnsuitableErrorNew(buf []byte) xgb.Error { + v := ModeUnsuitableError{} + v.NiceName = "ModeUnsuitable" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadModeUnsuitable error. +// This is mostly used internally. +func (err ModeUnsuitableError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadModeUnsuitable error. If no bad value exists, 0 is returned. +func (err ModeUnsuitableError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadModeUnsuitable error. + +func (err ModeUnsuitableError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadModeUnsuitable {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][3] = ModeUnsuitableErrorNew +} + +const ( + PermissionRead = 1 + PermissionWrite = 2 +) + +type Syncrange uint32 + +// BadZoomLocked is the error number for a BadZoomLocked. +const BadZoomLocked = 6 + +type ZoomLockedError struct { + Sequence uint16 + NiceName string +} + +// ZoomLockedErrorNew constructs a ZoomLockedError value that implements xgb.Error from a byte slice. +func ZoomLockedErrorNew(buf []byte) xgb.Error { + v := ZoomLockedError{} + v.NiceName = "ZoomLocked" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadZoomLocked error. +// This is mostly used internally. +func (err ZoomLockedError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadZoomLocked error. If no bad value exists, 0 is returned. +func (err ZoomLockedError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadZoomLocked error. + +func (err ZoomLockedError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadZoomLocked {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFree86-VidModeExtension"][6] = ZoomLockedErrorNew +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AddModeLineCookie is a cookie used only for AddModeLine requests. +type AddModeLineCookie struct { + *xgb.Cookie +} + +// AddModeLine sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AddModeLine(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, AfterDotclock Dotclock, AfterHdisplay uint16, AfterHsyncstart uint16, AfterHsyncend uint16, AfterHtotal uint16, AfterHskew uint16, AfterVdisplay uint16, AfterVsyncstart uint16, AfterVsyncend uint16, AfterVtotal uint16, AfterFlags uint32, Private []byte) AddModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'AddModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(addModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, AfterDotclock, AfterHdisplay, AfterHsyncstart, AfterHsyncend, AfterHtotal, AfterHskew, AfterVdisplay, AfterVsyncstart, AfterVsyncend, AfterVtotal, AfterFlags, Private), cookie) + return AddModeLineCookie{cookie} +} + +// AddModeLineChecked sends a checked request. +// If an error occurs, it can be retrieved using AddModeLineCookie.Check() +func AddModeLineChecked(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, AfterDotclock Dotclock, AfterHdisplay uint16, AfterHsyncstart uint16, AfterHsyncend uint16, AfterHtotal uint16, AfterHskew uint16, AfterVdisplay uint16, AfterVsyncstart uint16, AfterVsyncend uint16, AfterVtotal uint16, AfterFlags uint32, Private []byte) AddModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'AddModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(addModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, AfterDotclock, AfterHdisplay, AfterHsyncstart, AfterHsyncend, AfterHtotal, AfterHskew, AfterVdisplay, AfterVsyncstart, AfterVsyncend, AfterVtotal, AfterFlags, Private), cookie) + return AddModeLineCookie{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 AddModeLineCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AddModeLine +// addModeLineRequest writes a AddModeLine request to a byte slice. +func addModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, AfterDotclock Dotclock, AfterHdisplay uint16, AfterHsyncstart uint16, AfterHsyncend uint16, AfterHtotal uint16, AfterHskew uint16, AfterVdisplay uint16, AfterVsyncstart uint16, AfterVsyncend uint16, AfterVtotal uint16, AfterFlags uint32, Private []byte) []byte { + size := xgb.Pad((92 + xgb.Pad((int(Privsize) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Dotclock)) + b += 4 + + xgb.Put16(buf[b:], Hdisplay) + b += 2 + + xgb.Put16(buf[b:], Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], Hsyncend) + b += 2 + + xgb.Put16(buf[b:], Htotal) + b += 2 + + xgb.Put16(buf[b:], Hskew) + b += 2 + + xgb.Put16(buf[b:], Vdisplay) + b += 2 + + xgb.Put16(buf[b:], Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], Vsyncend) + b += 2 + + xgb.Put16(buf[b:], Vtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], Privsize) + b += 4 + + xgb.Put32(buf[b:], uint32(AfterDotclock)) + b += 4 + + xgb.Put16(buf[b:], AfterHdisplay) + b += 2 + + xgb.Put16(buf[b:], AfterHsyncstart) + b += 2 + + xgb.Put16(buf[b:], AfterHsyncend) + b += 2 + + xgb.Put16(buf[b:], AfterHtotal) + b += 2 + + xgb.Put16(buf[b:], AfterHskew) + b += 2 + + xgb.Put16(buf[b:], AfterVdisplay) + b += 2 + + xgb.Put16(buf[b:], AfterVsyncstart) + b += 2 + + xgb.Put16(buf[b:], AfterVsyncend) + b += 2 + + xgb.Put16(buf[b:], AfterVtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], AfterFlags) + b += 4 + + b += 12 // padding + + copy(buf[b:], Private[:Privsize]) + b += int(Privsize) + + return buf +} + +// DeleteModeLineCookie is a cookie used only for DeleteModeLine requests. +type DeleteModeLineCookie struct { + *xgb.Cookie +} + +// DeleteModeLine sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteModeLine(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) DeleteModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'DeleteModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return DeleteModeLineCookie{cookie} +} + +// DeleteModeLineChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteModeLineCookie.Check() +func DeleteModeLineChecked(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) DeleteModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'DeleteModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return DeleteModeLineCookie{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 DeleteModeLineCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteModeLine +// deleteModeLineRequest writes a DeleteModeLine request to a byte slice. +func deleteModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) []byte { + size := xgb.Pad((52 + xgb.Pad((int(Privsize) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Dotclock)) + b += 4 + + xgb.Put16(buf[b:], Hdisplay) + b += 2 + + xgb.Put16(buf[b:], Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], Hsyncend) + b += 2 + + xgb.Put16(buf[b:], Htotal) + b += 2 + + xgb.Put16(buf[b:], Hskew) + b += 2 + + xgb.Put16(buf[b:], Vdisplay) + b += 2 + + xgb.Put16(buf[b:], Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], Vsyncend) + b += 2 + + xgb.Put16(buf[b:], Vtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], Privsize) + b += 4 + + copy(buf[b:], Private[:Privsize]) + b += int(Privsize) + + return buf +} + +// GetAllModeLinesCookie is a cookie used only for GetAllModeLines requests. +type GetAllModeLinesCookie struct { + *xgb.Cookie +} + +// GetAllModeLines sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetAllModeLinesCookie.Reply() +func GetAllModeLines(c *xgb.Conn, Screen uint16) GetAllModeLinesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetAllModeLines' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getAllModeLinesRequest(c, Screen), cookie) + return GetAllModeLinesCookie{cookie} +} + +// GetAllModeLinesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetAllModeLinesUnchecked(c *xgb.Conn, Screen uint16) GetAllModeLinesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetAllModeLines' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getAllModeLinesRequest(c, Screen), cookie) + return GetAllModeLinesCookie{cookie} +} + +// GetAllModeLinesReply represents the data returned from a GetAllModeLines request. +type GetAllModeLinesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Modecount uint32 + // padding: 20 bytes + Modeinfo []ModeInfo // size: xgb.Pad((int(Modecount) * 48)) +} + +// Reply blocks and returns the reply data for a GetAllModeLines request. +func (cook GetAllModeLinesCookie) Reply() (*GetAllModeLinesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getAllModeLinesReply(buf), nil +} + +// getAllModeLinesReply reads a byte slice into a GetAllModeLinesReply value. +func getAllModeLinesReply(buf []byte) *GetAllModeLinesReply { + v := new(GetAllModeLinesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Modecount = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Modeinfo = make([]ModeInfo, v.Modecount) + b += ModeInfoReadList(buf[b:], v.Modeinfo) + + return v +} + +// Write request to wire for GetAllModeLines +// getAllModeLinesRequest writes a GetAllModeLines request to a byte slice. +func getAllModeLinesRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetDotClocksCookie is a cookie used only for GetDotClocks requests. +type GetDotClocksCookie struct { + *xgb.Cookie +} + +// GetDotClocks sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDotClocksCookie.Reply() +func GetDotClocks(c *xgb.Conn, Screen uint16) GetDotClocksCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetDotClocks' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDotClocksRequest(c, Screen), cookie) + return GetDotClocksCookie{cookie} +} + +// GetDotClocksUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDotClocksUnchecked(c *xgb.Conn, Screen uint16) GetDotClocksCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetDotClocks' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDotClocksRequest(c, Screen), cookie) + return GetDotClocksCookie{cookie} +} + +// GetDotClocksReply represents the data returned from a GetDotClocks request. +type GetDotClocksReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Flags uint32 + Clocks uint32 + Maxclocks uint32 + // padding: 12 bytes + Clock []uint32 // size: xgb.Pad((((1 - (int(Flags) & 1)) * int(Clocks)) * 4)) +} + +// Reply blocks and returns the reply data for a GetDotClocks request. +func (cook GetDotClocksCookie) Reply() (*GetDotClocksReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDotClocksReply(buf), nil +} + +// getDotClocksReply reads a byte slice into a GetDotClocksReply value. +func getDotClocksReply(buf []byte) *GetDotClocksReply { + v := new(GetDotClocksReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + v.Clocks = xgb.Get32(buf[b:]) + b += 4 + + v.Maxclocks = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Clock = make([]uint32, ((1 - (int(v.Flags) & 1)) * int(v.Clocks))) + for i := 0; i < int(((1 - (int(v.Flags) & 1)) * int(v.Clocks))); i++ { + v.Clock[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetDotClocks +// getDotClocksRequest writes a GetDotClocks request to a byte slice. +func getDotClocksRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetGammaCookie is a cookie used only for GetGamma requests. +type GetGammaCookie struct { + *xgb.Cookie +} + +// GetGamma sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetGammaCookie.Reply() +func GetGamma(c *xgb.Conn, Screen uint16) GetGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGamma' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getGammaRequest(c, Screen), cookie) + return GetGammaCookie{cookie} +} + +// GetGammaUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetGammaUnchecked(c *xgb.Conn, Screen uint16) GetGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGamma' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getGammaRequest(c, Screen), cookie) + return GetGammaCookie{cookie} +} + +// GetGammaReply represents the data returned from a GetGamma request. +type GetGammaReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Red uint32 + Green uint32 + Blue uint32 + // padding: 12 bytes +} + +// Reply blocks and returns the reply data for a GetGamma request. +func (cook GetGammaCookie) Reply() (*GetGammaReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getGammaReply(buf), nil +} + +// getGammaReply reads a byte slice into a GetGammaReply value. +func getGammaReply(buf []byte) *GetGammaReply { + v := new(GetGammaReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Red = xgb.Get32(buf[b:]) + b += 4 + + v.Green = xgb.Get32(buf[b:]) + b += 4 + + v.Blue = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + return v +} + +// Write request to wire for GetGamma +// getGammaRequest writes a GetGamma request to a byte slice. +func getGammaRequest(c *xgb.Conn, Screen uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 26 // padding + + return buf +} + +// GetGammaRampCookie is a cookie used only for GetGammaRamp requests. +type GetGammaRampCookie struct { + *xgb.Cookie +} + +// GetGammaRamp sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetGammaRampCookie.Reply() +func GetGammaRamp(c *xgb.Conn, Screen uint16, Size uint16) GetGammaRampCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGammaRamp' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getGammaRampRequest(c, Screen, Size), cookie) + return GetGammaRampCookie{cookie} +} + +// GetGammaRampUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetGammaRampUnchecked(c *xgb.Conn, Screen uint16, Size uint16) GetGammaRampCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGammaRamp' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getGammaRampRequest(c, Screen, Size), cookie) + return GetGammaRampCookie{cookie} +} + +// GetGammaRampReply represents the data returned from a GetGammaRamp request. +type GetGammaRampReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Size uint16 + // padding: 22 bytes + Red []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + Green []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + Blue []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) +} + +// Reply blocks and returns the reply data for a GetGammaRamp request. +func (cook GetGammaRampCookie) Reply() (*GetGammaRampReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getGammaRampReply(buf), nil +} + +// getGammaRampReply reads a byte slice into a GetGammaRampReply value. +func getGammaRampReply(buf []byte) *GetGammaRampReply { + v := new(GetGammaRampReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Size = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Red = make([]uint16, ((int(v.Size) + 1) & -2)) + for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { + v.Red[i] = xgb.Get16(buf[b:]) + b += 2 + } + + v.Green = make([]uint16, ((int(v.Size) + 1) & -2)) + for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { + v.Green[i] = xgb.Get16(buf[b:]) + b += 2 + } + + v.Blue = make([]uint16, ((int(v.Size) + 1) & -2)) + for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { + v.Blue[i] = xgb.Get16(buf[b:]) + b += 2 + } + + return v +} + +// Write request to wire for GetGammaRamp +// getGammaRampRequest writes a GetGammaRamp request to a byte slice. +func getGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + xgb.Put16(buf[b:], Size) + b += 2 + + return buf +} + +// GetGammaRampSizeCookie is a cookie used only for GetGammaRampSize requests. +type GetGammaRampSizeCookie struct { + *xgb.Cookie +} + +// GetGammaRampSize sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetGammaRampSizeCookie.Reply() +func GetGammaRampSize(c *xgb.Conn, Screen uint16) GetGammaRampSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGammaRampSize' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getGammaRampSizeRequest(c, Screen), cookie) + return GetGammaRampSizeCookie{cookie} +} + +// GetGammaRampSizeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetGammaRampSizeUnchecked(c *xgb.Conn, Screen uint16) GetGammaRampSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetGammaRampSize' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getGammaRampSizeRequest(c, Screen), cookie) + return GetGammaRampSizeCookie{cookie} +} + +// GetGammaRampSizeReply represents the data returned from a GetGammaRampSize request. +type GetGammaRampSizeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Size uint16 + // padding: 22 bytes +} + +// Reply blocks and returns the reply data for a GetGammaRampSize request. +func (cook GetGammaRampSizeCookie) Reply() (*GetGammaRampSizeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getGammaRampSizeReply(buf), nil +} + +// getGammaRampSizeReply reads a byte slice into a GetGammaRampSizeReply value. +func getGammaRampSizeReply(buf []byte) *GetGammaRampSizeReply { + v := new(GetGammaRampSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Size = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + return v +} + +// Write request to wire for GetGammaRampSize +// getGammaRampSizeRequest writes a GetGammaRampSize request to a byte slice. +func getGammaRampSizeRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetModeLineCookie is a cookie used only for GetModeLine requests. +type GetModeLineCookie struct { + *xgb.Cookie +} + +// GetModeLine sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetModeLineCookie.Reply() +func GetModeLine(c *xgb.Conn, Screen uint16) GetModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getModeLineRequest(c, Screen), cookie) + return GetModeLineCookie{cookie} +} + +// GetModeLineUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetModeLineUnchecked(c *xgb.Conn, Screen uint16) GetModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getModeLineRequest(c, Screen), cookie) + return GetModeLineCookie{cookie} +} + +// GetModeLineReply represents the data returned from a GetModeLine request. +type GetModeLineReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Dotclock Dotclock + Hdisplay uint16 + Hsyncstart uint16 + Hsyncend uint16 + Htotal uint16 + Hskew uint16 + Vdisplay uint16 + Vsyncstart uint16 + Vsyncend uint16 + Vtotal uint16 + // padding: 2 bytes + Flags uint32 + // padding: 12 bytes + Privsize uint32 + Private []byte // size: xgb.Pad((int(Privsize) * 1)) +} + +// Reply blocks and returns the reply data for a GetModeLine request. +func (cook GetModeLineCookie) Reply() (*GetModeLineReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getModeLineReply(buf), nil +} + +// getModeLineReply reads a byte slice into a GetModeLineReply value. +func getModeLineReply(buf []byte) *GetModeLineReply { + v := new(GetModeLineReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Dotclock = Dotclock(xgb.Get32(buf[b:])) + b += 4 + + v.Hdisplay = xgb.Get16(buf[b:]) + b += 2 + + v.Hsyncstart = xgb.Get16(buf[b:]) + b += 2 + + v.Hsyncend = xgb.Get16(buf[b:]) + b += 2 + + v.Htotal = xgb.Get16(buf[b:]) + b += 2 + + v.Hskew = xgb.Get16(buf[b:]) + b += 2 + + v.Vdisplay = xgb.Get16(buf[b:]) + b += 2 + + v.Vsyncstart = xgb.Get16(buf[b:]) + b += 2 + + v.Vsyncend = xgb.Get16(buf[b:]) + b += 2 + + v.Vtotal = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Privsize = xgb.Get32(buf[b:]) + b += 4 + + v.Private = make([]byte, v.Privsize) + copy(v.Private[:v.Privsize], buf[b:]) + b += int(v.Privsize) + + return v +} + +// Write request to wire for GetModeLine +// getModeLineRequest writes a GetModeLine request to a byte slice. +func getModeLineRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + 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.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetMonitorCookie is a cookie used only for GetMonitor requests. +type GetMonitorCookie struct { + *xgb.Cookie +} + +// GetMonitor sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMonitorCookie.Reply() +func GetMonitor(c *xgb.Conn, Screen uint16) GetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetMonitor' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMonitorRequest(c, Screen), cookie) + return GetMonitorCookie{cookie} +} + +// GetMonitorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMonitorUnchecked(c *xgb.Conn, Screen uint16) GetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetMonitor' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMonitorRequest(c, Screen), cookie) + return GetMonitorCookie{cookie} +} + +// GetMonitorReply represents the data returned from a GetMonitor request. +type GetMonitorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + VendorLength byte + ModelLength byte + NumHsync byte + NumVsync byte + // padding: 20 bytes + Hsync []Syncrange // size: xgb.Pad((int(NumHsync) * 4)) + Vsync []Syncrange // size: xgb.Pad((int(NumVsync) * 4)) + Vendor string // size: xgb.Pad((int(VendorLength) * 1)) + AlignmentPad []byte // size: xgb.Pad(((((int(VendorLength) + 3) & -4) - int(VendorLength)) * 1)) + Model string // size: xgb.Pad((int(ModelLength) * 1)) +} + +// Reply blocks and returns the reply data for a GetMonitor request. +func (cook GetMonitorCookie) Reply() (*GetMonitorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMonitorReply(buf), nil +} + +// getMonitorReply reads a byte slice into a GetMonitorReply value. +func getMonitorReply(buf []byte) *GetMonitorReply { + v := new(GetMonitorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.VendorLength = buf[b] + b += 1 + + v.ModelLength = buf[b] + b += 1 + + v.NumHsync = buf[b] + b += 1 + + v.NumVsync = buf[b] + b += 1 + + b += 20 // padding + + v.Hsync = make([]Syncrange, v.NumHsync) + for i := 0; i < int(v.NumHsync); i++ { + v.Hsync[i] = Syncrange(xgb.Get32(buf[b:])) + b += 4 + } + + v.Vsync = make([]Syncrange, v.NumVsync) + for i := 0; i < int(v.NumVsync); i++ { + v.Vsync[i] = Syncrange(xgb.Get32(buf[b:])) + b += 4 + } + + { + byteString := make([]byte, v.VendorLength) + copy(byteString[:v.VendorLength], buf[b:]) + v.Vendor = string(byteString) + b += int(v.VendorLength) + } + + v.AlignmentPad = make([]byte, (((int(v.VendorLength) + 3) & -4) - int(v.VendorLength))) + copy(v.AlignmentPad[:(((int(v.VendorLength)+3)&-4)-int(v.VendorLength))], buf[b:]) + b += int((((int(v.VendorLength) + 3) & -4) - int(v.VendorLength))) + + { + byteString := make([]byte, v.ModelLength) + copy(byteString[:v.ModelLength], buf[b:]) + v.Model = string(byteString) + b += int(v.ModelLength) + } + + return v +} + +// Write request to wire for GetMonitor +// getMonitorRequest writes a GetMonitor request to a byte slice. +func getMonitorRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetPermissionsCookie is a cookie used only for GetPermissions requests. +type GetPermissionsCookie struct { + *xgb.Cookie +} + +// GetPermissions sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPermissionsCookie.Reply() +func GetPermissions(c *xgb.Conn, Screen uint16) GetPermissionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetPermissions' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPermissionsRequest(c, Screen), cookie) + return GetPermissionsCookie{cookie} +} + +// GetPermissionsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPermissionsUnchecked(c *xgb.Conn, Screen uint16) GetPermissionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetPermissions' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPermissionsRequest(c, Screen), cookie) + return GetPermissionsCookie{cookie} +} + +// GetPermissionsReply represents the data returned from a GetPermissions request. +type GetPermissionsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Permissions uint32 + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a GetPermissions request. +func (cook GetPermissionsCookie) Reply() (*GetPermissionsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPermissionsReply(buf), nil +} + +// getPermissionsReply reads a byte slice into a GetPermissionsReply value. +func getPermissionsReply(buf []byte) *GetPermissionsReply { + v := new(GetPermissionsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Permissions = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for GetPermissions +// getPermissionsRequest writes a GetPermissions request to a byte slice. +func getPermissionsRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// GetViewPortCookie is a cookie used only for GetViewPort requests. +type GetViewPortCookie struct { + *xgb.Cookie +} + +// GetViewPort sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetViewPortCookie.Reply() +func GetViewPort(c *xgb.Conn, Screen uint16) GetViewPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetViewPort' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getViewPortRequest(c, Screen), cookie) + return GetViewPortCookie{cookie} +} + +// GetViewPortUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetViewPortUnchecked(c *xgb.Conn, Screen uint16) GetViewPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'GetViewPort' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getViewPortRequest(c, Screen), cookie) + return GetViewPortCookie{cookie} +} + +// GetViewPortReply represents the data returned from a GetViewPort request. +type GetViewPortReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + X uint32 + Y uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a GetViewPort request. +func (cook GetViewPortCookie) Reply() (*GetViewPortReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getViewPortReply(buf), nil +} + +// getViewPortReply reads a byte slice into a GetViewPortReply value. +func getViewPortReply(buf []byte) *GetViewPortReply { + v := new(GetViewPortReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.X = xgb.Get32(buf[b:]) + b += 4 + + v.Y = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for GetViewPort +// getViewPortRequest writes a GetViewPort request to a byte slice. +func getViewPortRequest(c *xgb.Conn, Screen uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + return buf +} + +// LockModeSwitchCookie is a cookie used only for LockModeSwitch requests. +type LockModeSwitchCookie struct { + *xgb.Cookie +} + +// LockModeSwitch sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func LockModeSwitch(c *xgb.Conn, Screen uint16, Lock uint16) LockModeSwitchCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'LockModeSwitch' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(lockModeSwitchRequest(c, Screen, Lock), cookie) + return LockModeSwitchCookie{cookie} +} + +// LockModeSwitchChecked sends a checked request. +// If an error occurs, it can be retrieved using LockModeSwitchCookie.Check() +func LockModeSwitchChecked(c *xgb.Conn, Screen uint16, Lock uint16) LockModeSwitchCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'LockModeSwitch' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(lockModeSwitchRequest(c, Screen, Lock), cookie) + return LockModeSwitchCookie{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 LockModeSwitchCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for LockModeSwitch +// lockModeSwitchRequest writes a LockModeSwitch request to a byte slice. +func lockModeSwitchRequest(c *xgb.Conn, Screen uint16, Lock uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + xgb.Put16(buf[b:], Lock) + b += 2 + + return buf +} + +// ModModeLineCookie is a cookie used only for ModModeLine requests. +type ModModeLineCookie struct { + *xgb.Cookie +} + +// ModModeLine sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ModModeLine(c *xgb.Conn, Screen uint32, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) ModModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'ModModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(modModeLineRequest(c, Screen, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return ModModeLineCookie{cookie} +} + +// ModModeLineChecked sends a checked request. +// If an error occurs, it can be retrieved using ModModeLineCookie.Check() +func ModModeLineChecked(c *xgb.Conn, Screen uint32, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) ModModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'ModModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(modModeLineRequest(c, Screen, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return ModModeLineCookie{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 ModModeLineCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ModModeLine +// modModeLineRequest writes a ModModeLine request to a byte slice. +func modModeLineRequest(c *xgb.Conn, Screen uint32, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) []byte { + size := xgb.Pad((48 + xgb.Pad((int(Privsize) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put16(buf[b:], Hdisplay) + b += 2 + + xgb.Put16(buf[b:], Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], Hsyncend) + b += 2 + + xgb.Put16(buf[b:], Htotal) + b += 2 + + xgb.Put16(buf[b:], Hskew) + b += 2 + + xgb.Put16(buf[b:], Vdisplay) + b += 2 + + xgb.Put16(buf[b:], Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], Vsyncend) + b += 2 + + xgb.Put16(buf[b:], Vtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], Privsize) + b += 4 + + copy(buf[b:], Private[:Privsize]) + b += int(Privsize) + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// SetClientVersionCookie is a cookie used only for SetClientVersion requests. +type SetClientVersionCookie struct { + *xgb.Cookie +} + +// SetClientVersion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetClientVersion(c *xgb.Conn, Major uint16, Minor uint16) SetClientVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetClientVersion' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setClientVersionRequest(c, Major, Minor), cookie) + return SetClientVersionCookie{cookie} +} + +// SetClientVersionChecked sends a checked request. +// If an error occurs, it can be retrieved using SetClientVersionCookie.Check() +func SetClientVersionChecked(c *xgb.Conn, Major uint16, Minor uint16) SetClientVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetClientVersion' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setClientVersionRequest(c, Major, Minor), cookie) + return SetClientVersionCookie{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 SetClientVersionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetClientVersion +// setClientVersionRequest writes a SetClientVersion request to a byte slice. +func setClientVersionRequest(c *xgb.Conn, Major uint16, Minor uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Major) + b += 2 + + xgb.Put16(buf[b:], Minor) + b += 2 + + return buf +} + +// SetGammaCookie is a cookie used only for SetGamma requests. +type SetGammaCookie struct { + *xgb.Cookie +} + +// SetGamma sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetGamma(c *xgb.Conn, Screen uint16, Red uint32, Green uint32, Blue uint32) SetGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetGamma' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setGammaRequest(c, Screen, Red, Green, Blue), cookie) + return SetGammaCookie{cookie} +} + +// SetGammaChecked sends a checked request. +// If an error occurs, it can be retrieved using SetGammaCookie.Check() +func SetGammaChecked(c *xgb.Conn, Screen uint16, Red uint32, Green uint32, Blue uint32) SetGammaCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetGamma' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setGammaRequest(c, Screen, Red, Green, Blue), cookie) + return SetGammaCookie{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 SetGammaCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetGamma +// setGammaRequest writes a SetGamma request to a byte slice. +func setGammaRequest(c *xgb.Conn, Screen uint16, Red uint32, Green uint32, Blue uint32) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Red) + b += 4 + + xgb.Put32(buf[b:], Green) + b += 4 + + xgb.Put32(buf[b:], Blue) + b += 4 + + b += 12 // padding + + return buf +} + +// SetGammaRampCookie is a cookie used only for SetGammaRamp requests. +type SetGammaRampCookie struct { + *xgb.Cookie +} + +// SetGammaRamp sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetGammaRamp(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, Green []uint16, Blue []uint16) SetGammaRampCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetGammaRamp' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setGammaRampRequest(c, Screen, Size, Red, Green, Blue), cookie) + return SetGammaRampCookie{cookie} +} + +// SetGammaRampChecked sends a checked request. +// If an error occurs, it can be retrieved using SetGammaRampCookie.Check() +func SetGammaRampChecked(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, Green []uint16, Blue []uint16) SetGammaRampCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetGammaRamp' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setGammaRampRequest(c, Screen, Size, Red, Green, Blue), cookie) + return SetGammaRampCookie{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 SetGammaRampCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetGammaRamp +// setGammaRampRequest writes a SetGammaRamp request to a byte slice. +func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, Green []uint16, Blue []uint16) []byte { + size := xgb.Pad((((8 + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + xgb.Put16(buf[b:], Size) + b += 2 + + for i := 0; i < int(((int(Size) + 1) & -2)); i++ { + xgb.Put16(buf[b:], Red[i]) + b += 2 + } + + for i := 0; i < int(((int(Size) + 1) & -2)); i++ { + xgb.Put16(buf[b:], Green[i]) + b += 2 + } + + for i := 0; i < int(((int(Size) + 1) & -2)); i++ { + xgb.Put16(buf[b:], Blue[i]) + b += 2 + } + + return buf +} + +// SetViewPortCookie is a cookie used only for SetViewPort requests. +type SetViewPortCookie struct { + *xgb.Cookie +} + +// SetViewPort sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetViewPort(c *xgb.Conn, Screen uint16, X uint32, Y uint32) SetViewPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetViewPort' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setViewPortRequest(c, Screen, X, Y), cookie) + return SetViewPortCookie{cookie} +} + +// SetViewPortChecked sends a checked request. +// If an error occurs, it can be retrieved using SetViewPortCookie.Check() +func SetViewPortChecked(c *xgb.Conn, Screen uint16, X uint32, Y uint32) SetViewPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SetViewPort' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setViewPortRequest(c, Screen, X, Y), cookie) + return SetViewPortCookie{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 SetViewPortCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetViewPort +// setViewPortRequest writes a SetViewPort request to a byte slice. +func setViewPortRequest(c *xgb.Conn, Screen uint16, X uint32, Y uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], Screen) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], X) + b += 4 + + xgb.Put32(buf[b:], Y) + b += 4 + + return buf +} + +// SwitchModeCookie is a cookie used only for SwitchMode requests. +type SwitchModeCookie struct { + *xgb.Cookie +} + +// SwitchMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SwitchMode(c *xgb.Conn, Screen uint16, Zoom uint16) SwitchModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SwitchMode' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(switchModeRequest(c, Screen, Zoom), cookie) + return SwitchModeCookie{cookie} +} + +// SwitchModeChecked sends a checked request. +// If an error occurs, it can be retrieved using SwitchModeCookie.Check() +func SwitchModeChecked(c *xgb.Conn, Screen uint16, Zoom uint16) SwitchModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SwitchMode' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(switchModeRequest(c, Screen, Zoom), cookie) + return SwitchModeCookie{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 SwitchModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SwitchMode +// switchModeRequest writes a SwitchMode request to a byte slice. +func switchModeRequest(c *xgb.Conn, Screen uint16, Zoom uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + 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 + + xgb.Put16(buf[b:], Screen) + b += 2 + + xgb.Put16(buf[b:], Zoom) + b += 2 + + return buf +} + +// SwitchToModeCookie is a cookie used only for SwitchToMode requests. +type SwitchToModeCookie struct { + *xgb.Cookie +} + +// SwitchToMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SwitchToMode(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) SwitchToModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SwitchToMode' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(switchToModeRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return SwitchToModeCookie{cookie} +} + +// SwitchToModeChecked sends a checked request. +// If an error occurs, it can be retrieved using SwitchToModeCookie.Check() +func SwitchToModeChecked(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) SwitchToModeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'SwitchToMode' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(switchToModeRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return SwitchToModeCookie{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 SwitchToModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SwitchToMode +// switchToModeRequest writes a SwitchToMode request to a byte slice. +func switchToModeRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) []byte { + size := xgb.Pad((52 + xgb.Pad((int(Privsize) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Dotclock)) + b += 4 + + xgb.Put16(buf[b:], Hdisplay) + b += 2 + + xgb.Put16(buf[b:], Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], Hsyncend) + b += 2 + + xgb.Put16(buf[b:], Htotal) + b += 2 + + xgb.Put16(buf[b:], Hskew) + b += 2 + + xgb.Put16(buf[b:], Vdisplay) + b += 2 + + xgb.Put16(buf[b:], Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], Vsyncend) + b += 2 + + xgb.Put16(buf[b:], Vtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], Privsize) + b += 4 + + copy(buf[b:], Private[:Privsize]) + b += int(Privsize) + + return buf +} + +// ValidateModeLineCookie is a cookie used only for ValidateModeLine requests. +type ValidateModeLineCookie struct { + *xgb.Cookie +} + +// ValidateModeLine sends a checked request. +// If an error occurs, it will be returned with the reply by calling ValidateModeLineCookie.Reply() +func ValidateModeLine(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) ValidateModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'ValidateModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(validateModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return ValidateModeLineCookie{cookie} +} + +// ValidateModeLineUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ValidateModeLineUnchecked(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) ValidateModeLineCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFree86-VidModeExtension"]; !ok { + panic("Cannot issue request 'ValidateModeLine' using the uninitialized extension 'XFree86-VidModeExtension'. xf86vidmode.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(validateModeLineRequest(c, Screen, Dotclock, Hdisplay, Hsyncstart, Hsyncend, Htotal, Hskew, Vdisplay, Vsyncstart, Vsyncend, Vtotal, Flags, Privsize, Private), cookie) + return ValidateModeLineCookie{cookie} +} + +// ValidateModeLineReply represents the data returned from a ValidateModeLine request. +type ValidateModeLineReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Status uint32 + // padding: 20 bytes +} + +// Reply blocks and returns the reply data for a ValidateModeLine request. +func (cook ValidateModeLineCookie) Reply() (*ValidateModeLineReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return validateModeLineReply(buf), nil +} + +// validateModeLineReply reads a byte slice into a ValidateModeLineReply value. +func validateModeLineReply(buf []byte) *ValidateModeLineReply { + v := new(ValidateModeLineReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Status = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + return v +} + +// Write request to wire for ValidateModeLine +// validateModeLineRequest writes a ValidateModeLine request to a byte slice. +func validateModeLineRequest(c *xgb.Conn, Screen uint32, Dotclock Dotclock, Hdisplay uint16, Hsyncstart uint16, Hsyncend uint16, Htotal uint16, Hskew uint16, Vdisplay uint16, Vsyncstart uint16, Vsyncend uint16, Vtotal uint16, Flags uint32, Privsize uint32, Private []byte) []byte { + size := xgb.Pad((52 + xgb.Pad((int(Privsize) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFree86-VidModeExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Screen) + b += 4 + + xgb.Put32(buf[b:], uint32(Dotclock)) + b += 4 + + xgb.Put16(buf[b:], Hdisplay) + b += 2 + + xgb.Put16(buf[b:], Hsyncstart) + b += 2 + + xgb.Put16(buf[b:], Hsyncend) + b += 2 + + xgb.Put16(buf[b:], Htotal) + b += 2 + + xgb.Put16(buf[b:], Hskew) + b += 2 + + xgb.Put16(buf[b:], Vdisplay) + b += 2 + + xgb.Put16(buf[b:], Vsyncstart) + b += 2 + + xgb.Put16(buf[b:], Vsyncend) + b += 2 + + xgb.Put16(buf[b:], Vtotal) + b += 2 + + b += 2 // padding + + xgb.Put32(buf[b:], Flags) + b += 4 + + b += 12 // padding + + xgb.Put32(buf[b:], Privsize) + b += 4 + + copy(buf[b:], Private[:Privsize]) + b += int(Privsize) + + return buf +} diff --git a/nexgb/xfixes/xfixes.go b/nexgb/xfixes/xfixes.go new file mode 100644 index 0000000..440c3fd --- /dev/null +++ b/nexgb/xfixes/xfixes.go @@ -0,0 +1,2835 @@ +// Package xfixes is the X client API for the XFIXES extension. +package xfixes + +// This file is automatically generated from xfixes.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/render" + "github.com/BurntSushi/xgb/shape" + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XFIXES extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "XFIXES").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XFIXES could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XFIXES"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XFIXES"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XFIXES"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XFIXES"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XFIXES"] = make(map[int]xgb.NewErrorFun) +} + +// BadBadRegion is the error number for a BadBadRegion. +const BadBadRegion = 0 + +type BadRegionError struct { + Sequence uint16 + NiceName string +} + +// BadRegionErrorNew constructs a BadRegionError value that implements xgb.Error from a byte slice. +func BadRegionErrorNew(buf []byte) xgb.Error { + v := BadRegionError{} + v.NiceName = "BadRegion" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadRegion error. +// This is mostly used internally. +func (err BadRegionError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadRegion error. If no bad value exists, 0 is returned. +func (err BadRegionError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadRegion error. + +func (err BadRegionError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadRegion {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XFIXES"][0] = BadRegionErrorNew +} + +type Barrier uint32 + +func NewBarrierId(c *xgb.Conn) (Barrier, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Barrier(id), nil +} + +const ( + BarrierDirectionsPositiveX = 1 + BarrierDirectionsPositiveY = 2 + BarrierDirectionsNegativeX = 4 + BarrierDirectionsNegativeY = 8 +) + +// CursorNotify is the event number for a CursorNotifyEvent. +const CursorNotify = 1 + +type CursorNotifyEvent struct { + Sequence uint16 + Subtype byte + Window xproto.Window + CursorSerial uint32 + Timestamp xproto.Timestamp + Name xproto.Atom + // padding: 12 bytes +} + +// CursorNotifyEventNew constructs a CursorNotifyEvent value that implements xgb.Event from a byte slice. +func CursorNotifyEventNew(buf []byte) xgb.Event { + v := CursorNotifyEvent{} + b := 1 // don't read event number + + v.Subtype = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.CursorSerial = xgb.Get32(buf[b:]) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Name = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + b += 12 // padding + + return v +} + +// Bytes writes a CursorNotifyEvent value to a byte slice. +func (v CursorNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + buf[b] = v.Subtype + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], v.CursorSerial) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Name)) + b += 4 + + b += 12 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the CursorNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v CursorNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of CursorNotifyEvent. +func (v CursorNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Subtype: %d", v.Subtype)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("CursorSerial: %d", v.CursorSerial)) + fieldVals = append(fieldVals, xgb.Sprintf("Timestamp: %d", v.Timestamp)) + fieldVals = append(fieldVals, xgb.Sprintf("Name: %d", v.Name)) + return "CursorNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XFIXES"][1] = CursorNotifyEventNew +} + +const ( + CursorNotifyDisplayCursor = 0 +) + +const ( + CursorNotifyMaskDisplayCursor = 1 +) + +type Region uint32 + +func NewRegionId(c *xgb.Conn) (Region, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Region(id), nil +} + +const ( + RegionNone = 0 +) + +const ( + SaveSetMappingMap = 0 + SaveSetMappingUnmap = 1 +) + +const ( + SaveSetModeInsert = 0 + SaveSetModeDelete = 1 +) + +const ( + SaveSetTargetNearest = 0 + SaveSetTargetRoot = 1 +) + +const ( + SelectionEventSetSelectionOwner = 0 + SelectionEventSelectionWindowDestroy = 1 + SelectionEventSelectionClientClose = 2 +) + +const ( + SelectionEventMaskSetSelectionOwner = 1 + SelectionEventMaskSelectionWindowDestroy = 2 + SelectionEventMaskSelectionClientClose = 4 +) + +// SelectionNotify is the event number for a SelectionNotifyEvent. +const SelectionNotify = 0 + +type SelectionNotifyEvent struct { + Sequence uint16 + Subtype byte + Window xproto.Window + Owner xproto.Window + Selection xproto.Atom + Timestamp xproto.Timestamp + SelectionTimestamp xproto.Timestamp + // padding: 8 bytes +} + +// SelectionNotifyEventNew constructs a SelectionNotifyEvent value that implements xgb.Event from a byte slice. +func SelectionNotifyEventNew(buf []byte) xgb.Event { + v := SelectionNotifyEvent{} + b := 1 // don't read event number + + v.Subtype = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Owner = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Selection = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.SelectionTimestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + b += 8 // padding + + return v +} + +// Bytes writes a SelectionNotifyEvent value to a byte slice. +func (v SelectionNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.Subtype + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Owner)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Selection)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Timestamp)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.SelectionTimestamp)) + b += 4 + + b += 8 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the SelectionNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v SelectionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of SelectionNotifyEvent. +func (v SelectionNotifyEvent) String() string { + fieldVals := make([]string, 0, 7) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Subtype: %d", v.Subtype)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Owner: %d", v.Owner)) + fieldVals = append(fieldVals, xgb.Sprintf("Selection: %d", v.Selection)) + fieldVals = append(fieldVals, xgb.Sprintf("Timestamp: %d", v.Timestamp)) + fieldVals = append(fieldVals, xgb.Sprintf("SelectionTimestamp: %d", v.SelectionTimestamp)) + return "SelectionNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XFIXES"][0] = SelectionNotifyEventNew +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// ChangeCursorCookie is a cookie used only for ChangeCursor requests. +type ChangeCursorCookie struct { + *xgb.Cookie +} + +// ChangeCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeCursor(c *xgb.Conn, Source xproto.Cursor, Destination xproto.Cursor) ChangeCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeCursorRequest(c, Source, Destination), cookie) + return ChangeCursorCookie{cookie} +} + +// ChangeCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeCursorCookie.Check() +func ChangeCursorChecked(c *xgb.Conn, Source xproto.Cursor, Destination xproto.Cursor) ChangeCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeCursorRequest(c, Source, Destination), cookie) + return ChangeCursorCookie{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 ChangeCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeCursor +// changeCursorRequest writes a ChangeCursor request to a byte slice. +func changeCursorRequest(c *xgb.Conn, Source xproto.Cursor, Destination xproto.Cursor) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 26 // 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(Source)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// ChangeCursorByNameCookie is a cookie used only for ChangeCursorByName requests. +type ChangeCursorByNameCookie struct { + *xgb.Cookie +} + +// ChangeCursorByName sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeCursorByName(c *xgb.Conn, Src xproto.Cursor, Nbytes uint16, Name string) ChangeCursorByNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeCursorByName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeCursorByNameRequest(c, Src, Nbytes, Name), cookie) + return ChangeCursorByNameCookie{cookie} +} + +// ChangeCursorByNameChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeCursorByNameCookie.Check() +func ChangeCursorByNameChecked(c *xgb.Conn, Src xproto.Cursor, Nbytes uint16, Name string) ChangeCursorByNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeCursorByName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeCursorByNameRequest(c, Src, Nbytes, Name), cookie) + return ChangeCursorByNameCookie{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 ChangeCursorByNameCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeCursorByName +// changeCursorByNameRequest writes a ChangeCursorByName request to a byte slice. +func changeCursorByNameRequest(c *xgb.Conn, Src xproto.Cursor, Nbytes uint16, Name string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(Nbytes) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 27 // 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(Src)) + b += 4 + + xgb.Put16(buf[b:], Nbytes) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:Nbytes]) + b += int(Nbytes) + + return buf +} + +// ChangeSaveSetCookie is a cookie used only for ChangeSaveSet requests. +type ChangeSaveSetCookie struct { + *xgb.Cookie +} + +// ChangeSaveSet sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeSaveSet(c *xgb.Conn, Mode byte, Target byte, Map byte, Window xproto.Window) ChangeSaveSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeSaveSet' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeSaveSetRequest(c, Mode, Target, Map, Window), cookie) + return ChangeSaveSetCookie{cookie} +} + +// ChangeSaveSetChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeSaveSetCookie.Check() +func ChangeSaveSetChecked(c *xgb.Conn, Mode byte, Target byte, Map byte, Window xproto.Window) ChangeSaveSetCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ChangeSaveSet' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeSaveSetRequest(c, Mode, Target, Map, Window), cookie) + return ChangeSaveSetCookie{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 ChangeSaveSetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeSaveSet +// changeSaveSetRequest writes a ChangeSaveSet request to a byte slice. +func changeSaveSetRequest(c *xgb.Conn, Mode byte, Target byte, Map byte, Window xproto.Window) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + 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 + + buf[b] = Mode + b += 1 + + buf[b] = Target + b += 1 + + buf[b] = Map + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// CopyRegionCookie is a cookie used only for CopyRegion requests. +type CopyRegionCookie struct { + *xgb.Cookie +} + +// CopyRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyRegion(c *xgb.Conn, Source Region, Destination Region) CopyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(copyRegionRequest(c, Source, Destination), cookie) + return CopyRegionCookie{cookie} +} + +// CopyRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyRegionCookie.Check() +func CopyRegionChecked(c *xgb.Conn, Source Region, Destination Region) CopyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(copyRegionRequest(c, Source, Destination), cookie) + return CopyRegionCookie{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 CopyRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyRegion +// copyRegionRequest writes a CopyRegion request to a byte slice. +func copyRegionRequest(c *xgb.Conn, Source Region, Destination Region) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Source)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// CreatePointerBarrierCookie is a cookie used only for CreatePointerBarrier requests. +type CreatePointerBarrierCookie struct { + *xgb.Cookie +} + +// CreatePointerBarrier sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePointerBarrier(c *xgb.Conn, Barrier Barrier, Window xproto.Window, X1 uint16, Y1 uint16, X2 uint16, Y2 uint16, Directions uint32, NumDevices uint16, Devices []uint16) CreatePointerBarrierCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreatePointerBarrier' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createPointerBarrierRequest(c, Barrier, Window, X1, Y1, X2, Y2, Directions, NumDevices, Devices), cookie) + return CreatePointerBarrierCookie{cookie} +} + +// CreatePointerBarrierChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePointerBarrierCookie.Check() +func CreatePointerBarrierChecked(c *xgb.Conn, Barrier Barrier, Window xproto.Window, X1 uint16, Y1 uint16, X2 uint16, Y2 uint16, Directions uint32, NumDevices uint16, Devices []uint16) CreatePointerBarrierCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreatePointerBarrier' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createPointerBarrierRequest(c, Barrier, Window, X1, Y1, X2, Y2, Directions, NumDevices, Devices), cookie) + return CreatePointerBarrierCookie{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 CreatePointerBarrierCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePointerBarrier +// createPointerBarrierRequest writes a CreatePointerBarrier request to a byte slice. +func createPointerBarrierRequest(c *xgb.Conn, Barrier Barrier, Window xproto.Window, X1 uint16, Y1 uint16, X2 uint16, Y2 uint16, Directions uint32, NumDevices uint16, Devices []uint16) []byte { + size := xgb.Pad((28 + xgb.Pad((int(NumDevices) * 2)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 31 // 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(Barrier)) + b += 4 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put16(buf[b:], X1) + b += 2 + + xgb.Put16(buf[b:], Y1) + b += 2 + + xgb.Put16(buf[b:], X2) + b += 2 + + xgb.Put16(buf[b:], Y2) + b += 2 + + xgb.Put32(buf[b:], Directions) + b += 4 + + b += 2 // padding + + xgb.Put16(buf[b:], NumDevices) + b += 2 + + for i := 0; i < int(NumDevices); i++ { + xgb.Put16(buf[b:], Devices[i]) + b += 2 + } + + return buf +} + +// CreateRegionCookie is a cookie used only for CreateRegion requests. +type CreateRegionCookie struct { + *xgb.Cookie +} + +// CreateRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegion(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) CreateRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionRequest(c, Region, Rectangles), cookie) + return CreateRegionCookie{cookie} +} + +// CreateRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionCookie.Check() +func CreateRegionChecked(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) CreateRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionRequest(c, Region, Rectangles), cookie) + return CreateRegionCookie{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 CreateRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegion +// createRegionRequest writes a CreateRegion request to a byte slice. +func createRegionRequest(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Region)) + b += 4 + + b += xproto.RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// CreateRegionFromBitmapCookie is a cookie used only for CreateRegionFromBitmap requests. +type CreateRegionFromBitmapCookie struct { + *xgb.Cookie +} + +// CreateRegionFromBitmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegionFromBitmap(c *xgb.Conn, Region Region, Bitmap xproto.Pixmap) CreateRegionFromBitmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromBitmap' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionFromBitmapRequest(c, Region, Bitmap), cookie) + return CreateRegionFromBitmapCookie{cookie} +} + +// CreateRegionFromBitmapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionFromBitmapCookie.Check() +func CreateRegionFromBitmapChecked(c *xgb.Conn, Region Region, Bitmap xproto.Pixmap) CreateRegionFromBitmapCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromBitmap' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionFromBitmapRequest(c, Region, Bitmap), cookie) + return CreateRegionFromBitmapCookie{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 CreateRegionFromBitmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegionFromBitmap +// createRegionFromBitmapRequest writes a CreateRegionFromBitmap request to a byte slice. +func createRegionFromBitmapRequest(c *xgb.Conn, Region Region, Bitmap xproto.Pixmap) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Region)) + b += 4 + + xgb.Put32(buf[b:], uint32(Bitmap)) + b += 4 + + return buf +} + +// CreateRegionFromGCCookie is a cookie used only for CreateRegionFromGC requests. +type CreateRegionFromGCCookie struct { + *xgb.Cookie +} + +// CreateRegionFromGC sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegionFromGC(c *xgb.Conn, Region Region, Gc xproto.Gcontext) CreateRegionFromGCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromGC' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionFromGCRequest(c, Region, Gc), cookie) + return CreateRegionFromGCCookie{cookie} +} + +// CreateRegionFromGCChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionFromGCCookie.Check() +func CreateRegionFromGCChecked(c *xgb.Conn, Region Region, Gc xproto.Gcontext) CreateRegionFromGCCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromGC' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionFromGCRequest(c, Region, Gc), cookie) + return CreateRegionFromGCCookie{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 CreateRegionFromGCCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegionFromGC +// createRegionFromGCRequest writes a CreateRegionFromGC request to a byte slice. +func createRegionFromGCRequest(c *xgb.Conn, Region Region, Gc xproto.Gcontext) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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(Region)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + return buf +} + +// CreateRegionFromPictureCookie is a cookie used only for CreateRegionFromPicture requests. +type CreateRegionFromPictureCookie struct { + *xgb.Cookie +} + +// CreateRegionFromPicture sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegionFromPicture(c *xgb.Conn, Region Region, Picture render.Picture) CreateRegionFromPictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromPicture' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionFromPictureRequest(c, Region, Picture), cookie) + return CreateRegionFromPictureCookie{cookie} +} + +// CreateRegionFromPictureChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionFromPictureCookie.Check() +func CreateRegionFromPictureChecked(c *xgb.Conn, Region Region, Picture render.Picture) CreateRegionFromPictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromPicture' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionFromPictureRequest(c, Region, Picture), cookie) + return CreateRegionFromPictureCookie{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 CreateRegionFromPictureCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegionFromPicture +// createRegionFromPictureRequest writes a CreateRegionFromPicture request to a byte slice. +func createRegionFromPictureRequest(c *xgb.Conn, Region Region, Picture render.Picture) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // 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(Region)) + b += 4 + + xgb.Put32(buf[b:], uint32(Picture)) + b += 4 + + return buf +} + +// CreateRegionFromWindowCookie is a cookie used only for CreateRegionFromWindow requests. +type CreateRegionFromWindowCookie struct { + *xgb.Cookie +} + +// CreateRegionFromWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateRegionFromWindow(c *xgb.Conn, Region Region, Window xproto.Window, Kind shape.Kind) CreateRegionFromWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromWindow' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createRegionFromWindowRequest(c, Region, Window, Kind), cookie) + return CreateRegionFromWindowCookie{cookie} +} + +// CreateRegionFromWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateRegionFromWindowCookie.Check() +func CreateRegionFromWindowChecked(c *xgb.Conn, Region Region, Window xproto.Window, Kind shape.Kind) CreateRegionFromWindowCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'CreateRegionFromWindow' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createRegionFromWindowRequest(c, Region, Window, Kind), cookie) + return CreateRegionFromWindowCookie{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 CreateRegionFromWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateRegionFromWindow +// createRegionFromWindowRequest writes a CreateRegionFromWindow request to a byte slice. +func createRegionFromWindowRequest(c *xgb.Conn, Region Region, Window xproto.Window, Kind shape.Kind) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Region)) + b += 4 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + buf[b] = byte(Kind) + b += 1 + + b += 3 // padding + + return buf +} + +// DeletePointerBarrierCookie is a cookie used only for DeletePointerBarrier requests. +type DeletePointerBarrierCookie struct { + *xgb.Cookie +} + +// DeletePointerBarrier sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeletePointerBarrier(c *xgb.Conn, Barrier Barrier) DeletePointerBarrierCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'DeletePointerBarrier' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deletePointerBarrierRequest(c, Barrier), cookie) + return DeletePointerBarrierCookie{cookie} +} + +// DeletePointerBarrierChecked sends a checked request. +// If an error occurs, it can be retrieved using DeletePointerBarrierCookie.Check() +func DeletePointerBarrierChecked(c *xgb.Conn, Barrier Barrier) DeletePointerBarrierCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'DeletePointerBarrier' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deletePointerBarrierRequest(c, Barrier), cookie) + return DeletePointerBarrierCookie{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 DeletePointerBarrierCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeletePointerBarrier +// deletePointerBarrierRequest writes a DeletePointerBarrier request to a byte slice. +func deletePointerBarrierRequest(c *xgb.Conn, Barrier Barrier) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 32 // 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(Barrier)) + b += 4 + + return buf +} + +// DestroyRegionCookie is a cookie used only for DestroyRegion requests. +type DestroyRegionCookie struct { + *xgb.Cookie +} + +// DestroyRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyRegion(c *xgb.Conn, Region Region) DestroyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'DestroyRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyRegionRequest(c, Region), cookie) + return DestroyRegionCookie{cookie} +} + +// DestroyRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyRegionCookie.Check() +func DestroyRegionChecked(c *xgb.Conn, Region Region) DestroyRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'DestroyRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyRegionRequest(c, Region), cookie) + return DestroyRegionCookie{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 DestroyRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyRegion +// destroyRegionRequest writes a DestroyRegion request to a byte slice. +func destroyRegionRequest(c *xgb.Conn, Region Region) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // 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(Region)) + b += 4 + + return buf +} + +// ExpandRegionCookie is a cookie used only for ExpandRegion requests. +type ExpandRegionCookie struct { + *xgb.Cookie +} + +// ExpandRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ExpandRegion(c *xgb.Conn, Source Region, Destination Region, Left uint16, Right uint16, Top uint16, Bottom uint16) ExpandRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ExpandRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(expandRegionRequest(c, Source, Destination, Left, Right, Top, Bottom), cookie) + return ExpandRegionCookie{cookie} +} + +// ExpandRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using ExpandRegionCookie.Check() +func ExpandRegionChecked(c *xgb.Conn, Source Region, Destination Region, Left uint16, Right uint16, Top uint16, Bottom uint16) ExpandRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ExpandRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(expandRegionRequest(c, Source, Destination, Left, Right, Top, Bottom), cookie) + return ExpandRegionCookie{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 ExpandRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ExpandRegion +// expandRegionRequest writes a ExpandRegion request to a byte slice. +func expandRegionRequest(c *xgb.Conn, Source Region, Destination Region, Left uint16, Right uint16, Top uint16, Bottom uint16) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 28 // 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(Source)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + xgb.Put16(buf[b:], Left) + b += 2 + + xgb.Put16(buf[b:], Right) + b += 2 + + xgb.Put16(buf[b:], Top) + b += 2 + + xgb.Put16(buf[b:], Bottom) + b += 2 + + return buf +} + +// FetchRegionCookie is a cookie used only for FetchRegion requests. +type FetchRegionCookie struct { + *xgb.Cookie +} + +// FetchRegion sends a checked request. +// If an error occurs, it will be returned with the reply by calling FetchRegionCookie.Reply() +func FetchRegion(c *xgb.Conn, Region Region) FetchRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'FetchRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(fetchRegionRequest(c, Region), cookie) + return FetchRegionCookie{cookie} +} + +// FetchRegionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FetchRegionUnchecked(c *xgb.Conn, Region Region) FetchRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'FetchRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(fetchRegionRequest(c, Region), cookie) + return FetchRegionCookie{cookie} +} + +// FetchRegionReply represents the data returned from a FetchRegion request. +type FetchRegionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Extents xproto.Rectangle + // padding: 16 bytes + Rectangles []xproto.Rectangle // size: xgb.Pad(((int(Length) / 2) * 8)) +} + +// Reply blocks and returns the reply data for a FetchRegion request. +func (cook FetchRegionCookie) Reply() (*FetchRegionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return fetchRegionReply(buf), nil +} + +// fetchRegionReply reads a byte slice into a FetchRegionReply value. +func fetchRegionReply(buf []byte) *FetchRegionReply { + v := new(FetchRegionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Extents = xproto.Rectangle{} + b += xproto.RectangleRead(buf[b:], &v.Extents) + + b += 16 // padding + + v.Rectangles = make([]xproto.Rectangle, (int(v.Length) / 2)) + b += xproto.RectangleReadList(buf[b:], v.Rectangles) + + return v +} + +// Write request to wire for FetchRegion +// fetchRegionRequest writes a FetchRegion request to a byte slice. +func fetchRegionRequest(c *xgb.Conn, Region Region) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Region)) + b += 4 + + return buf +} + +// GetCursorImageCookie is a cookie used only for GetCursorImage requests. +type GetCursorImageCookie struct { + *xgb.Cookie +} + +// GetCursorImage sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCursorImageCookie.Reply() +func GetCursorImage(c *xgb.Conn) GetCursorImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorImage' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCursorImageRequest(c), cookie) + return GetCursorImageCookie{cookie} +} + +// GetCursorImageUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCursorImageUnchecked(c *xgb.Conn) GetCursorImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorImage' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCursorImageRequest(c), cookie) + return GetCursorImageCookie{cookie} +} + +// GetCursorImageReply represents the data returned from a GetCursorImage request. +type GetCursorImageReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + X int16 + Y int16 + Width uint16 + Height uint16 + Xhot uint16 + Yhot uint16 + CursorSerial uint32 + // padding: 8 bytes + CursorImage []uint32 // size: xgb.Pad(((int(Width) * int(Height)) * 4)) +} + +// Reply blocks and returns the reply data for a GetCursorImage request. +func (cook GetCursorImageCookie) Reply() (*GetCursorImageReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCursorImageReply(buf), nil +} + +// getCursorImageReply reads a byte slice into a GetCursorImageReply value. +func getCursorImageReply(buf []byte) *GetCursorImageReply { + v := new(GetCursorImageReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Xhot = xgb.Get16(buf[b:]) + b += 2 + + v.Yhot = xgb.Get16(buf[b:]) + b += 2 + + v.CursorSerial = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + v.CursorImage = make([]uint32, (int(v.Width) * int(v.Height))) + for i := 0; i < int((int(v.Width) * int(v.Height))); i++ { + v.CursorImage[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for GetCursorImage +// getCursorImageRequest writes a GetCursorImage request to a byte slice. +func getCursorImageRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetCursorImageAndNameCookie is a cookie used only for GetCursorImageAndName requests. +type GetCursorImageAndNameCookie struct { + *xgb.Cookie +} + +// GetCursorImageAndName sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCursorImageAndNameCookie.Reply() +func GetCursorImageAndName(c *xgb.Conn) GetCursorImageAndNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorImageAndName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCursorImageAndNameRequest(c), cookie) + return GetCursorImageAndNameCookie{cookie} +} + +// GetCursorImageAndNameUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCursorImageAndNameUnchecked(c *xgb.Conn) GetCursorImageAndNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorImageAndName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCursorImageAndNameRequest(c), cookie) + return GetCursorImageAndNameCookie{cookie} +} + +// GetCursorImageAndNameReply represents the data returned from a GetCursorImageAndName request. +type GetCursorImageAndNameReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + X int16 + Y int16 + Width uint16 + Height uint16 + Xhot uint16 + Yhot uint16 + CursorSerial uint32 + CursorAtom xproto.Atom + Nbytes uint16 + // padding: 2 bytes + CursorImage []uint32 // size: xgb.Pad(((int(Width) * int(Height)) * 4)) + Name string // size: xgb.Pad((int(Nbytes) * 1)) +} + +// Reply blocks and returns the reply data for a GetCursorImageAndName request. +func (cook GetCursorImageAndNameCookie) Reply() (*GetCursorImageAndNameReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCursorImageAndNameReply(buf), nil +} + +// getCursorImageAndNameReply reads a byte slice into a GetCursorImageAndNameReply value. +func getCursorImageAndNameReply(buf []byte) *GetCursorImageAndNameReply { + v := new(GetCursorImageAndNameReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Xhot = xgb.Get16(buf[b:]) + b += 2 + + v.Yhot = xgb.Get16(buf[b:]) + b += 2 + + v.CursorSerial = xgb.Get32(buf[b:]) + b += 4 + + v.CursorAtom = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Nbytes = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.CursorImage = make([]uint32, (int(v.Width) * int(v.Height))) + for i := 0; i < int((int(v.Width) * int(v.Height))); i++ { + v.CursorImage[i] = xgb.Get32(buf[b:]) + b += 4 + } + + { + byteString := make([]byte, v.Nbytes) + copy(byteString[:v.Nbytes], buf[b:]) + v.Name = string(byteString) + b += int(v.Nbytes) + } + + return v +} + +// Write request to wire for GetCursorImageAndName +// getCursorImageAndNameRequest writes a GetCursorImageAndName request to a byte slice. +func getCursorImageAndNameRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 25 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetCursorNameCookie is a cookie used only for GetCursorName requests. +type GetCursorNameCookie struct { + *xgb.Cookie +} + +// GetCursorName sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetCursorNameCookie.Reply() +func GetCursorName(c *xgb.Conn, Cursor xproto.Cursor) GetCursorNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getCursorNameRequest(c, Cursor), cookie) + return GetCursorNameCookie{cookie} +} + +// GetCursorNameUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetCursorNameUnchecked(c *xgb.Conn, Cursor xproto.Cursor) GetCursorNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'GetCursorName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getCursorNameRequest(c, Cursor), cookie) + return GetCursorNameCookie{cookie} +} + +// GetCursorNameReply represents the data returned from a GetCursorName request. +type GetCursorNameReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Atom xproto.Atom + Nbytes uint16 + // padding: 18 bytes + Name string // size: xgb.Pad((int(Nbytes) * 1)) +} + +// Reply blocks and returns the reply data for a GetCursorName request. +func (cook GetCursorNameCookie) Reply() (*GetCursorNameReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getCursorNameReply(buf), nil +} + +// getCursorNameReply reads a byte slice into a GetCursorNameReply value. +func getCursorNameReply(buf []byte) *GetCursorNameReply { + v := new(GetCursorNameReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Atom = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Nbytes = xgb.Get16(buf[b:]) + b += 2 + + b += 18 // padding + + { + byteString := make([]byte, v.Nbytes) + copy(byteString[:v.Nbytes], buf[b:]) + v.Name = string(byteString) + b += int(v.Nbytes) + } + + return v +} + +// Write request to wire for GetCursorName +// getCursorNameRequest writes a GetCursorName request to a byte slice. +func getCursorNameRequest(c *xgb.Conn, Cursor xproto.Cursor) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 24 // 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(Cursor)) + b += 4 + + return buf +} + +// HideCursorCookie is a cookie used only for HideCursor requests. +type HideCursorCookie struct { + *xgb.Cookie +} + +// HideCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func HideCursor(c *xgb.Conn, Window xproto.Window) HideCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'HideCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(hideCursorRequest(c, Window), cookie) + return HideCursorCookie{cookie} +} + +// HideCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using HideCursorCookie.Check() +func HideCursorChecked(c *xgb.Conn, Window xproto.Window) HideCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'HideCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(hideCursorRequest(c, Window), cookie) + return HideCursorCookie{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 HideCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for HideCursor +// hideCursorRequest writes a HideCursor request to a byte slice. +func hideCursorRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 29 // 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 + + return buf +} + +// IntersectRegionCookie is a cookie used only for IntersectRegion requests. +type IntersectRegionCookie struct { + *xgb.Cookie +} + +// IntersectRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IntersectRegion(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) IntersectRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'IntersectRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(intersectRegionRequest(c, Source1, Source2, Destination), cookie) + return IntersectRegionCookie{cookie} +} + +// IntersectRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using IntersectRegionCookie.Check() +func IntersectRegionChecked(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) IntersectRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'IntersectRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(intersectRegionRequest(c, Source1, Source2, Destination), cookie) + return IntersectRegionCookie{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 IntersectRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for IntersectRegion +// intersectRegionRequest writes a IntersectRegion request to a byte slice. +func intersectRegionRequest(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // 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(Source1)) + b += 4 + + xgb.Put32(buf[b:], uint32(Source2)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// InvertRegionCookie is a cookie used only for InvertRegion requests. +type InvertRegionCookie struct { + *xgb.Cookie +} + +// InvertRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func InvertRegion(c *xgb.Conn, Source Region, Bounds xproto.Rectangle, Destination Region) InvertRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'InvertRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(invertRegionRequest(c, Source, Bounds, Destination), cookie) + return InvertRegionCookie{cookie} +} + +// InvertRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using InvertRegionCookie.Check() +func InvertRegionChecked(c *xgb.Conn, Source Region, Bounds xproto.Rectangle, Destination Region) InvertRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'InvertRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(invertRegionRequest(c, Source, Bounds, Destination), cookie) + return InvertRegionCookie{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 InvertRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for InvertRegion +// invertRegionRequest writes a InvertRegion request to a byte slice. +func invertRegionRequest(c *xgb.Conn, Source Region, Bounds xproto.Rectangle, Destination Region) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // 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(Source)) + b += 4 + + { + structBytes := Bounds.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint32 + MinorVersion uint32 + // padding: 16 bytes +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get32(buf[b:]) + b += 4 + + v.MinorVersion = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], ClientMajorVersion) + b += 4 + + xgb.Put32(buf[b:], ClientMinorVersion) + b += 4 + + return buf +} + +// RegionExtentsCookie is a cookie used only for RegionExtents requests. +type RegionExtentsCookie struct { + *xgb.Cookie +} + +// RegionExtents sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RegionExtents(c *xgb.Conn, Source Region, Destination Region) RegionExtentsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'RegionExtents' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(regionExtentsRequest(c, Source, Destination), cookie) + return RegionExtentsCookie{cookie} +} + +// RegionExtentsChecked sends a checked request. +// If an error occurs, it can be retrieved using RegionExtentsCookie.Check() +func RegionExtentsChecked(c *xgb.Conn, Source Region, Destination Region) RegionExtentsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'RegionExtents' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(regionExtentsRequest(c, Source, Destination), cookie) + return RegionExtentsCookie{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 RegionExtentsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RegionExtents +// regionExtentsRequest writes a RegionExtents request to a byte slice. +func regionExtentsRequest(c *xgb.Conn, Source Region, Destination Region) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // 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(Source)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// SelectCursorInputCookie is a cookie used only for SelectCursorInput requests. +type SelectCursorInputCookie struct { + *xgb.Cookie +} + +// SelectCursorInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectCursorInput(c *xgb.Conn, Window xproto.Window, EventMask uint32) SelectCursorInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SelectCursorInput' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectCursorInputRequest(c, Window, EventMask), cookie) + return SelectCursorInputCookie{cookie} +} + +// SelectCursorInputChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectCursorInputCookie.Check() +func SelectCursorInputChecked(c *xgb.Conn, Window xproto.Window, EventMask uint32) SelectCursorInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SelectCursorInput' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectCursorInputRequest(c, Window, EventMask), cookie) + return SelectCursorInputCookie{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 SelectCursorInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectCursorInput +// selectCursorInputRequest writes a SelectCursorInput request to a byte slice. +func selectCursorInputRequest(c *xgb.Conn, Window xproto.Window, EventMask uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + return buf +} + +// SelectSelectionInputCookie is a cookie used only for SelectSelectionInput requests. +type SelectSelectionInputCookie struct { + *xgb.Cookie +} + +// SelectSelectionInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectSelectionInput(c *xgb.Conn, Window xproto.Window, Selection xproto.Atom, EventMask uint32) SelectSelectionInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SelectSelectionInput' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectSelectionInputRequest(c, Window, Selection, EventMask), cookie) + return SelectSelectionInputCookie{cookie} +} + +// SelectSelectionInputChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectSelectionInputCookie.Check() +func SelectSelectionInputChecked(c *xgb.Conn, Window xproto.Window, Selection xproto.Atom, EventMask uint32) SelectSelectionInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SelectSelectionInput' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectSelectionInputRequest(c, Window, Selection, EventMask), cookie) + return SelectSelectionInputCookie{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 SelectSelectionInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectSelectionInput +// selectSelectionInputRequest writes a SelectSelectionInput request to a byte slice. +func selectSelectionInputRequest(c *xgb.Conn, Window xproto.Window, Selection xproto.Atom, EventMask uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(Selection)) + b += 4 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + return buf +} + +// SetCursorNameCookie is a cookie used only for SetCursorName requests. +type SetCursorNameCookie struct { + *xgb.Cookie +} + +// SetCursorName sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetCursorName(c *xgb.Conn, Cursor xproto.Cursor, Nbytes uint16, Name string) SetCursorNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetCursorName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setCursorNameRequest(c, Cursor, Nbytes, Name), cookie) + return SetCursorNameCookie{cookie} +} + +// SetCursorNameChecked sends a checked request. +// If an error occurs, it can be retrieved using SetCursorNameCookie.Check() +func SetCursorNameChecked(c *xgb.Conn, Cursor xproto.Cursor, Nbytes uint16, Name string) SetCursorNameCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetCursorName' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setCursorNameRequest(c, Cursor, Nbytes, Name), cookie) + return SetCursorNameCookie{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 SetCursorNameCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetCursorName +// setCursorNameRequest writes a SetCursorName request to a byte slice. +func setCursorNameRequest(c *xgb.Conn, Cursor xproto.Cursor, Nbytes uint16, Name string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(Nbytes) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 23 // 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(Cursor)) + b += 4 + + xgb.Put16(buf[b:], Nbytes) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:Nbytes]) + b += int(Nbytes) + + return buf +} + +// SetGCClipRegionCookie is a cookie used only for SetGCClipRegion requests. +type SetGCClipRegionCookie struct { + *xgb.Cookie +} + +// SetGCClipRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetGCClipRegion(c *xgb.Conn, Gc xproto.Gcontext, Region Region, XOrigin int16, YOrigin int16) SetGCClipRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetGCClipRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setGCClipRegionRequest(c, Gc, Region, XOrigin, YOrigin), cookie) + return SetGCClipRegionCookie{cookie} +} + +// SetGCClipRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using SetGCClipRegionCookie.Check() +func SetGCClipRegionChecked(c *xgb.Conn, Gc xproto.Gcontext, Region Region, XOrigin int16, YOrigin int16) SetGCClipRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetGCClipRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setGCClipRegionRequest(c, Gc, Region, XOrigin, YOrigin), cookie) + return SetGCClipRegionCookie{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 SetGCClipRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetGCClipRegion +// setGCClipRegionRequest writes a SetGCClipRegion request to a byte slice. +func setGCClipRegionRequest(c *xgb.Conn, Gc xproto.Gcontext, Region Region, XOrigin int16, YOrigin int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // 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(Gc)) + b += 4 + + xgb.Put32(buf[b:], uint32(Region)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOrigin)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOrigin)) + b += 2 + + return buf +} + +// SetPictureClipRegionCookie is a cookie used only for SetPictureClipRegion requests. +type SetPictureClipRegionCookie struct { + *xgb.Cookie +} + +// SetPictureClipRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPictureClipRegion(c *xgb.Conn, Picture render.Picture, Region Region, XOrigin int16, YOrigin int16) SetPictureClipRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetPictureClipRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPictureClipRegionRequest(c, Picture, Region, XOrigin, YOrigin), cookie) + return SetPictureClipRegionCookie{cookie} +} + +// SetPictureClipRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPictureClipRegionCookie.Check() +func SetPictureClipRegionChecked(c *xgb.Conn, Picture render.Picture, Region Region, XOrigin int16, YOrigin int16) SetPictureClipRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetPictureClipRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPictureClipRegionRequest(c, Picture, Region, XOrigin, YOrigin), cookie) + return SetPictureClipRegionCookie{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 SetPictureClipRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPictureClipRegion +// setPictureClipRegionRequest writes a SetPictureClipRegion request to a byte slice. +func setPictureClipRegionRequest(c *xgb.Conn, Picture render.Picture, Region Region, XOrigin int16, YOrigin int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // 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(Picture)) + b += 4 + + xgb.Put32(buf[b:], uint32(Region)) + b += 4 + + xgb.Put16(buf[b:], uint16(XOrigin)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOrigin)) + b += 2 + + return buf +} + +// SetRegionCookie is a cookie used only for SetRegion requests. +type SetRegionCookie struct { + *xgb.Cookie +} + +// SetRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetRegion(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) SetRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setRegionRequest(c, Region, Rectangles), cookie) + return SetRegionCookie{cookie} +} + +// SetRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using SetRegionCookie.Check() +func SetRegionChecked(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) SetRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setRegionRequest(c, Region, Rectangles), cookie) + return SetRegionCookie{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 SetRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetRegion +// setRegionRequest writes a SetRegion request to a byte slice. +func setRegionRequest(c *xgb.Conn, Region Region, Rectangles []xproto.Rectangle) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(Region)) + b += 4 + + b += xproto.RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// SetWindowShapeRegionCookie is a cookie used only for SetWindowShapeRegion requests. +type SetWindowShapeRegionCookie struct { + *xgb.Cookie +} + +// SetWindowShapeRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetWindowShapeRegion(c *xgb.Conn, Dest xproto.Window, DestKind shape.Kind, XOffset int16, YOffset int16, Region Region) SetWindowShapeRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetWindowShapeRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setWindowShapeRegionRequest(c, Dest, DestKind, XOffset, YOffset, Region), cookie) + return SetWindowShapeRegionCookie{cookie} +} + +// SetWindowShapeRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using SetWindowShapeRegionCookie.Check() +func SetWindowShapeRegionChecked(c *xgb.Conn, Dest xproto.Window, DestKind shape.Kind, XOffset int16, YOffset int16, Region Region) SetWindowShapeRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SetWindowShapeRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setWindowShapeRegionRequest(c, Dest, DestKind, XOffset, YOffset, Region), cookie) + return SetWindowShapeRegionCookie{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 SetWindowShapeRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetWindowShapeRegion +// setWindowShapeRegionRequest writes a SetWindowShapeRegion request to a byte slice. +func setWindowShapeRegionRequest(c *xgb.Conn, Dest xproto.Window, DestKind shape.Kind, XOffset int16, YOffset int16, Region Region) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 21 // 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(Dest)) + b += 4 + + buf[b] = byte(DestKind) + b += 1 + + b += 3 // padding + + xgb.Put16(buf[b:], uint16(XOffset)) + b += 2 + + xgb.Put16(buf[b:], uint16(YOffset)) + b += 2 + + xgb.Put32(buf[b:], uint32(Region)) + b += 4 + + return buf +} + +// ShowCursorCookie is a cookie used only for ShowCursor requests. +type ShowCursorCookie struct { + *xgb.Cookie +} + +// ShowCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ShowCursor(c *xgb.Conn, Window xproto.Window) ShowCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ShowCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(showCursorRequest(c, Window), cookie) + return ShowCursorCookie{cookie} +} + +// ShowCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using ShowCursorCookie.Check() +func ShowCursorChecked(c *xgb.Conn, Window xproto.Window) ShowCursorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'ShowCursor' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(showCursorRequest(c, Window), cookie) + return ShowCursorCookie{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 ShowCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ShowCursor +// showCursorRequest writes a ShowCursor request to a byte slice. +func showCursorRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 30 // 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 + + return buf +} + +// SubtractRegionCookie is a cookie used only for SubtractRegion requests. +type SubtractRegionCookie struct { + *xgb.Cookie +} + +// SubtractRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SubtractRegion(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) SubtractRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SubtractRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(subtractRegionRequest(c, Source1, Source2, Destination), cookie) + return SubtractRegionCookie{cookie} +} + +// SubtractRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using SubtractRegionCookie.Check() +func SubtractRegionChecked(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) SubtractRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'SubtractRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(subtractRegionRequest(c, Source1, Source2, Destination), cookie) + return SubtractRegionCookie{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 SubtractRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SubtractRegion +// subtractRegionRequest writes a SubtractRegion request to a byte slice. +func subtractRegionRequest(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // 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(Source1)) + b += 4 + + xgb.Put32(buf[b:], uint32(Source2)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} + +// TranslateRegionCookie is a cookie used only for TranslateRegion requests. +type TranslateRegionCookie struct { + *xgb.Cookie +} + +// TranslateRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func TranslateRegion(c *xgb.Conn, Region Region, Dx int16, Dy int16) TranslateRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'TranslateRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(translateRegionRequest(c, Region, Dx, Dy), cookie) + return TranslateRegionCookie{cookie} +} + +// TranslateRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using TranslateRegionCookie.Check() +func TranslateRegionChecked(c *xgb.Conn, Region Region, Dx int16, Dy int16) TranslateRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'TranslateRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(translateRegionRequest(c, Region, Dx, Dy), cookie) + return TranslateRegionCookie{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 TranslateRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for TranslateRegion +// translateRegionRequest writes a TranslateRegion request to a byte slice. +func translateRegionRequest(c *xgb.Conn, Region Region, Dx int16, Dy int16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // 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(Region)) + b += 4 + + xgb.Put16(buf[b:], uint16(Dx)) + b += 2 + + xgb.Put16(buf[b:], uint16(Dy)) + b += 2 + + return buf +} + +// UnionRegionCookie is a cookie used only for UnionRegion requests. +type UnionRegionCookie struct { + *xgb.Cookie +} + +// UnionRegion sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnionRegion(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) UnionRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'UnionRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(unionRegionRequest(c, Source1, Source2, Destination), cookie) + return UnionRegionCookie{cookie} +} + +// UnionRegionChecked sends a checked request. +// If an error occurs, it can be retrieved using UnionRegionCookie.Check() +func UnionRegionChecked(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) UnionRegionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XFIXES"]; !ok { + panic("Cannot issue request 'UnionRegion' using the uninitialized extension 'XFIXES'. xfixes.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(unionRegionRequest(c, Source1, Source2, Destination), cookie) + return UnionRegionCookie{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 UnionRegionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnionRegion +// unionRegionRequest writes a UnionRegion request to a byte slice. +func unionRegionRequest(c *xgb.Conn, Source1 Region, Source2 Region, Destination Region) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XFIXES"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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(Source1)) + b += 4 + + xgb.Put32(buf[b:], uint32(Source2)) + b += 4 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + return buf +} diff --git a/nexgb/xgb.go b/nexgb/xgb.go new file mode 100644 index 0000000..3d2c61f --- /dev/null +++ b/nexgb/xgb.go @@ -0,0 +1,554 @@ +package xgb + +import ( + "errors" + "io" + "log" + "net" + "os" + "sync" +) + +var ( + // Where to log error-messages. Defaults to stderr. + // To disable logging, just set this to log.New(ioutil.Discard, "", 0) + Logger = log.New(os.Stderr, "XGB: ", log.Lshortfile) +) + +const ( + // cookieBuffer represents the queue size of cookies existing at any + // point in time. The size of the buffer is really only important when + // there are many requests without replies made in sequence. Once the + // buffer fills, a round trip request is made to clear the buffer. + cookieBuffer = 1000 + + // xidBuffer represents the queue size of the xid channel. + // I don't think this value matters much, since xid generation is not + // that expensive. + xidBuffer = 5 + + // seqBuffer represents the queue size of the sequence number channel. + // I don't think this value matters much, since sequence number generation + // is not that expensive. + seqBuffer = 5 + + // reqBuffer represents the queue size of the number of requests that + // can be made until new ones block. This value seems OK. + reqBuffer = 100 + + // eventBuffer represents the queue size of the number of events or errors + // that can be loaded off the wire and not grabbed with WaitForEvent + // until reading an event blocks. This value should be big enough to handle + // bursts of events. + eventBuffer = 5000 +) + +// A Conn represents a connection to an X server. +type Conn struct { + host string + conn net.Conn + display string + DisplayNumber int + DefaultScreen int + SetupBytes []byte + + setupResourceIdBase uint32 + setupResourceIdMask uint32 + + eventChan chan eventOrError + cookieChan chan *Cookie + xidChan chan xid + seqChan chan uint16 + reqChan chan *request + closing chan chan struct{} + + // ExtLock is a lock used whenever new extensions are initialized. + // It should not be used. It is exported for use in the extension + // sub-packages. + ExtLock sync.RWMutex + + // Extensions is a map from extension name to major opcode. It should + // not be used. It is exported for use in the extension sub-packages. + Extensions map[string]byte +} + +// NewConn creates a new connection instance. It initializes locks, data +// structures, and performs the initial handshake. (The code for the handshake +// has been relegated to conn.go.) +func NewConn() (*Conn, error) { + return NewConnDisplay("") +} + +// NewConnDisplay is just like NewConn, but allows a specific DISPLAY +// string to be used. +// If 'display' is empty it will be taken from os.Getenv("DISPLAY"). +// +// Examples: +// NewConn(":1") -> net.Dial("unix", "", "/tmp/.X11-unix/X1") +// NewConn("/tmp/launch-12/:0") -> net.Dial("unix", "", "/tmp/launch-12/:0") +// NewConn("hostname:2.1") -> net.Dial("tcp", "", "hostname:6002") +// NewConn("tcp/hostname:1.0") -> net.Dial("tcp", "", "hostname:6001") +func NewConnDisplay(display string) (*Conn, error) { + conn := &Conn{} + + // First connect. This reads authority, checks DISPLAY environment + // variable, and loads the initial Setup info. + err := conn.connect(display) + if err != nil { + return nil, err + } + + return postNewConn(conn) +} + +// NewConnDisplay is just like NewConn, but allows a specific net.Conn +// to be used. +func NewConnNet(netConn net.Conn) (*Conn, error) { + conn := &Conn{} + + // First connect. This reads authority, checks DISPLAY environment + // variable, and loads the initial Setup info. + err := conn.connectNet(netConn) + + if err != nil { + return nil, err + } + + return postNewConn(conn) +} + +func postNewConn(conn *Conn) (*Conn, error) { + conn.Extensions = make(map[string]byte) + + conn.cookieChan = make(chan *Cookie, cookieBuffer) + conn.xidChan = make(chan xid, xidBuffer) + conn.seqChan = make(chan uint16, seqBuffer) + conn.reqChan = make(chan *request, reqBuffer) + conn.eventChan = make(chan eventOrError, eventBuffer) + conn.closing = make(chan chan struct{}, 1) + + go conn.generateXIds() + go conn.generateSeqIds() + go conn.sendRequests() + go conn.readResponses() + + return conn, nil +} + +// Close gracefully closes the connection to the X server. +func (c *Conn) Close() { + close(c.reqChan) +} + +// Event is an interface that can contain any of the events returned by the +// server. Use a type assertion switch to extract the Event structs. +type Event interface { + Bytes() []byte + String() string +} + +// NewEventFun is the type of function use to construct events from raw bytes. +// It should not be used. It is exported for use in the extension sub-packages. +type NewEventFun func(buf []byte) Event + +// NewEventFuncs is a map from event numbers to functions that create +// the corresponding event. It should not be used. It is exported for use +// in the extension sub-packages. +var NewEventFuncs = make(map[int]NewEventFun) + +// NewExtEventFuncs is a temporary map that stores event constructor functions +// for each extension. When an extension is initialized, each event for that +// extension is added to the 'NewEventFuncs' map. It should not be used. It is +// exported for use in the extension sub-packages. +var NewExtEventFuncs = make(map[string]map[int]NewEventFun) + +// Error is an interface that can contain any of the errors returned by +// the server. Use a type assertion switch to extract the Error structs. +type Error interface { + SequenceId() uint16 + BadId() uint32 + Error() string +} + +// NewErrorFun is the type of function use to construct errors from raw bytes. +// It should not be used. It is exported for use in the extension sub-packages. +type NewErrorFun func(buf []byte) Error + +// NewErrorFuncs is a map from error numbers to functions that create +// the corresponding error. It should not be used. It is exported for use in +// the extension sub-packages. +var NewErrorFuncs = make(map[int]NewErrorFun) + +// NewExtErrorFuncs is a temporary map that stores error constructor functions +// for each extension. When an extension is initialized, each error for that +// extension is added to the 'NewErrorFuncs' map. It should not be used. It is +// exported for use in the extension sub-packages. +var NewExtErrorFuncs = make(map[string]map[int]NewErrorFun) + +// eventOrError corresponds to values that can be either an event or an +// error. +type eventOrError interface{} + +// NewId generates a new unused ID for use with requests like CreateWindow. +// If no new ids can be generated, the id returned is 0 and error is non-nil. +// This shouldn't be used directly, and is exported for use in the extension +// sub-packages. +// If you need identifiers, use the appropriate constructor. +// e.g., For a window id, use xproto.NewWindowId. For +// a new pixmap id, use xproto.NewPixmapId. And so on. +func (c *Conn) NewId() (uint32, error) { + xid := <-c.xidChan + if xid.err != nil { + return 0, xid.err + } + return xid.id, nil +} + +// xid encapsulates a resource identifier being sent over the Conn.xidChan +// channel. If no new resource id can be generated, id is set to 0 and a +// non-nil error is set in xid.err. +type xid struct { + id uint32 + err error +} + +// generateXids sends new Ids down the channel for NewId to use. +// generateXids should be run in its own goroutine. +// This needs to be updated to use the XC Misc extension once we run out of +// new ids. +// Thanks to libxcb/src/xcb_xid.c. This code is greatly inspired by it. +func (conn *Conn) generateXIds() { + defer close(conn.xidChan) + + // This requires some explanation. From the horse's mouth: + // "The resource-id-mask contains a single contiguous set of bits (at least + // 18). The client allocates resource IDs for types WINDOW, PIXMAP, + // CURSOR, FONT, GCONTEXT, and COLORMAP by choosing a value with only some + // subset of these bits set and ORing it with resource-id-base. Only values + // constructed in this way can be used to name newly created resources over + // this connection." + // So for example (using 8 bit integers), the mask might look like: + // 00111000 + // So that valid values would be 00101000, 00110000, 00001000, and so on. + // Thus, the idea is to increment it by the place of the last least + // significant '1'. In this case, that value would be 00001000. To get + // that value, we can AND the original mask with its two's complement: + // 00111000 & 11001000 = 00001000. + // And we use that value to increment the last resource id to get a new one. + // (And then, of course, we OR it with resource-id-base.) + inc := conn.setupResourceIdMask & -conn.setupResourceIdMask + max := conn.setupResourceIdMask + last := uint32(0) + for { + // TODO: Use the XC Misc extension to look for released ids. + if last > 0 && last >= max-inc+1 { + conn.xidChan <- xid{ + id: 0, + err: errors.New("There are no more available resource" + + "identifiers."), + } + } + + last += inc + conn.xidChan <- xid{ + id: last | conn.setupResourceIdBase, + err: nil, + } + } +} + +// newSeqId fetches the next sequence id from the Conn.seqChan channel. +func (c *Conn) newSequenceId() uint16 { + return <-c.seqChan +} + +// generateSeqIds returns new sequence ids. It is meant to be run in its +// own goroutine. +// A sequence id is generated for *every* request. It's the identifier used +// to match up replies with requests. +// Since sequence ids can only be 16 bit integers we start over at zero when it +// comes time to wrap. +// N.B. As long as the cookie buffer is less than 2^16, there are no limitations +// on the number (or kind) of requests made in sequence. +func (c *Conn) generateSeqIds() { + defer close(c.seqChan) + + seqid := uint16(1) + for { + c.seqChan <- seqid + if seqid == uint16((1<<16)-1) { + seqid = 0 + } else { + seqid++ + } + } +} + +// request encapsulates a buffer of raw bytes (containing the request data) +// and a cookie, which when combined represents a single request. +// The cookie is used to match up the reply/error. +type request struct { + buf []byte + cookie *Cookie + + // seq is closed when the request (cookie) has been sequenced by the Conn. + seq chan struct{} +} + +// NewRequest takes the bytes and a cookie of a particular request, constructs +// a request type, and sends it over the Conn.reqChan channel. +// Note that the sequence number is added to the cookie after it is sent +// over the request channel, but before it is sent to X. +// +// Note that you may safely use NewRequest to send arbitrary byte requests +// to X. The resulting cookie can be used just like any normal cookie and +// abides by the same rules, except that for replies, you'll get back the +// raw byte data. This may be useful for performance critical sections where +// every allocation counts, since all X requests in XGB allocate a new byte +// slice. In contrast, NewRequest allocates one small request struct and +// nothing else. (Except when the cookie buffer is full and has to be flushed.) +// +// If you're using NewRequest manually, you'll need to use NewCookie to create +// a new cookie. +// +// In all likelihood, you should be able to copy and paste with some minor +// edits the generated code for the request you want to issue. +func (c *Conn) NewRequest(buf []byte, cookie *Cookie) { + seq := make(chan struct{}) + c.reqChan <- &request{buf: buf, cookie: cookie, seq: seq} + <-seq +} + +// sendRequests is run as a single goroutine that takes requests and writes +// the bytes to the wire and adds the cookie to the cookie queue. +// It is meant to be run as its own goroutine. +func (c *Conn) sendRequests() { + defer close(c.cookieChan) + + for req := range c.reqChan { + // ho there! if the cookie channel is nearly full, force a round + // trip to clear out the cookie buffer. + // Note that we circumvent the request channel, because we're *in* + // the request channel. + if len(c.cookieChan) == cookieBuffer-1 { + if err := c.noop(); err != nil { + // Shut everything down. + break + } + } + req.cookie.Sequence = c.newSequenceId() + c.cookieChan <- req.cookie + c.writeBuffer(req.buf) + close(req.seq) + } + response := make(chan struct{}) + c.closing <- response + c.noop() // Flush the response reading goroutine, ignore error. + <-response + c.conn.Close() +} + +// noop circumvents the usual request sending goroutines and forces a round +// trip request manually. +func (c *Conn) noop() error { + cookie := c.NewCookie(true, true) + cookie.Sequence = c.newSequenceId() + c.cookieChan <- cookie + if err := c.writeBuffer(c.getInputFocusRequest()); err != nil { + return err + } + cookie.Reply() // wait for the buffer to clear + return nil +} + +// writeBuffer is a convenience function for writing a byte slice to the wire. +func (c *Conn) writeBuffer(buf []byte) error { + if _, err := c.conn.Write(buf); err != nil { + Logger.Printf("A write error is unrecoverable: %s", err) + return err + } else { + return nil + } +} + +// readResponses is a goroutine that reads events, errors and +// replies off the wire. +// When an event is read, it is always added to the event channel. +// When an error is read, if it corresponds to an existing checked cookie, +// it is sent to that cookie's error channel. Otherwise it is added to the +// event channel. +// When a reply is read, it is added to the corresponding cookie's reply +// channel. (It is an error if no such cookie exists in this case.) +// Finally, cookies that came "before" this reply are always cleaned up. +func (c *Conn) readResponses() { + defer close(c.eventChan) + + var ( + err Error + seq uint16 + replyBytes []byte + ) + + for { + select { + case respond := <-c.closing: + respond <- struct{}{} + return + default: + } + + buf := make([]byte, 32) + err, seq = nil, 0 + if _, err := io.ReadFull(c.conn, buf); err != nil { + Logger.Printf("A read error is unrecoverable: %s", err) + c.eventChan <- err + c.Close() + continue + } + switch buf[0] { + case 0: // This is an error + // Use the constructor function for this error (that is auto + // generated) by looking it up by the error number. + newErrFun, ok := NewErrorFuncs[int(buf[1])] + if !ok { + Logger.Printf("BUG: Could not find error constructor function "+ + "for error with number %d.", buf[1]) + continue + } + err = newErrFun(buf) + seq = err.SequenceId() + + // This error is either sent to the event channel or a specific + // cookie's error channel below. + case 1: // This is a reply + seq = Get16(buf[2:]) + + // check to see if this reply has more bytes to be read + size := Get32(buf[4:]) + if size > 0 { + byteCount := 32 + size*4 + biggerBuf := make([]byte, byteCount) + copy(biggerBuf[:32], buf) + if _, err := io.ReadFull(c.conn, biggerBuf[32:]); err != nil { + Logger.Printf("A read error is unrecoverable: %s", err) + c.eventChan <- err + c.Close() + continue + } + replyBytes = biggerBuf + } else { + replyBytes = buf + } + + // This reply is sent to its corresponding cookie below. + default: // This is an event + // Use the constructor function for this event (like for errors, + // and is also auto generated) by looking it up by the event number. + // Note that we AND the event number with 127 so that we ignore + // the most significant bit (which is set when it was sent from + // a SendEvent request). + evNum := int(buf[0] & 127) + newEventFun, ok := NewEventFuncs[evNum] + if !ok { + Logger.Printf("BUG: Could not find event construct function "+ + "for event with number %d.", evNum) + continue + } + c.eventChan <- newEventFun(buf) + continue + } + + // At this point, we have a sequence number and we're either + // processing an error or a reply, which are both responses to + // requests. So all we have to do is find the cookie corresponding + // to this error/reply, and send the appropriate data to it. + // In doing so, we make sure that any cookies that came before it + // are marked as successful if they are void and checked. + // If there's a cookie that requires a reply that is before this + // reply, then something is wrong. + for cookie := range c.cookieChan { + // This is the cookie we're looking for. Process and break. + if cookie.Sequence == seq { + if err != nil { // this is an error to a request + // synchronous processing + if cookie.errorChan != nil { + cookie.errorChan <- err + } else { // asynchronous processing + c.eventChan <- err + // if this is an unchecked reply, ping the cookie too + if cookie.pingChan != nil { + cookie.pingChan <- true + } + } + } else { // this is a reply + if cookie.replyChan == nil { + Logger.Printf("Reply with sequence id %d does not "+ + "have a cookie with a valid reply channel.", seq) + continue + } else { + cookie.replyChan <- replyBytes + } + } + break + } + + switch { + // Checked requests with replies + case cookie.replyChan != nil && cookie.errorChan != nil: + Logger.Printf("Found cookie with sequence id %d that is "+ + "expecting a reply but will never get it. Currently "+ + "on sequence number %d", cookie.Sequence, seq) + // Unchecked requests with replies + case cookie.replyChan != nil && cookie.pingChan != nil: + Logger.Printf("Found cookie with sequence id %d that is "+ + "expecting a reply (and not an error) but will never "+ + "get it. Currently on sequence number %d", + cookie.Sequence, seq) + // Checked requests without replies + case cookie.pingChan != nil && cookie.errorChan != nil: + cookie.pingChan <- true + // Unchecked requests without replies don't have any channels, + // so we can't do anything with them except let them pass by. + } + } + } +} + +// processEventOrError takes an eventOrError, type switches on it, +// and returns it in Go idiomatic style. +func processEventOrError(everr eventOrError) (Event, Error) { + switch ee := everr.(type) { + case Event: + return ee, nil + case Error: + return nil, ee + default: + Logger.Printf("Invalid event/error type: %T", everr) + return nil, nil + } +} + +// WaitForEvent returns the next event from the server. +// It will block until an event is available. +// WaitForEvent returns either an Event or an Error. (Returning both +// is a bug.) Note than an Error here is an X error and not an XGB error. That +// is, X errors are sometimes completely expected (and you may want to ignore +// them in some cases). +// +// If both the event and error are nil, then the connection has been closed. +func (c *Conn) WaitForEvent() (Event, Error) { + return processEventOrError(<-c.eventChan) +} + +// PollForEvent returns the next event from the server if one is available in +// the internal queue without blocking. Note that unlike WaitForEvent, both +// Event and Error could be nil. Indeed, they are both nil when the event queue +// is empty. +func (c *Conn) PollForEvent() (Event, Error) { + select { + case everr := <-c.eventChan: + return processEventOrError(everr) + default: + return nil, nil + } +} diff --git a/nexgb/xgbgen/COPYING b/nexgb/xgbgen/COPYING new file mode 100644 index 0000000..5c93f45 --- /dev/null +++ b/nexgb/xgbgen/COPYING @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/nexgb/xgbgen/context.go b/nexgb/xgbgen/context.go new file mode 100644 index 0000000..0728b64 --- /dev/null +++ b/nexgb/xgbgen/context.go @@ -0,0 +1,168 @@ +package main + +import ( + "bytes" + "encoding/xml" + "fmt" + "log" + "sort" +) + +// Context represents the protocol we're converting to Go, and a writer +// buffer to write the Go source to. +type Context struct { + protocol *Protocol + out *bytes.Buffer +} + +func newContext() *Context { + return &Context{ + out: bytes.NewBuffer([]byte{}), + } +} + +// Putln calls put and adds a new line to the end of 'format'. +func (c *Context) Putln(format string, v ...interface{}) { + c.Put(format+"\n", v...) +} + +// Put is a short alias to write to 'out'. +func (c *Context) Put(format string, v ...interface{}) { + _, err := c.out.WriteString(fmt.Sprintf(format, v...)) + if err != nil { + log.Fatalf("There was an error writing to context buffer: %s", err) + } +} + +// Morph is the big daddy of them all. It takes in an XML byte slice, +// parse it, transforms the XML types into more usable types, +// and writes Go code to the 'out' buffer. +func (c *Context) Morph(xmlBytes []byte) { + parsedXml := &XML{} + err := xml.Unmarshal(xmlBytes, parsedXml) + if err != nil { + log.Fatal(err) + } + + // Parse all imports + parsedXml.Imports.Eval() + + // Translate XML types to nice types + c.protocol = parsedXml.Translate(nil) + + // For backwards compatibility we patch the type of the send_event field of + // PutImage to be byte + if c.protocol.Name == "shm" { + for _, req := range c.protocol.Requests { + if req.xmlName != "PutImage" { + continue + } + for _, ifield := range req.Fields { + field, ok := ifield.(*SingleField) + if !ok || field.xmlName != "send_event" { + continue + } + field.Type = &Base{ srcName: "byte", xmlName: "CARD8", size: newFixedSize(1, true) } + } + } + } + + // Start with Go header. + c.Putln("// Package %s is the X client API for the %s extension.", + c.protocol.PkgName(), c.protocol.ExtXName) + c.Putln("package %s", c.protocol.PkgName()) + c.Putln("") + c.Putln("// This file is automatically generated from %s.xml. "+ + "Edit at your peril!", c.protocol.Name) + c.Putln("") + + // Write imports. We always need to import at least xgb. + // We also need to import xproto if it's an extension. + c.Putln("import (") + c.Putln("\"github.com/BurntSushi/xgb\"") + c.Putln("") + if c.protocol.isExt() { + c.Putln("\"github.com/BurntSushi/xgb/xproto\"") + } + + sort.Sort(Protocols(c.protocol.Imports)) + for _, imp := range c.protocol.Imports { + // We always import xproto, so skip it if it's explicitly imported + if imp.Name == "xproto" { + continue + } + c.Putln("\"github.com/BurntSushi/xgb/%s\"", imp.Name) + } + c.Putln(")") + c.Putln("") + + // If this is an extension, create a function to initialize the extension + // before it can be used. + if c.protocol.isExt() { + xname := c.protocol.ExtXName + + c.Putln("// Init must be called before using the %s extension.", + xname) + c.Putln("func Init(c *xgb.Conn) error {") + c.Putln("reply, err := xproto.QueryExtension(c, %d, \"%s\").Reply()", + len(xname), xname) + c.Putln("switch {") + c.Putln("case err != nil:") + c.Putln("return err") + c.Putln("case !reply.Present:") + c.Putln("return xgb.Errorf(\"No extension named %s could be found on "+ + "on the server.\")", xname) + c.Putln("}") + c.Putln("") + c.Putln("c.ExtLock.Lock()") + c.Putln("c.Extensions[\"%s\"] = reply.MajorOpcode", xname) + c.Putln("c.ExtLock.Unlock()") + c.Putln("for evNum, fun := range xgb.NewExtEventFuncs[\"%s\"] {", + xname) + c.Putln("xgb.NewEventFuncs[int(reply.FirstEvent) + evNum] = fun") + c.Putln("}") + c.Putln("for errNum, fun := range xgb.NewExtErrorFuncs[\"%s\"] {", + xname) + c.Putln("xgb.NewErrorFuncs[int(reply.FirstError) + errNum] = fun") + c.Putln("}") + c.Putln("return nil") + c.Putln("}") + c.Putln("") + + // Make sure newExtEventFuncs["EXT_NAME"] map is initialized. + // Same deal for newExtErrorFuncs["EXT_NAME"] + c.Putln("func init() {") + c.Putln("xgb.NewExtEventFuncs[\"%s\"] = make(map[int]xgb.NewEventFun)", + xname) + c.Putln("xgb.NewExtErrorFuncs[\"%s\"] = make(map[int]xgb.NewErrorFun)", + xname) + c.Putln("}") + c.Putln("") + } else { + // In the xproto package, we must provide a Setup function that uses + // SetupBytes in xgb.Conn to return a SetupInfo structure. + c.Putln("// Setup parses the setup bytes retrieved when") + c.Putln("// connecting into a SetupInfo struct.") + c.Putln("func Setup(c *xgb.Conn) *SetupInfo {") + c.Putln("setup := new(SetupInfo)") + c.Putln("SetupInfoRead(c.SetupBytes, setup)") + c.Putln("return setup") + c.Putln("}") + c.Putln("") + c.Putln("// DefaultScreen gets the default screen info from SetupInfo.") + c.Putln("func (s *SetupInfo) DefaultScreen(c *xgb.Conn) *ScreenInfo {") + c.Putln("return &s.Roots[c.DefaultScreen]") + c.Putln("}") + c.Putln("") + } + + // Now write Go source code + sort.Sort(Types(c.protocol.Types)) + sort.Sort(Requests(c.protocol.Requests)) + for _, typ := range c.protocol.Types { + typ.Define(c) + } + for _, req := range c.protocol.Requests { + req.Define(c) + } +} diff --git a/nexgb/xgbgen/doc.go b/nexgb/xgbgen/doc.go new file mode 100644 index 0000000..4ba6145 --- /dev/null +++ b/nexgb/xgbgen/doc.go @@ -0,0 +1,74 @@ +/* +xgbgen constructs Go source files from xproto XML description files. xgbgen +accomplishes the same task as the Python code generator for XCB and xpyb. + +Usage: + xgbgen [flags] some-protocol.xml + +The flags are: + --proto-path path + The path to a directory containing xproto XML description files. + This is only necessary when 'some-protocol.xml' imports other + protocol files. + --gofmt=true + When false, the outputted Go code will not be gofmt'd. And it won't + be very pretty at all. This is typically useful if there are syntax + errors that need to be debugged in code generation. gofmt will hiccup; + this will allow you to see the raw code. + +How it works + +xgbgen works by parsing the input XML file using Go's encoding/xml package. +The majority of this work is done in xml.go and xml_fields.go, where the +appropriate types are declared. + +Due to the nature of the XML in the protocol description files, the types +required to parse the XML are not well suited to reasoning about code +generation. Because of this, all data parsed in the XML types is translated +into more reasonable types. This translation is done in translation.go, +and is mainly grunt work. (The only interesting tidbits are the translation +of XML names to Go source names, and connecting fields with their +appropriate types.) + +The organization of these types is greatly +inspired by the description of the XML found here: +http://cgit.freedesktop.org/xcb/proto/tree/doc/xml-xcb.txt + +These types come with a lot of supporting methods to make their use in +code generation easier. They can be found in expression.go, field.go, +protocol.go, request_reply.go and type.go. Of particular interest are +expression evaluation and size calculation (in bytes). + +These types also come with supporting methods that convert their +representation into Go source code. I've quartered such methods in +go.go, go_error.go, go_event.go, go_list.go, go_request_reply.go, +go_single_field.go, go_struct.go and go_union.go. The idea is to keep +as much of the Go specific code generation in one area as possible. Namely, +while not *all* Go related code is found in the 'go*.go' files, *most* +of it is. (If there's any interest in using xgbgen for other languages, +I'd be happy to try and make xgbgen a little more friendly in this regard. +I did, however, design xgbgen with this in mind, so it shouldn't involve +anything as serious as a re-design.) + +Why + +I wrote xgbgen because I found the existing code generator that was written in +Python to be unwieldy. In particular, static and strong typing greatly helped +me reason better about the code generation task. + +What does not work + +The core X protocol should be completely working. As far as I know, most +extensions should work too, although I've only tested (and not much) the +Xinerama and RandR extensions. + +XKB does not work. I don't have any real plans of working on this unless there +is demand and I have some test cases to work with. (i.e., even if I could get +something generated for XKB, I don't have the inclination to understand it +enough to verify that it works.) XKB poses several extremely difficult +problems that XCB also has trouble with. More info on that can be found at +http://cgit.freedesktop.org/xcb/libxcb/tree/doc/xkb_issues and +http://cgit.freedesktop.org/xcb/libxcb/tree/doc/xkb_internals. + +*/ +package main diff --git a/nexgb/xgbgen/expression.go b/nexgb/xgbgen/expression.go new file mode 100644 index 0000000..3e2235d --- /dev/null +++ b/nexgb/xgbgen/expression.go @@ -0,0 +1,436 @@ +package main + +import ( + "fmt" + "log" +) + +// Expression represents all the different forms of expressions possible in +// side an XML protocol description file. It's also received a few custom +// addendums to make applying special functions (like padding) easier. +type Expression interface { + // Concrete determines whether this particular expression can be computed + // to some constant value inside xgbgen. (The alternative is that the + // expression can only be computed with values at run time of the + // generated code.) + Concrete() bool + + // Eval evaluates a concrete expression. It is an error to call Eval + // on any expression that is not concrete (or contains any sub-expression + // that is not concrete). + Eval() int + + // Reduce attempts to evaluate any concrete sub-expressions. + // i.e., (1 + 2 * (5 + 1 + someSizeOfStruct) reduces to + // (3 * (6 + someSizeOfStruct)). + // 'prefix' is used preprended to any field reference name. + Reduce(prefix string) string + + // String is an alias for Reduce("") + String() string + + // Initialize makes sure all names in this expression and any subexpressions + // have been translated to Go source names. + Initialize(p *Protocol) + + // Makes all field references relative to path + Specialize(path string) Expression +} + +// Function is a custom expression not found in the XML. It's simply used +// to apply a function named in 'Name' to the Expr expression. +type Function struct { + Name string + Expr Expression +} + +func (e *Function) Concrete() bool { + return false +} + +func (e *Function) Eval() int { + log.Fatalf("Cannot evaluate a 'Function'. It is not concrete.") + panic("unreachable") +} + +func (e *Function) Reduce(prefix string) string { + return fmt.Sprintf("%s(%s)", e.Name, e.Expr.Reduce(prefix)) +} + +func (e *Function) String() string { + return e.Reduce("") +} + +func (e *Function) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + +func (e *Function) Specialize(path string) Expression { + r := *e + r.Expr = r.Expr.Specialize(path) + return &r +} + +// BinaryOp is an expression that performs some operation (defined in the XML +// file) with Expr1 and Expr2 as operands. +type BinaryOp struct { + Op string + Expr1 Expression + Expr2 Expression +} + +// newBinaryOp constructs a new binary expression when both expr1 and expr2 +// are not nil. If one or both are nil, then the non-nil expression is +// returned unchanged or nil is returned. +func newBinaryOp(op string, expr1, expr2 Expression) Expression { + switch { + case expr1 != nil && expr2 != nil: + return &BinaryOp{ + Op: op, + Expr1: expr1, + Expr2: expr2, + } + case expr1 != nil && expr2 == nil: + return expr1 + case expr1 == nil && expr2 != nil: + return expr2 + case expr1 == nil && expr2 == nil: + return nil + } + panic("unreachable") +} + +func (e *BinaryOp) Concrete() bool { + return e.Expr1.Concrete() && e.Expr2.Concrete() +} + +func (e *BinaryOp) Eval() int { + switch e.Op { + case "+": + return e.Expr1.Eval() + e.Expr2.Eval() + case "-": + return e.Expr1.Eval() - e.Expr2.Eval() + case "*": + return e.Expr1.Eval() * e.Expr2.Eval() + case "/": + return e.Expr1.Eval() / e.Expr2.Eval() + case "&": + return e.Expr1.Eval() & e.Expr2.Eval() + case "<<": + return int(uint(e.Expr1.Eval()) << uint(e.Expr2.Eval())) + } + + log.Fatalf("Invalid binary operator '%s' for expression.", e.Op) + panic("unreachable") +} + +func (e *BinaryOp) Reduce(prefix string) string { + if e.Concrete() { + return fmt.Sprintf("%d", e.Eval()) + } + + // An incredibly dirty hack to make sure any time we perform an operation + // on a field, we're dealing with ints... + expr1, expr2 := e.Expr1, e.Expr2 + switch expr1.(type) { + case *FieldRef: + expr1 = &Function{ + Name: "int", + Expr: expr1, + } + } + switch expr2.(type) { + case *FieldRef: + expr2 = &Function{ + Name: "int", + Expr: expr2, + } + } + return fmt.Sprintf("(%s %s %s)", + expr1.Reduce(prefix), e.Op, expr2.Reduce(prefix)) +} + +func (e *BinaryOp) String() string { + return e.Reduce("") +} + +func (e *BinaryOp) Initialize(p *Protocol) { + e.Expr1.Initialize(p) + e.Expr2.Initialize(p) +} + +func (e *BinaryOp) Specialize(path string) Expression { + r := *e + r.Expr1 = r.Expr1.Specialize(path) + r.Expr2 = r.Expr2.Specialize(path) + return &r +} + +// UnaryOp is the same as BinaryOp, except it's a unary operator with only +// one sub-expression. +type UnaryOp struct { + Op string + Expr Expression +} + +func (e *UnaryOp) Concrete() bool { + return e.Expr.Concrete() +} + +func (e *UnaryOp) Eval() int { + switch e.Op { + case "~": + return ^e.Expr.Eval() + } + + log.Fatalf("Invalid unary operator '%s' for expression.", e.Op) + panic("unreachable") +} + +func (e *UnaryOp) Reduce(prefix string) string { + if e.Concrete() { + return fmt.Sprintf("%d", e.Eval()) + } + return fmt.Sprintf("(%s (%s))", e.Op, e.Expr.Reduce(prefix)) +} + +func (e *UnaryOp) String() string { + return e.Reduce("") +} + +func (e *UnaryOp) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + +func (e *UnaryOp) Specialize(path string) Expression { + r := *e + r.Expr = r.Expr.Specialize(path) + return &r +} + +// Padding represents the application of the 'pad' function to some +// sub-expression. +type Padding struct { + Expr Expression +} + +func (e *Padding) Concrete() bool { + return e.Expr.Concrete() +} + +func (e *Padding) Eval() int { + return pad(e.Expr.Eval()) +} + +func (e *Padding) Reduce(prefix string) string { + if e.Concrete() { + return fmt.Sprintf("%d", e.Eval()) + } + return fmt.Sprintf("xgb.Pad(%s)", e.Expr.Reduce(prefix)) +} + +func (e *Padding) String() string { + return e.Reduce("") +} + +func (e *Padding) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + +func (e *Padding) Specialize(path string) Expression { + r := *e + r.Expr = r.Expr.Specialize(path) + return &r +} + +// PopCount represents the application of the 'PopCount' function to +// some sub-expression. +type PopCount struct { + Expr Expression +} + +func (e *PopCount) Concrete() bool { + return e.Expr.Concrete() +} + +func (e *PopCount) Eval() int { + return int(popCount(uint(e.Expr.Eval()))) +} + +func (e *PopCount) Reduce(prefix string) string { + if e.Concrete() { + return fmt.Sprintf("%d", e.Eval()) + } + return fmt.Sprintf("xgb.PopCount(%s)", e.Expr.Reduce(prefix)) +} + +func (e *PopCount) String() string { + return e.Reduce("") +} + +func (e *PopCount) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + +func (e *PopCount) Specialize(path string) Expression { + r := *e + r.Expr = r.Expr.Specialize(path) + return &r +} + +// Value represents some constant integer. +type Value struct { + v int +} + +func (e *Value) Concrete() bool { + return true +} + +func (e *Value) Eval() int { + return e.v +} + +func (e *Value) Reduce(prefix string) string { + return fmt.Sprintf("%d", e.v) +} + +func (e *Value) String() string { + return e.Reduce("") +} + +func (e *Value) Initialize(p *Protocol) {} + +func (e *Value) Specialize(path string) Expression { + return e +} + +// Bit represents some bit whose value is computed by '1 << bit'. +type Bit struct { + b int +} + +func (e *Bit) Concrete() bool { + return true +} + +func (e *Bit) Eval() int { + return int(1 << uint(e.b)) +} + +func (e *Bit) Reduce(prefix string) string { + return fmt.Sprintf("%d", e.Eval()) +} + +func (e *Bit) String() string { + return e.Reduce("") +} + +func (e *Bit) Initialize(p *Protocol) {} + +func (e *Bit) Specialize(path string) Expression { + return e +} + +// FieldRef represents a reference to some variable in the generated code +// with name Name. +type FieldRef struct { + Name string +} + +func (e *FieldRef) Concrete() bool { + return false +} + +func (e *FieldRef) Eval() int { + log.Fatalf("Cannot evaluate a 'FieldRef'. It is not concrete.") + panic("unreachable") +} + +func (e *FieldRef) Reduce(prefix string) string { + val := e.Name + if len(prefix) > 0 { + val = fmt.Sprintf("%s%s", prefix, val) + } + return val +} + +func (e *FieldRef) String() string { + return e.Reduce("") +} + +func (e *FieldRef) Initialize(p *Protocol) { + e.Name = SrcName(p, e.Name) +} + +func (e *FieldRef) Specialize(path string) Expression { + return &FieldRef{Name: path + "." + e.Name} +} + +// EnumRef represents a reference to some enumeration field. +// EnumKind is the "group" an EnumItem is the name of the specific enumeration +// value inside that group. +type EnumRef struct { + EnumKind Type + EnumItem string +} + +func (e *EnumRef) Concrete() bool { + return false +} + +func (e *EnumRef) Eval() int { + log.Fatalf("Cannot evaluate an 'EnumRef'. It is not concrete.") + panic("unreachable") +} + +func (e *EnumRef) Reduce(prefix string) string { + return fmt.Sprintf("%s%s", e.EnumKind, e.EnumItem) +} + +func (e *EnumRef) String() string { + return e.Reduce("") +} + +func (e *EnumRef) Initialize(p *Protocol) { + e.EnumKind = e.EnumKind.(*Translation).RealType(p) + e.EnumItem = SrcName(p, e.EnumItem) +} + +func (e *EnumRef) Specialize(path string) Expression { + return e +} + +// SumOf represents a summation of the variable in the generated code named by +// Name. It is not currently used. (It's XKB voodoo.) +type SumOf struct { + Name string +} + +func (e *SumOf) Concrete() bool { + return false +} + +func (e *SumOf) Eval() int { + log.Fatalf("Cannot evaluate a 'SumOf'. It is not concrete.") + panic("unreachable") +} + +func (e *SumOf) Reduce(prefix string) string { + if len(prefix) > 0 { + return fmt.Sprintf("sum(%s%s)", prefix, e.Name) + } + return fmt.Sprintf("sum(%s)", e.Name) +} + +func (e *SumOf) String() string { + return e.Reduce("") +} + +func (e *SumOf) Initialize(p *Protocol) { + e.Name = SrcName(p, e.Name) +} + +func (e *SumOf) Specialize(path string) Expression { + return e +} diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go new file mode 100644 index 0000000..d6957b7 --- /dev/null +++ b/nexgb/xgbgen/field.go @@ -0,0 +1,398 @@ +package main + +import ( + "fmt" + "log" + "strings" +) + +// Field corresponds to any field described in an XML protocol description +// file. This includes struct fields, union fields, request fields, +// reply fields and so on. +// To make code generation easier, fields that have types are also stored. +// Note that not all fields support all methods defined in this interface. +// For instance, a padding field does not have a source name. +type Field interface { + // Initialize sets up the source name of this field. + Initialize(p *Protocol) + + // SrcName is the Go source name of this field. + SrcName() string + + // XmlName is the name of this field from the XML file. + XmlName() string + + // SrcType is the Go source type name of this field. + SrcType() string + + // Size returns an expression that computes the size (in bytes) + // of this field. + Size() Size + + // Define writes the Go code to declare this field (in a struct definition). + Define(c *Context) + + // Read writes the Go code to convert a byte slice to a Go value + // of this field. + // 'prefix' is the prefix of the name of the Go value. + Read(c *Context, prefix string) + + // Write writes the Go code to convert a Go value to a byte slice of + // this field. + // 'prefix' is the prefix of the name of the Go value. + Write(c *Context, prefix string) +} + +func (pad *PadField) Initialize(p *Protocol) {} + +// PadField represents any type of padding. It is omitted from +// definitions, but is used in Read/Write to increment the buffer index. +// It is also used in size calculation. +type PadField struct { + Bytes uint + Align uint16 +} + +func (p *PadField) SrcName() string { + panic("illegal to take source name of a pad field") +} + +func (p *PadField) XmlName() string { + panic("illegal to take XML name of a pad field") +} + +func (f *PadField) SrcType() string { + panic("it is illegal to call SrcType on a PadField field") +} + +func (p *PadField) Size() Size { + if p.Align > 0 { + return newFixedSize(uint(p.Align), false) + } else { + return newFixedSize(p.Bytes, true) + } +} + +type RequiredStartAlign struct { +} + +func (f *RequiredStartAlign) Initialize(p *Protocol) {} + +func (f *RequiredStartAlign) SrcName() string { + panic("illegal to take source name of a required_start_align field") +} + +func (f *RequiredStartAlign) XmlName() string { + panic("illegal to take XML name of a required_start_align field") +} + +func (f *RequiredStartAlign) SrcType() string { + panic("it is illegal to call SrcType on a required_start_align field") +} + +func (f *RequiredStartAlign) Size() Size { + return newFixedSize(0, true) +} + +func (f *RequiredStartAlign) Define(c *Context) {} + +func (f *RequiredStartAlign) Read(c *Context, prefix string) {} +func (f *RequiredStartAlign) Write(c *Context, prefix string) {} + +// SingleField represents most of the fields in an XML protocol description. +// It corresponds to any single value. +type SingleField struct { + srcName string + xmlName string + Type Type +} + +func (f *SingleField) Initialize(p *Protocol) { + f.srcName = SrcName(p, f.XmlName()) + f.Type = f.Type.(*Translation).RealType(p) +} + +func (f *SingleField) SrcName() string { + if f.srcName == "Bytes" { + return "Bytes_" + } + return f.srcName +} + +func (f *SingleField) XmlName() string { + return f.xmlName +} + +func (f *SingleField) SrcType() string { + return f.Type.SrcName() +} + +func (f *SingleField) Size() Size { + return f.Type.Size() +} + +// ListField represents a list of values. +type ListField struct { + srcName string + xmlName string + Type Type + LengthExpr Expression +} + +func (f *ListField) SrcName() string { + return f.srcName +} + +func (f *ListField) XmlName() string { + return f.xmlName +} + +func (f *ListField) SrcType() string { + if strings.ToLower(f.Type.XmlName()) == "char" { + return fmt.Sprintf("string") + } + return fmt.Sprintf("[]%s", f.Type.SrcName()) +} + +// Length computes the *number* of values in a list. +// If this ListField does not have any length expression, we throw our hands +// up and simply compute the 'len' of the field name of this list. +func (f *ListField) Length() Size { + if f.LengthExpr == nil { + return newExpressionSize(&Function{ + Name: "len", + Expr: &FieldRef{ + Name: f.SrcName(), + }, + }, true) + } + return newExpressionSize(f.LengthExpr, true) +} + +// Size computes the *size* of a list (in bytes). +// It it typically a simple matter of multiplying the length of the list by +// the size of the type of the list. +// But if it's a list of struct where the struct has a list field, we use a +// special function written in go_struct.go to compute the size (since the +// size in this case can only be computed recursively). +func (f *ListField) Size() Size { + elsz := f.Type.Size() + simpleLen := &Padding{ + Expr: newBinaryOp("*", f.Length().Expression, elsz.Expression), + } + + switch field := f.Type.(type) { + case *Struct: + if field.HasList() { + sizeFun := &Function{ + Name: fmt.Sprintf("%sListSize", f.Type.SrcName()), + Expr: &FieldRef{Name: f.SrcName()}, + } + return newExpressionSize(sizeFun, elsz.exact) + } else { + return newExpressionSize(simpleLen, elsz.exact) + } + case *Union: + return newExpressionSize(simpleLen, elsz.exact) + case *Base: + return newExpressionSize(simpleLen, elsz.exact) + case *Resource: + return newExpressionSize(simpleLen, elsz.exact) + case *TypeDef: + return newExpressionSize(simpleLen, elsz.exact) + default: + log.Panicf("Cannot compute list size with type '%T'.", f.Type) + } + panic("unreachable") +} + +func (f *ListField) Initialize(p *Protocol) { + f.srcName = SrcName(p, f.XmlName()) + f.Type = f.Type.(*Translation).RealType(p) + if f.LengthExpr != nil { + f.LengthExpr.Initialize(p) + } +} + +// LocalField is exactly the same as a regular SingleField, except it isn't +// sent over the wire. (i.e., it's probably used to compute an ExprField). +type LocalField struct { + *SingleField +} + +// ExprField is a field that is not parameterized, but is computed from values +// of other fields. +type ExprField struct { + srcName string + xmlName string + Type Type + Expr Expression +} + +func (f *ExprField) SrcName() string { + return f.srcName +} + +func (f *ExprField) XmlName() string { + return f.xmlName +} + +func (f *ExprField) SrcType() string { + return f.Type.SrcName() +} + +func (f *ExprField) Size() Size { + return f.Type.Size() +} + +func (f *ExprField) Initialize(p *Protocol) { + f.srcName = SrcName(p, f.XmlName()) + f.Type = f.Type.(*Translation).RealType(p) + f.Expr.Initialize(p) +} + +// ValueField represents two fields in one: a mask and a list of 4-byte +// integers. The mask specifies which kinds of values are in the list. +// (i.e., See ConfigureWindow, CreateWindow, ChangeWindowAttributes, etc.) +type ValueField struct { + Parent interface{} + MaskType Type + MaskName string + ListName string +} + +func (f *ValueField) SrcName() string { + panic("it is illegal to call SrcName on a ValueField field") +} + +func (f *ValueField) XmlName() string { + panic("it is illegal to call XmlName on a ValueField field") +} + +func (f *ValueField) SrcType() string { + return f.MaskType.SrcName() +} + +// Size computes the size in bytes of the combination of the mask and list +// in this value field. +// The expression to compute this looks complicated, but it's really just +// the number of bits set in the mask multiplied 4 (and padded of course). +func (f *ValueField) Size() Size { + maskSize := f.MaskType.Size() + listSize := newExpressionSize(&Function{ + Name: "xgb.Pad", + Expr: &BinaryOp{ + Op: "*", + Expr1: &Value{v: 4}, + Expr2: &PopCount{ + Expr: &Function{ + Name: "int", + Expr: &FieldRef{ + Name: f.MaskName, + }, + }, + }, + }, + }, true) + return maskSize.Add(listSize) +} + +func (f *ValueField) ListLength() Size { + return newExpressionSize(&PopCount{ + Expr: &Function{ + Name: "int", + Expr: &FieldRef{ + Name: f.MaskName, + }, + }, + }, true) +} + +func (f *ValueField) Initialize(p *Protocol) { + f.MaskType = f.MaskType.(*Translation).RealType(p) + f.MaskName = SrcName(p, f.MaskName) + f.ListName = SrcName(p, f.ListName) +} + +// SwitchField represents a 'switch' element in the XML protocol description +// file. +// Currently we translate this to a slice of uint32 and let the user sort +// through it. +type SwitchField struct { + xmlName string + Name string + MaskName string + Expr Expression + Bitcases []*Bitcase +} + +func (f *SwitchField) SrcName() string { + return f.Name +} + +func (f *SwitchField) XmlName() string { + return f.xmlName +} + +func (f *SwitchField) SrcType() string { + return "[]uint32" +} + +func (f *SwitchField) Size() Size { + // TODO: size expression used here is not correct unless every element of + // the switch is 32 bit long. This assumption holds for xproto but may not + // hold for other protocols (xkb?) + + listSize := newExpressionSize(&Function{ + Name: "xgb.Pad", + Expr: &BinaryOp{ + Op: "*", + Expr1: &Value{v: 4}, + Expr2: &PopCount{ + Expr: &Function{ + Name: "int", + Expr: &FieldRef{ + Name: f.MaskName, + }, + }, + }, + }, + }, true) + + return listSize +} + +func (f *SwitchField) ListLength() Size { + return newExpressionSize(&PopCount{ + Expr: &Function{ + Name: "int", + Expr: &FieldRef{ + Name: f.MaskName, + }, + }, + }, true) +} + +func (f *SwitchField) Initialize(p *Protocol) { + f.xmlName = f.Name + f.Name = SrcName(p, f.Name) + f.Expr.Initialize(p) + fieldref, ok := f.Expr.(*FieldRef) + if !ok { + panic("switch field's expression not a fieldref") + } + f.MaskName = SrcName(p, fieldref.Name) + for _, bitcase := range f.Bitcases { + bitcase.Expr.Initialize(p) + for _, field := range bitcase.Fields { + field.Initialize(p) + } + } +} + +// Bitcase represents a single bitcase inside a switch expression. +// It is not currently used. (i.e., it's XKB voodoo.) +type Bitcase struct { + Fields []Field + Expr Expression +} diff --git a/nexgb/xgbgen/go.go b/nexgb/xgbgen/go.go new file mode 100644 index 0000000..87b5028 --- /dev/null +++ b/nexgb/xgbgen/go.go @@ -0,0 +1,220 @@ +package main + +import ( + "fmt" +) + +// BaseTypeMap is a map from X base types to Go types. +// X base types should correspond to the smallest set of X types +// that can be used to rewrite ALL X types in terms of Go types. +// That is, if you remove any of the following types, at least one +// XML protocol description will produce an invalid Go program. +// The types on the left *never* show themselves in the source. +var BaseTypeMap = map[string]string{ + "CARD8": "byte", + "CARD16": "uint16", + "CARD32": "uint32", + "INT8": "int8", + "INT16": "int16", + "INT32": "int32", + "BYTE": "byte", + "BOOL": "bool", + "float": "float64", + "double": "float64", + "char": "byte", + "void": "byte", +} + +// BaseTypeSizes should have precisely the same keys as in BaseTypeMap, +// and the values should correspond to the size of the type in bytes. +var BaseTypeSizes = map[string]uint{ + "CARD8": 1, + "CARD16": 2, + "CARD32": 4, + "INT8": 1, + "INT16": 2, + "INT32": 4, + "BYTE": 1, + "BOOL": 1, + "float": 4, + "double": 8, + "char": 1, + "void": 1, + + // Id is a special type used to determine the size of all Xid types. + // "Id" is not actually written in the source. + "Id": 4, +} + +// TypeMap is a map from types in the XML to type names that is used +// in the functions that follow. Basically, every occurrence of the key +// type is replaced with the value type. +var TypeMap = map[string]string{ + "VISUALTYPE": "VisualInfo", + "DEPTH": "DepthInfo", + "SCREEN": "ScreenInfo", + "Setup": "SetupInfo", +} + +// NameMap is the same as TypeMap, but for names. +var NameMap = map[string]string{} + +// Reading, writing and defining... + +// Base types +func (b *Base) Define(c *Context) { + c.Putln("// Skipping definition for base type '%s'", + SrcName(c.protocol, b.XmlName())) + c.Putln("") +} + +// Enum types +func (enum *Enum) Define(c *Context) { + c.Putln("const (") + for _, item := range enum.Items { + c.Putln("%s%s = %d", enum.SrcName(), item.srcName, item.Expr.Eval()) + } + c.Putln(")") + c.Putln("") +} + +// Resource types +func (res *Resource) Define(c *Context) { + c.Putln("type %s uint32", res.SrcName()) + c.Putln("") + c.Putln("func New%sId(c *xgb.Conn) (%s, error) {", + res.SrcName(), res.SrcName()) + c.Putln("id, err := c.NewId()") + c.Putln("if err != nil {") + c.Putln("return 0, err") + c.Putln("}") + c.Putln("return %s(id), nil", res.SrcName()) + c.Putln("}") + c.Putln("") +} + +// TypeDef types +func (td *TypeDef) Define(c *Context) { + c.Putln("type %s %s", td.srcName, td.Old.SrcName()) + c.Putln("") +} + +// Field definitions, reads and writes. + +// Pad fields +func (f *PadField) Define(c *Context) { + if f.Align > 0 { + c.Putln("// alignment gap to multiple of %d", f.Align) + } else { + c.Putln("// padding: %d bytes", f.Bytes) + } +} + +func (f *PadField) Read(c *Context, prefix string) { + if f.Align > 0 { + c.Putln("b = (b + %d) & ^%d // alignment gap", f.Align-1, f.Align-1) + } else { + c.Putln("b += %s // padding", f.Size()) + } +} + +func (f *PadField) Write(c *Context, prefix string) { + if f.Align > 0 { + c.Putln("b = (b + %d) & ^%d // alignment gap", f.Align-1, f.Align-1) + } else { + c.Putln("b += %s // padding", f.Size()) + } +} + +// Local fields +func (f *LocalField) Define(c *Context) { + c.Putln("// local field: %s %s", f.SrcName(), f.Type.SrcName()) + panic("unreachable") +} + +func (f *LocalField) Read(c *Context, prefix string) { + c.Putln("// reading local field: %s (%s) :: %s", + f.SrcName(), f.Size(), f.Type.SrcName()) + panic("unreachable") +} + +func (f *LocalField) Write(c *Context, prefix string) { + c.Putln("// skip writing local field: %s (%s) :: %s", + f.SrcName(), f.Size(), f.Type.SrcName()) +} + +// Expr fields +func (f *ExprField) Define(c *Context) { + c.Putln("// expression field: %s %s (%s)", + f.SrcName(), f.Type.SrcName(), f.Expr) + panic("unreachable") +} + +func (f *ExprField) Read(c *Context, prefix string) { + c.Putln("// reading expression field: %s (%s) (%s) :: %s", + f.SrcName(), f.Size(), f.Expr, f.Type.SrcName()) + panic("unreachable") +} + +func (f *ExprField) Write(c *Context, prefix string) { + // Special case for bools, grrr. + if f.Type.SrcName() == "bool" { + c.Putln("buf[b] = byte(%s)", f.Expr.Reduce(prefix)) + c.Putln("b += 1") + } else { + WriteSimpleSingleField(c, f.Expr.Reduce(prefix), f.Type) + } +} + +// Value field +func (f *ValueField) Define(c *Context) { + c.Putln("%s %s", f.MaskName, f.SrcType()) + c.Putln("%s []uint32", f.ListName) +} + +func (f *ValueField) Read(c *Context, prefix string) { + ReadSimpleSingleField(c, + fmt.Sprintf("%s%s", prefix, f.MaskName), f.MaskType) + c.Putln("") + c.Putln("%s%s = make([]uint32, %s)", + prefix, f.ListName, f.ListLength().Reduce(prefix)) + c.Putln("for i := 0; i < %s; i++ {", f.ListLength().Reduce(prefix)) + c.Putln("%s%s[i] = xgb.Get32(buf[b:])", prefix, f.ListName) + c.Putln("b += 4") + c.Putln("}") + c.Putln("b = xgb.Pad(b)") +} + +func (f *ValueField) Write(c *Context, prefix string) { + WriteSimpleSingleField(c, + fmt.Sprintf("%s%s", prefix, f.MaskName), f.MaskType) + c.Putln("for i := 0; i < %s; i++ {", f.ListLength().Reduce(prefix)) + c.Putln("xgb.Put32(buf[b:], %s%s[i])", prefix, f.ListName) + c.Putln("b += 4") + c.Putln("}") + c.Putln("b = xgb.Pad(b)") +} + +// Switch field +func (f *SwitchField) Define(c *Context) { + c.Putln("%s []uint32", f.Name) +} + +func (f *SwitchField) Read(c *Context, prefix string) { + c.Putln("") + c.Putln("%s%s = make([]uint32, %s)", + prefix, f.Name, f.ListLength().Reduce(prefix)) + c.Putln("for i := 0; i < %s; i++ {", f.ListLength().Reduce(prefix)) + c.Putln("%s%s[i] = xgb.Get32(buf[b:])", prefix, f.Name) + c.Putln("b += 4") + c.Putln("}") + c.Putln("b = xgb.Pad(b)") +} + +func (f *SwitchField) Write(c *Context, prefix string) { + c.Putln("for i := 0; i < %s; i++ {", f.ListLength().Reduce(prefix)) + c.Putln("xgb.Put32(buf[b:], %s%s[i])", prefix, f.Name) + c.Putln("b += 4") + c.Putln("}") + c.Putln("b = xgb.Pad(b)") +} diff --git a/nexgb/xgbgen/go_error.go b/nexgb/xgbgen/go_error.go new file mode 100644 index 0000000..55fd28b --- /dev/null +++ b/nexgb/xgbgen/go_error.go @@ -0,0 +1,179 @@ +package main + +import ( + "fmt" +) + +// Error types +func (e *Error) Define(c *Context) { + c.Putln("// %s is the error number for a %s.", e.ErrConst(), e.ErrConst()) + c.Putln("const %s = %d", e.ErrConst(), e.Number) + c.Putln("") + c.Putln("type %s struct {", e.ErrType()) + c.Putln("Sequence uint16") + c.Putln("NiceName string") + for _, field := range e.Fields { + field.Define(c) + } + c.Putln("}") + c.Putln("") + + // Read defines a function that transforms a byte slice into this + // error struct. + e.Read(c) + + // Makes sure this error type implements the xgb.Error interface. + e.ImplementsError(c) + + // Let's the XGB event loop read this error. + c.Putln("func init() {") + if c.protocol.isExt() { + c.Putln("xgb.NewExtErrorFuncs[\"%s\"][%d] = %sNew", + c.protocol.ExtXName, e.Number, e.ErrType()) + } else { + c.Putln("xgb.NewErrorFuncs[%d] = %sNew", e.Number, e.ErrType()) + } + c.Putln("}") + c.Putln("") +} + +func (e *Error) Read(c *Context) { + c.Putln("// %sNew constructs a %s value that implements xgb.Error from "+ + "a byte slice.", e.ErrType(), e.ErrType()) + c.Putln("func %sNew(buf []byte) xgb.Error {", e.ErrType()) + c.Putln("v := %s{}", e.ErrType()) + c.Putln("v.NiceName = \"%s\"", e.SrcName()) + c.Putln("") + c.Putln("b := 1 // skip error determinant") + c.Putln("b += 1 // don't read error number") + c.Putln("") + c.Putln("v.Sequence = xgb.Get16(buf[b:])") + c.Putln("b += 2") + c.Putln("") + for _, field := range e.Fields { + field.Read(c, "v.") + c.Putln("") + } + c.Putln("return v") + c.Putln("}") + c.Putln("") +} + +// ImplementsError writes functions to implement the XGB Error interface. +func (e *Error) ImplementsError(c *Context) { + c.Putln("// SequenceId returns the sequence id attached to the %s error.", + e.ErrConst()) + c.Putln("// This is mostly used internally.") + c.Putln("func (err %s) SequenceId() uint16 {", e.ErrType()) + c.Putln("return err.Sequence") + c.Putln("}") + c.Putln("") + c.Putln("// BadId returns the 'BadValue' number if one exists for the "+ + "%s error. If no bad value exists, 0 is returned.", e.ErrConst()) + c.Putln("func (err %s) BadId() uint32 {", e.ErrType()) + if !c.protocol.isExt() { + c.Putln("return err.BadValue") + } else { + c.Putln("return 0") + } + c.Putln("}") + c.Putln("// Error returns a rudimentary string representation of the %s "+ + "error.", e.ErrConst()) + c.Putln("") + c.Putln("func (err %s) Error() string {", e.ErrType()) + ErrorFieldString(c, e.Fields, e.ErrConst()) + c.Putln("}") + c.Putln("") +} + +// ErrorCopy types +func (e *ErrorCopy) Define(c *Context) { + c.Putln("// %s is the error number for a %s.", e.ErrConst(), e.ErrConst()) + c.Putln("const %s = %d", e.ErrConst(), e.Number) + c.Putln("") + c.Putln("type %s %s", e.ErrType(), e.Old.(*Error).ErrType()) + c.Putln("") + + // Read defines a function that transforms a byte slice into this + // error struct. + e.Read(c) + + // Makes sure this error type implements the xgb.Error interface. + e.ImplementsError(c) + + // Let's the XGB know how to read this error. + c.Putln("func init() {") + if c.protocol.isExt() { + c.Putln("xgb.NewExtErrorFuncs[\"%s\"][%d] = %sNew", + c.protocol.ExtXName, e.Number, e.ErrType()) + } else { + c.Putln("xgb.NewErrorFuncs[%d] = %sNew", e.Number, e.ErrType()) + } + c.Putln("}") + c.Putln("") +} + +func (e *ErrorCopy) Read(c *Context) { + c.Putln("// %sNew constructs a %s value that implements xgb.Error from "+ + "a byte slice.", e.ErrType(), e.ErrType()) + c.Putln("func %sNew(buf []byte) xgb.Error {", e.ErrType()) + c.Putln("v := %s(%sNew(buf).(%s))", + e.ErrType(), e.Old.(*Error).ErrType(), e.Old.(*Error).ErrType()) + c.Putln("v.NiceName = \"%s\"", e.SrcName()) + c.Putln("return v") + c.Putln("}") + c.Putln("") +} + +// ImplementsError writes functions to implement the XGB Error interface. +func (e *ErrorCopy) ImplementsError(c *Context) { + c.Putln("// SequenceId returns the sequence id attached to the %s error.", + e.ErrConst()) + c.Putln("// This is mostly used internally.") + c.Putln("func (err %s) SequenceId() uint16 {", e.ErrType()) + c.Putln("return err.Sequence") + c.Putln("}") + c.Putln("") + c.Putln("// BadId returns the 'BadValue' number if one exists for the "+ + "%s error. If no bad value exists, 0 is returned.", e.ErrConst()) + c.Putln("func (err %s) BadId() uint32 {", e.ErrType()) + if !c.protocol.isExt() { + c.Putln("return err.BadValue") + } else { + c.Putln("return 0") + } + c.Putln("}") + c.Putln("") + c.Putln("// Error returns a rudimentary string representation of the %s "+ + "error.", e.ErrConst()) + c.Putln("func (err %s) Error() string {", e.ErrType()) + ErrorFieldString(c, e.Old.(*Error).Fields, e.ErrConst()) + c.Putln("}") + c.Putln("") +} + +// ErrorFieldString works for both Error and ErrorCopy. It assembles all of the +// fields in an error and formats them into a single string. +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, "+ + "xgb.Sprintf(\"Sequence: %s\", err.Sequence))", "%d") + for _, field := range fields { + switch field.(type) { + case *PadField: + continue + default: + if field.SrcType() == "string" { + c.Putln("fieldVals = append(fieldVals, \"%s: \" + err.%s)", + field.SrcName(), field.SrcName()) + } else { + format := fmt.Sprintf("xgb.Sprintf(\"%s: %s\", err.%s)", + field.SrcName(), "%d", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + } + } + } + c.Putln("return \"%s {\" + xgb.StringsJoin(fieldVals, \", \") + \"}\"", + errName) +} diff --git a/nexgb/xgbgen/go_event.go b/nexgb/xgbgen/go_event.go new file mode 100644 index 0000000..9b5e748 --- /dev/null +++ b/nexgb/xgbgen/go_event.go @@ -0,0 +1,209 @@ +package main + +import ( + "fmt" +) + +// Event types +func (e *Event) Define(c *Context) { + c.Putln("// %s is the event number for a %s.", e.SrcName(), e.EvType()) + c.Putln("const %s = %d", e.SrcName(), e.Number) + c.Putln("") + c.Putln("type %s struct {", e.EvType()) + if !e.NoSequence { + c.Putln("Sequence uint16") + } + for _, field := range e.Fields { + field.Define(c) + } + c.Putln("}") + c.Putln("") + + // Read defines a function that transforms a byte slice into this + // event struct. + e.Read(c) + + // Write defines a function that transforms this event struct into + // a byte slice. + e.Write(c) + + // Makes sure that this event type is an Event interface. + c.Putln("// SequenceId returns the sequence id attached to the %s event.", + e.SrcName()) + c.Putln("// Events without a sequence number (KeymapNotify) return 0.") + c.Putln("// This is mostly used internally.") + c.Putln("func (v %s) SequenceId() uint16 {", e.EvType()) + if e.NoSequence { + c.Putln("return uint16(0)") + } else { + c.Putln("return v.Sequence") + } + c.Putln("}") + c.Putln("") + c.Putln("// String is a rudimentary string representation of %s.", + e.EvType()) + c.Putln("func (v %s) String() string {", e.EvType()) + EventFieldString(c, e.Fields, e.SrcName()) + c.Putln("}") + c.Putln("") + + // Let's the XGB event loop read this event. + c.Putln("func init() {") + if c.protocol.isExt() { + c.Putln("xgb.NewExtEventFuncs[\"%s\"][%d] = %sNew", + c.protocol.ExtXName, e.Number, e.EvType()) + } else { + c.Putln("xgb.NewEventFuncs[%d] = %sNew", e.Number, e.EvType()) + } + c.Putln("}") + c.Putln("") +} + +func (e *Event) Read(c *Context) { + c.Putln("// %sNew constructs a %s value that implements xgb.Event from "+ + "a byte slice.", e.EvType(), e.EvType()) + c.Putln("func %sNew(buf []byte) xgb.Event {", e.EvType()) + c.Putln("v := %s{}", e.EvType()) + c.Putln("b := 1 // don't read event number") + c.Putln("") + for i, field := range e.Fields { + if i == 1 && !e.NoSequence { + c.Putln("v.Sequence = xgb.Get16(buf[b:])") + c.Putln("b += 2") + c.Putln("") + } + field.Read(c, "v.") + c.Putln("") + } + c.Putln("return v") + c.Putln("}") + c.Putln("") +} + +func (e *Event) Write(c *Context) { + c.Putln("// Bytes writes a %s value to a byte slice.", e.EvType()) + c.Putln("func (v %s) Bytes() []byte {", e.EvType()) + c.Putln("buf := make([]byte, %s)", e.Size()) + c.Putln("b := 0") + c.Putln("") + c.Putln("// write event number") + c.Putln("buf[b] = %d", e.Number) + c.Putln("b += 1") + c.Putln("") + for i, field := range e.Fields { + if i == 1 && !e.NoSequence { + c.Putln("b += 2 // skip sequence number") + c.Putln("") + } + field.Write(c, "v.") + c.Putln("") + } + c.Putln("return buf") + c.Putln("}") + c.Putln("") +} + +// EventCopy types +func (e *EventCopy) Define(c *Context) { + c.Putln("// %s is the event number for a %s.", e.SrcName(), e.EvType()) + c.Putln("const %s = %d", e.SrcName(), e.Number) + c.Putln("") + c.Putln("type %s %s", e.EvType(), e.Old.(*Event).EvType()) + c.Putln("") + + // Read defines a function that transforms a byte slice into this + // event struct. + e.Read(c) + + // Write defines a function that transoforms this event struct into + // a byte slice. + e.Write(c) + + // Makes sure that this event type is an Event interface. + c.Putln("// SequenceId returns the sequence id attached to the %s event.", + e.SrcName()) + c.Putln("// Events without a sequence number (KeymapNotify) return 0.") + c.Putln("// This is mostly used internally.") + c.Putln("func (v %s) SequenceId() uint16 {", e.EvType()) + if e.Old.(*Event).NoSequence { + c.Putln("return uint16(0)") + } else { + c.Putln("return v.Sequence") + } + c.Putln("}") + c.Putln("") + c.Putln("func (v %s) String() string {", e.EvType()) + EventFieldString(c, e.Old.(*Event).Fields, e.SrcName()) + c.Putln("}") + c.Putln("") + + // Let's the XGB event loop read this event. + c.Putln("func init() {") + if c.protocol.isExt() { + c.Putln("xgb.NewExtEventFuncs[\"%s\"][%d] = %sNew", + c.protocol.ExtXName, e.Number, e.EvType()) + } else { + c.Putln("xgb.NewEventFuncs[%d] = %sNew", e.Number, e.EvType()) + } + c.Putln("}") + c.Putln("") +} + +func (e *EventCopy) Read(c *Context) { + c.Putln("// %sNew constructs a %s value that implements xgb.Event from "+ + "a byte slice.", e.EvType(), e.EvType()) + c.Putln("func %sNew(buf []byte) xgb.Event {", e.EvType()) + c.Putln("return %s(%sNew(buf).(%s))", + e.EvType(), e.Old.(*Event).EvType(), e.Old.(*Event).EvType()) + c.Putln("}") + c.Putln("") +} + +func (e *EventCopy) Write(c *Context) { + c.Putln("// Bytes writes a %s value to a byte slice.", e.EvType()) + c.Putln("func (v %s) Bytes() []byte {", e.EvType()) + c.Putln("return %s(v).Bytes()", e.Old.(*Event).EvType()) + c.Putln("}") + c.Putln("") +} + +// EventFieldString works for both Event and EventCopy. It assembles all of the +// fields in an event and formats them into a single string. +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, "+ + "xgb.Sprintf(\"Sequence: %s\", v.Sequence))", "%d") + } + for _, field := range fields { + switch f := field.(type) { + case *PadField: + continue + case *SingleField: + switch f.Type.(type) { + case *Base: + case *Resource: + case *TypeDef: + default: + continue + } + + switch field.SrcType() { + case "string": + format := fmt.Sprintf("xgb.Sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%s", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + case "bool": + format := fmt.Sprintf("xgb.Sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%t", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + default: + format := fmt.Sprintf("xgb.Sprintf(\"%s: %s\", v.%s)", + field.SrcName(), "%d", field.SrcName()) + c.Putln("fieldVals = append(fieldVals, %s)", format) + } + } + } + c.Putln("return \"%s {\" + xgb.StringsJoin(fieldVals, \", \") + \"}\"", + evName) +} diff --git a/nexgb/xgbgen/go_list.go b/nexgb/xgbgen/go_list.go new file mode 100644 index 0000000..1e85d9f --- /dev/null +++ b/nexgb/xgbgen/go_list.go @@ -0,0 +1,107 @@ +package main + +import ( + "fmt" + "log" + "strings" +) + +// List fields +func (f *ListField) Define(c *Context) { + c.Putln("%s %s // size: %s", + f.SrcName(), f.SrcType(), f.Size()) +} + +func (f *ListField) Read(c *Context, prefix string) { + switch t := f.Type.(type) { + case *Resource: + length := f.LengthExpr.Reduce(prefix) + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), length) + c.Putln("for i := 0; i < int(%s); i++ {", length) + ReadSimpleSingleField(c, fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + case *Base: + length := f.LengthExpr.Reduce(prefix) + if strings.ToLower(t.XmlName()) == "char" { + c.Putln("{") + c.Putln("byteString := make([]%s, %s)", t.SrcName(), length) + c.Putln("copy(byteString[:%s], buf[b:])", length) + c.Putln("%s%s = string(byteString)", prefix, f.SrcName()) + // This is apparently a special case. The "Str" type itself + // doesn't specify any padding. I suppose it's up to the + // request/reply spec that uses it to get the padding right? + c.Putln("b += int(%s)", length) + c.Putln("}") + } else if t.SrcName() == "byte" { + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), length) + c.Putln("copy(%s%s[:%s], buf[b:])", prefix, f.SrcName(), length) + c.Putln("b += int(%s)", length) + } else { + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), length) + c.Putln("for i := 0; i < int(%s); i++ {", length) + ReadSimpleSingleField(c, + fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + } + case *TypeDef: + length := f.LengthExpr.Reduce(prefix) + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), length) + c.Putln("for i := 0; i < int(%s); i++ {", length) + ReadSimpleSingleField(c, fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + case *Union: + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), f.LengthExpr.Reduce(prefix)) + c.Putln("b += %sReadList(buf[b:], %s%s)", + t.SrcName(), prefix, f.SrcName()) + case *Struct: + c.Putln("%s%s = make([]%s, %s)", + prefix, f.SrcName(), t.SrcName(), f.LengthExpr.Reduce(prefix)) + c.Putln("b += %sReadList(buf[b:], %s%s)", + t.SrcName(), prefix, f.SrcName()) + default: + log.Panicf("Cannot read list field '%s' with %T type.", + f.XmlName(), f.Type) + } +} + +func (f *ListField) Write(c *Context, prefix string) { + switch t := f.Type.(type) { + case *Resource: + length := f.Length().Reduce(prefix) + c.Putln("for i := 0; i < int(%s); i++ {", length) + WriteSimpleSingleField(c, + fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + case *Base: + length := f.Length().Reduce(prefix) + if t.SrcName() == "byte" { + c.Putln("copy(buf[b:], %s%s[:%s])", prefix, f.SrcName(), length) + c.Putln("b += int(%s)", length) + } else { + c.Putln("for i := 0; i < int(%s); i++ {", length) + WriteSimpleSingleField(c, + fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + } + case *TypeDef: + length := f.Length().Reduce(prefix) + c.Putln("for i := 0; i < int(%s); i++ {", length) + WriteSimpleSingleField(c, + fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t) + c.Putln("}") + case *Union: + c.Putln("b += %sListBytes(buf[b:], %s%s)", + t.SrcName(), prefix, f.SrcName()) + case *Struct: + c.Putln("b += %sListBytes(buf[b:], %s%s)", + t.SrcName(), prefix, f.SrcName()) + default: + log.Panicf("Cannot write list field '%s' with %T type.", + f.XmlName(), f.Type) + } +} diff --git a/nexgb/xgbgen/go_request_reply.go b/nexgb/xgbgen/go_request_reply.go new file mode 100644 index 0000000..9cadc33 --- /dev/null +++ b/nexgb/xgbgen/go_request_reply.go @@ -0,0 +1,242 @@ +package main + +import ( + "fmt" + "strings" +) + +func (r *Request) Define(c *Context) { + c.Putln("// %s is a cookie used only for %s requests.", + r.CookieName(), r.SrcName()) + c.Putln("type %s struct {", r.CookieName()) + c.Putln("*xgb.Cookie") + c.Putln("}") + c.Putln("") + if r.Reply != nil { + c.Putln("// %s sends a checked request.", r.SrcName()) + c.Putln("// If an error occurs, it will be returned with the reply "+ + "by calling %s.Reply()", r.CookieName()) + c.Putln("func %s(c *xgb.Conn, %s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + r.CheckExt(c) + c.Putln("cookie := c.NewCookie(true, true)") + c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s{cookie}", r.CookieName()) + c.Putln("}") + c.Putln("") + + c.Putln("// %sUnchecked sends an unchecked request.", r.SrcName()) + c.Putln("// If an error occurs, it can only be retrieved using " + + "xgb.WaitForEvent or xgb.PollForEvent.") + c.Putln("func %sUnchecked(c *xgb.Conn, %s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + r.CheckExt(c) + c.Putln("cookie := c.NewCookie(false, true)") + c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s{cookie}", r.CookieName()) + c.Putln("}") + c.Putln("") + + r.ReadReply(c) + } else { + c.Putln("// %s sends an unchecked request.", r.SrcName()) + c.Putln("// If an error occurs, it can only be retrieved using " + + "xgb.WaitForEvent or xgb.PollForEvent.") + c.Putln("func %s(c *xgb.Conn, %s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + r.CheckExt(c) + c.Putln("cookie := c.NewCookie(false, false)") + c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s{cookie}", r.CookieName()) + c.Putln("}") + c.Putln("") + + c.Putln("// %sChecked sends a checked request.", r.SrcName()) + c.Putln("// If an error occurs, it can be retrieved using "+ + "%s.Check()", r.CookieName()) + c.Putln("func %sChecked(c *xgb.Conn, %s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + r.CheckExt(c) + c.Putln("cookie := c.NewCookie(true, false)") + c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s{cookie}", r.CookieName()) + c.Putln("}") + c.Putln("") + + c.Putln("// Check returns an error if one occurred for checked " + + "requests that are not expecting a reply.") + c.Putln("// This cannot be called for requests expecting a reply, " + + "nor for unchecked requests.") + c.Putln("func (cook %s) Check() error {", r.CookieName()) + c.Putln("return cook.Cookie.Check()") + c.Putln("}") + c.Putln("") + } + r.WriteRequest(c) +} + +func (r *Request) CheckExt(c *Context) { + if !c.protocol.isExt() { + return + } + c.Putln("c.ExtLock.RLock()") + c.Putln("defer c.ExtLock.RUnlock()") + c.Putln("if _, ok := c.Extensions[\"%s\"]; !ok {", c.protocol.ExtXName) + c.Putln("panic(\"Cannot issue request '%s' using the uninitialized "+ + "extension '%s'. %s.Init(connObj) must be called first.\")", + r.SrcName(), c.protocol.ExtXName, c.protocol.PkgName()) + c.Putln("}") +} + +func (r *Request) ReadReply(c *Context) { + c.Putln("// %s represents the data returned from a %s request.", + r.ReplyTypeName(), r.SrcName()) + c.Putln("type %s struct {", r.ReplyTypeName()) + c.Putln("Sequence uint16 // sequence number of the request for this reply") + c.Putln("Length uint32 // number of bytes in this reply") + for _, field := range r.Reply.Fields { + field.Define(c) + } + c.Putln("}") + c.Putln("") + + c.Putln("// Reply blocks and returns the reply data for a %s request.", + r.SrcName()) + c.Putln("func (cook %s) Reply() (*%s, error) {", + r.CookieName(), r.ReplyTypeName()) + c.Putln("buf, err := cook.Cookie.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("") + + c.Putln("// %s reads a byte slice into a %s value.", + r.ReplyName(), r.ReplyTypeName()) + c.Putln("func %s(buf []byte) *%s {", + r.ReplyName(), r.ReplyTypeName()) + c.Putln("v := new(%s)", r.ReplyTypeName()) + c.Putln("b := 1 // skip reply determinant") + c.Putln("") + for i, field := range r.Reply.Fields { + field.Read(c, "v.") + c.Putln("") + if i == 0 { + c.Putln("v.Sequence = xgb.Get16(buf[b:])") + c.Putln("b += 2") + c.Putln("") + c.Putln("v.Length = xgb.Get32(buf[b:]) // 4-byte units") + c.Putln("b += 4") + c.Putln("") + } + } + c.Putln("return v") + c.Putln("}") + c.Putln("") +} + +func (r *Request) WriteRequest(c *Context) { + sz := r.Size(c) + writeSize1 := func() { + if sz.exact { + c.Putln("xgb.Put16(buf[b:], uint16(size / 4)) " + + "// write request size in 4-byte units") + } else { + c.Putln("blen := b") + } + c.Putln("b += 2") + c.Putln("") + } + writeSize2 := func() { + if sz.exact { + c.Putln("return buf") + return + } + c.Putln("b = xgb.Pad(b)") + c.Putln("xgb.Put16(buf[blen:], uint16(b / 4)) " + + "// write request size in 4-byte units") + c.Putln("return buf[:b]") + } + c.Putln("// Write request to wire for %s", r.SrcName()) + c.Putln("// %s writes a %s request to a byte slice.", + r.ReqName(), r.SrcName()) + c.Putln("func %s(c *xgb.Conn, %s) []byte {", + r.ReqName(), r.ParamNameTypes()) + c.Putln("size := %s", sz) + c.Putln("b := 0") + c.Putln("buf := make([]byte, size)") + c.Putln("") + if c.protocol.isExt() { + c.Putln("c.ExtLock.RLock()") + c.Putln("buf[b] = c.Extensions[\"%s\"]", c.protocol.ExtXName) + c.Putln("c.ExtLock.RUnlock()") + c.Putln("b += 1") + c.Putln("") + } + c.Putln("buf[b] = %d // request opcode", r.Opcode) + c.Putln("b += 1") + c.Putln("") + if len(r.Fields) == 0 { + if !c.protocol.isExt() { + c.Putln("b += 1 // padding") + } + writeSize1() + } else if c.protocol.isExt() { + writeSize1() + } + for i, field := range r.Fields { + field.Write(c, "") + c.Putln("") + if i == 0 && !c.protocol.isExt() { + writeSize1() + } + } + writeSize2() + c.Putln("}") + c.Putln("") +} + +func (r *Request) ParamNames() string { + names := make([]string, 0, len(r.Fields)) + for _, field := range r.Fields { + switch f := field.(type) { + case *ValueField: + names = append(names, f.MaskName) + names = append(names, f.ListName) + case *PadField: + continue + case *ExprField: + continue + default: + names = append(names, fmt.Sprintf("%s", field.SrcName())) + } + } + return strings.Join(names, ", ") +} + +func (r *Request) ParamNameTypes() string { + nameTypes := make([]string, 0, len(r.Fields)) + for _, field := range r.Fields { + switch f := field.(type) { + case *ValueField: + nameTypes = append(nameTypes, + fmt.Sprintf("%s %s", f.MaskName, f.MaskType.SrcName())) + nameTypes = append(nameTypes, + fmt.Sprintf("%s []uint32", f.ListName)) + case *PadField: + continue + case *ExprField: + continue + case *RequiredStartAlign: + continue + default: + nameTypes = append(nameTypes, + fmt.Sprintf("%s %s", field.SrcName(), field.SrcType())) + } + } + return strings.Join(nameTypes, ", ") +} diff --git a/nexgb/xgbgen/go_single_field.go b/nexgb/xgbgen/go_single_field.go new file mode 100644 index 0000000..6c7218e --- /dev/null +++ b/nexgb/xgbgen/go_single_field.go @@ -0,0 +1,166 @@ +package main + +import ( + "fmt" + "log" +) + +func (f *SingleField) Define(c *Context) { + c.Putln("%s %s", f.SrcName(), f.Type.SrcName()) +} + +func ReadSimpleSingleField(c *Context, name string, typ Type) { + switch t := typ.(type) { + case *Resource: + c.Putln("%s = %s(xgb.Get32(buf[b:]))", name, t.SrcName()) + case *TypeDef: + switch t.Size().Eval() { + case 1: + c.Putln("%s = %s(buf[b])", name, t.SrcName()) + case 2: + c.Putln("%s = %s(xgb.Get16(buf[b:]))", name, t.SrcName()) + case 4: + c.Putln("%s = %s(xgb.Get32(buf[b:]))", name, t.SrcName()) + case 8: + c.Putln("%s = %s(xgb.Get64(buf[b:]))", name, t.SrcName()) + } + case *Base: + // If this is a bool, stop short and do something special. + if t.SrcName() == "bool" { + c.Putln("if buf[b] == 1 {") + c.Putln("%s = true", name) + c.Putln("} else {") + c.Putln("%s = false", name) + c.Putln("}") + break + } + + var val string + switch t.Size().Eval() { + case 1: + val = fmt.Sprintf("buf[b]") + case 2: + val = fmt.Sprintf("xgb.Get16(buf[b:])") + case 4: + val = fmt.Sprintf("xgb.Get32(buf[b:])") + case 8: + val = fmt.Sprintf("xgb.Get64(buf[b:])") + } + + // We need to convert base types if they aren't uintXX or byte + ty := t.SrcName() + if ty != "byte" && ty != "uint16" && ty != "uint32" && ty != "uint64" { + val = fmt.Sprintf("%s(%s)", ty, val) + } + c.Putln("%s = %s", name, val) + default: + log.Panicf("Cannot read field '%s' as a simple field with %T type.", + name, typ) + } + + c.Putln("b += %s", typ.Size()) +} + +func (f *SingleField) Read(c *Context, prefix string) { + switch t := f.Type.(type) { + case *Resource: + ReadSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *TypeDef: + ReadSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *Base: + ReadSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *Struct: + c.Putln("%s%s = %s{}", prefix, f.SrcName(), t.SrcName()) + c.Putln("b += %sRead(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) + case *Union: + c.Putln("%s%s = %s{}", prefix, f.SrcName(), t.SrcName()) + c.Putln("b += %sRead(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) + default: + log.Panicf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type) + } +} + +func WriteSimpleSingleField(c *Context, name string, typ Type) { + switch t := typ.(type) { + case *Resource: + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) + case *TypeDef: + switch t.Size().Eval() { + case 1: + c.Putln("buf[b] = byte(%s)", name) + case 2: + c.Putln("xgb.Put16(buf[b:], uint16(%s))", name) + case 4: + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) + case 8: + c.Putln("xgb.Put64(buf[b:], uint64(%s))", name) + } + case *Base: + // If this is a bool, stop short and do something special. + if t.SrcName() == "bool" { + c.Putln("if %s {", name) + c.Putln("buf[b] = 1") + c.Putln("} else {") + c.Putln("buf[b] = 0") + c.Putln("}") + break + } + + switch t.Size().Eval() { + case 1: + if t.SrcName() != "byte" { + c.Putln("buf[b] = byte(%s)", name) + } else { + c.Putln("buf[b] = %s", name) + } + case 2: + if t.SrcName() != "uint16" { + c.Putln("xgb.Put16(buf[b:], uint16(%s))", name) + } else { + c.Putln("xgb.Put16(buf[b:], %s)", name) + } + case 4: + if t.SrcName() != "uint32" { + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) + } else { + c.Putln("xgb.Put32(buf[b:], %s)", name) + } + case 8: + if t.SrcName() != "uint64" { + c.Putln("xgb.Put64(buf[b:], uint64(%s))", name) + } else { + c.Putln("xgb.Put64(buf[b:], %s)", name) + } + } + default: + log.Fatalf("Cannot read field '%s' as a simple field with %T type.", + name, typ) + } + + c.Putln("b += %s", typ.Size()) +} + +func (f *SingleField) Write(c *Context, prefix string) { + switch t := f.Type.(type) { + case *Resource: + WriteSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *TypeDef: + WriteSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *Base: + WriteSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) + case *Union: + c.Putln("{") + c.Putln("unionBytes := %s%s.Bytes()", prefix, f.SrcName()) + c.Putln("copy(buf[b:], unionBytes)") + c.Putln("b += len(unionBytes)") + c.Putln("}") + case *Struct: + c.Putln("{") + c.Putln("structBytes := %s%s.Bytes()", prefix, f.SrcName()) + c.Putln("copy(buf[b:], structBytes)") + c.Putln("b += len(structBytes)") + c.Putln("}") + default: + log.Fatalf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type) + } +} diff --git a/nexgb/xgbgen/go_struct.go b/nexgb/xgbgen/go_struct.go new file mode 100644 index 0000000..ee74d90 --- /dev/null +++ b/nexgb/xgbgen/go_struct.go @@ -0,0 +1,118 @@ +package main + +func (s *Struct) Define(c *Context) { + c.Putln("type %s struct {", s.SrcName()) + for _, field := range s.Fields { + field.Define(c) + } + c.Putln("}") + c.Putln("") + + // Write function that reads bytes and produces this struct. + s.Read(c) + + // Write function that reads bytes and produces a list of this struct. + s.ReadList(c) + + // Write function that writes bytes given this struct. + s.Write(c) + + // Write function that writes a list of this struct. + s.WriteList(c) + + // Write function that computes the size of a list of these structs, + // IF there is a list field in this struct. + if s.HasList() { + s.WriteListSize(c) + } +} + +// Read for a struct creates a function 'ReadStructName' that takes a source +// byte slice (i.e., the buffer) and a destination struct, and returns +// the number of bytes read off the buffer. +// 'ReadStructName' should only be used to read raw reply data from the wire. +func (s *Struct) Read(c *Context) { + c.Putln("// %sRead reads a byte slice into a %s value.", + s.SrcName(), s.SrcName()) + c.Putln("func %sRead(buf []byte, v *%s) int {", s.SrcName(), s.SrcName()) + + c.Putln("b := 0") + c.Putln("") + for _, field := range s.Fields { + field.Read(c, "v.") + c.Putln("") + } + c.Putln("return b") + + c.Putln("}") + c.Putln("") +} + +// ReadList for a struct creates a function 'ReadStructNameList' that takes +// a source (i.e., the buffer) byte slice, and a destination slice and returns +// the number of bytes read from the byte slice. +func (s *Struct) ReadList(c *Context) { + c.Putln("// %sReadList reads a byte slice into a list of %s values.", + s.SrcName(), s.SrcName()) + c.Putln("func %sReadList(buf []byte, dest []%s) int {", + s.SrcName(), s.SrcName()) + c.Putln("b := 0") + c.Putln("for i := 0; i < len(dest); i++ {") + c.Putln("dest[i] = %s{}", s.SrcName()) + c.Putln("b += %sRead(buf[b:], &dest[i])", s.SrcName()) + c.Putln("}") + + c.Putln("return xgb.Pad(b)") + + c.Putln("}") + c.Putln("") +} + +func (s *Struct) Write(c *Context) { + c.Putln("// Bytes writes a %s value to a byte slice.", s.SrcName()) + c.Putln("func (v %s) Bytes() []byte {", s.SrcName()) + c.Putln("buf := make([]byte, %s)", s.Size().Reduce("v.")) + c.Putln("b := 0") + c.Putln("") + for _, field := range s.Fields { + field.Write(c, "v.") + c.Putln("") + } + c.Putln("return buf[:b]") + c.Putln("}") + c.Putln("") +} + +func (s *Struct) WriteList(c *Context) { + c.Putln("// %sListBytes writes a list of %s values to a byte slice.", + s.SrcName(), s.SrcName()) + c.Putln("func %sListBytes(buf []byte, list []%s) int {", + s.SrcName(), s.SrcName()) + c.Putln("b := 0") + c.Putln("var structBytes []byte") + c.Putln("for _, item := range list {") + c.Putln("structBytes = item.Bytes()") + c.Putln("copy(buf[b:], structBytes)") + c.Putln("b += len(structBytes)") + c.Putln("}") + c.Putln("return xgb.Pad(b)") + c.Putln("}") + c.Putln("") +} + +func (s *Struct) WriteListSize(c *Context) { + c.Putln("// %sListSize computes the size (bytes) of a list of %s values.", + s.SrcName(), s.SrcName()) + c.Putln("func %sListSize(list []%s) int {", s.SrcName(), s.SrcName()) + c.Putln("size := 0") + if s.Size().Expression.Concrete() { + c.Putln("for _ = range list {") + } else { + c.Putln("for _, item := range list {") + } + c.Putln("size += %s", s.Size().Reduce("item.")) + c.Putln("}") + c.Putln("return size") + c.Putln("}") + c.Putln("") +} diff --git a/nexgb/xgbgen/go_union.go b/nexgb/xgbgen/go_union.go new file mode 100644 index 0000000..74816d3 --- /dev/null +++ b/nexgb/xgbgen/go_union.go @@ -0,0 +1,147 @@ +package main + +// Union types +func (u *Union) Define(c *Context) { + c.Putln("// %s is a represention of the %s union type.", + u.SrcName(), u.SrcName()) + c.Putln("// Note that to *create* a Union, you should *never* create") + c.Putln("// this struct directly (unless you know what you're doing).") + c.Putln("// Instead use one of the following constructors for '%s':", + u.SrcName()) + for _, field := range u.Fields { + c.Putln("// %s%sNew(%s %s) %s", u.SrcName(), field.SrcName(), + field.SrcName(), field.SrcType(), u.SrcName()) + } + + c.Putln("type %s struct {", u.SrcName()) + for _, field := range u.Fields { + field.Define(c) + } + c.Putln("}") + c.Putln("") + + // Write functions for each field that create instances of this + // union using the corresponding field. + u.New(c) + + // Write function that reads bytes and produces this union. + u.Read(c) + + // Write function that reads bytes and produces a list of this union. + u.ReadList(c) + + // Write function that writes bytes given this union. + u.Write(c) + + // Write function that writes a list of this union. + u.WriteList(c) +} + +func (u *Union) New(c *Context) { + for _, field := range u.Fields { + c.Putln("// %s%sNew constructs a new %s union type with the %s field.", + u.SrcName(), field.SrcName(), u.SrcName(), field.SrcName()) + c.Putln("func %s%sNew(%s %s) %s {", + u.SrcName(), field.SrcName(), field.SrcName(), + field.SrcType(), u.SrcName()) + c.Putln("var b int") + c.Putln("buf := make([]byte, %s)", u.Size()) + c.Putln("") + field.Write(c, "") + c.Putln("") + c.Putln("// Create the Union type") + c.Putln("v := %s{}", u.SrcName()) + c.Putln("") + c.Putln("// Now copy buf into all fields") + c.Putln("") + for _, field2 := range u.Fields { + c.Putln("b = 0 // always read the same bytes") + field2.Read(c, "v.") + c.Putln("") + } + c.Putln("return v") + c.Putln("}") + c.Putln("") + } +} + +func (u *Union) Read(c *Context) { + c.Putln("// %sRead reads a byte slice into a %s value.", + u.SrcName(), u.SrcName()) + c.Putln("func %sRead(buf []byte, v *%s) int {", u.SrcName(), u.SrcName()) + c.Putln("var b int") + c.Putln("") + for _, field := range u.Fields { + c.Putln("b = 0 // re-read the same bytes") + field.Read(c, "v.") + c.Putln("") + } + c.Putln("return %s", u.Size()) + c.Putln("}") + c.Putln("") +} + +func (u *Union) ReadList(c *Context) { + c.Putln("// %sReadList reads a byte slice into a list of %s values.", + u.SrcName(), u.SrcName()) + c.Putln("func %sReadList(buf []byte, dest []%s) int {", + u.SrcName(), u.SrcName()) + c.Putln("b := 0") + c.Putln("for i := 0; i < len(dest); i++ {") + c.Putln("dest[i] = %s{}", u.SrcName()) + c.Putln("b += %sRead(buf[b:], &dest[i])", u.SrcName()) + c.Putln("}") + c.Putln("return xgb.Pad(b)") + c.Putln("}") + c.Putln("") +} + +// This is a bit tricky since writing from a Union implies that only +// the data inside ONE of the elements is actually written. +// However, we only currently support unions where every field has the +// *same* *fixed* size. Thus, we make sure to always read bytes into +// every field which allows us to simply pick the first field and write it. +func (u *Union) Write(c *Context) { + c.Putln("// Bytes writes a %s value to a byte slice.", u.SrcName()) + c.Putln("// Each field in a union must contain the same data.") + c.Putln("// So simply pick the first field and write that to the wire.") + c.Putln("func (v %s) Bytes() []byte {", u.SrcName()) + c.Putln("buf := make([]byte, %s)", u.Size().Reduce("v.")) + c.Putln("b := 0") + c.Putln("") + u.Fields[0].Write(c, "v.") + c.Putln("return buf") + c.Putln("}") + c.Putln("") +} + +func (u *Union) WriteList(c *Context) { + c.Putln("// %sListBytes writes a list of %s values to a byte slice.", + u.SrcName(), u.SrcName()) + c.Putln("func %sListBytes(buf []byte, list []%s) int {", + u.SrcName(), u.SrcName()) + c.Putln("b := 0") + c.Putln("var unionBytes []byte") + c.Putln("for _, item := range list {") + c.Putln("unionBytes = item.Bytes()") + c.Putln("copy(buf[b:], unionBytes)") + c.Putln("b += xgb.Pad(len(unionBytes))") + c.Putln("}") + c.Putln("return b") + c.Putln("}") + c.Putln("") +} + +func (u *Union) WriteListSize(c *Context) { + c.Putln("// Union list size %s", u.SrcName()) + c.Putln("// %sListSize computes the size (bytes) of a list of %s values.", + u.SrcName()) + c.Putln("func %sListSize(list []%s) int {", u.SrcName(), u.SrcName()) + c.Putln("size := 0") + c.Putln("for _, item := range list {") + c.Putln("size += %s", u.Size().Reduce("item.")) + c.Putln("}") + c.Putln("return size") + c.Putln("}") + c.Putln("") +} diff --git a/nexgb/xgbgen/main.go b/nexgb/xgbgen/main.go new file mode 100644 index 0000000..fd5eac7 --- /dev/null +++ b/nexgb/xgbgen/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "flag" + "io/ioutil" + "log" + "os" + "os/exec" + "strings" +) + +var ( + protoPath = flag.String("proto-path", + "/usr/share/xcb", "path to directory of X protocol XML files") + gofmt = flag.Bool("gofmt", true, + "When disabled, gofmt will not be run before outputting Go code") +) + +func usage() { + basename := os.Args[0] + if lastSlash := strings.LastIndex(basename, "/"); lastSlash > -1 { + basename = basename[lastSlash+1:] + } + log.Printf("Usage: %s [flags] xml-file", basename) + flag.PrintDefaults() + os.Exit(1) +} + +func init() { + log.SetFlags(0) +} + +func main() { + flag.Usage = usage + flag.Parse() + + if flag.NArg() != 1 { + log.Printf("A single XML protocol file can be processed at once.") + flag.Usage() + } + + // Read the single XML file into []byte + xmlBytes, err := ioutil.ReadFile(flag.Arg(0)) + if err != nil { + log.Fatal(err) + } + + // Initialize the buffer, parse it, and filter it through gofmt. + c := newContext() + c.Morph(xmlBytes) + + if !*gofmt { + c.out.WriteTo(os.Stdout) + } else { + cmdGofmt := exec.Command("gofmt") + cmdGofmt.Stdin = c.out + cmdGofmt.Stdout = os.Stdout + cmdGofmt.Stderr = os.Stderr + err = cmdGofmt.Run() + if err != nil { + log.Fatal(err) + } + } +} diff --git a/nexgb/xgbgen/misc.go b/nexgb/xgbgen/misc.go new file mode 100644 index 0000000..85d788f --- /dev/null +++ b/nexgb/xgbgen/misc.go @@ -0,0 +1,49 @@ +package main + +import ( + "regexp" + "strings" +) + +// AllCaps is a regex to test if a string identifier is made of +// all upper case letters. +var allCaps = regexp.MustCompile("^[A-Z0-9]+$") + +// popCount counts number of bits 'set' in mask. +func popCount(mask uint) uint { + m := uint32(mask) + n := uint(0) + for i := uint32(0); i < 32; i++ { + if m&(1<<i) != 0 { + n++ + } + } + return n +} + +// pad makes sure 'n' aligns on 4 bytes. +func pad(n int) int { + return (n + 3) & ^3 +} + +// splitAndTitle takes a string, splits it by underscores, capitalizes the +// first letter of each chunk, and smushes'em back together. +func splitAndTitle(s string) string { + // If the string is all caps, lower it and capitalize first letter. + if allCaps.MatchString(s) { + return strings.Title(strings.ToLower(s)) + } + + // If the string has no underscores, capitalize it and leave it be. + if i := strings.Index(s, "_"); i == -1 { + return strings.Title(s) + } + + // Now split the name at underscores, capitalize the first + // letter of each chunk, and smush'em back together. + chunks := strings.Split(s, "_") + for i, chunk := range chunks { + chunks[i] = strings.Title(strings.ToLower(chunk)) + } + return strings.Join(chunks, "") +} diff --git a/nexgb/xgbgen/protocol.go b/nexgb/xgbgen/protocol.go new file mode 100644 index 0000000..433f4e2 --- /dev/null +++ b/nexgb/xgbgen/protocol.go @@ -0,0 +1,70 @@ +package main + +import ( + "log" + "strings" +) + +// Protocol is a type that encapsulates all information about one +// particular XML file. It also contains links to other protocol types +// if this protocol imports other other extensions. The import relationship +// is recursive. +type Protocol struct { + Parent *Protocol + Name string + ExtXName string + ExtName string + MajorVersion string + MinorVersion string + + Imports []*Protocol + Types []Type + Requests []*Request +} + +type Protocols []*Protocol + +func (ps Protocols) Len() int { return len(ps) } +func (ps Protocols) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] } +func (ps Protocols) Less(i, j int) bool { return ps[i].ExtName < ps[j].ExtName } + +// Initialize traverses all structures, looks for 'Translation' type, +// and looks up the real type in the namespace. It also sets the source +// name for all relevant fields/structures. +// This is necessary because we don't traverse the XML in order initially. +func (p *Protocol) Initialize() { + for _, typ := range p.Types { + typ.Initialize(p) + } + for _, req := range p.Requests { + req.Initialize(p) + } +} + +// PkgName returns the name of this package. +// i.e., 'xproto' for the core X protocol, 'randr' for the RandR extension, etc. +func (p *Protocol) PkgName() string { + return strings.Replace(p.Name, "_", "", -1) +} + +// ProtocolGet searches the current context for the protocol with the given +// name. (i.e., the current protocol and its imports.) +// It is an error if one is not found. +func (p *Protocol) ProtocolFind(name string) *Protocol { + if p.Name == name { + return p // that was easy + } + for _, imp := range p.Imports { + if imp.Name == name { + return imp + } + } + log.Panicf("Could not find protocol with name '%s'.", name) + panic("unreachable") +} + +// isExt returns true if this protocol is an extension. +// i.e., it's name isn't "xproto". +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 new file mode 100644 index 0000000..5032e31 --- /dev/null +++ b/nexgb/xgbgen/request_reply.go @@ -0,0 +1,152 @@ +package main + +import ( + "fmt" + "log" + "unicode" +) + +// Request represents all XML 'request' nodes. +// If the request doesn't have a reply, Reply is nil. +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. + Fields []Field // All fields in the request. + Reply *Reply // A reply, if one exists for this request. +} + +type Requests []*Request + +func (rs Requests) Len() int { return len(rs) } +func (rs Requests) Swap(i, j int) { rs[i], rs[j] = rs[j], rs[i] } +func (rs Requests) Less(i, j int) bool { return rs[i].xmlName < rs[j].xmlName } + +// Initialize creates the proper Go source name for this request. +// It also initializes the reply if one exists, and all fields in this request. +func (r *Request) Initialize(p *Protocol) { + r.srcName = SrcName(p, r.xmlName) + if p.isExt() { + r.srcName = r.srcName + } + + if r.Reply != nil { + r.Reply.Initialize(p) + } + for _, field := range r.Fields { + field.Initialize(p) + } +} + +func (r *Request) SrcName() string { + return r.srcName +} + +func (r *Request) XmlName() string { + return r.xmlName +} + +// ReplyName gets the Go source name of the function that generates a +// reply type from a slice of bytes. +// The generated function is not currently exported. +func (r *Request) ReplyName() string { + if r.Reply == nil { + log.Panicf("Cannot call 'ReplyName' on request %s, which has no reply.", + r.SrcName()) + } + name := r.SrcName() + lower := string(unicode.ToLower(rune(name[0]))) + name[1:] + return fmt.Sprintf("%sReply", lower) +} + +// ReplyTypeName gets the Go source name of the type holding all reply data +// for this request. +func (r *Request) ReplyTypeName() string { + if r.Reply == nil { + log.Panicf("Cannot call 'ReplyName' on request %s, which has no reply.", + r.SrcName()) + } + return fmt.Sprintf("%sReply", r.SrcName()) +} + +// ReqName gets the Go source name of the function that generates a byte +// slice from a list of parameters. +// The generated function is not currently exported. +func (r *Request) ReqName() string { + name := r.SrcName() + lower := string(unicode.ToLower(rune(name[0]))) + name[1:] + return fmt.Sprintf("%sRequest", lower) +} + +// CookieName gets the Go source name of the type that holds cookies for +// this request. +func (r *Request) CookieName() string { + return fmt.Sprintf("%sCookie", r.SrcName()) +} + +// Size for Request needs a context. +// Namely, if this is an extension, we need to account for *four* bytes +// of a header (extension opcode, request opcode, and the sequence number). +// If it's a core protocol request, then we only account for *three* +// bytes of the header (remove the extension opcode). +func (r *Request) Size(c *Context) Size { + size := newFixedSize(0, true) + + // If this is a core protocol request, we squeeze in an extra byte of + // data (from the fields below) between the opcode and the size of the + // request. In an extension request, this byte is always occupied + // by the opcode of the request (while the first byte is always occupied + // by the opcode of the extension). + if !c.protocol.isExt() { + size = size.Add(newFixedSize(3, true)) + } else { + size = size.Add(newFixedSize(4, true)) + } + + for _, field := range r.Fields { + switch field := field.(type) { + case *LocalField: // local fields don't go over the wire + continue + case *SingleField: + fsz := field.Size() + if _, isstruct := field.Type.(*Struct); isstruct { + fsz.Expression = fsz.Expression.Specialize(field.SrcName()) + } + size = size.Add(fsz) + default: + size = size.Add(field.Size()) + } + } + return newExpressionSize(&Padding{ + Expr: size.Expression, + }, size.exact) +} + +// Reply encapsulates the fields associated with a 'reply' element. +type Reply struct { + Fields []Field +} + +// Size gets the number of bytes in this request's reply. +// A reply always has at least 7 bytes: +// 1 byte: A reply discriminant (first byte set to 1) +// 2 bytes: A sequence number +// 4 bytes: Number of additional bytes in 4-byte units past initial 32 bytes. +func (r *Reply) Size() Size { + size := newFixedSize(0, true) + + // Account for reply discriminant, sequence number and reply length + size = size.Add(newFixedSize(7, true)) + + for _, field := range r.Fields { + size = size.Add(field.Size()) + } + return size +} + +func (r *Reply) Initialize(p *Protocol) { + for _, field := range r.Fields { + field.Initialize(p) + } +} diff --git a/nexgb/xgbgen/size.go b/nexgb/xgbgen/size.go new file mode 100644 index 0000000..6e49371 --- /dev/null +++ b/nexgb/xgbgen/size.go @@ -0,0 +1,31 @@ +package main + +// Size corresponds to an expression that represents the number of bytes +// in some *thing*. Generally, sizes are used to allocate buffers and to +// inform X how big requests are. +// Size is basically a thin layer over an Expression that yields easy methods +// for adding and multiplying sizes. +type Size struct { + Expression + exact bool +} + +// newFixedSize creates a new Size with some fixed and known value. +func newFixedSize(fixed uint, exact bool) Size { + return Size{&Value{v: int(fixed)}, exact} +} + +// newExpressionSize creates a new Size with some expression. +func newExpressionSize(variable Expression, exact bool) Size { + return Size{variable, exact} +} + +// Add adds s1 and s2 and returns a new Size. +func (s1 Size) Add(s2 Size) Size { + return Size{newBinaryOp("+", s1, s2), s1.exact && s2.exact} +} + +// Multiply mupltiplies s1 and s2 and returns a new Size. +func (s1 Size) Multiply(s2 Size) Size { + return Size{newBinaryOp("*", s1, s2), s1.exact && s2.exact} +} diff --git a/nexgb/xgbgen/translation.go b/nexgb/xgbgen/translation.go new file mode 100644 index 0000000..d35fa88 --- /dev/null +++ b/nexgb/xgbgen/translation.go @@ -0,0 +1,427 @@ +package main + +/* + translation.go provides a 'Translate' method on every XML type that converts + the XML type into our "better" representation. + + i.e., the representation of Fields and Expressions is just too general. + We end up losing a lot of the advantages of static typing if we keep + the types that encoding/xml forces us into. + + Please see 'representation.go' for the type definitions that we're + translating to. +*/ + +import ( + "log" + "strconv" + "strings" +) + +func (xml *XML) Translate(parent *Protocol) *Protocol { + protocol := &Protocol{ + Parent: parent, + Name: xml.Header, + ExtXName: xml.ExtensionXName, + ExtName: xml.ExtensionName, + MajorVersion: xml.MajorVersion, + MinorVersion: xml.MinorVersion, + + Imports: make([]*Protocol, 0), + Types: make([]Type, 0), + Requests: make([]*Request, len(xml.Requests)), + } + + for _, imp := range xml.Imports { + if imp.xml != nil { + protocol.Imports = append(protocol.Imports, + imp.xml.Translate(protocol)) + } + } + + for xmlName, srcName := range BaseTypeMap { + newBaseType := &Base{ + srcName: srcName, + xmlName: xmlName, + size: newFixedSize(BaseTypeSizes[xmlName], true), + } + protocol.Types = append(protocol.Types, newBaseType) + } + for _, enum := range xml.Enums { + protocol.Types = append(protocol.Types, enum.Translate()) + } + for _, xid := range xml.Xids { + protocol.Types = append(protocol.Types, xid.Translate()) + } + for _, xidunion := range xml.XidUnions { + protocol.Types = append(protocol.Types, xidunion.Translate()) + } + for _, typedef := range xml.TypeDefs { + protocol.Types = append(protocol.Types, typedef.Translate()) + } + for _, s := range xml.Structs { + protocol.Types = append(protocol.Types, s.Translate()) + } + for _, union := range xml.Unions { + protocol.Types = append(protocol.Types, union.Translate()) + } + for _, ev := range xml.Events { + protocol.Types = append(protocol.Types, ev.Translate()) + } + for _, evcopy := range xml.EventCopies { + protocol.Types = append(protocol.Types, evcopy.Translate()) + } + for _, err := range xml.Errors { + protocol.Types = append(protocol.Types, err.Translate()) + } + for _, errcopy := range xml.ErrorCopies { + protocol.Types = append(protocol.Types, errcopy.Translate()) + } + + for i, request := range xml.Requests { + protocol.Requests[i] = request.Translate() + } + + // Now load all of the type and source name information. + protocol.Initialize() + + // Make sure all enums have concrete values. + for _, typ := range protocol.Types { + enum, ok := typ.(*Enum) + if !ok { + continue + } + nextValue := 0 + for _, item := range enum.Items { + if item.Expr == nil { + item.Expr = &Value{v: nextValue} + nextValue++ + } else { + nextValue = item.Expr.Eval() + 1 + } + } + } + + return protocol +} + +func (x *XMLEnum) Translate() *Enum { + enum := &Enum{ + xmlName: x.Name, + Items: make([]*EnumItem, len(x.Items)), + } + for i, item := range x.Items { + enum.Items[i] = &EnumItem{ + xmlName: item.Name, + Expr: item.Expr.Translate(), + } + } + return enum +} + +func (x *XMLXid) Translate() *Resource { + return &Resource{ + xmlName: x.Name, + } +} + +func (x *XMLTypeDef) Translate() *TypeDef { + return &TypeDef{ + xmlName: x.New, + Old: newTranslation(x.Old), + } +} + +func (x *XMLEvent) Translate() *Event { + ev := &Event{ + xmlName: x.Name, + Number: x.Number, + NoSequence: x.NoSequence, + Fields: make([]Field, 0, len(x.Fields)), + } + for _, field := range x.Fields { + if field.XMLName.Local == "doc" { + continue + } + ev.Fields = append(ev.Fields, field.Translate(ev)) + } + return ev +} + +func (x *XMLEventCopy) Translate() *EventCopy { + return &EventCopy{ + xmlName: x.Name, + Number: x.Number, + Old: newTranslation(x.Ref), + } +} + +func (x *XMLError) Translate() *Error { + err := &Error{ + xmlName: x.Name, + Number: x.Number, + Fields: make([]Field, len(x.Fields)), + } + for i, field := range x.Fields { + err.Fields[i] = field.Translate(err) + } + return err +} + +func (x *XMLErrorCopy) Translate() *ErrorCopy { + return &ErrorCopy{ + xmlName: x.Name, + Number: x.Number, + Old: newTranslation(x.Ref), + } +} + +func (x *XMLStruct) Translate() *Struct { + s := &Struct{ + xmlName: x.Name, + Fields: make([]Field, len(x.Fields)), + } + for i, field := range x.Fields { + s.Fields[i] = field.Translate(s) + } + return s +} + +func (x *XMLUnion) Translate() *Union { + u := &Union{ + xmlName: x.Name, + Fields: make([]Field, len(x.Fields)), + } + for i, field := range x.Fields { + u.Fields[i] = field.Translate(u) + } + return u +} + +func (x *XMLRequest) Translate() *Request { + r := &Request{ + xmlName: x.Name, + Opcode: x.Opcode, + Combine: x.Combine, + Fields: make([]Field, 0, len(x.Fields)), + Reply: x.Reply.Translate(), + } + for _, field := range x.Fields { + if field.XMLName.Local == "doc" || field.XMLName.Local == "fd" { + continue + } + r.Fields = append(r.Fields, field.Translate(r)) + } + + // Address bug (or legacy code) in QueryTextExtents. + // The XML protocol description references 'string_len' in the + // computation of the 'odd_length' field. However, 'string_len' is not + // defined. Therefore, let's forcefully add it as a 'local field'. + // (i.e., a parameter in the caller but does not get sent over the wire.) + if x.Name == "QueryTextExtents" { + stringLenLocal := &LocalField{&SingleField{ + xmlName: "string_len", + Type: newTranslation("CARD16"), + }} + r.Fields = append(r.Fields, stringLenLocal) + } + + return r +} + +func (x *XMLReply) Translate() *Reply { + if x == nil { + return nil + } + + r := &Reply{ + Fields: make([]Field, 0, len(x.Fields)), + } + for _, field := range x.Fields { + if field.XMLName.Local == "doc" || field.XMLName.Local == "fd" { + continue + } + r.Fields = append(r.Fields, field.Translate(r)) + } + return r +} + +func (x *XMLExpression) Translate() Expression { + if x == nil { + return nil + } + + switch x.XMLName.Local { + case "op": + if len(x.Exprs) != 2 { + log.Panicf("'op' found %d expressions; expected 2.", len(x.Exprs)) + } + return &BinaryOp{ + Op: x.Op, + Expr1: x.Exprs[0].Translate(), + Expr2: x.Exprs[1].Translate(), + } + case "unop": + if len(x.Exprs) != 1 { + log.Panicf("'unop' found %d expressions; expected 1.", len(x.Exprs)) + } + return &UnaryOp{ + Op: x.Op, + Expr: x.Exprs[0].Translate(), + } + case "popcount": + if len(x.Exprs) != 1 { + log.Panicf("'popcount' found %d expressions; expected 1.", + len(x.Exprs)) + } + return &PopCount{ + Expr: x.Exprs[0].Translate(), + } + case "value": + val, err := strconv.Atoi(strings.TrimSpace(x.Data)) + if err != nil { + log.Panicf("Could not convert '%s' in 'value' expression to int.", + x.Data) + } + return &Value{ + v: val, + } + case "bit": + bit, err := strconv.Atoi(strings.TrimSpace(x.Data)) + if err != nil { + log.Panicf("Could not convert '%s' in 'bit' expression to int.", + x.Data) + } + if bit < 0 || bit > 31 { + log.Panicf("A 'bit' literal must be in the range [0, 31], but "+ + " is %d", bit) + } + return &Bit{ + b: bit, + } + case "fieldref": + return &FieldRef{ + Name: x.Data, + } + case "enumref": + return &EnumRef{ + EnumKind: newTranslation(x.Ref), + EnumItem: x.Data, + } + case "sumof": + return &SumOf{ + Name: x.Ref, + } + } + + log.Panicf("Unrecognized tag '%s' in expression context. Expected one of "+ + "op, fieldref, value, bit, enumref, unop, sumof or popcount.", + x.XMLName.Local) + panic("unreachable") +} + +func (x *XMLField) Translate(parent interface{}) Field { + switch x.XMLName.Local { + case "pad": + return &PadField{ + Bytes: x.Bytes, + Align: x.Align, + } + case "field": + s := &SingleField{ + xmlName: x.Name, + Type: newTranslation(x.Type), + } + return s + case "list": + return &ListField{ + xmlName: x.Name, + Type: newTranslation(x.Type), + LengthExpr: x.Expr.Translate(), + } + case "localfield": + return &LocalField{&SingleField{ + xmlName: x.Name, + Type: newTranslation(x.Type), + }} + case "exprfield": + return &ExprField{ + xmlName: x.Name, + Type: newTranslation(x.Type), + Expr: x.Expr.Translate(), + } + case "valueparam": + return &ValueField{ + Parent: parent, + MaskType: newTranslation(x.ValueMaskType), + MaskName: x.ValueMaskName, + ListName: x.ValueListName, + } + case "switch": + swtch := &SwitchField{ + Name: x.Name, + Expr: x.Expr.Translate(), + Bitcases: make([]*Bitcase, len(x.Bitcases)), + } + for i, bitcase := range x.Bitcases { + swtch.Bitcases[i] = bitcase.Translate() + } + return swtch + case "required_start_align": + return &RequiredStartAlign{} + } + + log.Panicf("Unrecognized field element: %s", x.XMLName.Local) + panic("unreachable") +} + +func (x *XMLBitcase) Translate() *Bitcase { + b := &Bitcase{ + Expr: x.Expr().Translate(), + Fields: make([]Field, len(x.Fields)), + } + for i, field := range x.Fields { + b.Fields[i] = field.Translate(b) + } + return b +} + +// SrcName is used to translate any identifier into a Go name. +// Mostly used for fields, but used in a couple other places too (enum items). +func SrcName(p *Protocol, name string) string { + // If it's in the name map, use that translation. + if newn, ok := NameMap[name]; ok { + return newn + } + return splitAndTitle(name) +} + +func TypeSrcName(p *Protocol, typ Type) string { + t := typ.XmlName() + + // If this is a base type, then write the raw Go type. + if baseType, ok := typ.(*Base); ok { + return baseType.SrcName() + } + + // If it's in the type map, use that translation. + if newt, ok := TypeMap[t]; ok { + return newt + } + + // If there's a namespace to this type, just use it and be done. + if colon := strings.Index(t, ":"); colon > -1 { + namespace := t[:colon] + rest := t[colon+1:] + return p.ProtocolFind(namespace).PkgName() + "." + splitAndTitle(rest) + } + + // Since there's no namespace, we're left with the raw type name. + // If the type is part of the source we're generating (i.e., there is + // no parent protocol), then just return that type name. + // Otherwise, we must qualify it with a package name. + if p.Parent == nil { + return splitAndTitle(t) + } + return p.PkgName() + "." + splitAndTitle(t) +} diff --git a/nexgb/xgbgen/type.go b/nexgb/xgbgen/type.go new file mode 100644 index 0000000..59f1a2d --- /dev/null +++ b/nexgb/xgbgen/type.go @@ -0,0 +1,390 @@ +package main + +import ( + "fmt" + "strings" +) + +type Type interface { + Initialize(p *Protocol) + SrcName() string + XmlName() string + Size() Size + + Define(c *Context) +} + +type Types []Type + +func (ts Types) Len() int { return len(ts) } +func (ts Types) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] } +func (ts Types) Less(i, j int) bool { + x1, x2 := ts[i].XmlName(), ts[j].XmlName() + s1, s2 := ts[i].SrcName(), ts[j].SrcName() + return (s1 == s2 && x1 < x2) || s1 < s2 +} + +// Translation is used *only* when transitioning from XML types to +// our better representation. They are placeholders for the real types (below) +// that will replace them. +type Translation struct { + xmlName string +} + +func newTranslation(name string) *Translation { + return &Translation{xmlName: name} +} + +// RealType takes 'XmlName' and finds its real concrete type in our Protocol. +// It is an error if we can't find such a type. +func (t *Translation) RealType(p *Protocol) Type { + // Check to see if there is a namespace. If so, strip it and use it to + // make sure we only look for a type in that protocol. + namespace, typeName := "", t.XmlName() + if ni := strings.Index(t.XmlName(), ":"); ni > -1 { + namespace, typeName = strings.ToLower(typeName[:ni]), typeName[ni+1:] + } + + if len(namespace) == 0 || namespace == strings.ToLower(p.Name) { + for _, typ := range p.Types { + if typeName == typ.XmlName() { + return typ + } + } + } + for _, imp := range p.Imports { + if len(namespace) == 0 || namespace == strings.ToLower(imp.Name) { + for _, typ := range imp.Types { + if typeName == typ.XmlName() { + return typ + } + } + } + } + panic("Could not find real type for translation type: " + t.XmlName()) +} + +func (t *Translation) SrcName() string { + panic("it is illegal to call SrcName on a translation type") +} + +func (t *Translation) XmlName() string { + return t.xmlName +} + +func (t *Translation) Size() Size { + panic("it is illegal to call Size on a translation type") +} + +func (t *Translation) Define(c *Context) { + panic("it is illegal to call Define on a translation type") +} + +func (t *Translation) Initialize(p *Protocol) { + panic("it is illegal to call Initialize on a translation type") +} + +type Base struct { + srcName string + xmlName string + size Size +} + +func (b *Base) SrcName() string { + return b.srcName +} + +func (b *Base) XmlName() string { + return b.xmlName +} + +func (b *Base) Size() Size { + return b.size +} + +func (b *Base) Initialize(p *Protocol) { + b.srcName = TypeSrcName(p, b) +} + +type Enum struct { + srcName string + xmlName string + Items []*EnumItem +} + +type EnumItem struct { + srcName string + xmlName string + Expr Expression +} + +func (enum *Enum) SrcName() string { + return enum.srcName +} + +func (enum *Enum) XmlName() string { + return enum.xmlName +} + +func (enum *Enum) Size() Size { + panic("Cannot take size of enum") +} + +func (enum *Enum) Initialize(p *Protocol) { + enum.srcName = TypeSrcName(p, enum) + for _, item := range enum.Items { + item.srcName = SrcName(p, item.xmlName) + if item.Expr != nil { + item.Expr.Initialize(p) + } + } +} + +type Resource struct { + srcName string + xmlName string +} + +func (r *Resource) SrcName() string { + return r.srcName +} + +func (r *Resource) XmlName() string { + return r.xmlName +} + +func (r *Resource) Size() Size { + return newFixedSize(BaseTypeSizes["Id"], true) +} + +func (r *Resource) Initialize(p *Protocol) { + r.srcName = TypeSrcName(p, r) +} + +type TypeDef struct { + srcName string + xmlName string + Old Type +} + +func (t *TypeDef) SrcName() string { + return t.srcName +} + +func (t *TypeDef) XmlName() string { + return t.xmlName +} + +func (t *TypeDef) Size() Size { + return t.Old.Size() +} + +func (t *TypeDef) Initialize(p *Protocol) { + t.Old = t.Old.(*Translation).RealType(p) + t.srcName = TypeSrcName(p, t) +} + +type Event struct { + srcName string + xmlName string + Number int + NoSequence bool + Fields []Field +} + +func (e *Event) SrcName() string { + return e.srcName +} + +func (e *Event) XmlName() string { + return e.xmlName +} + +func (e *Event) Size() Size { + return newExpressionSize(&Value{v: 32}, true) +} + +func (e *Event) Initialize(p *Protocol) { + e.srcName = TypeSrcName(p, e) + for _, field := range e.Fields { + field.Initialize(p) + } +} + +func (e *Event) EvType() string { + return fmt.Sprintf("%sEvent", e.srcName) +} + +type EventCopy struct { + srcName string + xmlName string + Old Type + Number int +} + +func (e *EventCopy) SrcName() string { + return e.srcName +} + +func (e *EventCopy) XmlName() string { + return e.xmlName +} + +func (e *EventCopy) Size() Size { + return newExpressionSize(&Value{v: 32}, true) +} + +func (e *EventCopy) Initialize(p *Protocol) { + e.srcName = TypeSrcName(p, e) + e.Old = e.Old.(*Translation).RealType(p) + if _, ok := e.Old.(*Event); !ok { + panic("an EventCopy's old type *must* be *Event") + } +} + +func (e *EventCopy) EvType() string { + return fmt.Sprintf("%sEvent", e.srcName) +} + +type Error struct { + srcName string + xmlName string + Number int + Fields []Field +} + +func (e *Error) SrcName() string { + return e.srcName +} + +func (e *Error) XmlName() string { + return e.xmlName +} + +func (e *Error) Size() Size { + return newExpressionSize(&Value{v: 32}, true) +} + +func (e *Error) Initialize(p *Protocol) { + e.srcName = TypeSrcName(p, e) + for _, field := range e.Fields { + field.Initialize(p) + } +} + +func (e *Error) ErrConst() string { + return fmt.Sprintf("Bad%s", e.srcName) +} + +func (e *Error) ErrType() string { + return fmt.Sprintf("%sError", e.srcName) +} + +type ErrorCopy struct { + srcName string + xmlName string + Old Type + Number int +} + +func (e *ErrorCopy) SrcName() string { + return e.srcName +} + +func (e *ErrorCopy) XmlName() string { + return e.xmlName +} + +func (e *ErrorCopy) Size() Size { + return newExpressionSize(&Value{v: 32}, true) +} + +func (e *ErrorCopy) Initialize(p *Protocol) { + e.srcName = TypeSrcName(p, e) + e.Old = e.Old.(*Translation).RealType(p) + if _, ok := e.Old.(*Error); !ok { + panic("an ErrorCopy's old type *must* be *Event") + } +} + +func (e *ErrorCopy) ErrConst() string { + return fmt.Sprintf("Bad%s", e.srcName) +} + +func (e *ErrorCopy) ErrType() string { + return fmt.Sprintf("%sError", e.srcName) +} + +type Struct struct { + srcName string + xmlName string + Fields []Field +} + +func (s *Struct) SrcName() string { + return s.srcName +} + +func (s *Struct) XmlName() string { + return s.xmlName +} + +func (s *Struct) Size() Size { + size := newFixedSize(0, true) + for _, field := range s.Fields { + size = size.Add(field.Size()) + } + return size +} + +func (s *Struct) Initialize(p *Protocol) { + s.srcName = TypeSrcName(p, s) + for _, field := range s.Fields { + field.Initialize(p) + } +} + +// HasList returns whether there is a field in this struct that is a list. +// When true, a more involved calculation is necessary to compute this struct's +// size. +func (s *Struct) HasList() bool { + for _, field := range s.Fields { + if _, ok := field.(*ListField); ok { + return true + } + } + return false +} + +type Union struct { + srcName string + xmlName string + Fields []Field +} + +func (u *Union) SrcName() string { + return u.srcName +} + +func (u *Union) XmlName() string { + return u.xmlName +} + +// Size for Union is broken. At least, it's broken for XKB. +// It *looks* like the protocol inherently relies on some amount of +// memory unsafety, since some members of unions in XKB are *variable* in +// length! The only thing I can come up with, maybe, is when a union has +// variable size, simply return the raw bytes. Then it's up to the user to +// pass those raw bytes into the appropriate New* constructor. GROSS! +// As of now, just pluck out the first field and return that size. This +// should work for union elements in randr.xml and xproto.xml. +func (u *Union) Size() Size { + return u.Fields[0].Size() +} + +func (u *Union) Initialize(p *Protocol) { + u.srcName = fmt.Sprintf("%sUnion", TypeSrcName(p, u)) + for _, field := range u.Fields { + field.Initialize(p) + } +} diff --git a/nexgb/xgbgen/xml.go b/nexgb/xgbgen/xml.go new file mode 100644 index 0000000..440d0a8 --- /dev/null +++ b/nexgb/xgbgen/xml.go @@ -0,0 +1,138 @@ +package main + +import ( + "encoding/xml" + "io/ioutil" + "log" +) + +type XML struct { + // Root 'xcb' element properties. + XMLName xml.Name `xml:"xcb"` + Header string `xml:"header,attr"` + ExtensionXName string `xml:"extension-xname,attr"` + ExtensionName string `xml:"extension-name,attr"` + MajorVersion string `xml:"major-version,attr"` + MinorVersion string `xml:"minor-version,attr"` + + // 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"` + EventCopies []*XMLEventCopy `xml:"eventcopy"` + ErrorCopies []*XMLErrorCopy `xml:"errorcopy"` + + // Here are the complex ones, i.e., anything with "structure contents" + Structs []*XMLStruct `xml:"struct"` + Unions []*XMLUnion `xml:"union"` + Requests []*XMLRequest `xml:"request"` + Events []*XMLEvent `xml:"event"` + Errors []*XMLError `xml:"error"` +} + +type XMLImports []*XMLImport + +func (imports XMLImports) Eval() { + for _, imp := range imports { + xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml") + if err != nil { + log.Fatalf("Could not read X protocol description for import "+ + "'%s' because: %s", imp.Name, err) + } + + imp.xml = &XML{} + err = xml.Unmarshal(xmlBytes, imp.xml) + if err != nil { + log.Fatal("Could not parse X protocol description for import "+ + "'%s' because: %s", imp.Name, err) + } + + // recursive imports... + imp.xml.Imports.Eval() + } +} + +type XMLImport struct { + Name string `xml:",chardata"` + xml *XML `xml:"-"` +} + +type XMLEnum struct { + Name string `xml:"name,attr"` + Items []*XMLEnumItem `xml:"item"` +} + +type XMLEnumItem struct { + Name string `xml:"name,attr"` + Expr *XMLExpression `xml:",any"` +} + +type XMLXid struct { + XMLName xml.Name + Name string `xml:"name,attr"` +} + +type XMLTypeDef struct { + Old string `xml:"oldname,attr"` + New string `xml:"newname,attr"` +} + +type XMLEventCopy struct { + Name string `xml:"name,attr"` + Number int `xml:"number,attr"` + Ref string `xml:"ref,attr"` +} + +type XMLErrorCopy struct { + Name string `xml:"name,attr"` + Number int `xml:"number,attr"` + Ref string `xml:"ref,attr"` +} + +type XMLStruct struct { + Name string `xml:"name,attr"` + Fields []*XMLField `xml:",any"` +} + +type XMLUnion struct { + 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"` + Fields []*XMLField `xml:",any"` + Reply *XMLReply `xml:"reply"` +} + +type XMLReply struct { + Fields []*XMLField `xml:",any"` +} + +type XMLEvent struct { + 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"` + Fields []*XMLField `xml:",any"` +} + +type XMLExpression struct { + XMLName xml.Name + + Exprs []*XMLExpression `xml:",any"` + + Data string `xml:",chardata"` + Op string `xml:"op,attr"` + Ref string `xml:"ref,attr"` +} diff --git a/nexgb/xgbgen/xml_fields.go b/nexgb/xgbgen/xml_fields.go new file mode 100644 index 0000000..8b7b5c7 --- /dev/null +++ b/nexgb/xgbgen/xml_fields.go @@ -0,0 +1,86 @@ +package main + +import ( + "encoding/xml" + "log" +) + +type XMLField struct { + XMLName xml.Name + + // For 'pad' element + Bytes uint `xml:"bytes,attr"` + Align uint16 `xml:"align,attr"` + + // For 'field', 'list', 'localfield', 'exprfield' and 'switch' elements. + Name string `xml:"name,attr"` + + // For 'field', 'list', 'localfield', and 'exprfield' elements. + Type string `xml:"type,attr"` + + // For 'list', 'exprfield' and 'switch' elements. + Expr *XMLExpression `xml:",any"` + + // For 'valueparm' element. + ValueMaskType string `xml:"value-mask-type,attr"` + ValueMaskName string `xml:"value-mask-name,attr"` + ValueListName string `xml:"value-list-name,attr"` + + // For 'switch' element. + Bitcases []*XMLBitcase `xml:"bitcase"` + + // I don't know which elements these are for. The documentation is vague. + // They also seem to be completely optional. + OptEnum string `xml:"enum,attr"` + OptMask string `xml:"mask,attr"` + OptAltEnum string `xml:"altenum,attr"` +} + +// Bitcase represents a single expression followed by any number of fields. +// Namely, if the switch's expression (all bitcases are inside a switch), +// and'd with the bitcase's expression is equal to the bitcase expression, +// then the fields should be included in its parent structure. +// Note that since a bitcase is unique in that expressions and fields are +// siblings, we must exhaustively search for one of them. Essentially, +// it's the closest thing to a Union I can get to in Go without interfaces. +// Would an '<expression>' tag have been too much to ask? :-( +type XMLBitcase struct { + Fields []*XMLField `xml:",any"` + + // All the different expressions. + // When it comes time to choose one, use the 'Expr' method. + ExprOp *XMLExpression `xml:"op"` + ExprUnOp *XMLExpression `xml:"unop"` + ExprField *XMLExpression `xml:"fieldref"` + ExprValue *XMLExpression `xml:"value"` + ExprBit *XMLExpression `xml:"bit"` + ExprEnum *XMLExpression `xml:"enumref"` + ExprSum *XMLExpression `xml:"sumof"` + ExprPop *XMLExpression `xml:"popcount"` +} + +// Expr chooses the only non-nil Expr* field from Bitcase. +// Panic if there is more than one non-nil expression. +func (b *XMLBitcase) Expr() *XMLExpression { + choices := []*XMLExpression{ + b.ExprOp, b.ExprUnOp, b.ExprField, b.ExprValue, + b.ExprBit, b.ExprEnum, b.ExprSum, b.ExprPop, + } + + var choice *XMLExpression = nil + numNonNil := 0 + for _, c := range choices { + if c != nil { + numNonNil++ + choice = c + } + } + + if choice == nil { + log.Panicf("No top level expression found in a bitcase.") + } + if numNonNil > 1 { + log.Panicf("More than one top-level expression was found in a bitcase.") + } + return choice +} diff --git a/nexgb/xinerama/xinerama.go b/nexgb/xinerama/xinerama.go new file mode 100644 index 0000000..ec97406 --- /dev/null +++ b/nexgb/xinerama/xinerama.go @@ -0,0 +1,718 @@ +// Package xinerama is the X client API for the XINERAMA extension. +package xinerama + +// This file is automatically generated from xinerama.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XINERAMA extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 8, "XINERAMA").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XINERAMA could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XINERAMA"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XINERAMA"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XINERAMA"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XINERAMA"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XINERAMA"] = make(map[int]xgb.NewErrorFun) +} + +type ScreenInfo struct { + XOrg int16 + YOrg int16 + Width uint16 + Height uint16 +} + +// ScreenInfoRead reads a byte slice into a ScreenInfo value. +func ScreenInfoRead(buf []byte, v *ScreenInfo) int { + b := 0 + + v.XOrg = int16(xgb.Get16(buf[b:])) + b += 2 + + v.YOrg = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// ScreenInfoReadList reads a byte slice into a list of ScreenInfo values. +func ScreenInfoReadList(buf []byte, dest []ScreenInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ScreenInfo{} + b += ScreenInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ScreenInfo value to a byte slice. +func (v ScreenInfo) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], uint16(v.XOrg)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.YOrg)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + return buf[:b] +} + +// ScreenInfoListBytes writes a list of ScreenInfo values to a byte slice. +func ScreenInfoListBytes(buf []byte, list []ScreenInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// GetScreenCountCookie is a cookie used only for GetScreenCount requests. +type GetScreenCountCookie struct { + *xgb.Cookie +} + +// GetScreenCount sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenCountCookie.Reply() +func GetScreenCount(c *xgb.Conn, Window xproto.Window) GetScreenCountCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetScreenCount' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenCountRequest(c, Window), cookie) + return GetScreenCountCookie{cookie} +} + +// GetScreenCountUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenCountUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenCountCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetScreenCount' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenCountRequest(c, Window), cookie) + return GetScreenCountCookie{cookie} +} + +// GetScreenCountReply represents the data returned from a GetScreenCount request. +type GetScreenCountReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + ScreenCount byte + Window xproto.Window +} + +// Reply blocks and returns the reply data for a GetScreenCount request. +func (cook GetScreenCountCookie) Reply() (*GetScreenCountReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenCountReply(buf), nil +} + +// getScreenCountReply reads a byte slice into a GetScreenCountReply value. +func getScreenCountReply(buf []byte) *GetScreenCountReply { + v := new(GetScreenCountReply) + b := 1 // skip reply determinant + + v.ScreenCount = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetScreenCount +// getScreenCountRequest writes a GetScreenCount request to a byte slice. +func getScreenCountRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// GetScreenSizeCookie is a cookie used only for GetScreenSize requests. +type GetScreenSizeCookie struct { + *xgb.Cookie +} + +// GetScreenSize sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenSizeCookie.Reply() +func GetScreenSize(c *xgb.Conn, Window xproto.Window, Screen uint32) GetScreenSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetScreenSize' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenSizeRequest(c, Window, Screen), cookie) + return GetScreenSizeCookie{cookie} +} + +// GetScreenSizeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenSizeUnchecked(c *xgb.Conn, Window xproto.Window, Screen uint32) GetScreenSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetScreenSize' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenSizeRequest(c, Window, Screen), cookie) + return GetScreenSizeCookie{cookie} +} + +// GetScreenSizeReply represents the data returned from a GetScreenSize request. +type GetScreenSizeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Width uint32 + Height uint32 + Window xproto.Window + Screen uint32 +} + +// Reply blocks and returns the reply data for a GetScreenSize request. +func (cook GetScreenSizeCookie) Reply() (*GetScreenSizeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenSizeReply(buf), nil +} + +// getScreenSizeReply reads a byte slice into a GetScreenSizeReply value. +func getScreenSizeReply(buf []byte) *GetScreenSizeReply { + v := new(GetScreenSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = xgb.Get32(buf[b:]) + b += 4 + + v.Height = xgb.Get32(buf[b:]) + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + v.Screen = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for GetScreenSize +// getScreenSizeRequest writes a GetScreenSize request to a byte slice. +func getScreenSizeRequest(c *xgb.Conn, Window xproto.Window, Screen uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], Screen) + b += 4 + + return buf +} + +// GetStateCookie is a cookie used only for GetState requests. +type GetStateCookie struct { + *xgb.Cookie +} + +// GetState sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetStateCookie.Reply() +func GetState(c *xgb.Conn, Window xproto.Window) GetStateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetState' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getStateRequest(c, Window), cookie) + return GetStateCookie{cookie} +} + +// GetStateUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetStateUnchecked(c *xgb.Conn, Window xproto.Window) GetStateCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'GetState' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getStateRequest(c, Window), cookie) + return GetStateCookie{cookie} +} + +// GetStateReply represents the data returned from a GetState request. +type GetStateReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + State byte + Window xproto.Window +} + +// Reply blocks and returns the reply data for a GetState request. +func (cook GetStateCookie) Reply() (*GetStateReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getStateReply(buf), nil +} + +// getStateReply reads a byte slice into a GetStateReply value. +func getStateReply(buf []byte) *GetStateReply { + v := new(GetStateReply) + b := 1 // skip reply determinant + + v.State = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Window = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetState +// getStateRequest writes a GetState request to a byte slice. +func getStateRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// IsActiveCookie is a cookie used only for IsActive requests. +type IsActiveCookie struct { + *xgb.Cookie +} + +// IsActive sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsActiveCookie.Reply() +func IsActive(c *xgb.Conn) IsActiveCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'IsActive' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isActiveRequest(c), cookie) + return IsActiveCookie{cookie} +} + +// IsActiveUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsActiveUnchecked(c *xgb.Conn) IsActiveCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'IsActive' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isActiveRequest(c), cookie) + return IsActiveCookie{cookie} +} + +// IsActiveReply represents the data returned from a IsActive request. +type IsActiveReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + State uint32 +} + +// Reply blocks and returns the reply data for a IsActive request. +func (cook IsActiveCookie) Reply() (*IsActiveReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isActiveReply(buf), nil +} + +// isActiveReply reads a byte slice into a IsActiveReply value. +func isActiveReply(buf []byte) *IsActiveReply { + v := new(IsActiveReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.State = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for IsActive +// isActiveRequest writes a IsActive request to a byte slice. +func isActiveRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// QueryScreensCookie is a cookie used only for QueryScreens requests. +type QueryScreensCookie struct { + *xgb.Cookie +} + +// QueryScreens sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryScreensCookie.Reply() +func QueryScreens(c *xgb.Conn) QueryScreensCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'QueryScreens' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryScreensRequest(c), cookie) + return QueryScreensCookie{cookie} +} + +// QueryScreensUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryScreensUnchecked(c *xgb.Conn) QueryScreensCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'QueryScreens' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryScreensRequest(c), cookie) + return QueryScreensCookie{cookie} +} + +// QueryScreensReply represents the data returned from a QueryScreens request. +type QueryScreensReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Number uint32 + // padding: 20 bytes + ScreenInfo []ScreenInfo // size: xgb.Pad((int(Number) * 8)) +} + +// Reply blocks and returns the reply data for a QueryScreens request. +func (cook QueryScreensCookie) Reply() (*QueryScreensReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryScreensReply(buf), nil +} + +// queryScreensReply reads a byte slice into a QueryScreensReply value. +func queryScreensReply(buf []byte) *QueryScreensReply { + v := new(QueryScreensReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Number = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.ScreenInfo = make([]ScreenInfo, v.Number) + b += ScreenInfoReadList(buf[b:], v.ScreenInfo) + + return v +} + +// Write request to wire for QueryScreens +// queryScreensRequest writes a QueryScreens request to a byte slice. +func queryScreensRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, Major byte, Minor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, Major, Minor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, Major byte, Minor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XINERAMA"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, Major, Minor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Major uint16 + Minor uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Major = xgb.Get16(buf[b:]) + b += 2 + + v.Minor = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, Major byte, Minor byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XINERAMA"] + c.ExtLock.RUnlock() + 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] = Major + b += 1 + + buf[b] = Minor + b += 1 + + return buf +} diff --git a/nexgb/xprint/xprint.go b/nexgb/xprint/xprint.go new file mode 100644 index 0000000..330003d --- /dev/null +++ b/nexgb/xprint/xprint.go @@ -0,0 +1,2540 @@ +// Package xprint is the X client API for the XpExtension extension. +package xprint + +// This file is automatically generated from xprint.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XpExtension extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 11, "XpExtension").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XpExtension could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XpExtension"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XpExtension"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XpExtension"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XpExtension"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XpExtension"] = make(map[int]xgb.NewErrorFun) +} + +const ( + AttrJobAttr = 1 + AttrDocAttr = 2 + AttrPageAttr = 3 + AttrPrinterAttr = 4 + AttrServerAttr = 5 + AttrMediumAttr = 6 + AttrSpoolerAttr = 7 +) + +// AttributNotify is the event number for a AttributNotifyEvent. +const AttributNotify = 1 + +type AttributNotifyEvent struct { + Sequence uint16 + Detail byte + Context Pcontext +} + +// AttributNotifyEventNew constructs a AttributNotifyEvent value that implements xgb.Event from a byte slice. +func AttributNotifyEventNew(buf []byte) xgb.Event { + v := AttributNotifyEvent{} + b := 1 // don't read event number + + v.Detail = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Context = Pcontext(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a AttributNotifyEvent value to a byte slice. +func (v AttributNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + buf[b] = v.Detail + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Context)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the AttributNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v AttributNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of AttributNotifyEvent. +func (v AttributNotifyEvent) String() string { + fieldVals := make([]string, 0, 2) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Context: %d", v.Context)) + return "AttributNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XpExtension"][1] = AttributNotifyEventNew +} + +// BadBadContext is the error number for a BadBadContext. +const BadBadContext = 0 + +type BadContextError struct { + Sequence uint16 + NiceName string +} + +// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. +func BadContextErrorNew(buf []byte) xgb.Error { + v := BadContextError{} + v.NiceName = "BadContext" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadContext error. +// This is mostly used internally. +func (err BadContextError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. +func (err BadContextError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadContext error. + +func (err BadContextError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XpExtension"][0] = BadContextErrorNew +} + +// BadBadSequence is the error number for a BadBadSequence. +const BadBadSequence = 1 + +type BadSequenceError struct { + Sequence uint16 + NiceName string +} + +// BadSequenceErrorNew constructs a BadSequenceError value that implements xgb.Error from a byte slice. +func BadSequenceErrorNew(buf []byte) xgb.Error { + v := BadSequenceError{} + v.NiceName = "BadSequence" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadSequence error. +// This is mostly used internally. +func (err BadSequenceError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadSequence error. If no bad value exists, 0 is returned. +func (err BadSequenceError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadSequence error. + +func (err BadSequenceError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadSequence {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XpExtension"][1] = BadSequenceErrorNew +} + +const ( + DetailStartJobNotify = 1 + DetailEndJobNotify = 2 + DetailStartDocNotify = 3 + DetailEndDocNotify = 4 + DetailStartPageNotify = 5 + DetailEndPageNotify = 6 +) + +const ( + EvMaskNoEventMask = 0 + EvMaskPrintMask = 1 + EvMaskAttributeMask = 2 +) + +const ( + GetDocFinished = 0 + GetDocSecondConsumer = 1 +) + +// Notify is the event number for a NotifyEvent. +const Notify = 0 + +type NotifyEvent struct { + Sequence uint16 + Detail byte + Context Pcontext + Cancel bool +} + +// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. +func NotifyEventNew(buf []byte) xgb.Event { + v := NotifyEvent{} + b := 1 // don't read event number + + v.Detail = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Context = Pcontext(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.Cancel = true + } else { + v.Cancel = false + } + b += 1 + + return v +} + +// Bytes writes a NotifyEvent value to a byte slice. +func (v NotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.Detail + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Context)) + b += 4 + + if v.Cancel { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// SequenceId returns the sequence id attached to the Notify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NotifyEvent. +func (v NotifyEvent) String() string { + fieldVals := make([]string, 0, 3) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Context: %d", v.Context)) + fieldVals = append(fieldVals, xgb.Sprintf("Cancel: %t", v.Cancel)) + return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XpExtension"][0] = NotifyEventNew +} + +type Pcontext uint32 + +func NewPcontextId(c *xgb.Conn) (Pcontext, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Pcontext(id), nil +} + +type Printer struct { + NameLen uint32 + Name []String8 // size: xgb.Pad((int(NameLen) * 1)) + // alignment gap to multiple of 4 + DescLen uint32 + Description []String8 // size: xgb.Pad((int(DescLen) * 1)) + // alignment gap to multiple of 4 +} + +// PrinterRead reads a byte slice into a Printer value. +func PrinterRead(buf []byte, v *Printer) int { + b := 0 + + v.NameLen = xgb.Get32(buf[b:]) + b += 4 + + v.Name = make([]String8, v.NameLen) + for i := 0; i < int(v.NameLen); i++ { + v.Name[i] = String8(buf[b]) + b += 1 + } + + b = (b + 3) & ^3 // alignment gap + + v.DescLen = xgb.Get32(buf[b:]) + b += 4 + + v.Description = make([]String8, v.DescLen) + for i := 0; i < int(v.DescLen); i++ { + v.Description[i] = String8(buf[b]) + b += 1 + } + + b = (b + 3) & ^3 // alignment gap + + return b +} + +// PrinterReadList reads a byte slice into a list of Printer values. +func PrinterReadList(buf []byte, dest []Printer) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Printer{} + b += PrinterRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Printer value to a byte slice. +func (v Printer) Bytes() []byte { + buf := make([]byte, (((((4 + xgb.Pad((int(v.NameLen) * 1))) + 4) + 4) + xgb.Pad((int(v.DescLen) * 1))) + 4)) + b := 0 + + xgb.Put32(buf[b:], v.NameLen) + b += 4 + + for i := 0; i < int(v.NameLen); i++ { + buf[b] = byte(v.Name[i]) + b += 1 + } + + b = (b + 3) & ^3 // alignment gap + + xgb.Put32(buf[b:], v.DescLen) + b += 4 + + for i := 0; i < int(v.DescLen); i++ { + buf[b] = byte(v.Description[i]) + b += 1 + } + + b = (b + 3) & ^3 // alignment gap + + return buf[:b] +} + +// PrinterListBytes writes a list of Printer values to a byte slice. +func PrinterListBytes(buf []byte, list []Printer) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// PrinterListSize computes the size (bytes) of a list of Printer values. +func PrinterListSize(list []Printer) int { + size := 0 + for _, item := range list { + size += (((((4 + xgb.Pad((int(item.NameLen) * 1))) + 4) + 4) + xgb.Pad((int(item.DescLen) * 1))) + 4) + } + return size +} + +type String8 byte + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CreateContextCookie is a cookie used only for CreateContext requests. +type CreateContextCookie struct { + *xgb.Cookie +} + +// CreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContext(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(createContextRequest(c, ContextId, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateContextCookie.Check() +func CreateContextChecked(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(createContextRequest(c, ContextId, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) + return CreateContextCookie{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 CreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. +func createContextRequest(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) []byte { + size := xgb.Pad(((16 + xgb.Pad((int(PrinterNameLen) * 1))) + xgb.Pad((int(LocaleLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], ContextId) + b += 4 + + xgb.Put32(buf[b:], PrinterNameLen) + b += 4 + + xgb.Put32(buf[b:], LocaleLen) + b += 4 + + for i := 0; i < int(PrinterNameLen); i++ { + buf[b] = byte(PrinterName[i]) + b += 1 + } + + for i := 0; i < int(LocaleLen); i++ { + buf[b] = byte(Locale[i]) + b += 1 + } + + return buf +} + +// PrintDestroyContextCookie is a cookie used only for PrintDestroyContext requests. +type PrintDestroyContextCookie struct { + *xgb.Cookie +} + +// PrintDestroyContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintDestroyContext(c *xgb.Conn, Context uint32) PrintDestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintDestroyContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printDestroyContextRequest(c, Context), cookie) + return PrintDestroyContextCookie{cookie} +} + +// PrintDestroyContextChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintDestroyContextCookie.Check() +func PrintDestroyContextChecked(c *xgb.Conn, Context uint32) PrintDestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintDestroyContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printDestroyContextRequest(c, Context), cookie) + return PrintDestroyContextCookie{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 PrintDestroyContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintDestroyContext +// printDestroyContextRequest writes a PrintDestroyContext request to a byte slice. +func printDestroyContextRequest(c *xgb.Conn, Context uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Context) + b += 4 + + return buf +} + +// PrintEndDocCookie is a cookie used only for PrintEndDoc requests. +type PrintEndDocCookie struct { + *xgb.Cookie +} + +// PrintEndDoc sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintEndDoc(c *xgb.Conn, Cancel bool) PrintEndDocCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printEndDocRequest(c, Cancel), cookie) + return PrintEndDocCookie{cookie} +} + +// PrintEndDocChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintEndDocCookie.Check() +func PrintEndDocChecked(c *xgb.Conn, Cancel bool) PrintEndDocCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printEndDocRequest(c, Cancel), cookie) + return PrintEndDocCookie{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 PrintEndDocCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintEndDoc +// printEndDocRequest writes a PrintEndDoc request to a byte slice. +func printEndDocRequest(c *xgb.Conn, Cancel bool) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + if Cancel { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// PrintEndJobCookie is a cookie used only for PrintEndJob requests. +type PrintEndJobCookie struct { + *xgb.Cookie +} + +// PrintEndJob sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintEndJob(c *xgb.Conn, Cancel bool) PrintEndJobCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printEndJobRequest(c, Cancel), cookie) + return PrintEndJobCookie{cookie} +} + +// PrintEndJobChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintEndJobCookie.Check() +func PrintEndJobChecked(c *xgb.Conn, Cancel bool) PrintEndJobCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printEndJobRequest(c, Cancel), cookie) + return PrintEndJobCookie{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 PrintEndJobCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintEndJob +// printEndJobRequest writes a PrintEndJob request to a byte slice. +func printEndJobRequest(c *xgb.Conn, Cancel bool) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + if Cancel { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// PrintEndPageCookie is a cookie used only for PrintEndPage requests. +type PrintEndPageCookie struct { + *xgb.Cookie +} + +// PrintEndPage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintEndPage(c *xgb.Conn, Cancel bool) PrintEndPageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printEndPageRequest(c, Cancel), cookie) + return PrintEndPageCookie{cookie} +} + +// PrintEndPageChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintEndPageCookie.Check() +func PrintEndPageChecked(c *xgb.Conn, Cancel bool) PrintEndPageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintEndPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printEndPageRequest(c, Cancel), cookie) + return PrintEndPageCookie{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 PrintEndPageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintEndPage +// printEndPageRequest writes a PrintEndPage request to a byte slice. +func printEndPageRequest(c *xgb.Conn, Cancel bool) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + if Cancel { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// PrintGetAttributesCookie is a cookie used only for PrintGetAttributes requests. +type PrintGetAttributesCookie struct { + *xgb.Cookie +} + +// PrintGetAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetAttributesCookie.Reply() +func PrintGetAttributes(c *xgb.Conn, Context Pcontext, Pool byte) PrintGetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetAttributesRequest(c, Context, Pool), cookie) + return PrintGetAttributesCookie{cookie} +} + +// PrintGetAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetAttributesUnchecked(c *xgb.Conn, Context Pcontext, Pool byte) PrintGetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetAttributesRequest(c, Context, Pool), cookie) + return PrintGetAttributesCookie{cookie} +} + +// PrintGetAttributesReply represents the data returned from a PrintGetAttributes request. +type PrintGetAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + StringLen uint32 + // padding: 20 bytes + Attributes []String8 // size: xgb.Pad((int(StringLen) * 1)) +} + +// Reply blocks and returns the reply data for a PrintGetAttributes request. +func (cook PrintGetAttributesCookie) Reply() (*PrintGetAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetAttributesReply(buf), nil +} + +// printGetAttributesReply reads a byte slice into a PrintGetAttributesReply value. +func printGetAttributesReply(buf []byte) *PrintGetAttributesReply { + v := new(PrintGetAttributesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.StringLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Attributes = make([]String8, v.StringLen) + for i := 0; i < int(v.StringLen); i++ { + v.Attributes[i] = String8(buf[b]) + b += 1 + } + + return v +} + +// Write request to wire for PrintGetAttributes +// printGetAttributesRequest writes a PrintGetAttributes request to a byte slice. +func printGetAttributesRequest(c *xgb.Conn, Context Pcontext, Pool byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // 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(Context)) + b += 4 + + buf[b] = Pool + b += 1 + + b += 3 // padding + + return buf +} + +// PrintGetContextCookie is a cookie used only for PrintGetContext requests. +type PrintGetContextCookie struct { + *xgb.Cookie +} + +// PrintGetContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetContextCookie.Reply() +func PrintGetContext(c *xgb.Conn) PrintGetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetContextRequest(c), cookie) + return PrintGetContextCookie{cookie} +} + +// PrintGetContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetContextUnchecked(c *xgb.Conn) PrintGetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetContextRequest(c), cookie) + return PrintGetContextCookie{cookie} +} + +// PrintGetContextReply represents the data returned from a PrintGetContext request. +type PrintGetContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Context uint32 +} + +// Reply blocks and returns the reply data for a PrintGetContext request. +func (cook PrintGetContextCookie) Reply() (*PrintGetContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetContextReply(buf), nil +} + +// printGetContextReply reads a byte slice into a PrintGetContextReply value. +func printGetContextReply(buf []byte) *PrintGetContextReply { + v := new(PrintGetContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Context = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for PrintGetContext +// printGetContextRequest writes a PrintGetContext request to a byte slice. +func printGetContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// PrintGetDocumentDataCookie is a cookie used only for PrintGetDocumentData requests. +type PrintGetDocumentDataCookie struct { + *xgb.Cookie +} + +// PrintGetDocumentData sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetDocumentDataCookie.Reply() +func PrintGetDocumentData(c *xgb.Conn, Context Pcontext, MaxBytes uint32) PrintGetDocumentDataCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetDocumentDataRequest(c, Context, MaxBytes), cookie) + return PrintGetDocumentDataCookie{cookie} +} + +// PrintGetDocumentDataUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetDocumentDataUnchecked(c *xgb.Conn, Context Pcontext, MaxBytes uint32) PrintGetDocumentDataCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetDocumentDataRequest(c, Context, MaxBytes), cookie) + return PrintGetDocumentDataCookie{cookie} +} + +// PrintGetDocumentDataReply represents the data returned from a PrintGetDocumentData request. +type PrintGetDocumentDataReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + StatusCode uint32 + FinishedFlag uint32 + DataLen uint32 + // padding: 12 bytes + Data []byte // size: xgb.Pad((int(DataLen) * 1)) +} + +// Reply blocks and returns the reply data for a PrintGetDocumentData request. +func (cook PrintGetDocumentDataCookie) Reply() (*PrintGetDocumentDataReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetDocumentDataReply(buf), nil +} + +// printGetDocumentDataReply reads a byte slice into a PrintGetDocumentDataReply value. +func printGetDocumentDataReply(buf []byte) *PrintGetDocumentDataReply { + v := new(PrintGetDocumentDataReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.StatusCode = xgb.Get32(buf[b:]) + b += 4 + + v.FinishedFlag = xgb.Get32(buf[b:]) + b += 4 + + v.DataLen = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Data = make([]byte, v.DataLen) + copy(v.Data[:v.DataLen], buf[b:]) + b += int(v.DataLen) + + return v +} + +// Write request to wire for PrintGetDocumentData +// printGetDocumentDataRequest writes a PrintGetDocumentData request to a byte slice. +func printGetDocumentDataRequest(c *xgb.Conn, Context Pcontext, MaxBytes uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], MaxBytes) + b += 4 + + return buf +} + +// PrintGetImageResolutionCookie is a cookie used only for PrintGetImageResolution requests. +type PrintGetImageResolutionCookie struct { + *xgb.Cookie +} + +// PrintGetImageResolution sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetImageResolutionCookie.Reply() +func PrintGetImageResolution(c *xgb.Conn, Context Pcontext) PrintGetImageResolutionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetImageResolutionRequest(c, Context), cookie) + return PrintGetImageResolutionCookie{cookie} +} + +// PrintGetImageResolutionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetImageResolutionUnchecked(c *xgb.Conn, Context Pcontext) PrintGetImageResolutionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetImageResolutionRequest(c, Context), cookie) + return PrintGetImageResolutionCookie{cookie} +} + +// PrintGetImageResolutionReply represents the data returned from a PrintGetImageResolution request. +type PrintGetImageResolutionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ImageResolution uint16 +} + +// Reply blocks and returns the reply data for a PrintGetImageResolution request. +func (cook PrintGetImageResolutionCookie) Reply() (*PrintGetImageResolutionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetImageResolutionReply(buf), nil +} + +// printGetImageResolutionReply reads a byte slice into a PrintGetImageResolutionReply value. +func printGetImageResolutionReply(buf []byte) *PrintGetImageResolutionReply { + v := new(PrintGetImageResolutionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ImageResolution = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for PrintGetImageResolution +// printGetImageResolutionRequest writes a PrintGetImageResolution request to a byte slice. +func printGetImageResolutionRequest(c *xgb.Conn, Context Pcontext) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 24 // 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(Context)) + b += 4 + + return buf +} + +// PrintGetOneAttributesCookie is a cookie used only for PrintGetOneAttributes requests. +type PrintGetOneAttributesCookie struct { + *xgb.Cookie +} + +// PrintGetOneAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetOneAttributesCookie.Reply() +func PrintGetOneAttributes(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) PrintGetOneAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetOneAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetOneAttributesRequest(c, Context, NameLen, Pool, Name), cookie) + return PrintGetOneAttributesCookie{cookie} +} + +// PrintGetOneAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetOneAttributesUnchecked(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) PrintGetOneAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetOneAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetOneAttributesRequest(c, Context, NameLen, Pool, Name), cookie) + return PrintGetOneAttributesCookie{cookie} +} + +// PrintGetOneAttributesReply represents the data returned from a PrintGetOneAttributes request. +type PrintGetOneAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ValueLen uint32 + // padding: 20 bytes + Value []String8 // size: xgb.Pad((int(ValueLen) * 1)) +} + +// Reply blocks and returns the reply data for a PrintGetOneAttributes request. +func (cook PrintGetOneAttributesCookie) Reply() (*PrintGetOneAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetOneAttributesReply(buf), nil +} + +// printGetOneAttributesReply reads a byte slice into a PrintGetOneAttributesReply value. +func printGetOneAttributesReply(buf []byte) *PrintGetOneAttributesReply { + v := new(PrintGetOneAttributesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ValueLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Value = make([]String8, v.ValueLen) + for i := 0; i < int(v.ValueLen); i++ { + v.Value[i] = String8(buf[b]) + b += 1 + } + + return v +} + +// Write request to wire for PrintGetOneAttributes +// printGetOneAttributesRequest writes a PrintGetOneAttributes request to a byte slice. +func printGetOneAttributesRequest(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) []byte { + size := xgb.Pad((16 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], NameLen) + b += 4 + + buf[b] = Pool + b += 1 + + b += 3 // padding + + for i := 0; i < int(NameLen); i++ { + buf[b] = byte(Name[i]) + b += 1 + } + + return buf +} + +// PrintGetPageDimensionsCookie is a cookie used only for PrintGetPageDimensions requests. +type PrintGetPageDimensionsCookie struct { + *xgb.Cookie +} + +// PrintGetPageDimensions sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetPageDimensionsCookie.Reply() +func PrintGetPageDimensions(c *xgb.Conn, Context Pcontext) PrintGetPageDimensionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetPageDimensions' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetPageDimensionsRequest(c, Context), cookie) + return PrintGetPageDimensionsCookie{cookie} +} + +// PrintGetPageDimensionsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetPageDimensionsUnchecked(c *xgb.Conn, Context Pcontext) PrintGetPageDimensionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetPageDimensions' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetPageDimensionsRequest(c, Context), cookie) + return PrintGetPageDimensionsCookie{cookie} +} + +// PrintGetPageDimensionsReply represents the data returned from a PrintGetPageDimensions request. +type PrintGetPageDimensionsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Width uint16 + Height uint16 + OffsetX uint16 + OffsetY uint16 + ReproducibleWidth uint16 + ReproducibleHeight uint16 +} + +// Reply blocks and returns the reply data for a PrintGetPageDimensions request. +func (cook PrintGetPageDimensionsCookie) Reply() (*PrintGetPageDimensionsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetPageDimensionsReply(buf), nil +} + +// printGetPageDimensionsReply reads a byte slice into a PrintGetPageDimensionsReply value. +func printGetPageDimensionsReply(buf []byte) *PrintGetPageDimensionsReply { + v := new(PrintGetPageDimensionsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.OffsetX = xgb.Get16(buf[b:]) + b += 2 + + v.OffsetY = xgb.Get16(buf[b:]) + b += 2 + + v.ReproducibleWidth = xgb.Get16(buf[b:]) + b += 2 + + v.ReproducibleHeight = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for PrintGetPageDimensions +// printGetPageDimensionsRequest writes a PrintGetPageDimensions request to a byte slice. +func printGetPageDimensionsRequest(c *xgb.Conn, Context Pcontext) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 21 // 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(Context)) + b += 4 + + return buf +} + +// PrintGetPrinterListCookie is a cookie used only for PrintGetPrinterList requests. +type PrintGetPrinterListCookie struct { + *xgb.Cookie +} + +// PrintGetPrinterList sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetPrinterListCookie.Reply() +func PrintGetPrinterList(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) PrintGetPrinterListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetPrinterListRequest(c, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) + return PrintGetPrinterListCookie{cookie} +} + +// PrintGetPrinterListUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetPrinterListUnchecked(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) PrintGetPrinterListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetPrinterListRequest(c, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) + return PrintGetPrinterListCookie{cookie} +} + +// PrintGetPrinterListReply represents the data returned from a PrintGetPrinterList request. +type PrintGetPrinterListReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ListCount uint32 + // padding: 20 bytes + Printers []Printer // size: PrinterListSize(Printers) +} + +// Reply blocks and returns the reply data for a PrintGetPrinterList request. +func (cook PrintGetPrinterListCookie) Reply() (*PrintGetPrinterListReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetPrinterListReply(buf), nil +} + +// printGetPrinterListReply reads a byte slice into a PrintGetPrinterListReply value. +func printGetPrinterListReply(buf []byte) *PrintGetPrinterListReply { + v := new(PrintGetPrinterListReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ListCount = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Printers = make([]Printer, v.ListCount) + b += PrinterReadList(buf[b:], v.Printers) + + return v +} + +// Write request to wire for PrintGetPrinterList +// printGetPrinterListRequest writes a PrintGetPrinterList request to a byte slice. +func printGetPrinterListRequest(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) []byte { + size := xgb.Pad(((12 + xgb.Pad((int(PrinterNameLen) * 1))) + xgb.Pad((int(LocaleLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + 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:], PrinterNameLen) + b += 4 + + xgb.Put32(buf[b:], LocaleLen) + b += 4 + + for i := 0; i < int(PrinterNameLen); i++ { + buf[b] = byte(PrinterName[i]) + b += 1 + } + + for i := 0; i < int(LocaleLen); i++ { + buf[b] = byte(Locale[i]) + b += 1 + } + + return buf +} + +// PrintGetScreenOfContextCookie is a cookie used only for PrintGetScreenOfContext requests. +type PrintGetScreenOfContextCookie struct { + *xgb.Cookie +} + +// PrintGetScreenOfContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintGetScreenOfContextCookie.Reply() +func PrintGetScreenOfContext(c *xgb.Conn) PrintGetScreenOfContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetScreenOfContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printGetScreenOfContextRequest(c), cookie) + return PrintGetScreenOfContextCookie{cookie} +} + +// PrintGetScreenOfContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintGetScreenOfContextUnchecked(c *xgb.Conn) PrintGetScreenOfContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintGetScreenOfContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printGetScreenOfContextRequest(c), cookie) + return PrintGetScreenOfContextCookie{cookie} +} + +// PrintGetScreenOfContextReply represents the data returned from a PrintGetScreenOfContext request. +type PrintGetScreenOfContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Root xproto.Window +} + +// Reply blocks and returns the reply data for a PrintGetScreenOfContext request. +func (cook PrintGetScreenOfContextCookie) Reply() (*PrintGetScreenOfContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printGetScreenOfContextReply(buf), nil +} + +// printGetScreenOfContextReply reads a byte slice into a PrintGetScreenOfContextReply value. +func printGetScreenOfContextReply(buf []byte) *PrintGetScreenOfContextReply { + v := new(PrintGetScreenOfContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Root = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for PrintGetScreenOfContext +// printGetScreenOfContextRequest writes a PrintGetScreenOfContext request to a byte slice. +func printGetScreenOfContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// PrintInputSelectedCookie is a cookie used only for PrintInputSelected requests. +type PrintInputSelectedCookie struct { + *xgb.Cookie +} + +// PrintInputSelected sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintInputSelectedCookie.Reply() +func PrintInputSelected(c *xgb.Conn, Context Pcontext) PrintInputSelectedCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintInputSelected' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printInputSelectedRequest(c, Context), cookie) + return PrintInputSelectedCookie{cookie} +} + +// PrintInputSelectedUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintInputSelectedUnchecked(c *xgb.Conn, Context Pcontext) PrintInputSelectedCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintInputSelected' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printInputSelectedRequest(c, Context), cookie) + return PrintInputSelectedCookie{cookie} +} + +// PrintInputSelectedReply represents the data returned from a PrintInputSelected request. +type PrintInputSelectedReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + EventMask uint32 + AllEventsMask uint32 +} + +// Reply blocks and returns the reply data for a PrintInputSelected request. +func (cook PrintInputSelectedCookie) Reply() (*PrintInputSelectedReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printInputSelectedReply(buf), nil +} + +// printInputSelectedReply reads a byte slice into a PrintInputSelectedReply value. +func printInputSelectedReply(buf []byte) *PrintInputSelectedReply { + v := new(PrintInputSelectedReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.EventMask = xgb.Get32(buf[b:]) + b += 4 + + v.AllEventsMask = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for PrintInputSelected +// printInputSelectedRequest writes a PrintInputSelected request to a byte slice. +func printInputSelectedRequest(c *xgb.Conn, Context Pcontext) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // 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(Context)) + b += 4 + + return buf +} + +// PrintPutDocumentDataCookie is a cookie used only for PrintPutDocumentData requests. +type PrintPutDocumentDataCookie struct { + *xgb.Cookie +} + +// PrintPutDocumentData sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintPutDocumentData(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) PrintPutDocumentDataCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintPutDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printPutDocumentDataRequest(c, Drawable, LenData, LenFmt, LenOptions, Data, DocFormat, Options), cookie) + return PrintPutDocumentDataCookie{cookie} +} + +// PrintPutDocumentDataChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintPutDocumentDataCookie.Check() +func PrintPutDocumentDataChecked(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) PrintPutDocumentDataCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintPutDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printPutDocumentDataRequest(c, Drawable, LenData, LenFmt, LenOptions, Data, DocFormat, Options), cookie) + return PrintPutDocumentDataCookie{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 PrintPutDocumentDataCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintPutDocumentData +// printPutDocumentDataRequest writes a PrintPutDocumentData request to a byte slice. +func printPutDocumentDataRequest(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) []byte { + size := xgb.Pad((((16 + xgb.Pad((int(LenData) * 1))) + xgb.Pad((int(LenFmt) * 1))) + xgb.Pad((int(LenOptions) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(Drawable)) + b += 4 + + xgb.Put32(buf[b:], LenData) + b += 4 + + xgb.Put16(buf[b:], LenFmt) + b += 2 + + xgb.Put16(buf[b:], LenOptions) + b += 2 + + copy(buf[b:], Data[:LenData]) + b += int(LenData) + + for i := 0; i < int(LenFmt); i++ { + buf[b] = byte(DocFormat[i]) + b += 1 + } + + for i := 0; i < int(LenOptions); i++ { + buf[b] = byte(Options[i]) + b += 1 + } + + return buf +} + +// PrintQueryScreensCookie is a cookie used only for PrintQueryScreens requests. +type PrintQueryScreensCookie struct { + *xgb.Cookie +} + +// PrintQueryScreens sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintQueryScreensCookie.Reply() +func PrintQueryScreens(c *xgb.Conn) PrintQueryScreensCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintQueryScreens' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printQueryScreensRequest(c), cookie) + return PrintQueryScreensCookie{cookie} +} + +// PrintQueryScreensUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintQueryScreensUnchecked(c *xgb.Conn) PrintQueryScreensCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintQueryScreens' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printQueryScreensRequest(c), cookie) + return PrintQueryScreensCookie{cookie} +} + +// PrintQueryScreensReply represents the data returned from a PrintQueryScreens request. +type PrintQueryScreensReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ListCount uint32 + // padding: 20 bytes + Roots []xproto.Window // size: xgb.Pad((int(ListCount) * 4)) +} + +// Reply blocks and returns the reply data for a PrintQueryScreens request. +func (cook PrintQueryScreensCookie) Reply() (*PrintQueryScreensReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printQueryScreensReply(buf), nil +} + +// printQueryScreensReply reads a byte slice into a PrintQueryScreensReply value. +func printQueryScreensReply(buf []byte) *PrintQueryScreensReply { + v := new(PrintQueryScreensReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ListCount = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Roots = make([]xproto.Window, v.ListCount) + for i := 0; i < int(v.ListCount); i++ { + v.Roots[i] = xproto.Window(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for PrintQueryScreens +// printQueryScreensRequest writes a PrintQueryScreens request to a byte slice. +func printQueryScreensRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// PrintQueryVersionCookie is a cookie used only for PrintQueryVersion requests. +type PrintQueryVersionCookie struct { + *xgb.Cookie +} + +// PrintQueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintQueryVersionCookie.Reply() +func PrintQueryVersion(c *xgb.Conn) PrintQueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintQueryVersion' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printQueryVersionRequest(c), cookie) + return PrintQueryVersionCookie{cookie} +} + +// PrintQueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintQueryVersionUnchecked(c *xgb.Conn) PrintQueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintQueryVersion' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printQueryVersionRequest(c), cookie) + return PrintQueryVersionCookie{cookie} +} + +// PrintQueryVersionReply represents the data returned from a PrintQueryVersion request. +type PrintQueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 +} + +// Reply blocks and returns the reply data for a PrintQueryVersion request. +func (cook PrintQueryVersionCookie) Reply() (*PrintQueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printQueryVersionReply(buf), nil +} + +// printQueryVersionReply reads a byte slice into a PrintQueryVersionReply value. +func printQueryVersionReply(buf []byte) *PrintQueryVersionReply { + v := new(PrintQueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for PrintQueryVersion +// printQueryVersionRequest writes a PrintQueryVersion request to a byte slice. +func printQueryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// PrintRehashPrinterListCookie is a cookie used only for PrintRehashPrinterList requests. +type PrintRehashPrinterListCookie struct { + *xgb.Cookie +} + +// PrintRehashPrinterList sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintRehashPrinterList(c *xgb.Conn) PrintRehashPrinterListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintRehashPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printRehashPrinterListRequest(c), cookie) + return PrintRehashPrinterListCookie{cookie} +} + +// PrintRehashPrinterListChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintRehashPrinterListCookie.Check() +func PrintRehashPrinterListChecked(c *xgb.Conn) PrintRehashPrinterListCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintRehashPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printRehashPrinterListRequest(c), cookie) + return PrintRehashPrinterListCookie{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 PrintRehashPrinterListCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintRehashPrinterList +// printRehashPrinterListRequest writes a PrintRehashPrinterList request to a byte slice. +func printRehashPrinterListRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// PrintSelectInputCookie is a cookie used only for PrintSelectInput requests. +type PrintSelectInputCookie struct { + *xgb.Cookie +} + +// PrintSelectInput sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintSelectInput(c *xgb.Conn, Context Pcontext, EventMask uint32) PrintSelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printSelectInputRequest(c, Context, EventMask), cookie) + return PrintSelectInputCookie{cookie} +} + +// PrintSelectInputChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintSelectInputCookie.Check() +func PrintSelectInputChecked(c *xgb.Conn, Context Pcontext, EventMask uint32) PrintSelectInputCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printSelectInputRequest(c, Context, EventMask), cookie) + return PrintSelectInputCookie{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 PrintSelectInputCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintSelectInput +// printSelectInputRequest writes a PrintSelectInput request to a byte slice. +func printSelectInputRequest(c *xgb.Conn, Context Pcontext, EventMask uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + return buf +} + +// PrintSetAttributesCookie is a cookie used only for PrintSetAttributes requests. +type PrintSetAttributesCookie struct { + *xgb.Cookie +} + +// PrintSetAttributes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintSetAttributes(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) PrintSetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printSetAttributesRequest(c, Context, StringLen, Pool, Rule, Attributes), cookie) + return PrintSetAttributesCookie{cookie} +} + +// PrintSetAttributesChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintSetAttributesCookie.Check() +func PrintSetAttributesChecked(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) PrintSetAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printSetAttributesRequest(c, Context, StringLen, Pool, Rule, Attributes), cookie) + return PrintSetAttributesCookie{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 PrintSetAttributesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintSetAttributes +// printSetAttributesRequest writes a PrintSetAttributes request to a byte slice. +func printSetAttributesRequest(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Attributes) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // 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(Context)) + b += 4 + + xgb.Put32(buf[b:], StringLen) + b += 4 + + buf[b] = Pool + b += 1 + + buf[b] = Rule + b += 1 + + b += 2 // padding + + for i := 0; i < int(len(Attributes)); i++ { + buf[b] = byte(Attributes[i]) + b += 1 + } + + return buf +} + +// PrintSetContextCookie is a cookie used only for PrintSetContext requests. +type PrintSetContextCookie struct { + *xgb.Cookie +} + +// PrintSetContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintSetContext(c *xgb.Conn, Context uint32) PrintSetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printSetContextRequest(c, Context), cookie) + return PrintSetContextCookie{cookie} +} + +// PrintSetContextChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintSetContextCookie.Check() +func PrintSetContextChecked(c *xgb.Conn, Context uint32) PrintSetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printSetContextRequest(c, Context), cookie) + return PrintSetContextCookie{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 PrintSetContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintSetContext +// printSetContextRequest writes a PrintSetContext request to a byte slice. +func printSetContextRequest(c *xgb.Conn, Context uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Context) + b += 4 + + return buf +} + +// PrintSetImageResolutionCookie is a cookie used only for PrintSetImageResolution requests. +type PrintSetImageResolutionCookie struct { + *xgb.Cookie +} + +// PrintSetImageResolution sends a checked request. +// If an error occurs, it will be returned with the reply by calling PrintSetImageResolutionCookie.Reply() +func PrintSetImageResolution(c *xgb.Conn, Context Pcontext, ImageResolution uint16) PrintSetImageResolutionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(printSetImageResolutionRequest(c, Context, ImageResolution), cookie) + return PrintSetImageResolutionCookie{cookie} +} + +// PrintSetImageResolutionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintSetImageResolutionUnchecked(c *xgb.Conn, Context Pcontext, ImageResolution uint16) PrintSetImageResolutionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintSetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(printSetImageResolutionRequest(c, Context, ImageResolution), cookie) + return PrintSetImageResolutionCookie{cookie} +} + +// PrintSetImageResolutionReply represents the data returned from a PrintSetImageResolution request. +type PrintSetImageResolutionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status bool + PreviousResolutions uint16 +} + +// Reply blocks and returns the reply data for a PrintSetImageResolution request. +func (cook PrintSetImageResolutionCookie) Reply() (*PrintSetImageResolutionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return printSetImageResolutionReply(buf), nil +} + +// printSetImageResolutionReply reads a byte slice into a PrintSetImageResolutionReply value. +func printSetImageResolutionReply(buf []byte) *PrintSetImageResolutionReply { + v := new(PrintSetImageResolutionReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.Status = true + } else { + v.Status = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PreviousResolutions = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for PrintSetImageResolution +// printSetImageResolutionRequest writes a PrintSetImageResolution request to a byte slice. +func printSetImageResolutionRequest(c *xgb.Conn, Context Pcontext, ImageResolution uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 23 // 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(Context)) + b += 4 + + xgb.Put16(buf[b:], ImageResolution) + b += 2 + + return buf +} + +// PrintStartDocCookie is a cookie used only for PrintStartDoc requests. +type PrintStartDocCookie struct { + *xgb.Cookie +} + +// PrintStartDoc sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintStartDoc(c *xgb.Conn, DriverMode byte) PrintStartDocCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printStartDocRequest(c, DriverMode), cookie) + return PrintStartDocCookie{cookie} +} + +// PrintStartDocChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintStartDocCookie.Check() +func PrintStartDocChecked(c *xgb.Conn, DriverMode byte) PrintStartDocCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printStartDocRequest(c, DriverMode), cookie) + return PrintStartDocCookie{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 PrintStartDocCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintStartDoc +// printStartDocRequest writes a PrintStartDoc request to a byte slice. +func printStartDocRequest(c *xgb.Conn, DriverMode byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = DriverMode + b += 1 + + return buf +} + +// PrintStartJobCookie is a cookie used only for PrintStartJob requests. +type PrintStartJobCookie struct { + *xgb.Cookie +} + +// PrintStartJob sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintStartJob(c *xgb.Conn, OutputMode byte) PrintStartJobCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printStartJobRequest(c, OutputMode), cookie) + return PrintStartJobCookie{cookie} +} + +// PrintStartJobChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintStartJobCookie.Check() +func PrintStartJobChecked(c *xgb.Conn, OutputMode byte) PrintStartJobCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printStartJobRequest(c, OutputMode), cookie) + return PrintStartJobCookie{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 PrintStartJobCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintStartJob +// printStartJobRequest writes a PrintStartJob request to a byte slice. +func printStartJobRequest(c *xgb.Conn, OutputMode byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = OutputMode + b += 1 + + return buf +} + +// PrintStartPageCookie is a cookie used only for PrintStartPage requests. +type PrintStartPageCookie struct { + *xgb.Cookie +} + +// PrintStartPage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PrintStartPage(c *xgb.Conn, Window xproto.Window) PrintStartPageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(printStartPageRequest(c, Window), cookie) + return PrintStartPageCookie{cookie} +} + +// PrintStartPageChecked sends a checked request. +// If an error occurs, it can be retrieved using PrintStartPageCookie.Check() +func PrintStartPageChecked(c *xgb.Conn, Window xproto.Window) PrintStartPageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XpExtension"]; !ok { + panic("Cannot issue request 'PrintStartPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(printStartPageRequest(c, Window), cookie) + return PrintStartPageCookie{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 PrintStartPageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PrintStartPage +// printStartPageRequest writes a PrintStartPage request to a byte slice. +func printStartPageRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XpExtension"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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 + + return buf +} diff --git a/nexgb/xproto/xproto.go b/nexgb/xproto/xproto.go new file mode 100644 index 0000000..237f3cb --- /dev/null +++ b/nexgb/xproto/xproto.go @@ -0,0 +1,14913 @@ +// Package xproto is the X client API for the extension. +package xproto + +// This file is automatically generated from xproto.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" +) + +// Setup parses the setup bytes retrieved when +// connecting into a SetupInfo struct. +func Setup(c *xgb.Conn) *SetupInfo { + setup := new(SetupInfo) + SetupInfoRead(c.SetupBytes, setup) + return setup +} + +// DefaultScreen gets the default screen info from SetupInfo. +func (s *SetupInfo) DefaultScreen(c *xgb.Conn) *ScreenInfo { + return &s.Roots[c.DefaultScreen] +} + +// BadAccess is the error number for a BadAccess. +const BadAccess = 10 + +type AccessError RequestError + +// AccessErrorNew constructs a AccessError value that implements xgb.Error from a byte slice. +func AccessErrorNew(buf []byte) xgb.Error { + v := AccessError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Access" + return v +} + +// SequenceId returns the sequence id attached to the BadAccess error. +// This is mostly used internally. +func (err AccessError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadAccess error. If no bad value exists, 0 is returned. +func (err AccessError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadAccess error. +func (err AccessError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadAccess {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[10] = AccessErrorNew +} + +const ( + AccessControlDisable = 0 + AccessControlEnable = 1 +) + +// BadAlloc is the error number for a BadAlloc. +const BadAlloc = 11 + +type AllocError RequestError + +// AllocErrorNew constructs a AllocError value that implements xgb.Error from a byte slice. +func AllocErrorNew(buf []byte) xgb.Error { + v := AllocError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Alloc" + return v +} + +// SequenceId returns the sequence id attached to the BadAlloc error. +// This is mostly used internally. +func (err AllocError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadAlloc error. If no bad value exists, 0 is returned. +func (err AllocError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadAlloc error. +func (err AllocError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadAlloc {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[11] = AllocErrorNew +} + +const ( + AllowAsyncPointer = 0 + AllowSyncPointer = 1 + AllowReplayPointer = 2 + AllowAsyncKeyboard = 3 + AllowSyncKeyboard = 4 + AllowReplayKeyboard = 5 + AllowAsyncBoth = 6 + AllowSyncBoth = 7 +) + +type Arc struct { + X int16 + Y int16 + Width uint16 + Height uint16 + Angle1 int16 + Angle2 int16 +} + +// ArcRead reads a byte slice into a Arc value. +func ArcRead(buf []byte, v *Arc) int { + b := 0 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Angle1 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Angle2 = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// ArcReadList reads a byte slice into a list of Arc values. +func ArcReadList(buf []byte, dest []Arc) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Arc{} + b += ArcRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Arc value to a byte slice. +func (v Arc) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Angle1)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Angle2)) + b += 2 + + return buf[:b] +} + +// ArcListBytes writes a list of Arc values to a byte slice. +func ArcListBytes(buf []byte, list []Arc) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + ArcModeChord = 0 + ArcModePieSlice = 1 +) + +type Atom uint32 + +func NewAtomId(c *xgb.Conn) (Atom, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Atom(id), nil +} + +const ( + AtomNone = 0 + AtomAny = 0 + AtomPrimary = 1 + AtomSecondary = 2 + AtomArc = 3 + AtomAtom = 4 + AtomBitmap = 5 + AtomCardinal = 6 + AtomColormap = 7 + AtomCursor = 8 + AtomCutBuffer0 = 9 + AtomCutBuffer1 = 10 + AtomCutBuffer2 = 11 + AtomCutBuffer3 = 12 + AtomCutBuffer4 = 13 + AtomCutBuffer5 = 14 + AtomCutBuffer6 = 15 + AtomCutBuffer7 = 16 + AtomDrawable = 17 + AtomFont = 18 + AtomInteger = 19 + AtomPixmap = 20 + AtomPoint = 21 + AtomRectangle = 22 + AtomResourceManager = 23 + AtomRgbColorMap = 24 + AtomRgbBestMap = 25 + AtomRgbBlueMap = 26 + AtomRgbDefaultMap = 27 + AtomRgbGrayMap = 28 + AtomRgbGreenMap = 29 + AtomRgbRedMap = 30 + AtomString = 31 + AtomVisualid = 32 + AtomWindow = 33 + AtomWmCommand = 34 + AtomWmHints = 35 + AtomWmClientMachine = 36 + AtomWmIconName = 37 + AtomWmIconSize = 38 + AtomWmName = 39 + AtomWmNormalHints = 40 + AtomWmSizeHints = 41 + AtomWmZoomHints = 42 + AtomMinSpace = 43 + AtomNormSpace = 44 + AtomMaxSpace = 45 + AtomEndSpace = 46 + AtomSuperscriptX = 47 + AtomSuperscriptY = 48 + AtomSubscriptX = 49 + AtomSubscriptY = 50 + AtomUnderlinePosition = 51 + AtomUnderlineThickness = 52 + AtomStrikeoutAscent = 53 + AtomStrikeoutDescent = 54 + AtomItalicAngle = 55 + AtomXHeight = 56 + AtomQuadWidth = 57 + AtomWeight = 58 + AtomPointSize = 59 + AtomResolution = 60 + AtomCopyright = 61 + AtomNotice = 62 + AtomFontName = 63 + AtomFamilyName = 64 + AtomFullName = 65 + AtomCapHeight = 66 + AtomWmClass = 67 + AtomWmTransientFor = 68 +) + +// BadAtom is the error number for a BadAtom. +const BadAtom = 5 + +type AtomError ValueError + +// AtomErrorNew constructs a AtomError value that implements xgb.Error from a byte slice. +func AtomErrorNew(buf []byte) xgb.Error { + v := AtomError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Atom" + return v +} + +// SequenceId returns the sequence id attached to the BadAtom error. +// This is mostly used internally. +func (err AtomError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadAtom error. If no bad value exists, 0 is returned. +func (err AtomError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadAtom error. +func (err AtomError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadAtom {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[5] = AtomErrorNew +} + +const ( + AutoRepeatModeOff = 0 + AutoRepeatModeOn = 1 + AutoRepeatModeDefault = 2 +) + +const ( + BackPixmapNone = 0 + BackPixmapParentRelative = 1 +) + +const ( + BackingStoreNotUseful = 0 + BackingStoreWhenMapped = 1 + BackingStoreAlways = 2 +) + +const ( + BlankingNotPreferred = 0 + BlankingPreferred = 1 + BlankingDefault = 2 +) + +type Bool32 uint32 + +type Button byte + +const ( + ButtonIndexAny = 0 + ButtonIndex1 = 1 + ButtonIndex2 = 2 + ButtonIndex3 = 3 + ButtonIndex4 = 4 + ButtonIndex5 = 5 +) + +const ( + ButtonMask1 = 256 + ButtonMask2 = 512 + ButtonMask3 = 1024 + ButtonMask4 = 2048 + ButtonMask5 = 4096 + ButtonMaskAny = 32768 +) + +// ButtonPress is the event number for a ButtonPressEvent. +const ButtonPress = 4 + +type ButtonPressEvent struct { + Sequence uint16 + Detail Button + Time Timestamp + Root Window + Event Window + Child Window + RootX int16 + RootY int16 + EventX int16 + EventY int16 + State uint16 + SameScreen bool + // padding: 1 bytes +} + +// ButtonPressEventNew constructs a ButtonPressEvent value that implements xgb.Event from a byte slice. +func ButtonPressEventNew(buf []byte) xgb.Event { + v := ButtonPressEvent{} + b := 1 // don't read event number + + v.Detail = Button(buf[b]) + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.State = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a ButtonPressEvent value to a byte slice. +func (v ButtonPressEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 4 + b += 1 + + buf[b] = byte(v.Detail) + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Child)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.RootX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.RootY)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventY)) + b += 2 + + xgb.Put16(buf[b:], v.State) + b += 2 + + if v.SameScreen { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the ButtonPress event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ButtonPressEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ButtonPressEvent. +func (v ButtonPressEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + return "ButtonPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[4] = ButtonPressEventNew +} + +// ButtonRelease is the event number for a ButtonReleaseEvent. +const ButtonRelease = 5 + +type ButtonReleaseEvent ButtonPressEvent + +// ButtonReleaseEventNew constructs a ButtonReleaseEvent value that implements xgb.Event from a byte slice. +func ButtonReleaseEventNew(buf []byte) xgb.Event { + return ButtonReleaseEvent(ButtonPressEventNew(buf).(ButtonPressEvent)) +} + +// Bytes writes a ButtonReleaseEvent value to a byte slice. +func (v ButtonReleaseEvent) Bytes() []byte { + return ButtonPressEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the ButtonRelease event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ButtonReleaseEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v ButtonReleaseEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + return "ButtonRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[5] = ButtonReleaseEventNew +} + +const ( + CapStyleNotLast = 0 + CapStyleButt = 1 + CapStyleRound = 2 + CapStyleProjecting = 3 +) + +type Char2b struct { + Byte1 byte + Byte2 byte +} + +// Char2bRead reads a byte slice into a Char2b value. +func Char2bRead(buf []byte, v *Char2b) int { + b := 0 + + v.Byte1 = buf[b] + b += 1 + + v.Byte2 = buf[b] + b += 1 + + return b +} + +// Char2bReadList reads a byte slice into a list of Char2b values. +func Char2bReadList(buf []byte, dest []Char2b) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Char2b{} + b += Char2bRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Char2b value to a byte slice. +func (v Char2b) Bytes() []byte { + buf := make([]byte, 2) + b := 0 + + buf[b] = v.Byte1 + b += 1 + + buf[b] = v.Byte2 + b += 1 + + return buf[:b] +} + +// Char2bListBytes writes a list of Char2b values to a byte slice. +func Char2bListBytes(buf []byte, list []Char2b) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Charinfo struct { + LeftSideBearing int16 + RightSideBearing int16 + CharacterWidth int16 + Ascent int16 + Descent int16 + Attributes uint16 +} + +// CharinfoRead reads a byte slice into a Charinfo value. +func CharinfoRead(buf []byte, v *Charinfo) int { + b := 0 + + v.LeftSideBearing = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RightSideBearing = int16(xgb.Get16(buf[b:])) + b += 2 + + v.CharacterWidth = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Ascent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Descent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Attributes = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// CharinfoReadList reads a byte slice into a list of Charinfo values. +func CharinfoReadList(buf []byte, dest []Charinfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Charinfo{} + b += CharinfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Charinfo value to a byte slice. +func (v Charinfo) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put16(buf[b:], uint16(v.LeftSideBearing)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.RightSideBearing)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.CharacterWidth)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Ascent)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Descent)) + b += 2 + + xgb.Put16(buf[b:], v.Attributes) + b += 2 + + return buf[:b] +} + +// CharinfoListBytes writes a list of Charinfo values to a byte slice. +func CharinfoListBytes(buf []byte, list []Charinfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + CirculateRaiseLowest = 0 + CirculateLowerHighest = 1 +) + +// CirculateNotify is the event number for a CirculateNotifyEvent. +const CirculateNotify = 26 + +type CirculateNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + // padding: 4 bytes + Place byte + // padding: 3 bytes +} + +// CirculateNotifyEventNew constructs a CirculateNotifyEvent value that implements xgb.Event from a byte slice. +func CirculateNotifyEventNew(buf []byte) xgb.Event { + v := CirculateNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + b += 4 // padding + + v.Place = buf[b] + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a CirculateNotifyEvent value to a byte slice. +func (v CirculateNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 26 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + b += 4 // padding + + buf[b] = v.Place + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the CirculateNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v CirculateNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of CirculateNotifyEvent. +func (v CirculateNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Place: %d", v.Place)) + return "CirculateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[26] = CirculateNotifyEventNew +} + +// CirculateRequest is the event number for a CirculateRequestEvent. +const CirculateRequest = 27 + +type CirculateRequestEvent CirculateNotifyEvent + +// CirculateRequestEventNew constructs a CirculateRequestEvent value that implements xgb.Event from a byte slice. +func CirculateRequestEventNew(buf []byte) xgb.Event { + return CirculateRequestEvent(CirculateNotifyEventNew(buf).(CirculateNotifyEvent)) +} + +// Bytes writes a CirculateRequestEvent value to a byte slice. +func (v CirculateRequestEvent) Bytes() []byte { + return CirculateNotifyEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the CirculateRequest event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v CirculateRequestEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v CirculateRequestEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Place: %d", v.Place)) + return "CirculateRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[27] = CirculateRequestEventNew +} + +// ClientMessage is the event number for a ClientMessageEvent. +const ClientMessage = 33 + +type ClientMessageEvent struct { + Sequence uint16 + Format byte + Window Window + Type Atom + Data ClientMessageDataUnion +} + +// ClientMessageEventNew constructs a ClientMessageEvent value that implements xgb.Event from a byte slice. +func ClientMessageEventNew(buf []byte) xgb.Event { + v := ClientMessageEvent{} + b := 1 // don't read event number + + v.Format = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Type = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Data = ClientMessageDataUnion{} + b += ClientMessageDataUnionRead(buf[b:], &v.Data) + + return v +} + +// Bytes writes a ClientMessageEvent value to a byte slice. +func (v ClientMessageEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 33 + b += 1 + + buf[b] = v.Format + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Type)) + b += 4 + + { + unionBytes := v.Data.Bytes() + copy(buf[b:], unionBytes) + b += len(unionBytes) + } + + return buf +} + +// SequenceId returns the sequence id attached to the ClientMessage event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ClientMessageEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ClientMessageEvent. +func (v ClientMessageEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Format: %d", v.Format)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Type: %d", v.Type)) + return "ClientMessage {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[33] = ClientMessageEventNew +} + +// ClientMessageDataUnion is a represention of the ClientMessageDataUnion union type. +// Note that to *create* a Union, you should *never* create +// this struct directly (unless you know what you're doing). +// Instead use one of the following constructors for 'ClientMessageDataUnion': +// ClientMessageDataUnionData8New(Data8 []byte) ClientMessageDataUnion +// ClientMessageDataUnionData16New(Data16 []uint16) ClientMessageDataUnion +// ClientMessageDataUnionData32New(Data32 []uint32) ClientMessageDataUnion +type ClientMessageDataUnion struct { + Data8 []byte // size: 20 + Data16 []uint16 // size: 20 + Data32 []uint32 // size: 20 +} + +// ClientMessageDataUnionData8New constructs a new ClientMessageDataUnion union type with the Data8 field. +func ClientMessageDataUnionData8New(Data8 []byte) ClientMessageDataUnion { + var b int + buf := make([]byte, 20) + + copy(buf[b:], Data8[:20]) + b += int(20) + + // Create the Union type + v := ClientMessageDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Data8 = make([]byte, 20) + copy(v.Data8[:20], buf[b:]) + b += int(20) + + b = 0 // always read the same bytes + v.Data16 = make([]uint16, 10) + for i := 0; i < int(10); i++ { + v.Data16[i] = xgb.Get16(buf[b:]) + b += 2 + } + + b = 0 // always read the same bytes + v.Data32 = make([]uint32, 5) + for i := 0; i < int(5); i++ { + v.Data32[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// ClientMessageDataUnionData16New constructs a new ClientMessageDataUnion union type with the Data16 field. +func ClientMessageDataUnionData16New(Data16 []uint16) ClientMessageDataUnion { + var b int + buf := make([]byte, 20) + + for i := 0; i < int(10); i++ { + xgb.Put16(buf[b:], Data16[i]) + b += 2 + } + + // Create the Union type + v := ClientMessageDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Data8 = make([]byte, 20) + copy(v.Data8[:20], buf[b:]) + b += int(20) + + b = 0 // always read the same bytes + v.Data16 = make([]uint16, 10) + for i := 0; i < int(10); i++ { + v.Data16[i] = xgb.Get16(buf[b:]) + b += 2 + } + + b = 0 // always read the same bytes + v.Data32 = make([]uint32, 5) + for i := 0; i < int(5); i++ { + v.Data32[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// ClientMessageDataUnionData32New constructs a new ClientMessageDataUnion union type with the Data32 field. +func ClientMessageDataUnionData32New(Data32 []uint32) ClientMessageDataUnion { + var b int + buf := make([]byte, 20) + + for i := 0; i < int(5); i++ { + xgb.Put32(buf[b:], Data32[i]) + b += 4 + } + + // Create the Union type + v := ClientMessageDataUnion{} + + // Now copy buf into all fields + + b = 0 // always read the same bytes + v.Data8 = make([]byte, 20) + copy(v.Data8[:20], buf[b:]) + b += int(20) + + b = 0 // always read the same bytes + v.Data16 = make([]uint16, 10) + for i := 0; i < int(10); i++ { + v.Data16[i] = xgb.Get16(buf[b:]) + b += 2 + } + + b = 0 // always read the same bytes + v.Data32 = make([]uint32, 5) + for i := 0; i < int(5); i++ { + v.Data32[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// ClientMessageDataUnionRead reads a byte slice into a ClientMessageDataUnion value. +func ClientMessageDataUnionRead(buf []byte, v *ClientMessageDataUnion) int { + var b int + + b = 0 // re-read the same bytes + v.Data8 = make([]byte, 20) + copy(v.Data8[:20], buf[b:]) + b += int(20) + + b = 0 // re-read the same bytes + v.Data16 = make([]uint16, 10) + for i := 0; i < int(10); i++ { + v.Data16[i] = xgb.Get16(buf[b:]) + b += 2 + } + + b = 0 // re-read the same bytes + v.Data32 = make([]uint32, 5) + for i := 0; i < int(5); i++ { + v.Data32[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return 20 +} + +// ClientMessageDataUnionReadList reads a byte slice into a list of ClientMessageDataUnion values. +func ClientMessageDataUnionReadList(buf []byte, dest []ClientMessageDataUnion) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ClientMessageDataUnion{} + b += ClientMessageDataUnionRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ClientMessageDataUnion value to a byte slice. +// Each field in a union must contain the same data. +// So simply pick the first field and write that to the wire. +func (v ClientMessageDataUnion) Bytes() []byte { + buf := make([]byte, 20) + b := 0 + + copy(buf[b:], v.Data8[:20]) + b += int(20) + return buf +} + +// ClientMessageDataUnionListBytes writes a list of ClientMessageDataUnion values to a byte slice. +func ClientMessageDataUnionListBytes(buf []byte, list []ClientMessageDataUnion) int { + b := 0 + var unionBytes []byte + for _, item := range list { + unionBytes = item.Bytes() + copy(buf[b:], unionBytes) + b += xgb.Pad(len(unionBytes)) + } + return b +} + +const ( + ClipOrderingUnsorted = 0 + ClipOrderingYSorted = 1 + ClipOrderingYXSorted = 2 + ClipOrderingYXBanded = 3 +) + +const ( + CloseDownDestroyAll = 0 + CloseDownRetainPermanent = 1 + CloseDownRetainTemporary = 2 +) + +const ( + ColorFlagRed = 1 + ColorFlagGreen = 2 + ColorFlagBlue = 4 +) + +type Coloritem struct { + Pixel uint32 + Red uint16 + Green uint16 + Blue uint16 + Flags byte + // padding: 1 bytes +} + +// ColoritemRead reads a byte slice into a Coloritem value. +func ColoritemRead(buf []byte, v *Coloritem) int { + b := 0 + + v.Pixel = xgb.Get32(buf[b:]) + b += 4 + + v.Red = xgb.Get16(buf[b:]) + b += 2 + + v.Green = xgb.Get16(buf[b:]) + b += 2 + + v.Blue = xgb.Get16(buf[b:]) + b += 2 + + v.Flags = buf[b] + b += 1 + + b += 1 // padding + + return b +} + +// ColoritemReadList reads a byte slice into a list of Coloritem values. +func ColoritemReadList(buf []byte, dest []Coloritem) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Coloritem{} + b += ColoritemRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Coloritem value to a byte slice. +func (v Coloritem) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + xgb.Put32(buf[b:], v.Pixel) + b += 4 + + xgb.Put16(buf[b:], v.Red) + b += 2 + + xgb.Put16(buf[b:], v.Green) + b += 2 + + xgb.Put16(buf[b:], v.Blue) + b += 2 + + buf[b] = v.Flags + b += 1 + + b += 1 // padding + + return buf[:b] +} + +// ColoritemListBytes writes a list of Coloritem values to a byte slice. +func ColoritemListBytes(buf []byte, list []Coloritem) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Colormap uint32 + +func NewColormapId(c *xgb.Conn) (Colormap, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Colormap(id), nil +} + +const ( + ColormapNone = 0 +) + +// BadColormap is the error number for a BadColormap. +const BadColormap = 12 + +type ColormapError ValueError + +// ColormapErrorNew constructs a ColormapError value that implements xgb.Error from a byte slice. +func ColormapErrorNew(buf []byte) xgb.Error { + v := ColormapError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Colormap" + return v +} + +// SequenceId returns the sequence id attached to the BadColormap error. +// This is mostly used internally. +func (err ColormapError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadColormap error. If no bad value exists, 0 is returned. +func (err ColormapError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadColormap error. +func (err ColormapError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadColormap {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[12] = ColormapErrorNew +} + +const ( + ColormapAllocNone = 0 + ColormapAllocAll = 1 +) + +// ColormapNotify is the event number for a ColormapNotifyEvent. +const ColormapNotify = 32 + +type ColormapNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Window Window + Colormap Colormap + New bool + State byte + // padding: 2 bytes +} + +// ColormapNotifyEventNew constructs a ColormapNotifyEvent value that implements xgb.Event from a byte slice. +func ColormapNotifyEventNew(buf []byte) xgb.Event { + v := ColormapNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Colormap = Colormap(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.New = true + } else { + v.New = false + } + b += 1 + + v.State = buf[b] + b += 1 + + b += 2 // padding + + return v +} + +// Bytes writes a ColormapNotifyEvent value to a byte slice. +func (v ColormapNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 32 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Colormap)) + b += 4 + + if v.New { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + buf[b] = v.State + b += 1 + + b += 2 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the ColormapNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ColormapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ColormapNotifyEvent. +func (v ColormapNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Colormap: %d", v.Colormap)) + fieldVals = append(fieldVals, xgb.Sprintf("New: %t", v.New)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + return "ColormapNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[32] = ColormapNotifyEventNew +} + +const ( + ColormapStateUninstalled = 0 + ColormapStateInstalled = 1 +) + +const ( + ConfigWindowX = 1 + ConfigWindowY = 2 + ConfigWindowWidth = 4 + ConfigWindowHeight = 8 + ConfigWindowBorderWidth = 16 + ConfigWindowSibling = 32 + ConfigWindowStackMode = 64 +) + +// ConfigureNotify is the event number for a ConfigureNotifyEvent. +const ConfigureNotify = 22 + +type ConfigureNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + AboveSibling Window + X int16 + Y int16 + Width uint16 + Height uint16 + BorderWidth uint16 + OverrideRedirect bool + // padding: 1 bytes +} + +// ConfigureNotifyEventNew constructs a ConfigureNotifyEvent value that implements xgb.Event from a byte slice. +func ConfigureNotifyEventNew(buf []byte) xgb.Event { + v := ConfigureNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.AboveSibling = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.BorderWidth = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.OverrideRedirect = true + } else { + v.OverrideRedirect = false + } + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a ConfigureNotifyEvent value to a byte slice. +func (v ConfigureNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 22 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.AboveSibling)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.BorderWidth) + b += 2 + + if v.OverrideRedirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the ConfigureNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ConfigureNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ConfigureNotifyEvent. +func (v ConfigureNotifyEvent) String() string { + fieldVals := make([]string, 0, 11) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("AboveSibling: %d", v.AboveSibling)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("BorderWidth: %d", v.BorderWidth)) + fieldVals = append(fieldVals, xgb.Sprintf("OverrideRedirect: %t", v.OverrideRedirect)) + return "ConfigureNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[22] = ConfigureNotifyEventNew +} + +// ConfigureRequest is the event number for a ConfigureRequestEvent. +const ConfigureRequest = 23 + +type ConfigureRequestEvent struct { + Sequence uint16 + StackMode byte + Parent Window + Window Window + Sibling Window + X int16 + Y int16 + Width uint16 + Height uint16 + BorderWidth uint16 + ValueMask uint16 +} + +// ConfigureRequestEventNew constructs a ConfigureRequestEvent value that implements xgb.Event from a byte slice. +func ConfigureRequestEventNew(buf []byte) xgb.Event { + v := ConfigureRequestEvent{} + b := 1 // don't read event number + + v.StackMode = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Parent = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Sibling = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.BorderWidth = xgb.Get16(buf[b:]) + b += 2 + + v.ValueMask = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Bytes writes a ConfigureRequestEvent value to a byte slice. +func (v ConfigureRequestEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 23 + b += 1 + + buf[b] = v.StackMode + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Parent)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Sibling)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.BorderWidth) + b += 2 + + xgb.Put16(buf[b:], v.ValueMask) + b += 2 + + return buf +} + +// SequenceId returns the sequence id attached to the ConfigureRequest event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ConfigureRequestEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ConfigureRequestEvent. +func (v ConfigureRequestEvent) String() string { + fieldVals := make([]string, 0, 10) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("StackMode: %d", v.StackMode)) + fieldVals = append(fieldVals, xgb.Sprintf("Parent: %d", v.Parent)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Sibling: %d", v.Sibling)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("BorderWidth: %d", v.BorderWidth)) + fieldVals = append(fieldVals, xgb.Sprintf("ValueMask: %d", v.ValueMask)) + return "ConfigureRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[23] = ConfigureRequestEventNew +} + +const ( + CoordModeOrigin = 0 + CoordModePrevious = 1 +) + +// CreateNotify is the event number for a CreateNotifyEvent. +const CreateNotify = 16 + +type CreateNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Parent Window + Window Window + X int16 + Y int16 + Width uint16 + Height uint16 + BorderWidth uint16 + OverrideRedirect bool + // padding: 1 bytes +} + +// CreateNotifyEventNew constructs a CreateNotifyEvent value that implements xgb.Event from a byte slice. +func CreateNotifyEventNew(buf []byte) xgb.Event { + v := CreateNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Parent = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.BorderWidth = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.OverrideRedirect = true + } else { + v.OverrideRedirect = false + } + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a CreateNotifyEvent value to a byte slice. +func (v CreateNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 16 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Parent)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.BorderWidth) + b += 2 + + if v.OverrideRedirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the CreateNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v CreateNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of CreateNotifyEvent. +func (v CreateNotifyEvent) String() string { + fieldVals := make([]string, 0, 10) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Parent: %d", v.Parent)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("BorderWidth: %d", v.BorderWidth)) + fieldVals = append(fieldVals, xgb.Sprintf("OverrideRedirect: %t", v.OverrideRedirect)) + return "CreateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[16] = CreateNotifyEventNew +} + +type Cursor uint32 + +func NewCursorId(c *xgb.Conn) (Cursor, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Cursor(id), nil +} + +// BadCursor is the error number for a BadCursor. +const BadCursor = 6 + +type CursorError ValueError + +// CursorErrorNew constructs a CursorError value that implements xgb.Error from a byte slice. +func CursorErrorNew(buf []byte) xgb.Error { + v := CursorError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Cursor" + return v +} + +// SequenceId returns the sequence id attached to the BadCursor error. +// This is mostly used internally. +func (err CursorError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadCursor error. If no bad value exists, 0 is returned. +func (err CursorError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadCursor error. +func (err CursorError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadCursor {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[6] = CursorErrorNew +} + +const ( + CursorNone = 0 +) + +const ( + CwBackPixmap = 1 + CwBackPixel = 2 + CwBorderPixmap = 4 + CwBorderPixel = 8 + CwBitGravity = 16 + CwWinGravity = 32 + CwBackingStore = 64 + CwBackingPlanes = 128 + CwBackingPixel = 256 + CwOverrideRedirect = 512 + CwSaveUnder = 1024 + CwEventMask = 2048 + CwDontPropagate = 4096 + CwColormap = 8192 + CwCursor = 16384 +) + +type DepthInfo struct { + Depth byte + // padding: 1 bytes + VisualsLen uint16 + // padding: 4 bytes + Visuals []VisualInfo // size: xgb.Pad((int(VisualsLen) * 24)) +} + +// DepthInfoRead reads a byte slice into a DepthInfo value. +func DepthInfoRead(buf []byte, v *DepthInfo) int { + b := 0 + + v.Depth = buf[b] + b += 1 + + b += 1 // padding + + v.VisualsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 4 // padding + + v.Visuals = make([]VisualInfo, v.VisualsLen) + b += VisualInfoReadList(buf[b:], v.Visuals) + + return b +} + +// DepthInfoReadList reads a byte slice into a list of DepthInfo values. +func DepthInfoReadList(buf []byte, dest []DepthInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = DepthInfo{} + b += DepthInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a DepthInfo value to a byte slice. +func (v DepthInfo) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.VisualsLen) * 24)))) + b := 0 + + buf[b] = v.Depth + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], v.VisualsLen) + b += 2 + + b += 4 // padding + + b += VisualInfoListBytes(buf[b:], v.Visuals) + + return buf[:b] +} + +// DepthInfoListBytes writes a list of DepthInfo values to a byte slice. +func DepthInfoListBytes(buf []byte, list []DepthInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// DepthInfoListSize computes the size (bytes) of a list of DepthInfo values. +func DepthInfoListSize(list []DepthInfo) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.VisualsLen) * 24))) + } + return size +} + +// DestroyNotify is the event number for a DestroyNotifyEvent. +const DestroyNotify = 17 + +type DestroyNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window +} + +// DestroyNotifyEventNew constructs a DestroyNotifyEvent value that implements xgb.Event from a byte slice. +func DestroyNotifyEventNew(buf []byte) xgb.Event { + v := DestroyNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a DestroyNotifyEvent value to a byte slice. +func (v DestroyNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 17 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the DestroyNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DestroyNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of DestroyNotifyEvent. +func (v DestroyNotifyEvent) String() string { + fieldVals := make([]string, 0, 3) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + return "DestroyNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[17] = DestroyNotifyEventNew +} + +type Drawable uint32 + +func NewDrawableId(c *xgb.Conn) (Drawable, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Drawable(id), nil +} + +// BadDrawable is the error number for a BadDrawable. +const BadDrawable = 9 + +type DrawableError ValueError + +// DrawableErrorNew constructs a DrawableError value that implements xgb.Error from a byte slice. +func DrawableErrorNew(buf []byte) xgb.Error { + v := DrawableError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Drawable" + return v +} + +// SequenceId returns the sequence id attached to the BadDrawable error. +// This is mostly used internally. +func (err DrawableError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadDrawable error. If no bad value exists, 0 is returned. +func (err DrawableError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadDrawable error. +func (err DrawableError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadDrawable {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[9] = DrawableErrorNew +} + +// EnterNotify is the event number for a EnterNotifyEvent. +const EnterNotify = 7 + +type EnterNotifyEvent struct { + Sequence uint16 + Detail byte + Time Timestamp + Root Window + Event Window + Child Window + RootX int16 + RootY int16 + EventX int16 + EventY int16 + State uint16 + Mode byte + SameScreenFocus byte +} + +// EnterNotifyEventNew constructs a EnterNotifyEvent value that implements xgb.Event from a byte slice. +func EnterNotifyEventNew(buf []byte) xgb.Event { + v := EnterNotifyEvent{} + b := 1 // don't read event number + + v.Detail = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.State = xgb.Get16(buf[b:]) + b += 2 + + v.Mode = buf[b] + b += 1 + + v.SameScreenFocus = buf[b] + b += 1 + + return v +} + +// Bytes writes a EnterNotifyEvent value to a byte slice. +func (v EnterNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 7 + b += 1 + + buf[b] = v.Detail + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Child)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.RootX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.RootY)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventY)) + b += 2 + + xgb.Put16(buf[b:], v.State) + b += 2 + + buf[b] = v.Mode + b += 1 + + buf[b] = v.SameScreenFocus + b += 1 + + return buf +} + +// SequenceId returns the sequence id attached to the EnterNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v EnterNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of EnterNotifyEvent. +func (v EnterNotifyEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreenFocus: %d", v.SameScreenFocus)) + return "EnterNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[7] = EnterNotifyEventNew +} + +const ( + EventMaskNoEvent = 0 + EventMaskKeyPress = 1 + EventMaskKeyRelease = 2 + EventMaskButtonPress = 4 + EventMaskButtonRelease = 8 + EventMaskEnterWindow = 16 + EventMaskLeaveWindow = 32 + EventMaskPointerMotion = 64 + EventMaskPointerMotionHint = 128 + EventMaskButton1Motion = 256 + EventMaskButton2Motion = 512 + EventMaskButton3Motion = 1024 + EventMaskButton4Motion = 2048 + EventMaskButton5Motion = 4096 + EventMaskButtonMotion = 8192 + EventMaskKeymapState = 16384 + EventMaskExposure = 32768 + EventMaskVisibilityChange = 65536 + EventMaskStructureNotify = 131072 + EventMaskResizeRedirect = 262144 + EventMaskSubstructureNotify = 524288 + EventMaskSubstructureRedirect = 1048576 + EventMaskFocusChange = 2097152 + EventMaskPropertyChange = 4194304 + EventMaskColorMapChange = 8388608 + EventMaskOwnerGrabButton = 16777216 +) + +// Expose is the event number for a ExposeEvent. +const Expose = 12 + +type ExposeEvent struct { + Sequence uint16 + // padding: 1 bytes + Window Window + X uint16 + Y uint16 + Width uint16 + Height uint16 + Count uint16 + // padding: 2 bytes +} + +// ExposeEventNew constructs a ExposeEvent value that implements xgb.Event from a byte slice. +func ExposeEventNew(buf []byte) xgb.Event { + v := ExposeEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = xgb.Get16(buf[b:]) + b += 2 + + v.Y = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.Count = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + return v +} + +// Bytes writes a ExposeEvent value to a byte slice. +func (v ExposeEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 12 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put16(buf[b:], v.X) + b += 2 + + xgb.Put16(buf[b:], v.Y) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.Count) + b += 2 + + b += 2 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the Expose event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ExposeEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ExposeEvent. +func (v ExposeEvent) String() string { + fieldVals := make([]string, 0, 8) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) + return "Expose {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[12] = ExposeEventNew +} + +const ( + ExposuresNotAllowed = 0 + ExposuresAllowed = 1 + ExposuresDefault = 2 +) + +const ( + FamilyInternet = 0 + FamilyDECnet = 1 + FamilyChaos = 2 + FamilyServerInterpreted = 5 + FamilyInternet6 = 6 +) + +const ( + FillRuleEvenOdd = 0 + FillRuleWinding = 1 +) + +const ( + FillStyleSolid = 0 + FillStyleTiled = 1 + FillStyleStippled = 2 + FillStyleOpaqueStippled = 3 +) + +// FocusIn is the event number for a FocusInEvent. +const FocusIn = 9 + +type FocusInEvent struct { + Sequence uint16 + Detail byte + Event Window + Mode byte + // padding: 3 bytes +} + +// FocusInEventNew constructs a FocusInEvent value that implements xgb.Event from a byte slice. +func FocusInEventNew(buf []byte) xgb.Event { + v := FocusInEvent{} + b := 1 // don't read event number + + v.Detail = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Mode = buf[b] + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a FocusInEvent value to a byte slice. +func (v FocusInEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 9 + b += 1 + + buf[b] = v.Detail + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + buf[b] = v.Mode + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the FocusIn event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v FocusInEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of FocusInEvent. +func (v FocusInEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + return "FocusIn {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[9] = FocusInEventNew +} + +// FocusOut is the event number for a FocusOutEvent. +const FocusOut = 10 + +type FocusOutEvent FocusInEvent + +// FocusOutEventNew constructs a FocusOutEvent value that implements xgb.Event from a byte slice. +func FocusOutEventNew(buf []byte) xgb.Event { + return FocusOutEvent(FocusInEventNew(buf).(FocusInEvent)) +} + +// Bytes writes a FocusOutEvent value to a byte slice. +func (v FocusOutEvent) Bytes() []byte { + return FocusInEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the FocusOut event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v FocusOutEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v FocusOutEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + return "FocusOut {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[10] = FocusOutEventNew +} + +type Font uint32 + +func NewFontId(c *xgb.Conn) (Font, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Font(id), nil +} + +const ( + FontNone = 0 +) + +// BadFont is the error number for a BadFont. +const BadFont = 7 + +type FontError ValueError + +// FontErrorNew constructs a FontError value that implements xgb.Error from a byte slice. +func FontErrorNew(buf []byte) xgb.Error { + v := FontError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Font" + return v +} + +// SequenceId returns the sequence id attached to the BadFont error. +// This is mostly used internally. +func (err FontError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadFont error. If no bad value exists, 0 is returned. +func (err FontError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadFont error. +func (err FontError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadFont {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[7] = FontErrorNew +} + +const ( + FontDrawLeftToRight = 0 + FontDrawRightToLeft = 1 +) + +type Fontable uint32 + +func NewFontableId(c *xgb.Conn) (Fontable, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Fontable(id), nil +} + +type Fontprop struct { + Name Atom + Value uint32 +} + +// FontpropRead reads a byte slice into a Fontprop value. +func FontpropRead(buf []byte, v *Fontprop) int { + b := 0 + + v.Name = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Value = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// FontpropReadList reads a byte slice into a list of Fontprop values. +func FontpropReadList(buf []byte, dest []Fontprop) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Fontprop{} + b += FontpropRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Fontprop value to a byte slice. +func (v Fontprop) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Name)) + b += 4 + + xgb.Put32(buf[b:], v.Value) + b += 4 + + return buf[:b] +} + +// FontpropListBytes writes a list of Fontprop values to a byte slice. +func FontpropListBytes(buf []byte, list []Fontprop) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Format struct { + Depth byte + BitsPerPixel byte + ScanlinePad byte + // padding: 5 bytes +} + +// FormatRead reads a byte slice into a Format value. +func FormatRead(buf []byte, v *Format) int { + b := 0 + + v.Depth = buf[b] + b += 1 + + v.BitsPerPixel = buf[b] + b += 1 + + v.ScanlinePad = buf[b] + b += 1 + + b += 5 // padding + + return b +} + +// FormatReadList reads a byte slice into a list of Format values. +func FormatReadList(buf []byte, dest []Format) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Format{} + b += FormatRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Format value to a byte slice. +func (v Format) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + buf[b] = v.Depth + b += 1 + + buf[b] = v.BitsPerPixel + b += 1 + + buf[b] = v.ScanlinePad + b += 1 + + b += 5 // padding + + return buf[:b] +} + +// FormatListBytes writes a list of Format values to a byte slice. +func FormatListBytes(buf []byte, list []Format) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// BadGContext is the error number for a BadGContext. +const BadGContext = 13 + +type GContextError ValueError + +// GContextErrorNew constructs a GContextError value that implements xgb.Error from a byte slice. +func GContextErrorNew(buf []byte) xgb.Error { + v := GContextError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "GContext" + return v +} + +// SequenceId returns the sequence id attached to the BadGContext error. +// This is mostly used internally. +func (err GContextError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadGContext error. If no bad value exists, 0 is returned. +func (err GContextError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadGContext error. +func (err GContextError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadGContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[13] = GContextErrorNew +} + +const ( + GcFunction = 1 + GcPlaneMask = 2 + GcForeground = 4 + GcBackground = 8 + GcLineWidth = 16 + GcLineStyle = 32 + GcCapStyle = 64 + GcJoinStyle = 128 + GcFillStyle = 256 + GcFillRule = 512 + GcTile = 1024 + GcStipple = 2048 + GcTileStippleOriginX = 4096 + GcTileStippleOriginY = 8192 + GcFont = 16384 + GcSubwindowMode = 32768 + GcGraphicsExposures = 65536 + GcClipOriginX = 131072 + GcClipOriginY = 262144 + GcClipMask = 524288 + GcDashOffset = 1048576 + GcDashList = 2097152 + GcArcMode = 4194304 +) + +type Gcontext uint32 + +func NewGcontextId(c *xgb.Conn) (Gcontext, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Gcontext(id), nil +} + +// GeGeneric is the event number for a GeGenericEvent. +const GeGeneric = 35 + +type GeGenericEvent struct { + Sequence uint16 + // padding: 22 bytes +} + +// GeGenericEventNew constructs a GeGenericEvent value that implements xgb.Event from a byte slice. +func GeGenericEventNew(buf []byte) xgb.Event { + v := GeGenericEvent{} + b := 1 // don't read event number + + b += 22 // padding + + return v +} + +// Bytes writes a GeGenericEvent value to a byte slice. +func (v GeGenericEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 35 + b += 1 + + b += 22 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the GeGeneric event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v GeGenericEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of GeGenericEvent. +func (v GeGenericEvent) String() string { + fieldVals := make([]string, 0, 1) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + return "GeGeneric {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[35] = GeGenericEventNew +} + +const ( + GetPropertyTypeAny = 0 +) + +const ( + GrabAny = 0 +) + +const ( + GrabModeSync = 0 + GrabModeAsync = 1 +) + +const ( + GrabStatusSuccess = 0 + GrabStatusAlreadyGrabbed = 1 + GrabStatusInvalidTime = 2 + GrabStatusNotViewable = 3 + GrabStatusFrozen = 4 +) + +// GraphicsExposure is the event number for a GraphicsExposureEvent. +const GraphicsExposure = 13 + +type GraphicsExposureEvent struct { + Sequence uint16 + // padding: 1 bytes + Drawable Drawable + X uint16 + Y uint16 + Width uint16 + Height uint16 + MinorOpcode uint16 + Count uint16 + MajorOpcode byte + // padding: 3 bytes +} + +// GraphicsExposureEventNew constructs a GraphicsExposureEvent value that implements xgb.Event from a byte slice. +func GraphicsExposureEventNew(buf []byte) xgb.Event { + v := GraphicsExposureEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.X = xgb.Get16(buf[b:]) + b += 2 + + v.Y = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.MinorOpcode = xgb.Get16(buf[b:]) + b += 2 + + v.Count = xgb.Get16(buf[b:]) + b += 2 + + v.MajorOpcode = buf[b] + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a GraphicsExposureEvent value to a byte slice. +func (v GraphicsExposureEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 13 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put16(buf[b:], v.X) + b += 2 + + xgb.Put16(buf[b:], v.Y) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put16(buf[b:], v.MinorOpcode) + b += 2 + + xgb.Put16(buf[b:], v.Count) + b += 2 + + buf[b] = v.MajorOpcode + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the GraphicsExposure event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v GraphicsExposureEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of GraphicsExposureEvent. +func (v GraphicsExposureEvent) String() string { + fieldVals := make([]string, 0, 10) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", v.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", v.MajorOpcode)) + return "GraphicsExposure {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[13] = GraphicsExposureEventNew +} + +const ( + GravityBitForget = 0 + GravityWinUnmap = 0 + GravityNorthWest = 1 + GravityNorth = 2 + GravityNorthEast = 3 + GravityWest = 4 + GravityCenter = 5 + GravityEast = 6 + GravitySouthWest = 7 + GravitySouth = 8 + GravitySouthEast = 9 + GravityStatic = 10 +) + +// GravityNotify is the event number for a GravityNotifyEvent. +const GravityNotify = 24 + +type GravityNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + X int16 + Y int16 +} + +// GravityNotifyEventNew constructs a GravityNotifyEvent value that implements xgb.Event from a byte slice. +func GravityNotifyEventNew(buf []byte) xgb.Event { + v := GravityNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + return v +} + +// Bytes writes a GravityNotifyEvent value to a byte slice. +func (v GravityNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 24 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + return buf +} + +// SequenceId returns the sequence id attached to the GravityNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v GravityNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of GravityNotifyEvent. +func (v GravityNotifyEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + return "GravityNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[24] = GravityNotifyEventNew +} + +const ( + GxClear = 0 + GxAnd = 1 + GxAndReverse = 2 + GxCopy = 3 + GxAndInverted = 4 + GxNoop = 5 + GxXor = 6 + GxOr = 7 + GxNor = 8 + GxEquiv = 9 + GxInvert = 10 + GxOrReverse = 11 + GxCopyInverted = 12 + GxOrInverted = 13 + GxNand = 14 + GxSet = 15 +) + +type Host struct { + Family byte + // padding: 1 bytes + AddressLen uint16 + Address []byte // size: xgb.Pad((int(AddressLen) * 1)) + // alignment gap to multiple of 4 +} + +// HostRead reads a byte slice into a Host value. +func HostRead(buf []byte, v *Host) int { + b := 0 + + v.Family = buf[b] + b += 1 + + b += 1 // padding + + v.AddressLen = xgb.Get16(buf[b:]) + b += 2 + + v.Address = make([]byte, v.AddressLen) + copy(v.Address[:v.AddressLen], buf[b:]) + b += int(v.AddressLen) + + b = (b + 3) & ^3 // alignment gap + + return b +} + +// HostReadList reads a byte slice into a list of Host values. +func HostReadList(buf []byte, dest []Host) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Host{} + b += HostRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Host value to a byte slice. +func (v Host) Bytes() []byte { + buf := make([]byte, ((4 + xgb.Pad((int(v.AddressLen) * 1))) + 4)) + b := 0 + + buf[b] = v.Family + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], v.AddressLen) + b += 2 + + copy(buf[b:], v.Address[:v.AddressLen]) + b += int(v.AddressLen) + + b = (b + 3) & ^3 // alignment gap + + return buf[:b] +} + +// HostListBytes writes a list of Host values to a byte slice. +func HostListBytes(buf []byte, list []Host) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// HostListSize computes the size (bytes) of a list of Host values. +func HostListSize(list []Host) int { + size := 0 + for _, item := range list { + size += ((4 + xgb.Pad((int(item.AddressLen) * 1))) + 4) + } + return size +} + +const ( + HostModeInsert = 0 + HostModeDelete = 1 +) + +// BadIDChoice is the error number for a BadIDChoice. +const BadIDChoice = 14 + +type IDChoiceError ValueError + +// IDChoiceErrorNew constructs a IDChoiceError value that implements xgb.Error from a byte slice. +func IDChoiceErrorNew(buf []byte) xgb.Error { + v := IDChoiceError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "IDChoice" + return v +} + +// SequenceId returns the sequence id attached to the BadIDChoice error. +// This is mostly used internally. +func (err IDChoiceError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadIDChoice error. If no bad value exists, 0 is returned. +func (err IDChoiceError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadIDChoice error. +func (err IDChoiceError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadIDChoice {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[14] = IDChoiceErrorNew +} + +const ( + ImageFormatXYBitmap = 0 + ImageFormatXYPixmap = 1 + ImageFormatZPixmap = 2 +) + +const ( + ImageOrderLSBFirst = 0 + ImageOrderMSBFirst = 1 +) + +// BadImplementation is the error number for a BadImplementation. +const BadImplementation = 17 + +type ImplementationError RequestError + +// ImplementationErrorNew constructs a ImplementationError value that implements xgb.Error from a byte slice. +func ImplementationErrorNew(buf []byte) xgb.Error { + v := ImplementationError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Implementation" + return v +} + +// SequenceId returns the sequence id attached to the BadImplementation error. +// This is mostly used internally. +func (err ImplementationError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadImplementation error. If no bad value exists, 0 is returned. +func (err ImplementationError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadImplementation error. +func (err ImplementationError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadImplementation {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[17] = ImplementationErrorNew +} + +const ( + InputFocusNone = 0 + InputFocusPointerRoot = 1 + InputFocusParent = 2 + InputFocusFollowKeyboard = 3 +) + +const ( + JoinStyleMiter = 0 + JoinStyleRound = 1 + JoinStyleBevel = 2 +) + +const ( + KbKeyClickPercent = 1 + KbBellPercent = 2 + KbBellPitch = 4 + KbBellDuration = 8 + KbLed = 16 + KbLedMode = 32 + KbKey = 64 + KbAutoRepeatMode = 128 +) + +const ( + KeyButMaskShift = 1 + KeyButMaskLock = 2 + KeyButMaskControl = 4 + KeyButMaskMod1 = 8 + KeyButMaskMod2 = 16 + KeyButMaskMod3 = 32 + KeyButMaskMod4 = 64 + KeyButMaskMod5 = 128 + KeyButMaskButton1 = 256 + KeyButMaskButton2 = 512 + KeyButMaskButton3 = 1024 + KeyButMaskButton4 = 2048 + KeyButMaskButton5 = 4096 +) + +// KeyPress is the event number for a KeyPressEvent. +const KeyPress = 2 + +type KeyPressEvent struct { + Sequence uint16 + Detail Keycode + Time Timestamp + Root Window + Event Window + Child Window + RootX int16 + RootY int16 + EventX int16 + EventY int16 + State uint16 + SameScreen bool + // padding: 1 bytes +} + +// KeyPressEventNew constructs a KeyPressEvent value that implements xgb.Event from a byte slice. +func KeyPressEventNew(buf []byte) xgb.Event { + v := KeyPressEvent{} + b := 1 // don't read event number + + v.Detail = Keycode(buf[b]) + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.State = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a KeyPressEvent value to a byte slice. +func (v KeyPressEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 2 + b += 1 + + buf[b] = byte(v.Detail) + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Child)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.RootX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.RootY)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventY)) + b += 2 + + xgb.Put16(buf[b:], v.State) + b += 2 + + if v.SameScreen { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the KeyPress event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v KeyPressEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of KeyPressEvent. +func (v KeyPressEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + return "KeyPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[2] = KeyPressEventNew +} + +// KeyRelease is the event number for a KeyReleaseEvent. +const KeyRelease = 3 + +type KeyReleaseEvent KeyPressEvent + +// KeyReleaseEventNew constructs a KeyReleaseEvent value that implements xgb.Event from a byte slice. +func KeyReleaseEventNew(buf []byte) xgb.Event { + return KeyReleaseEvent(KeyPressEventNew(buf).(KeyPressEvent)) +} + +// Bytes writes a KeyReleaseEvent value to a byte slice. +func (v KeyReleaseEvent) Bytes() []byte { + return KeyPressEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the KeyRelease event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v KeyReleaseEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v KeyReleaseEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + return "KeyRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[3] = KeyReleaseEventNew +} + +type Keycode byte + +type Keycode32 uint32 + +// KeymapNotify is the event number for a KeymapNotifyEvent. +const KeymapNotify = 11 + +type KeymapNotifyEvent struct { + Keys []byte // size: 32 +} + +// KeymapNotifyEventNew constructs a KeymapNotifyEvent value that implements xgb.Event from a byte slice. +func KeymapNotifyEventNew(buf []byte) xgb.Event { + v := KeymapNotifyEvent{} + b := 1 // don't read event number + + v.Keys = make([]byte, 31) + copy(v.Keys[:31], buf[b:]) + b += int(31) + + return v +} + +// Bytes writes a KeymapNotifyEvent value to a byte slice. +func (v KeymapNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 11 + b += 1 + + copy(buf[b:], v.Keys[:31]) + b += int(31) + + return buf +} + +// SequenceId returns the sequence id attached to the KeymapNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v KeymapNotifyEvent) SequenceId() uint16 { + return uint16(0) +} + +// String is a rudimentary string representation of KeymapNotifyEvent. +func (v KeymapNotifyEvent) String() string { + fieldVals := make([]string, 0, 1) + return "KeymapNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[11] = KeymapNotifyEventNew +} + +type Keysym uint32 + +const ( + KillAllTemporary = 0 +) + +// LeaveNotify is the event number for a LeaveNotifyEvent. +const LeaveNotify = 8 + +type LeaveNotifyEvent EnterNotifyEvent + +// LeaveNotifyEventNew constructs a LeaveNotifyEvent value that implements xgb.Event from a byte slice. +func LeaveNotifyEventNew(buf []byte) xgb.Event { + return LeaveNotifyEvent(EnterNotifyEventNew(buf).(EnterNotifyEvent)) +} + +// Bytes writes a LeaveNotifyEvent value to a byte slice. +func (v LeaveNotifyEvent) Bytes() []byte { + return EnterNotifyEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the LeaveNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v LeaveNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v LeaveNotifyEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreenFocus: %d", v.SameScreenFocus)) + return "LeaveNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[8] = LeaveNotifyEventNew +} + +const ( + LedModeOff = 0 + LedModeOn = 1 +) + +// BadLength is the error number for a BadLength. +const BadLength = 16 + +type LengthError RequestError + +// LengthErrorNew constructs a LengthError value that implements xgb.Error from a byte slice. +func LengthErrorNew(buf []byte) xgb.Error { + v := LengthError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Length" + return v +} + +// SequenceId returns the sequence id attached to the BadLength error. +// This is mostly used internally. +func (err LengthError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadLength error. If no bad value exists, 0 is returned. +func (err LengthError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadLength error. +func (err LengthError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadLength {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[16] = LengthErrorNew +} + +const ( + LineStyleSolid = 0 + LineStyleOnOffDash = 1 + LineStyleDoubleDash = 2 +) + +const ( + MapIndexShift = 0 + MapIndexLock = 1 + MapIndexControl = 2 + MapIndex1 = 3 + MapIndex2 = 4 + MapIndex3 = 5 + MapIndex4 = 6 + MapIndex5 = 7 +) + +// MapNotify is the event number for a MapNotifyEvent. +const MapNotify = 19 + +type MapNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + OverrideRedirect bool + // padding: 3 bytes +} + +// MapNotifyEventNew constructs a MapNotifyEvent value that implements xgb.Event from a byte slice. +func MapNotifyEventNew(buf []byte) xgb.Event { + v := MapNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.OverrideRedirect = true + } else { + v.OverrideRedirect = false + } + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a MapNotifyEvent value to a byte slice. +func (v MapNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 19 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + if v.OverrideRedirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the MapNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v MapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of MapNotifyEvent. +func (v MapNotifyEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("OverrideRedirect: %t", v.OverrideRedirect)) + return "MapNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[19] = MapNotifyEventNew +} + +// MapRequest is the event number for a MapRequestEvent. +const MapRequest = 20 + +type MapRequestEvent struct { + Sequence uint16 + // padding: 1 bytes + Parent Window + Window Window +} + +// MapRequestEventNew constructs a MapRequestEvent value that implements xgb.Event from a byte slice. +func MapRequestEventNew(buf []byte) xgb.Event { + v := MapRequestEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Parent = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a MapRequestEvent value to a byte slice. +func (v MapRequestEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 20 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Parent)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the MapRequest event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v MapRequestEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of MapRequestEvent. +func (v MapRequestEvent) String() string { + fieldVals := make([]string, 0, 3) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Parent: %d", v.Parent)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + return "MapRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[20] = MapRequestEventNew +} + +const ( + MapStateUnmapped = 0 + MapStateUnviewable = 1 + MapStateViewable = 2 +) + +const ( + MappingModifier = 0 + MappingKeyboard = 1 + MappingPointer = 2 +) + +// MappingNotify is the event number for a MappingNotifyEvent. +const MappingNotify = 34 + +type MappingNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Request byte + FirstKeycode Keycode + Count byte + // padding: 1 bytes +} + +// MappingNotifyEventNew constructs a MappingNotifyEvent value that implements xgb.Event from a byte slice. +func MappingNotifyEventNew(buf []byte) xgb.Event { + v := MappingNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Request = buf[b] + b += 1 + + v.FirstKeycode = Keycode(buf[b]) + b += 1 + + v.Count = buf[b] + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a MappingNotifyEvent value to a byte slice. +func (v MappingNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 34 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + buf[b] = v.Request + b += 1 + + buf[b] = byte(v.FirstKeycode) + b += 1 + + buf[b] = v.Count + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the MappingNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v MappingNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of MappingNotifyEvent. +func (v MappingNotifyEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Request: %d", v.Request)) + fieldVals = append(fieldVals, xgb.Sprintf("FirstKeycode: %d", v.FirstKeycode)) + fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) + return "MappingNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[34] = MappingNotifyEventNew +} + +const ( + MappingStatusSuccess = 0 + MappingStatusBusy = 1 + MappingStatusFailure = 2 +) + +// BadMatch is the error number for a BadMatch. +const BadMatch = 8 + +type MatchError RequestError + +// MatchErrorNew constructs a MatchError value that implements xgb.Error from a byte slice. +func MatchErrorNew(buf []byte) xgb.Error { + v := MatchError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Match" + return v +} + +// SequenceId returns the sequence id attached to the BadMatch error. +// This is mostly used internally. +func (err MatchError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadMatch error. If no bad value exists, 0 is returned. +func (err MatchError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadMatch error. +func (err MatchError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadMatch {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[8] = MatchErrorNew +} + +const ( + ModMaskShift = 1 + ModMaskLock = 2 + ModMaskControl = 4 + ModMask1 = 8 + ModMask2 = 16 + ModMask3 = 32 + ModMask4 = 64 + ModMask5 = 128 + ModMaskAny = 32768 +) + +const ( + MotionNormal = 0 + MotionHint = 1 +) + +// MotionNotify is the event number for a MotionNotifyEvent. +const MotionNotify = 6 + +type MotionNotifyEvent struct { + Sequence uint16 + Detail byte + Time Timestamp + Root Window + Event Window + Child Window + RootX int16 + RootY int16 + EventX int16 + EventY int16 + State uint16 + SameScreen bool + // padding: 1 bytes +} + +// MotionNotifyEventNew constructs a MotionNotifyEvent value that implements xgb.Event from a byte slice. +func MotionNotifyEventNew(buf []byte) xgb.Event { + v := MotionNotifyEvent{} + b := 1 // don't read event number + + v.Detail = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.EventY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.State = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a MotionNotifyEvent value to a byte slice. +func (v MotionNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 6 + b += 1 + + buf[b] = v.Detail + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Child)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.RootX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.RootY)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventX)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.EventY)) + b += 2 + + xgb.Put16(buf[b:], v.State) + b += 2 + + if v.SameScreen { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the MotionNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v MotionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of MotionNotifyEvent. +func (v MotionNotifyEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + return "MotionNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[6] = MotionNotifyEventNew +} + +// BadName is the error number for a BadName. +const BadName = 15 + +type NameError RequestError + +// NameErrorNew constructs a NameError value that implements xgb.Error from a byte slice. +func NameErrorNew(buf []byte) xgb.Error { + v := NameError(RequestErrorNew(buf).(RequestError)) + v.NiceName = "Name" + return v +} + +// SequenceId returns the sequence id attached to the BadName error. +// This is mostly used internally. +func (err NameError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadName error. If no bad value exists, 0 is returned. +func (err NameError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadName error. +func (err NameError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadName {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[15] = NameErrorNew +} + +// NoExposure is the event number for a NoExposureEvent. +const NoExposure = 14 + +type NoExposureEvent struct { + Sequence uint16 + // padding: 1 bytes + Drawable Drawable + MinorOpcode uint16 + MajorOpcode byte + // padding: 1 bytes +} + +// NoExposureEventNew constructs a NoExposureEvent value that implements xgb.Event from a byte slice. +func NoExposureEventNew(buf []byte) xgb.Event { + v := NoExposureEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Drawable = Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.MinorOpcode = xgb.Get16(buf[b:]) + b += 2 + + v.MajorOpcode = buf[b] + b += 1 + + b += 1 // padding + + return v +} + +// Bytes writes a NoExposureEvent value to a byte slice. +func (v NoExposureEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 14 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put16(buf[b:], v.MinorOpcode) + b += 2 + + buf[b] = v.MajorOpcode + b += 1 + + b += 1 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the NoExposure event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v NoExposureEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of NoExposureEvent. +func (v NoExposureEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", v.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", v.MajorOpcode)) + return "NoExposure {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[14] = NoExposureEventNew +} + +const ( + NotifyDetailAncestor = 0 + NotifyDetailVirtual = 1 + NotifyDetailInferior = 2 + NotifyDetailNonlinear = 3 + NotifyDetailNonlinearVirtual = 4 + NotifyDetailPointer = 5 + NotifyDetailPointerRoot = 6 + NotifyDetailNone = 7 +) + +const ( + NotifyModeNormal = 0 + NotifyModeGrab = 1 + NotifyModeUngrab = 2 + NotifyModeWhileGrabbed = 3 +) + +type Pixmap uint32 + +func NewPixmapId(c *xgb.Conn) (Pixmap, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Pixmap(id), nil +} + +const ( + PixmapNone = 0 +) + +// BadPixmap is the error number for a BadPixmap. +const BadPixmap = 4 + +type PixmapError ValueError + +// PixmapErrorNew constructs a PixmapError value that implements xgb.Error from a byte slice. +func PixmapErrorNew(buf []byte) xgb.Error { + v := PixmapError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Pixmap" + return v +} + +// SequenceId returns the sequence id attached to the BadPixmap error. +// This is mostly used internally. +func (err PixmapError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadPixmap error. If no bad value exists, 0 is returned. +func (err PixmapError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadPixmap error. +func (err PixmapError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadPixmap {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[4] = PixmapErrorNew +} + +const ( + PlaceOnTop = 0 + PlaceOnBottom = 1 +) + +type Point struct { + X int16 + Y int16 +} + +// PointRead reads a byte slice into a Point value. +func PointRead(buf []byte, v *Point) int { + b := 0 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// PointReadList reads a byte slice into a list of Point values. +func PointReadList(buf []byte, dest []Point) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Point{} + b += PointRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Point value to a byte slice. +func (v Point) Bytes() []byte { + buf := make([]byte, 4) + b := 0 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + return buf[:b] +} + +// PointListBytes writes a list of Point values to a byte slice. +func PointListBytes(buf []byte, list []Point) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + PolyShapeComplex = 0 + PolyShapeNonconvex = 1 + PolyShapeConvex = 2 +) + +const ( + PropModeReplace = 0 + PropModePrepend = 1 + PropModeAppend = 2 +) + +const ( + PropertyNewValue = 0 + PropertyDelete = 1 +) + +// PropertyNotify is the event number for a PropertyNotifyEvent. +const PropertyNotify = 28 + +type PropertyNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Window Window + Atom Atom + Time Timestamp + State byte + // padding: 3 bytes +} + +// PropertyNotifyEventNew constructs a PropertyNotifyEvent value that implements xgb.Event from a byte slice. +func PropertyNotifyEventNew(buf []byte) xgb.Event { + v := PropertyNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Atom = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.State = buf[b] + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a PropertyNotifyEvent value to a byte slice. +func (v PropertyNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 28 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Atom)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + buf[b] = v.State + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the PropertyNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v PropertyNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of PropertyNotifyEvent. +func (v PropertyNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Atom: %d", v.Atom)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + return "PropertyNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[28] = PropertyNotifyEventNew +} + +const ( + QueryShapeOfLargestCursor = 0 + QueryShapeOfFastestTile = 1 + QueryShapeOfFastestStipple = 2 +) + +type Rectangle struct { + X int16 + Y int16 + Width uint16 + Height uint16 +} + +// RectangleRead reads a byte slice into a Rectangle value. +func RectangleRead(buf []byte, v *Rectangle) int { + b := 0 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// RectangleReadList reads a byte slice into a list of Rectangle values. +func RectangleReadList(buf []byte, dest []Rectangle) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Rectangle{} + b += RectangleRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Rectangle value to a byte slice. +func (v Rectangle) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + return buf[:b] +} + +// RectangleListBytes writes a list of Rectangle values to a byte slice. +func RectangleListBytes(buf []byte, list []Rectangle) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ReparentNotify is the event number for a ReparentNotifyEvent. +const ReparentNotify = 21 + +type ReparentNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + Parent Window + X int16 + Y int16 + OverrideRedirect bool + // padding: 3 bytes +} + +// ReparentNotifyEventNew constructs a ReparentNotifyEvent value that implements xgb.Event from a byte slice. +func ReparentNotifyEventNew(buf []byte) xgb.Event { + v := ReparentNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Parent = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + if buf[b] == 1 { + v.OverrideRedirect = true + } else { + v.OverrideRedirect = false + } + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a ReparentNotifyEvent value to a byte slice. +func (v ReparentNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 21 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Parent)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + if v.OverrideRedirect { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the ReparentNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ReparentNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ReparentNotifyEvent. +func (v ReparentNotifyEvent) String() string { + fieldVals := make([]string, 0, 8) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Parent: %d", v.Parent)) + fieldVals = append(fieldVals, xgb.Sprintf("X: %d", v.X)) + fieldVals = append(fieldVals, xgb.Sprintf("Y: %d", v.Y)) + fieldVals = append(fieldVals, xgb.Sprintf("OverrideRedirect: %t", v.OverrideRedirect)) + return "ReparentNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[21] = ReparentNotifyEventNew +} + +// BadRequest is the error number for a BadRequest. +const BadRequest = 1 + +type RequestError struct { + Sequence uint16 + NiceName string + BadValue uint32 + MinorOpcode uint16 + MajorOpcode byte + // padding: 1 bytes +} + +// RequestErrorNew constructs a RequestError value that implements xgb.Error from a byte slice. +func RequestErrorNew(buf []byte) xgb.Error { + v := RequestError{} + v.NiceName = "Request" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.BadValue = xgb.Get32(buf[b:]) + b += 4 + + v.MinorOpcode = xgb.Get16(buf[b:]) + b += 2 + + v.MajorOpcode = buf[b] + b += 1 + + b += 1 // padding + + return v +} + +// SequenceId returns the sequence id attached to the BadRequest error. +// This is mostly used internally. +func (err RequestError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadRequest error. If no bad value exists, 0 is returned. +func (err RequestError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadRequest error. + +func (err RequestError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[1] = RequestErrorNew +} + +// ResizeRequest is the event number for a ResizeRequestEvent. +const ResizeRequest = 25 + +type ResizeRequestEvent struct { + Sequence uint16 + // padding: 1 bytes + Window Window + Width uint16 + Height uint16 +} + +// ResizeRequestEventNew constructs a ResizeRequestEvent value that implements xgb.Event from a byte slice. +func ResizeRequestEventNew(buf []byte) xgb.Event { + v := ResizeRequestEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Bytes writes a ResizeRequestEvent value to a byte slice. +func (v ResizeRequestEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 25 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + return buf +} + +// SequenceId returns the sequence id attached to the ResizeRequest event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ResizeRequestEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of ResizeRequestEvent. +func (v ResizeRequestEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Width: %d", v.Width)) + fieldVals = append(fieldVals, xgb.Sprintf("Height: %d", v.Height)) + return "ResizeRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[25] = ResizeRequestEventNew +} + +type Rgb struct { + Red uint16 + Green uint16 + Blue uint16 + // padding: 2 bytes +} + +// RgbRead reads a byte slice into a Rgb value. +func RgbRead(buf []byte, v *Rgb) int { + b := 0 + + v.Red = xgb.Get16(buf[b:]) + b += 2 + + v.Green = xgb.Get16(buf[b:]) + b += 2 + + v.Blue = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + return b +} + +// RgbReadList reads a byte slice into a list of Rgb values. +func RgbReadList(buf []byte, dest []Rgb) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Rgb{} + b += RgbRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Rgb value to a byte slice. +func (v Rgb) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], v.Red) + b += 2 + + xgb.Put16(buf[b:], v.Green) + b += 2 + + xgb.Put16(buf[b:], v.Blue) + b += 2 + + b += 2 // padding + + return buf[:b] +} + +// RgbListBytes writes a list of Rgb values to a byte slice. +func RgbListBytes(buf []byte, list []Rgb) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type ScreenInfo struct { + Root Window + DefaultColormap Colormap + WhitePixel uint32 + BlackPixel uint32 + CurrentInputMasks uint32 + WidthInPixels uint16 + HeightInPixels uint16 + WidthInMillimeters uint16 + HeightInMillimeters uint16 + MinInstalledMaps uint16 + MaxInstalledMaps uint16 + RootVisual Visualid + BackingStores byte + SaveUnders bool + RootDepth byte + AllowedDepthsLen byte + AllowedDepths []DepthInfo // size: DepthInfoListSize(AllowedDepths) +} + +// ScreenInfoRead reads a byte slice into a ScreenInfo value. +func ScreenInfoRead(buf []byte, v *ScreenInfo) int { + b := 0 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.DefaultColormap = Colormap(xgb.Get32(buf[b:])) + b += 4 + + v.WhitePixel = xgb.Get32(buf[b:]) + b += 4 + + v.BlackPixel = xgb.Get32(buf[b:]) + b += 4 + + v.CurrentInputMasks = xgb.Get32(buf[b:]) + b += 4 + + v.WidthInPixels = xgb.Get16(buf[b:]) + b += 2 + + v.HeightInPixels = xgb.Get16(buf[b:]) + b += 2 + + v.WidthInMillimeters = xgb.Get16(buf[b:]) + b += 2 + + v.HeightInMillimeters = xgb.Get16(buf[b:]) + b += 2 + + v.MinInstalledMaps = xgb.Get16(buf[b:]) + b += 2 + + v.MaxInstalledMaps = xgb.Get16(buf[b:]) + b += 2 + + v.RootVisual = Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.BackingStores = buf[b] + b += 1 + + if buf[b] == 1 { + v.SaveUnders = true + } else { + v.SaveUnders = false + } + b += 1 + + v.RootDepth = buf[b] + b += 1 + + v.AllowedDepthsLen = buf[b] + b += 1 + + v.AllowedDepths = make([]DepthInfo, v.AllowedDepthsLen) + b += DepthInfoReadList(buf[b:], v.AllowedDepths) + + return b +} + +// ScreenInfoReadList reads a byte slice into a list of ScreenInfo values. +func ScreenInfoReadList(buf []byte, dest []ScreenInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ScreenInfo{} + b += ScreenInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ScreenInfo value to a byte slice. +func (v ScreenInfo) Bytes() []byte { + buf := make([]byte, (40 + DepthInfoListSize(v.AllowedDepths))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.DefaultColormap)) + b += 4 + + xgb.Put32(buf[b:], v.WhitePixel) + b += 4 + + xgb.Put32(buf[b:], v.BlackPixel) + b += 4 + + xgb.Put32(buf[b:], v.CurrentInputMasks) + b += 4 + + xgb.Put16(buf[b:], v.WidthInPixels) + b += 2 + + xgb.Put16(buf[b:], v.HeightInPixels) + b += 2 + + xgb.Put16(buf[b:], v.WidthInMillimeters) + b += 2 + + xgb.Put16(buf[b:], v.HeightInMillimeters) + b += 2 + + xgb.Put16(buf[b:], v.MinInstalledMaps) + b += 2 + + xgb.Put16(buf[b:], v.MaxInstalledMaps) + b += 2 + + xgb.Put32(buf[b:], uint32(v.RootVisual)) + b += 4 + + buf[b] = v.BackingStores + b += 1 + + if v.SaveUnders { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + buf[b] = v.RootDepth + b += 1 + + buf[b] = v.AllowedDepthsLen + b += 1 + + b += DepthInfoListBytes(buf[b:], v.AllowedDepths) + + return buf[:b] +} + +// ScreenInfoListBytes writes a list of ScreenInfo values to a byte slice. +func ScreenInfoListBytes(buf []byte, list []ScreenInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ScreenInfoListSize computes the size (bytes) of a list of ScreenInfo values. +func ScreenInfoListSize(list []ScreenInfo) int { + size := 0 + for _, item := range list { + size += (40 + DepthInfoListSize(item.AllowedDepths)) + } + return size +} + +const ( + ScreenSaverReset = 0 + ScreenSaverActive = 1 +) + +type Segment struct { + X1 int16 + Y1 int16 + X2 int16 + Y2 int16 +} + +// SegmentRead reads a byte slice into a Segment value. +func SegmentRead(buf []byte, v *Segment) int { + b := 0 + + v.X1 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y1 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.X2 = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y2 = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// SegmentReadList reads a byte slice into a list of Segment values. +func SegmentReadList(buf []byte, dest []Segment) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Segment{} + b += SegmentRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Segment value to a byte slice. +func (v Segment) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put16(buf[b:], uint16(v.X1)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y1)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X2)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y2)) + b += 2 + + return buf[:b] +} + +// SegmentListBytes writes a list of Segment values to a byte slice. +func SegmentListBytes(buf []byte, list []Segment) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// SelectionClear is the event number for a SelectionClearEvent. +const SelectionClear = 29 + +type SelectionClearEvent struct { + Sequence uint16 + // padding: 1 bytes + Time Timestamp + Owner Window + Selection Atom +} + +// SelectionClearEventNew constructs a SelectionClearEvent value that implements xgb.Event from a byte slice. +func SelectionClearEventNew(buf []byte) xgb.Event { + v := SelectionClearEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Owner = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Selection = Atom(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a SelectionClearEvent value to a byte slice. +func (v SelectionClearEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 29 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Owner)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Selection)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the SelectionClear event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v SelectionClearEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of SelectionClearEvent. +func (v SelectionClearEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Owner: %d", v.Owner)) + fieldVals = append(fieldVals, xgb.Sprintf("Selection: %d", v.Selection)) + return "SelectionClear {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[29] = SelectionClearEventNew +} + +// SelectionNotify is the event number for a SelectionNotifyEvent. +const SelectionNotify = 31 + +type SelectionNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Time Timestamp + Requestor Window + Selection Atom + Target Atom + Property Atom +} + +// SelectionNotifyEventNew constructs a SelectionNotifyEvent value that implements xgb.Event from a byte slice. +func SelectionNotifyEventNew(buf []byte) xgb.Event { + v := SelectionNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Requestor = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Selection = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Target = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Property = Atom(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a SelectionNotifyEvent value to a byte slice. +func (v SelectionNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 31 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Requestor)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Selection)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Target)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Property)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the SelectionNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v SelectionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of SelectionNotifyEvent. +func (v SelectionNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Requestor: %d", v.Requestor)) + fieldVals = append(fieldVals, xgb.Sprintf("Selection: %d", v.Selection)) + fieldVals = append(fieldVals, xgb.Sprintf("Target: %d", v.Target)) + fieldVals = append(fieldVals, xgb.Sprintf("Property: %d", v.Property)) + return "SelectionNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[31] = SelectionNotifyEventNew +} + +// SelectionRequest is the event number for a SelectionRequestEvent. +const SelectionRequest = 30 + +type SelectionRequestEvent struct { + Sequence uint16 + // padding: 1 bytes + Time Timestamp + Owner Window + Requestor Window + Selection Atom + Target Atom + Property Atom +} + +// SelectionRequestEventNew constructs a SelectionRequestEvent value that implements xgb.Event from a byte slice. +func SelectionRequestEventNew(buf []byte) xgb.Event { + v := SelectionRequestEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Owner = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Requestor = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Selection = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Target = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Property = Atom(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a SelectionRequestEvent value to a byte slice. +func (v SelectionRequestEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 30 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Owner)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Requestor)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Selection)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Target)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Property)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the SelectionRequest event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v SelectionRequestEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of SelectionRequestEvent. +func (v SelectionRequestEvent) String() string { + fieldVals := make([]string, 0, 7) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Owner: %d", v.Owner)) + fieldVals = append(fieldVals, xgb.Sprintf("Requestor: %d", v.Requestor)) + fieldVals = append(fieldVals, xgb.Sprintf("Selection: %d", v.Selection)) + fieldVals = append(fieldVals, xgb.Sprintf("Target: %d", v.Target)) + fieldVals = append(fieldVals, xgb.Sprintf("Property: %d", v.Property)) + return "SelectionRequest {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[30] = SelectionRequestEventNew +} + +const ( + SendEventDestPointerWindow = 0 + SendEventDestItemFocus = 1 +) + +const ( + SetModeInsert = 0 + SetModeDelete = 1 +) + +type SetupAuthenticate struct { + Status byte + // padding: 5 bytes + Length uint16 + Reason string // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// SetupAuthenticateRead reads a byte slice into a SetupAuthenticate value. +func SetupAuthenticateRead(buf []byte, v *SetupAuthenticate) int { + b := 0 + + v.Status = buf[b] + b += 1 + + b += 5 // padding + + v.Length = xgb.Get16(buf[b:]) + b += 2 + + { + byteString := make([]byte, (int(v.Length) * 4)) + copy(byteString[:(int(v.Length)*4)], buf[b:]) + v.Reason = string(byteString) + b += int((int(v.Length) * 4)) + } + + return b +} + +// SetupAuthenticateReadList reads a byte slice into a list of SetupAuthenticate values. +func SetupAuthenticateReadList(buf []byte, dest []SetupAuthenticate) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = SetupAuthenticate{} + b += SetupAuthenticateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a SetupAuthenticate value to a byte slice. +func (v SetupAuthenticate) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad(((int(v.Length) * 4) * 1)))) + b := 0 + + buf[b] = v.Status + b += 1 + + b += 5 // padding + + xgb.Put16(buf[b:], v.Length) + b += 2 + + copy(buf[b:], v.Reason[:(int(v.Length)*4)]) + b += int((int(v.Length) * 4)) + + return buf[:b] +} + +// SetupAuthenticateListBytes writes a list of SetupAuthenticate values to a byte slice. +func SetupAuthenticateListBytes(buf []byte, list []SetupAuthenticate) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// SetupAuthenticateListSize computes the size (bytes) of a list of SetupAuthenticate values. +func SetupAuthenticateListSize(list []SetupAuthenticate) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad(((int(item.Length) * 4) * 1))) + } + return size +} + +type SetupFailed struct { + Status byte + ReasonLen byte + ProtocolMajorVersion uint16 + ProtocolMinorVersion uint16 + Length uint16 + Reason string // size: xgb.Pad((int(ReasonLen) * 1)) +} + +// SetupFailedRead reads a byte slice into a SetupFailed value. +func SetupFailedRead(buf []byte, v *SetupFailed) int { + b := 0 + + v.Status = buf[b] + b += 1 + + v.ReasonLen = buf[b] + b += 1 + + v.ProtocolMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ProtocolMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get16(buf[b:]) + b += 2 + + { + byteString := make([]byte, v.ReasonLen) + copy(byteString[:v.ReasonLen], buf[b:]) + v.Reason = string(byteString) + b += int(v.ReasonLen) + } + + return b +} + +// SetupFailedReadList reads a byte slice into a list of SetupFailed values. +func SetupFailedReadList(buf []byte, dest []SetupFailed) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = SetupFailed{} + b += SetupFailedRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a SetupFailed value to a byte slice. +func (v SetupFailed) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.ReasonLen) * 1)))) + b := 0 + + buf[b] = v.Status + b += 1 + + buf[b] = v.ReasonLen + b += 1 + + xgb.Put16(buf[b:], v.ProtocolMajorVersion) + b += 2 + + xgb.Put16(buf[b:], v.ProtocolMinorVersion) + b += 2 + + xgb.Put16(buf[b:], v.Length) + b += 2 + + copy(buf[b:], v.Reason[:v.ReasonLen]) + b += int(v.ReasonLen) + + return buf[:b] +} + +// SetupFailedListBytes writes a list of SetupFailed values to a byte slice. +func SetupFailedListBytes(buf []byte, list []SetupFailed) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// SetupFailedListSize computes the size (bytes) of a list of SetupFailed values. +func SetupFailedListSize(list []SetupFailed) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.ReasonLen) * 1))) + } + return size +} + +type SetupInfo struct { + Status byte + // padding: 1 bytes + ProtocolMajorVersion uint16 + ProtocolMinorVersion uint16 + Length uint16 + ReleaseNumber uint32 + ResourceIdBase uint32 + ResourceIdMask uint32 + MotionBufferSize uint32 + VendorLen uint16 + MaximumRequestLength uint16 + RootsLen byte + PixmapFormatsLen byte + ImageByteOrder byte + BitmapFormatBitOrder byte + BitmapFormatScanlineUnit byte + BitmapFormatScanlinePad byte + MinKeycode Keycode + MaxKeycode Keycode + // padding: 4 bytes + Vendor string // size: xgb.Pad((int(VendorLen) * 1)) + // alignment gap to multiple of 4 + PixmapFormats []Format // size: xgb.Pad((int(PixmapFormatsLen) * 8)) + Roots []ScreenInfo // size: ScreenInfoListSize(Roots) +} + +// SetupInfoRead reads a byte slice into a SetupInfo value. +func SetupInfoRead(buf []byte, v *SetupInfo) int { + b := 0 + + v.Status = buf[b] + b += 1 + + b += 1 // padding + + v.ProtocolMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ProtocolMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get16(buf[b:]) + b += 2 + + v.ReleaseNumber = xgb.Get32(buf[b:]) + b += 4 + + v.ResourceIdBase = xgb.Get32(buf[b:]) + b += 4 + + v.ResourceIdMask = xgb.Get32(buf[b:]) + b += 4 + + v.MotionBufferSize = xgb.Get32(buf[b:]) + b += 4 + + v.VendorLen = xgb.Get16(buf[b:]) + b += 2 + + v.MaximumRequestLength = xgb.Get16(buf[b:]) + b += 2 + + v.RootsLen = buf[b] + b += 1 + + v.PixmapFormatsLen = buf[b] + b += 1 + + v.ImageByteOrder = buf[b] + b += 1 + + v.BitmapFormatBitOrder = buf[b] + b += 1 + + v.BitmapFormatScanlineUnit = buf[b] + b += 1 + + v.BitmapFormatScanlinePad = buf[b] + b += 1 + + v.MinKeycode = Keycode(buf[b]) + b += 1 + + v.MaxKeycode = Keycode(buf[b]) + b += 1 + + b += 4 // padding + + { + byteString := make([]byte, v.VendorLen) + copy(byteString[:v.VendorLen], buf[b:]) + v.Vendor = string(byteString) + b += int(v.VendorLen) + } + + b = (b + 3) & ^3 // alignment gap + + v.PixmapFormats = make([]Format, v.PixmapFormatsLen) + b += FormatReadList(buf[b:], v.PixmapFormats) + + v.Roots = make([]ScreenInfo, v.RootsLen) + b += ScreenInfoReadList(buf[b:], v.Roots) + + return b +} + +// SetupInfoReadList reads a byte slice into a list of SetupInfo values. +func SetupInfoReadList(buf []byte, dest []SetupInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = SetupInfo{} + b += SetupInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a SetupInfo value to a byte slice. +func (v SetupInfo) Bytes() []byte { + buf := make([]byte, ((((40 + xgb.Pad((int(v.VendorLen) * 1))) + 4) + xgb.Pad((int(v.PixmapFormatsLen) * 8))) + ScreenInfoListSize(v.Roots))) + b := 0 + + buf[b] = v.Status + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], v.ProtocolMajorVersion) + b += 2 + + xgb.Put16(buf[b:], v.ProtocolMinorVersion) + b += 2 + + xgb.Put16(buf[b:], v.Length) + b += 2 + + xgb.Put32(buf[b:], v.ReleaseNumber) + b += 4 + + xgb.Put32(buf[b:], v.ResourceIdBase) + b += 4 + + xgb.Put32(buf[b:], v.ResourceIdMask) + b += 4 + + xgb.Put32(buf[b:], v.MotionBufferSize) + b += 4 + + xgb.Put16(buf[b:], v.VendorLen) + b += 2 + + xgb.Put16(buf[b:], v.MaximumRequestLength) + b += 2 + + buf[b] = v.RootsLen + b += 1 + + buf[b] = v.PixmapFormatsLen + b += 1 + + buf[b] = v.ImageByteOrder + b += 1 + + buf[b] = v.BitmapFormatBitOrder + b += 1 + + buf[b] = v.BitmapFormatScanlineUnit + b += 1 + + buf[b] = v.BitmapFormatScanlinePad + b += 1 + + buf[b] = byte(v.MinKeycode) + b += 1 + + buf[b] = byte(v.MaxKeycode) + b += 1 + + b += 4 // padding + + copy(buf[b:], v.Vendor[:v.VendorLen]) + b += int(v.VendorLen) + + b = (b + 3) & ^3 // alignment gap + + b += FormatListBytes(buf[b:], v.PixmapFormats) + + b += ScreenInfoListBytes(buf[b:], v.Roots) + + return buf[:b] +} + +// SetupInfoListBytes writes a list of SetupInfo values to a byte slice. +func SetupInfoListBytes(buf []byte, list []SetupInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// SetupInfoListSize computes the size (bytes) of a list of SetupInfo values. +func SetupInfoListSize(list []SetupInfo) int { + size := 0 + for _, item := range list { + size += ((((40 + xgb.Pad((int(item.VendorLen) * 1))) + 4) + xgb.Pad((int(item.PixmapFormatsLen) * 8))) + ScreenInfoListSize(item.Roots)) + } + return size +} + +type SetupRequest struct { + ByteOrder byte + // padding: 1 bytes + ProtocolMajorVersion uint16 + ProtocolMinorVersion uint16 + AuthorizationProtocolNameLen uint16 + AuthorizationProtocolDataLen uint16 + // padding: 2 bytes + AuthorizationProtocolName string // size: xgb.Pad((int(AuthorizationProtocolNameLen) * 1)) + AuthorizationProtocolData string // size: xgb.Pad((int(AuthorizationProtocolDataLen) * 1)) +} + +// SetupRequestRead reads a byte slice into a SetupRequest value. +func SetupRequestRead(buf []byte, v *SetupRequest) int { + b := 0 + + v.ByteOrder = buf[b] + b += 1 + + b += 1 // padding + + v.ProtocolMajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.ProtocolMinorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.AuthorizationProtocolNameLen = xgb.Get16(buf[b:]) + b += 2 + + v.AuthorizationProtocolDataLen = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + { + byteString := make([]byte, v.AuthorizationProtocolNameLen) + copy(byteString[:v.AuthorizationProtocolNameLen], buf[b:]) + v.AuthorizationProtocolName = string(byteString) + b += int(v.AuthorizationProtocolNameLen) + } + + { + byteString := make([]byte, v.AuthorizationProtocolDataLen) + copy(byteString[:v.AuthorizationProtocolDataLen], buf[b:]) + v.AuthorizationProtocolData = string(byteString) + b += int(v.AuthorizationProtocolDataLen) + } + + return b +} + +// SetupRequestReadList reads a byte slice into a list of SetupRequest values. +func SetupRequestReadList(buf []byte, dest []SetupRequest) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = SetupRequest{} + b += SetupRequestRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a SetupRequest value to a byte slice. +func (v SetupRequest) Bytes() []byte { + buf := make([]byte, ((12 + xgb.Pad((int(v.AuthorizationProtocolNameLen) * 1))) + xgb.Pad((int(v.AuthorizationProtocolDataLen) * 1)))) + b := 0 + + buf[b] = v.ByteOrder + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], v.ProtocolMajorVersion) + b += 2 + + xgb.Put16(buf[b:], v.ProtocolMinorVersion) + b += 2 + + xgb.Put16(buf[b:], v.AuthorizationProtocolNameLen) + b += 2 + + xgb.Put16(buf[b:], v.AuthorizationProtocolDataLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], v.AuthorizationProtocolName[:v.AuthorizationProtocolNameLen]) + b += int(v.AuthorizationProtocolNameLen) + + copy(buf[b:], v.AuthorizationProtocolData[:v.AuthorizationProtocolDataLen]) + b += int(v.AuthorizationProtocolDataLen) + + return buf[:b] +} + +// SetupRequestListBytes writes a list of SetupRequest values to a byte slice. +func SetupRequestListBytes(buf []byte, list []SetupRequest) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// SetupRequestListSize computes the size (bytes) of a list of SetupRequest values. +func SetupRequestListSize(list []SetupRequest) int { + size := 0 + for _, item := range list { + size += ((12 + xgb.Pad((int(item.AuthorizationProtocolNameLen) * 1))) + xgb.Pad((int(item.AuthorizationProtocolDataLen) * 1))) + } + return size +} + +const ( + StackModeAbove = 0 + StackModeBelow = 1 + StackModeTopIf = 2 + StackModeBottomIf = 3 + StackModeOpposite = 4 +) + +type Str struct { + NameLen byte + Name string // size: xgb.Pad((int(NameLen) * 1)) +} + +// StrRead reads a byte slice into a Str value. +func StrRead(buf []byte, v *Str) int { + b := 0 + + v.NameLen = buf[b] + b += 1 + + { + byteString := make([]byte, v.NameLen) + copy(byteString[:v.NameLen], buf[b:]) + v.Name = string(byteString) + b += int(v.NameLen) + } + + return b +} + +// StrReadList reads a byte slice into a list of Str values. +func StrReadList(buf []byte, dest []Str) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Str{} + b += StrRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Str value to a byte slice. +func (v Str) Bytes() []byte { + buf := make([]byte, (1 + xgb.Pad((int(v.NameLen) * 1)))) + b := 0 + + buf[b] = v.NameLen + b += 1 + + copy(buf[b:], v.Name[:v.NameLen]) + b += int(v.NameLen) + + return buf[:b] +} + +// StrListBytes writes a list of Str values to a byte slice. +func StrListBytes(buf []byte, list []Str) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// StrListSize computes the size (bytes) of a list of Str values. +func StrListSize(list []Str) int { + size := 0 + for _, item := range list { + size += (1 + xgb.Pad((int(item.NameLen) * 1))) + } + return size +} + +const ( + SubwindowModeClipByChildren = 0 + SubwindowModeIncludeInferiors = 1 +) + +const ( + TimeCurrentTime = 0 +) + +type Timecoord struct { + Time Timestamp + X int16 + Y int16 +} + +// TimecoordRead reads a byte slice into a Timecoord value. +func TimecoordRead(buf []byte, v *Timecoord) int { + b := 0 + + v.Time = Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + return b +} + +// TimecoordReadList reads a byte slice into a list of Timecoord values. +func TimecoordReadList(buf []byte, dest []Timecoord) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Timecoord{} + b += TimecoordRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Timecoord value to a byte slice. +func (v Timecoord) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + return buf[:b] +} + +// TimecoordListBytes writes a list of Timecoord values to a byte slice. +func TimecoordListBytes(buf []byte, list []Timecoord) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Timestamp uint32 + +// UnmapNotify is the event number for a UnmapNotifyEvent. +const UnmapNotify = 18 + +type UnmapNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Event Window + Window Window + FromConfigure bool + // padding: 3 bytes +} + +// UnmapNotifyEventNew constructs a UnmapNotifyEvent value that implements xgb.Event from a byte slice. +func UnmapNotifyEventNew(buf []byte) xgb.Event { + v := UnmapNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Event = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.FromConfigure = true + } else { + v.FromConfigure = false + } + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a UnmapNotifyEvent value to a byte slice. +func (v UnmapNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 18 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + if v.FromConfigure { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the UnmapNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v UnmapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of UnmapNotifyEvent. +func (v UnmapNotifyEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("FromConfigure: %t", v.FromConfigure)) + return "UnmapNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[18] = UnmapNotifyEventNew +} + +// BadValue is the error number for a BadValue. +const BadValue = 2 + +type ValueError struct { + Sequence uint16 + NiceName string + BadValue uint32 + MinorOpcode uint16 + MajorOpcode byte + // padding: 1 bytes +} + +// ValueErrorNew constructs a ValueError value that implements xgb.Error from a byte slice. +func ValueErrorNew(buf []byte) xgb.Error { + v := ValueError{} + v.NiceName = "Value" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.BadValue = xgb.Get32(buf[b:]) + b += 4 + + v.MinorOpcode = xgb.Get16(buf[b:]) + b += 2 + + v.MajorOpcode = buf[b] + b += 1 + + b += 1 // padding + + return v +} + +// SequenceId returns the sequence id attached to the BadValue error. +// This is mostly used internally. +func (err ValueError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadValue error. If no bad value exists, 0 is returned. +func (err ValueError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadValue error. + +func (err ValueError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadValue {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[2] = ValueErrorNew +} + +const ( + VisibilityUnobscured = 0 + VisibilityPartiallyObscured = 1 + VisibilityFullyObscured = 2 +) + +// VisibilityNotify is the event number for a VisibilityNotifyEvent. +const VisibilityNotify = 15 + +type VisibilityNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Window Window + State byte + // padding: 3 bytes +} + +// VisibilityNotifyEventNew constructs a VisibilityNotifyEvent value that implements xgb.Event from a byte slice. +func VisibilityNotifyEventNew(buf []byte) xgb.Event { + v := VisibilityNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Window = Window(xgb.Get32(buf[b:])) + b += 4 + + v.State = buf[b] + b += 1 + + b += 3 // padding + + return v +} + +// Bytes writes a VisibilityNotifyEvent value to a byte slice. +func (v VisibilityNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 15 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Window)) + b += 4 + + buf[b] = v.State + b += 1 + + b += 3 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the VisibilityNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v VisibilityNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of VisibilityNotifyEvent. +func (v VisibilityNotifyEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + return "VisibilityNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewEventFuncs[15] = VisibilityNotifyEventNew +} + +const ( + VisualClassStaticGray = 0 + VisualClassGrayScale = 1 + VisualClassStaticColor = 2 + VisualClassPseudoColor = 3 + VisualClassTrueColor = 4 + VisualClassDirectColor = 5 +) + +type VisualInfo struct { + VisualId Visualid + Class byte + BitsPerRgbValue byte + ColormapEntries uint16 + RedMask uint32 + GreenMask uint32 + BlueMask uint32 + // padding: 4 bytes +} + +// VisualInfoRead reads a byte slice into a VisualInfo value. +func VisualInfoRead(buf []byte, v *VisualInfo) int { + b := 0 + + v.VisualId = Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.Class = buf[b] + b += 1 + + v.BitsPerRgbValue = buf[b] + b += 1 + + v.ColormapEntries = xgb.Get16(buf[b:]) + b += 2 + + v.RedMask = xgb.Get32(buf[b:]) + b += 4 + + v.GreenMask = xgb.Get32(buf[b:]) + b += 4 + + v.BlueMask = xgb.Get32(buf[b:]) + b += 4 + + b += 4 // padding + + return b +} + +// VisualInfoReadList reads a byte slice into a list of VisualInfo values. +func VisualInfoReadList(buf []byte, dest []VisualInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = VisualInfo{} + b += VisualInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a VisualInfo value to a byte slice. +func (v VisualInfo) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + xgb.Put32(buf[b:], uint32(v.VisualId)) + b += 4 + + buf[b] = v.Class + b += 1 + + buf[b] = v.BitsPerRgbValue + b += 1 + + xgb.Put16(buf[b:], v.ColormapEntries) + b += 2 + + xgb.Put32(buf[b:], v.RedMask) + b += 4 + + xgb.Put32(buf[b:], v.GreenMask) + b += 4 + + xgb.Put32(buf[b:], v.BlueMask) + b += 4 + + b += 4 // padding + + return buf[:b] +} + +// VisualInfoListBytes writes a list of VisualInfo values to a byte slice. +func VisualInfoListBytes(buf []byte, list []VisualInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +type Visualid uint32 + +type Window uint32 + +func NewWindowId(c *xgb.Conn) (Window, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Window(id), nil +} + +// BadWindow is the error number for a BadWindow. +const BadWindow = 3 + +type WindowError ValueError + +// WindowErrorNew constructs a WindowError value that implements xgb.Error from a byte slice. +func WindowErrorNew(buf []byte) xgb.Error { + v := WindowError(ValueErrorNew(buf).(ValueError)) + v.NiceName = "Window" + return v +} + +// SequenceId returns the sequence id attached to the BadWindow error. +// This is mostly used internally. +func (err WindowError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadWindow error. If no bad value exists, 0 is returned. +func (err WindowError) BadId() uint32 { + return err.BadValue +} + +// Error returns a rudimentary string representation of the BadWindow error. +func (err WindowError) Error() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue)) + fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode)) + fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode)) + return "BadWindow {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewErrorFuncs[3] = WindowErrorNew +} + +const ( + WindowNone = 0 +) + +const ( + WindowClassCopyFromParent = 0 + WindowClassInputOutput = 1 + WindowClassInputOnly = 2 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// AllocColorCookie is a cookie used only for AllocColor requests. +type AllocColorCookie struct { + *xgb.Cookie +} + +// AllocColor sends a checked request. +// If an error occurs, it will be returned with the reply by calling AllocColorCookie.Reply() +func AllocColor(c *xgb.Conn, Cmap Colormap, Red uint16, Green uint16, Blue uint16) AllocColorCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(allocColorRequest(c, Cmap, Red, Green, Blue), cookie) + return AllocColorCookie{cookie} +} + +// AllocColorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AllocColorUnchecked(c *xgb.Conn, Cmap Colormap, Red uint16, Green uint16, Blue uint16) AllocColorCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(allocColorRequest(c, Cmap, Red, Green, Blue), cookie) + return AllocColorCookie{cookie} +} + +// AllocColorReply represents the data returned from a AllocColor request. +type AllocColorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Red uint16 + Green uint16 + Blue uint16 + // padding: 2 bytes + Pixel uint32 +} + +// Reply blocks and returns the reply data for a AllocColor request. +func (cook AllocColorCookie) Reply() (*AllocColorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return allocColorReply(buf), nil +} + +// allocColorReply reads a byte slice into a AllocColorReply value. +func allocColorReply(buf []byte) *AllocColorReply { + v := new(AllocColorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Red = xgb.Get16(buf[b:]) + b += 2 + + v.Green = xgb.Get16(buf[b:]) + b += 2 + + v.Blue = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Pixel = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for AllocColor +// allocColorRequest writes a AllocColor request to a byte slice. +func allocColorRequest(c *xgb.Conn, Cmap Colormap, Red uint16, Green uint16, Blue uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 84 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put16(buf[b:], Red) + b += 2 + + xgb.Put16(buf[b:], Green) + b += 2 + + xgb.Put16(buf[b:], Blue) + b += 2 + + b += 2 // padding + + return buf +} + +// AllocColorCellsCookie is a cookie used only for AllocColorCells requests. +type AllocColorCellsCookie struct { + *xgb.Cookie +} + +// AllocColorCells sends a checked request. +// If an error occurs, it will be returned with the reply by calling AllocColorCellsCookie.Reply() +func AllocColorCells(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Planes uint16) AllocColorCellsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(allocColorCellsRequest(c, Contiguous, Cmap, Colors, Planes), cookie) + return AllocColorCellsCookie{cookie} +} + +// AllocColorCellsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AllocColorCellsUnchecked(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Planes uint16) AllocColorCellsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(allocColorCellsRequest(c, Contiguous, Cmap, Colors, Planes), cookie) + return AllocColorCellsCookie{cookie} +} + +// AllocColorCellsReply represents the data returned from a AllocColorCells request. +type AllocColorCellsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PixelsLen uint16 + MasksLen uint16 + // padding: 20 bytes + Pixels []uint32 // size: xgb.Pad((int(PixelsLen) * 4)) + Masks []uint32 // size: xgb.Pad((int(MasksLen) * 4)) +} + +// Reply blocks and returns the reply data for a AllocColorCells request. +func (cook AllocColorCellsCookie) Reply() (*AllocColorCellsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return allocColorCellsReply(buf), nil +} + +// allocColorCellsReply reads a byte slice into a AllocColorCellsReply value. +func allocColorCellsReply(buf []byte) *AllocColorCellsReply { + v := new(AllocColorCellsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PixelsLen = xgb.Get16(buf[b:]) + b += 2 + + v.MasksLen = xgb.Get16(buf[b:]) + b += 2 + + b += 20 // padding + + v.Pixels = make([]uint32, v.PixelsLen) + for i := 0; i < int(v.PixelsLen); i++ { + v.Pixels[i] = xgb.Get32(buf[b:]) + b += 4 + } + + v.Masks = make([]uint32, v.MasksLen) + for i := 0; i < int(v.MasksLen); i++ { + v.Masks[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for AllocColorCells +// allocColorCellsRequest writes a AllocColorCells request to a byte slice. +func allocColorCellsRequest(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Planes uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 86 // request opcode + b += 1 + + if Contiguous { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put16(buf[b:], Colors) + b += 2 + + xgb.Put16(buf[b:], Planes) + b += 2 + + return buf +} + +// AllocColorPlanesCookie is a cookie used only for AllocColorPlanes requests. +type AllocColorPlanesCookie struct { + *xgb.Cookie +} + +// AllocColorPlanes sends a checked request. +// If an error occurs, it will be returned with the reply by calling AllocColorPlanesCookie.Reply() +func AllocColorPlanes(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Reds uint16, Greens uint16, Blues uint16) AllocColorPlanesCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(allocColorPlanesRequest(c, Contiguous, Cmap, Colors, Reds, Greens, Blues), cookie) + return AllocColorPlanesCookie{cookie} +} + +// AllocColorPlanesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AllocColorPlanesUnchecked(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Reds uint16, Greens uint16, Blues uint16) AllocColorPlanesCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(allocColorPlanesRequest(c, Contiguous, Cmap, Colors, Reds, Greens, Blues), cookie) + return AllocColorPlanesCookie{cookie} +} + +// AllocColorPlanesReply represents the data returned from a AllocColorPlanes request. +type AllocColorPlanesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PixelsLen uint16 + // padding: 2 bytes + RedMask uint32 + GreenMask uint32 + BlueMask uint32 + // padding: 8 bytes + Pixels []uint32 // size: xgb.Pad((int(PixelsLen) * 4)) +} + +// Reply blocks and returns the reply data for a AllocColorPlanes request. +func (cook AllocColorPlanesCookie) Reply() (*AllocColorPlanesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return allocColorPlanesReply(buf), nil +} + +// allocColorPlanesReply reads a byte slice into a AllocColorPlanesReply value. +func allocColorPlanesReply(buf []byte) *AllocColorPlanesReply { + v := new(AllocColorPlanesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PixelsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.RedMask = xgb.Get32(buf[b:]) + b += 4 + + v.GreenMask = xgb.Get32(buf[b:]) + b += 4 + + v.BlueMask = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + v.Pixels = make([]uint32, v.PixelsLen) + for i := 0; i < int(v.PixelsLen); i++ { + v.Pixels[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for AllocColorPlanes +// allocColorPlanesRequest writes a AllocColorPlanes request to a byte slice. +func allocColorPlanesRequest(c *xgb.Conn, Contiguous bool, Cmap Colormap, Colors uint16, Reds uint16, Greens uint16, Blues uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 87 // request opcode + b += 1 + + if Contiguous { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put16(buf[b:], Colors) + b += 2 + + xgb.Put16(buf[b:], Reds) + b += 2 + + xgb.Put16(buf[b:], Greens) + b += 2 + + xgb.Put16(buf[b:], Blues) + b += 2 + + return buf +} + +// AllocNamedColorCookie is a cookie used only for AllocNamedColor requests. +type AllocNamedColorCookie struct { + *xgb.Cookie +} + +// AllocNamedColor sends a checked request. +// If an error occurs, it will be returned with the reply by calling AllocNamedColorCookie.Reply() +func AllocNamedColor(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) AllocNamedColorCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(allocNamedColorRequest(c, Cmap, NameLen, Name), cookie) + return AllocNamedColorCookie{cookie} +} + +// AllocNamedColorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AllocNamedColorUnchecked(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) AllocNamedColorCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(allocNamedColorRequest(c, Cmap, NameLen, Name), cookie) + return AllocNamedColorCookie{cookie} +} + +// AllocNamedColorReply represents the data returned from a AllocNamedColor request. +type AllocNamedColorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Pixel uint32 + ExactRed uint16 + ExactGreen uint16 + ExactBlue uint16 + VisualRed uint16 + VisualGreen uint16 + VisualBlue uint16 +} + +// Reply blocks and returns the reply data for a AllocNamedColor request. +func (cook AllocNamedColorCookie) Reply() (*AllocNamedColorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return allocNamedColorReply(buf), nil +} + +// allocNamedColorReply reads a byte slice into a AllocNamedColorReply value. +func allocNamedColorReply(buf []byte) *AllocNamedColorReply { + v := new(AllocNamedColorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Pixel = xgb.Get32(buf[b:]) + b += 4 + + v.ExactRed = xgb.Get16(buf[b:]) + b += 2 + + v.ExactGreen = xgb.Get16(buf[b:]) + b += 2 + + v.ExactBlue = xgb.Get16(buf[b:]) + b += 2 + + v.VisualRed = xgb.Get16(buf[b:]) + b += 2 + + v.VisualGreen = xgb.Get16(buf[b:]) + b += 2 + + v.VisualBlue = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for AllocNamedColor +// allocNamedColorRequest writes a AllocNamedColor request to a byte slice. +func allocNamedColorRequest(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 85 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// AllowEventsCookie is a cookie used only for AllowEvents requests. +type AllowEventsCookie struct { + *xgb.Cookie +} + +// AllowEvents sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func AllowEvents(c *xgb.Conn, Mode byte, Time Timestamp) AllowEventsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(allowEventsRequest(c, Mode, Time), cookie) + return AllowEventsCookie{cookie} +} + +// AllowEventsChecked sends a checked request. +// If an error occurs, it can be retrieved using AllowEventsCookie.Check() +func AllowEventsChecked(c *xgb.Conn, Mode byte, Time Timestamp) AllowEventsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(allowEventsRequest(c, Mode, Time), cookie) + return AllowEventsCookie{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 AllowEventsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for AllowEvents +// allowEventsRequest writes a AllowEvents request to a byte slice. +func allowEventsRequest(c *xgb.Conn, Mode byte, Time Timestamp) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 35 // request opcode + b += 1 + + buf[b] = Mode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// BellCookie is a cookie used only for Bell requests. +type BellCookie struct { + *xgb.Cookie +} + +// Bell sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func Bell(c *xgb.Conn, Percent int8) BellCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(bellRequest(c, Percent), cookie) + return BellCookie{cookie} +} + +// BellChecked sends a checked request. +// If an error occurs, it can be retrieved using BellCookie.Check() +func BellChecked(c *xgb.Conn, Percent int8) BellCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(bellRequest(c, Percent), cookie) + return BellCookie{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 BellCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for Bell +// bellRequest writes a Bell request to a byte slice. +func bellRequest(c *xgb.Conn, Percent int8) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 104 // request opcode + b += 1 + + buf[b] = byte(Percent) + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ChangeActivePointerGrabCookie is a cookie used only for ChangeActivePointerGrab requests. +type ChangeActivePointerGrabCookie struct { + *xgb.Cookie +} + +// ChangeActivePointerGrab sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeActivePointerGrab(c *xgb.Conn, Cursor Cursor, Time Timestamp, EventMask uint16) ChangeActivePointerGrabCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeActivePointerGrabRequest(c, Cursor, Time, EventMask), cookie) + return ChangeActivePointerGrabCookie{cookie} +} + +// ChangeActivePointerGrabChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeActivePointerGrabCookie.Check() +func ChangeActivePointerGrabChecked(c *xgb.Conn, Cursor Cursor, Time Timestamp, EventMask uint16) ChangeActivePointerGrabCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeActivePointerGrabRequest(c, Cursor, Time, EventMask), cookie) + return ChangeActivePointerGrabCookie{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 ChangeActivePointerGrabCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeActivePointerGrab +// changeActivePointerGrabRequest writes a ChangeActivePointerGrab request to a byte slice. +func changeActivePointerGrabRequest(c *xgb.Conn, Cursor Cursor, Time Timestamp, EventMask uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 30 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + xgb.Put16(buf[b:], EventMask) + b += 2 + + b += 2 // padding + + return buf +} + +// ChangeGCCookie is a cookie used only for ChangeGC requests. +type ChangeGCCookie struct { + *xgb.Cookie +} + +// ChangeGC sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeGC(c *xgb.Conn, Gc Gcontext, ValueMask uint32, ValueList []uint32) ChangeGCCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeGCRequest(c, Gc, ValueMask, ValueList), cookie) + return ChangeGCCookie{cookie} +} + +// ChangeGCChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeGCCookie.Check() +func ChangeGCChecked(c *xgb.Conn, Gc Gcontext, ValueMask uint32, ValueList []uint32) ChangeGCCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeGCRequest(c, Gc, ValueMask, ValueList), cookie) + return ChangeGCCookie{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 ChangeGCCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeGC +// changeGCRequest writes a ChangeGC request to a byte slice. +func changeGCRequest(c *xgb.Conn, Gc Gcontext, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 56 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// ChangeHostsCookie is a cookie used only for ChangeHosts requests. +type ChangeHostsCookie struct { + *xgb.Cookie +} + +// ChangeHosts sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeHosts(c *xgb.Conn, Mode byte, Family byte, AddressLen uint16, Address []byte) ChangeHostsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeHostsRequest(c, Mode, Family, AddressLen, Address), cookie) + return ChangeHostsCookie{cookie} +} + +// ChangeHostsChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeHostsCookie.Check() +func ChangeHostsChecked(c *xgb.Conn, Mode byte, Family byte, AddressLen uint16, Address []byte) ChangeHostsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeHostsRequest(c, Mode, Family, AddressLen, Address), cookie) + return ChangeHostsCookie{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 ChangeHostsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeHosts +// changeHostsRequest writes a ChangeHosts request to a byte slice. +func changeHostsRequest(c *xgb.Conn, Mode byte, Family byte, AddressLen uint16, Address []byte) []byte { + size := xgb.Pad((8 + xgb.Pad((int(AddressLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 109 // request opcode + b += 1 + + buf[b] = Mode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = Family + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], AddressLen) + b += 2 + + copy(buf[b:], Address[:AddressLen]) + b += int(AddressLen) + + return buf +} + +// ChangeKeyboardControlCookie is a cookie used only for ChangeKeyboardControl requests. +type ChangeKeyboardControlCookie struct { + *xgb.Cookie +} + +// ChangeKeyboardControl sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeKeyboardControl(c *xgb.Conn, ValueMask uint32, ValueList []uint32) ChangeKeyboardControlCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeKeyboardControlRequest(c, ValueMask, ValueList), cookie) + return ChangeKeyboardControlCookie{cookie} +} + +// ChangeKeyboardControlChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeKeyboardControlCookie.Check() +func ChangeKeyboardControlChecked(c *xgb.Conn, ValueMask uint32, ValueList []uint32) ChangeKeyboardControlCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeKeyboardControlRequest(c, ValueMask, ValueList), cookie) + return ChangeKeyboardControlCookie{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 ChangeKeyboardControlCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeKeyboardControl +// changeKeyboardControlRequest writes a ChangeKeyboardControl request to a byte slice. +func changeKeyboardControlRequest(c *xgb.Conn, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((8 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 102 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// ChangeKeyboardMappingCookie is a cookie used only for ChangeKeyboardMapping requests. +type ChangeKeyboardMappingCookie struct { + *xgb.Cookie +} + +// ChangeKeyboardMapping sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeKeyboardMapping(c *xgb.Conn, KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) ChangeKeyboardMappingCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeKeyboardMappingRequest(c, KeycodeCount, FirstKeycode, KeysymsPerKeycode, Keysyms), cookie) + return ChangeKeyboardMappingCookie{cookie} +} + +// ChangeKeyboardMappingChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeKeyboardMappingCookie.Check() +func ChangeKeyboardMappingChecked(c *xgb.Conn, KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) ChangeKeyboardMappingCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeKeyboardMappingRequest(c, KeycodeCount, FirstKeycode, KeysymsPerKeycode, Keysyms), cookie) + return ChangeKeyboardMappingCookie{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 ChangeKeyboardMappingCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeKeyboardMapping +// changeKeyboardMappingRequest writes a ChangeKeyboardMapping request to a byte slice. +func changeKeyboardMappingRequest(c *xgb.Conn, KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) []byte { + size := xgb.Pad((8 + xgb.Pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 100 // request opcode + b += 1 + + buf[b] = KeycodeCount + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = byte(FirstKeycode) + b += 1 + + buf[b] = KeysymsPerKeycode + b += 1 + + b += 2 // padding + + for i := 0; i < int((int(KeycodeCount) * int(KeysymsPerKeycode))); i++ { + xgb.Put32(buf[b:], uint32(Keysyms[i])) + b += 4 + } + + return buf +} + +// ChangePointerControlCookie is a cookie used only for ChangePointerControl requests. +type ChangePointerControlCookie struct { + *xgb.Cookie +} + +// ChangePointerControl sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangePointerControl(c *xgb.Conn, AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) ChangePointerControlCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changePointerControlRequest(c, AccelerationNumerator, AccelerationDenominator, Threshold, DoAcceleration, DoThreshold), cookie) + return ChangePointerControlCookie{cookie} +} + +// ChangePointerControlChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangePointerControlCookie.Check() +func ChangePointerControlChecked(c *xgb.Conn, AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) ChangePointerControlCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changePointerControlRequest(c, AccelerationNumerator, AccelerationDenominator, Threshold, DoAcceleration, DoThreshold), cookie) + return ChangePointerControlCookie{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 ChangePointerControlCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangePointerControl +// changePointerControlRequest writes a ChangePointerControl request to a byte slice. +func changePointerControlRequest(c *xgb.Conn, AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 105 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], uint16(AccelerationNumerator)) + b += 2 + + xgb.Put16(buf[b:], uint16(AccelerationDenominator)) + b += 2 + + xgb.Put16(buf[b:], uint16(Threshold)) + b += 2 + + if DoAcceleration { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if DoThreshold { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// ChangePropertyCookie is a cookie used only for ChangeProperty requests. +type ChangePropertyCookie struct { + *xgb.Cookie +} + +// ChangeProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeProperty(c *xgb.Conn, Mode byte, Window Window, Property Atom, Type Atom, Format byte, DataLen uint32, Data []byte) ChangePropertyCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changePropertyRequest(c, Mode, Window, Property, Type, Format, DataLen, Data), cookie) + return ChangePropertyCookie{cookie} +} + +// ChangePropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangePropertyCookie.Check() +func ChangePropertyChecked(c *xgb.Conn, Mode byte, Window Window, Property Atom, Type Atom, Format byte, DataLen uint32, Data []byte) ChangePropertyCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changePropertyRequest(c, Mode, Window, Property, Type, Format, DataLen, Data), cookie) + return ChangePropertyCookie{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 ChangePropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeProperty +// changePropertyRequest writes a ChangeProperty request to a byte slice. +func changePropertyRequest(c *xgb.Conn, Mode byte, Window Window, Property Atom, Type Atom, Format byte, DataLen uint32, Data []byte) []byte { + size := xgb.Pad((24 + xgb.Pad((((int(DataLen) * int(Format)) / 8) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 18 // request opcode + b += 1 + + buf[b] = Mode + 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(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + buf[b] = Format + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], DataLen) + b += 4 + + copy(buf[b:], Data[:((int(DataLen)*int(Format))/8)]) + b += int(((int(DataLen) * int(Format)) / 8)) + + return buf +} + +// ChangeSaveSetCookie is a cookie used only for ChangeSaveSet requests. +type ChangeSaveSetCookie struct { + *xgb.Cookie +} + +// ChangeSaveSet sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeSaveSet(c *xgb.Conn, Mode byte, Window Window) ChangeSaveSetCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeSaveSetRequest(c, Mode, Window), cookie) + return ChangeSaveSetCookie{cookie} +} + +// ChangeSaveSetChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeSaveSetCookie.Check() +func ChangeSaveSetChecked(c *xgb.Conn, Mode byte, Window Window) ChangeSaveSetCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeSaveSetRequest(c, Mode, Window), cookie) + return ChangeSaveSetCookie{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 ChangeSaveSetCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeSaveSet +// changeSaveSetRequest writes a ChangeSaveSet request to a byte slice. +func changeSaveSetRequest(c *xgb.Conn, Mode byte, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 6 // request opcode + b += 1 + + buf[b] = Mode + 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 + + return buf +} + +// ChangeWindowAttributesCookie is a cookie used only for ChangeWindowAttributes requests. +type ChangeWindowAttributesCookie struct { + *xgb.Cookie +} + +// ChangeWindowAttributes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeWindowAttributes(c *xgb.Conn, Window Window, ValueMask uint32, ValueList []uint32) ChangeWindowAttributesCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(changeWindowAttributesRequest(c, Window, ValueMask, ValueList), cookie) + return ChangeWindowAttributesCookie{cookie} +} + +// ChangeWindowAttributesChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeWindowAttributesCookie.Check() +func ChangeWindowAttributesChecked(c *xgb.Conn, Window Window, ValueMask uint32, ValueList []uint32) ChangeWindowAttributesCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(changeWindowAttributesRequest(c, Window, ValueMask, ValueList), cookie) + return ChangeWindowAttributesCookie{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 ChangeWindowAttributesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ChangeWindowAttributes +// changeWindowAttributesRequest writes a ChangeWindowAttributes request to a byte slice. +func changeWindowAttributesRequest(c *xgb.Conn, Window Window, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 2 // request opcode + b += 1 + + b += 1 // padding + + 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:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// CirculateWindowCookie is a cookie used only for CirculateWindow requests. +type CirculateWindowCookie struct { + *xgb.Cookie +} + +// CirculateWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CirculateWindow(c *xgb.Conn, Direction byte, Window Window) CirculateWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(circulateWindowRequest(c, Direction, Window), cookie) + return CirculateWindowCookie{cookie} +} + +// CirculateWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using CirculateWindowCookie.Check() +func CirculateWindowChecked(c *xgb.Conn, Direction byte, Window Window) CirculateWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(circulateWindowRequest(c, Direction, Window), cookie) + return CirculateWindowCookie{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 CirculateWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CirculateWindow +// circulateWindowRequest writes a CirculateWindow request to a byte slice. +func circulateWindowRequest(c *xgb.Conn, Direction byte, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 13 // request opcode + b += 1 + + buf[b] = Direction + 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 + + return buf +} + +// ClearAreaCookie is a cookie used only for ClearArea requests. +type ClearAreaCookie struct { + *xgb.Cookie +} + +// ClearArea sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ClearArea(c *xgb.Conn, Exposures bool, Window Window, X int16, Y int16, Width uint16, Height uint16) ClearAreaCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(clearAreaRequest(c, Exposures, Window, X, Y, Width, Height), cookie) + return ClearAreaCookie{cookie} +} + +// ClearAreaChecked sends a checked request. +// If an error occurs, it can be retrieved using ClearAreaCookie.Check() +func ClearAreaChecked(c *xgb.Conn, Exposures bool, Window Window, X int16, Y int16, Width uint16, Height uint16) ClearAreaCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(clearAreaRequest(c, Exposures, Window, X, Y, Width, Height), cookie) + return ClearAreaCookie{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 ClearAreaCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ClearArea +// clearAreaRequest writes a ClearArea request to a byte slice. +func clearAreaRequest(c *xgb.Conn, Exposures bool, Window Window, X int16, Y int16, Width uint16, Height uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 61 // request opcode + b += 1 + + if Exposures { + buf[b] = 1 + } else { + buf[b] = 0 + } + 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.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// CloseFontCookie is a cookie used only for CloseFont requests. +type CloseFontCookie struct { + *xgb.Cookie +} + +// CloseFont sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CloseFont(c *xgb.Conn, Font Font) CloseFontCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(closeFontRequest(c, Font), cookie) + return CloseFontCookie{cookie} +} + +// CloseFontChecked sends a checked request. +// If an error occurs, it can be retrieved using CloseFontCookie.Check() +func CloseFontChecked(c *xgb.Conn, Font Font) CloseFontCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(closeFontRequest(c, Font), cookie) + return CloseFontCookie{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 CloseFontCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CloseFont +// closeFontRequest writes a CloseFont request to a byte slice. +func closeFontRequest(c *xgb.Conn, Font Font) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 46 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Font)) + b += 4 + + return buf +} + +// ConfigureWindowCookie is a cookie used only for ConfigureWindow requests. +type ConfigureWindowCookie struct { + *xgb.Cookie +} + +// ConfigureWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ConfigureWindow(c *xgb.Conn, Window Window, ValueMask uint16, ValueList []uint32) ConfigureWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(configureWindowRequest(c, Window, ValueMask, ValueList), cookie) + return ConfigureWindowCookie{cookie} +} + +// ConfigureWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using ConfigureWindowCookie.Check() +func ConfigureWindowChecked(c *xgb.Conn, Window Window, ValueMask uint16, ValueList []uint32) ConfigureWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(configureWindowRequest(c, Window, ValueMask, ValueList), cookie) + return ConfigureWindowCookie{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 ConfigureWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ConfigureWindow +// configureWindowRequest writes a ConfigureWindow request to a byte slice. +func configureWindowRequest(c *xgb.Conn, Window Window, ValueMask uint16, ValueList []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 12 // request opcode + b += 1 + + b += 1 // padding + + 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.Put16(buf[b:], ValueMask) + b += 2 + + b += 2 // padding + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// ConvertSelectionCookie is a cookie used only for ConvertSelection requests. +type ConvertSelectionCookie struct { + *xgb.Cookie +} + +// ConvertSelection sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ConvertSelection(c *xgb.Conn, Requestor Window, Selection Atom, Target Atom, Property Atom, Time Timestamp) ConvertSelectionCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(convertSelectionRequest(c, Requestor, Selection, Target, Property, Time), cookie) + return ConvertSelectionCookie{cookie} +} + +// ConvertSelectionChecked sends a checked request. +// If an error occurs, it can be retrieved using ConvertSelectionCookie.Check() +func ConvertSelectionChecked(c *xgb.Conn, Requestor Window, Selection Atom, Target Atom, Property Atom, Time Timestamp) ConvertSelectionCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(convertSelectionRequest(c, Requestor, Selection, Target, Property, Time), cookie) + return ConvertSelectionCookie{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 ConvertSelectionCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ConvertSelection +// convertSelectionRequest writes a ConvertSelection request to a byte slice. +func convertSelectionRequest(c *xgb.Conn, Requestor Window, Selection Atom, Target Atom, Property Atom, Time Timestamp) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + buf[b] = 24 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Requestor)) + b += 4 + + xgb.Put32(buf[b:], uint32(Selection)) + b += 4 + + xgb.Put32(buf[b:], uint32(Target)) + b += 4 + + xgb.Put32(buf[b:], uint32(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// CopyAreaCookie is a cookie used only for CopyArea requests. +type CopyAreaCookie struct { + *xgb.Cookie +} + +// CopyArea sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyArea(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) CopyAreaCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(copyAreaRequest(c, SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height), cookie) + return CopyAreaCookie{cookie} +} + +// CopyAreaChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyAreaCookie.Check() +func CopyAreaChecked(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) CopyAreaCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(copyAreaRequest(c, SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height), cookie) + return CopyAreaCookie{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 CopyAreaCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyArea +// copyAreaRequest writes a CopyArea request to a byte slice. +func copyAreaRequest(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) []byte { + size := 28 + b := 0 + buf := make([]byte, size) + + buf[b] = 62 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(SrcDrawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(DstDrawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// CopyColormapAndFreeCookie is a cookie used only for CopyColormapAndFree requests. +type CopyColormapAndFreeCookie struct { + *xgb.Cookie +} + +// CopyColormapAndFree sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyColormapAndFree(c *xgb.Conn, Mid Colormap, SrcCmap Colormap) CopyColormapAndFreeCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(copyColormapAndFreeRequest(c, Mid, SrcCmap), cookie) + return CopyColormapAndFreeCookie{cookie} +} + +// CopyColormapAndFreeChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyColormapAndFreeCookie.Check() +func CopyColormapAndFreeChecked(c *xgb.Conn, Mid Colormap, SrcCmap Colormap) CopyColormapAndFreeCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(copyColormapAndFreeRequest(c, Mid, SrcCmap), cookie) + return CopyColormapAndFreeCookie{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 CopyColormapAndFreeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyColormapAndFree +// copyColormapAndFreeRequest writes a CopyColormapAndFree request to a byte slice. +func copyColormapAndFreeRequest(c *xgb.Conn, Mid Colormap, SrcCmap Colormap) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 80 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Mid)) + b += 4 + + xgb.Put32(buf[b:], uint32(SrcCmap)) + b += 4 + + return buf +} + +// CopyGCCookie is a cookie used only for CopyGC requests. +type CopyGCCookie struct { + *xgb.Cookie +} + +// CopyGC sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyGC(c *xgb.Conn, SrcGc Gcontext, DstGc Gcontext, ValueMask uint32) CopyGCCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(copyGCRequest(c, SrcGc, DstGc, ValueMask), cookie) + return CopyGCCookie{cookie} +} + +// CopyGCChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyGCCookie.Check() +func CopyGCChecked(c *xgb.Conn, SrcGc Gcontext, DstGc Gcontext, ValueMask uint32) CopyGCCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(copyGCRequest(c, SrcGc, DstGc, ValueMask), cookie) + return CopyGCCookie{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 CopyGCCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyGC +// copyGCRequest writes a CopyGC request to a byte slice. +func copyGCRequest(c *xgb.Conn, SrcGc Gcontext, DstGc Gcontext, ValueMask uint32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 57 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(SrcGc)) + b += 4 + + xgb.Put32(buf[b:], uint32(DstGc)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + return buf +} + +// CopyPlaneCookie is a cookie used only for CopyPlane requests. +type CopyPlaneCookie struct { + *xgb.Cookie +} + +// CopyPlane sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CopyPlane(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) CopyPlaneCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(copyPlaneRequest(c, SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height, BitPlane), cookie) + return CopyPlaneCookie{cookie} +} + +// CopyPlaneChecked sends a checked request. +// If an error occurs, it can be retrieved using CopyPlaneCookie.Check() +func CopyPlaneChecked(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) CopyPlaneCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(copyPlaneRequest(c, SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height, BitPlane), cookie) + return CopyPlaneCookie{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 CopyPlaneCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CopyPlane +// copyPlaneRequest writes a CopyPlane request to a byte slice. +func copyPlaneRequest(c *xgb.Conn, SrcDrawable Drawable, DstDrawable Drawable, Gc Gcontext, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + buf[b] = 63 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(SrcDrawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(DstDrawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put32(buf[b:], BitPlane) + b += 4 + + return buf +} + +// CreateColormapCookie is a cookie used only for CreateColormap requests. +type CreateColormapCookie struct { + *xgb.Cookie +} + +// CreateColormap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateColormap(c *xgb.Conn, Alloc byte, Mid Colormap, Window Window, Visual Visualid) CreateColormapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createColormapRequest(c, Alloc, Mid, Window, Visual), cookie) + return CreateColormapCookie{cookie} +} + +// CreateColormapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateColormapCookie.Check() +func CreateColormapChecked(c *xgb.Conn, Alloc byte, Mid Colormap, Window Window, Visual Visualid) CreateColormapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createColormapRequest(c, Alloc, Mid, Window, Visual), cookie) + return CreateColormapCookie{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 CreateColormapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateColormap +// createColormapRequest writes a CreateColormap request to a byte slice. +func createColormapRequest(c *xgb.Conn, Alloc byte, Mid Colormap, Window Window, Visual Visualid) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 78 // request opcode + b += 1 + + buf[b] = Alloc + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Mid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(Visual)) + b += 4 + + return buf +} + +// CreateCursorCookie is a cookie used only for CreateCursor requests. +type CreateCursorCookie struct { + *xgb.Cookie +} + +// CreateCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateCursor(c *xgb.Conn, Cid Cursor, Source Pixmap, Mask Pixmap, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) CreateCursorCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createCursorRequest(c, Cid, Source, Mask, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue, X, Y), cookie) + return CreateCursorCookie{cookie} +} + +// CreateCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateCursorCookie.Check() +func CreateCursorChecked(c *xgb.Conn, Cid Cursor, Source Pixmap, Mask Pixmap, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) CreateCursorCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createCursorRequest(c, Cid, Source, Mask, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue, X, Y), cookie) + return CreateCursorCookie{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 CreateCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateCursor +// createCursorRequest writes a CreateCursor request to a byte slice. +func createCursorRequest(c *xgb.Conn, Cid Cursor, Source Pixmap, Mask Pixmap, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + buf[b] = 93 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Source)) + b += 4 + + xgb.Put32(buf[b:], uint32(Mask)) + b += 4 + + xgb.Put16(buf[b:], ForeRed) + b += 2 + + xgb.Put16(buf[b:], ForeGreen) + b += 2 + + xgb.Put16(buf[b:], ForeBlue) + b += 2 + + xgb.Put16(buf[b:], BackRed) + b += 2 + + xgb.Put16(buf[b:], BackGreen) + b += 2 + + xgb.Put16(buf[b:], BackBlue) + b += 2 + + xgb.Put16(buf[b:], X) + b += 2 + + xgb.Put16(buf[b:], Y) + b += 2 + + return buf +} + +// CreateGCCookie is a cookie used only for CreateGC requests. +type CreateGCCookie struct { + *xgb.Cookie +} + +// CreateGC sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateGC(c *xgb.Conn, Cid Gcontext, Drawable Drawable, ValueMask uint32, ValueList []uint32) CreateGCCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createGCRequest(c, Cid, Drawable, ValueMask, ValueList), cookie) + return CreateGCCookie{cookie} +} + +// CreateGCChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateGCCookie.Check() +func CreateGCChecked(c *xgb.Conn, Cid Gcontext, Drawable Drawable, ValueMask uint32, ValueList []uint32) CreateGCCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createGCRequest(c, Cid, Drawable, ValueMask, ValueList), cookie) + return CreateGCCookie{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 CreateGCCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateGC +// createGCRequest writes a CreateGC request to a byte slice. +func createGCRequest(c *xgb.Conn, Cid Gcontext, Drawable Drawable, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((16 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 55 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// CreateGlyphCursorCookie is a cookie used only for CreateGlyphCursor requests. +type CreateGlyphCursorCookie struct { + *xgb.Cookie +} + +// CreateGlyphCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateGlyphCursor(c *xgb.Conn, Cid Cursor, SourceFont Font, MaskFont Font, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) CreateGlyphCursorCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createGlyphCursorRequest(c, Cid, SourceFont, MaskFont, SourceChar, MaskChar, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return CreateGlyphCursorCookie{cookie} +} + +// CreateGlyphCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateGlyphCursorCookie.Check() +func CreateGlyphCursorChecked(c *xgb.Conn, Cid Cursor, SourceFont Font, MaskFont Font, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) CreateGlyphCursorCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createGlyphCursorRequest(c, Cid, SourceFont, MaskFont, SourceChar, MaskChar, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return CreateGlyphCursorCookie{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 CreateGlyphCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateGlyphCursor +// createGlyphCursorRequest writes a CreateGlyphCursor request to a byte slice. +func createGlyphCursorRequest(c *xgb.Conn, Cid Cursor, SourceFont Font, MaskFont Font, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + buf[b] = 94 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cid)) + b += 4 + + xgb.Put32(buf[b:], uint32(SourceFont)) + b += 4 + + xgb.Put32(buf[b:], uint32(MaskFont)) + b += 4 + + xgb.Put16(buf[b:], SourceChar) + b += 2 + + xgb.Put16(buf[b:], MaskChar) + b += 2 + + xgb.Put16(buf[b:], ForeRed) + b += 2 + + xgb.Put16(buf[b:], ForeGreen) + b += 2 + + xgb.Put16(buf[b:], ForeBlue) + b += 2 + + xgb.Put16(buf[b:], BackRed) + b += 2 + + xgb.Put16(buf[b:], BackGreen) + b += 2 + + xgb.Put16(buf[b:], BackBlue) + b += 2 + + return buf +} + +// CreatePixmapCookie is a cookie used only for CreatePixmap requests. +type CreatePixmapCookie struct { + *xgb.Cookie +} + +// CreatePixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreatePixmap(c *xgb.Conn, Depth byte, Pid Pixmap, Drawable Drawable, Width uint16, Height uint16) CreatePixmapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createPixmapRequest(c, Depth, Pid, Drawable, Width, Height), cookie) + return CreatePixmapCookie{cookie} +} + +// CreatePixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using CreatePixmapCookie.Check() +func CreatePixmapChecked(c *xgb.Conn, Depth byte, Pid Pixmap, Drawable Drawable, Width uint16, Height uint16) CreatePixmapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createPixmapRequest(c, Depth, Pid, Drawable, Width, Height), cookie) + return CreatePixmapCookie{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 CreatePixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreatePixmap +// createPixmapRequest writes a CreatePixmap request to a byte slice. +func createPixmapRequest(c *xgb.Conn, Depth byte, Pid Pixmap, Drawable Drawable, Width uint16, Height uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 53 // request opcode + b += 1 + + buf[b] = Depth + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Pid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// CreateWindowCookie is a cookie used only for CreateWindow requests. +type CreateWindowCookie struct { + *xgb.Cookie +} + +// CreateWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateWindow(c *xgb.Conn, Depth byte, Wid Window, Parent Window, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) CreateWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createWindowRequest(c, Depth, Wid, Parent, X, Y, Width, Height, BorderWidth, Class, Visual, ValueMask, ValueList), cookie) + return CreateWindowCookie{cookie} +} + +// CreateWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateWindowCookie.Check() +func CreateWindowChecked(c *xgb.Conn, Depth byte, Wid Window, Parent Window, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) CreateWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createWindowRequest(c, Depth, Wid, Parent, X, Y, Width, Height, BorderWidth, Class, Visual, ValueMask, ValueList), cookie) + return CreateWindowCookie{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 CreateWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateWindow +// createWindowRequest writes a CreateWindow request to a byte slice. +func createWindowRequest(c *xgb.Conn, Depth byte, Wid Window, Parent Window, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) []byte { + size := xgb.Pad((32 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) + b := 0 + buf := make([]byte, size) + + buf[b] = 1 // request opcode + b += 1 + + buf[b] = Depth + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Wid)) + b += 4 + + xgb.Put32(buf[b:], uint32(Parent)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put16(buf[b:], BorderWidth) + b += 2 + + xgb.Put16(buf[b:], Class) + b += 2 + + xgb.Put32(buf[b:], uint32(Visual)) + b += 4 + + xgb.Put32(buf[b:], ValueMask) + b += 4 + + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { + xgb.Put32(buf[b:], ValueList[i]) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// DeletePropertyCookie is a cookie used only for DeleteProperty requests. +type DeletePropertyCookie struct { + *xgb.Cookie +} + +// DeleteProperty sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteProperty(c *xgb.Conn, Window Window, Property Atom) DeletePropertyCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(deletePropertyRequest(c, Window, Property), cookie) + return DeletePropertyCookie{cookie} +} + +// DeletePropertyChecked sends a checked request. +// If an error occurs, it can be retrieved using DeletePropertyCookie.Check() +func DeletePropertyChecked(c *xgb.Conn, Window Window, Property Atom) DeletePropertyCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(deletePropertyRequest(c, Window, Property), cookie) + return DeletePropertyCookie{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 DeletePropertyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteProperty +// deletePropertyRequest writes a DeleteProperty request to a byte slice. +func deletePropertyRequest(c *xgb.Conn, Window Window, Property Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 19 // request opcode + b += 1 + + b += 1 // padding + + 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(Property)) + b += 4 + + return buf +} + +// DestroySubwindowsCookie is a cookie used only for DestroySubwindows requests. +type DestroySubwindowsCookie struct { + *xgb.Cookie +} + +// DestroySubwindows sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroySubwindows(c *xgb.Conn, Window Window) DestroySubwindowsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(destroySubwindowsRequest(c, Window), cookie) + return DestroySubwindowsCookie{cookie} +} + +// DestroySubwindowsChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroySubwindowsCookie.Check() +func DestroySubwindowsChecked(c *xgb.Conn, Window Window) DestroySubwindowsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(destroySubwindowsRequest(c, Window), cookie) + return DestroySubwindowsCookie{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 DestroySubwindowsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroySubwindows +// destroySubwindowsRequest writes a DestroySubwindows request to a byte slice. +func destroySubwindowsRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 5 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// DestroyWindowCookie is a cookie used only for DestroyWindow requests. +type DestroyWindowCookie struct { + *xgb.Cookie +} + +// DestroyWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyWindow(c *xgb.Conn, Window Window) DestroyWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(destroyWindowRequest(c, Window), cookie) + return DestroyWindowCookie{cookie} +} + +// DestroyWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyWindowCookie.Check() +func DestroyWindowChecked(c *xgb.Conn, Window Window) DestroyWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(destroyWindowRequest(c, Window), cookie) + return DestroyWindowCookie{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 DestroyWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyWindow +// destroyWindowRequest writes a DestroyWindow request to a byte slice. +func destroyWindowRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 4 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// FillPolyCookie is a cookie used only for FillPoly requests. +type FillPolyCookie struct { + *xgb.Cookie +} + +// FillPoly sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FillPoly(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Shape byte, CoordinateMode byte, Points []Point) FillPolyCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(fillPolyRequest(c, Drawable, Gc, Shape, CoordinateMode, Points), cookie) + return FillPolyCookie{cookie} +} + +// FillPolyChecked sends a checked request. +// If an error occurs, it can be retrieved using FillPolyCookie.Check() +func FillPolyChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Shape byte, CoordinateMode byte, Points []Point) FillPolyCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(fillPolyRequest(c, Drawable, Gc, Shape, CoordinateMode, Points), cookie) + return FillPolyCookie{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 FillPolyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FillPoly +// fillPolyRequest writes a FillPoly request to a byte slice. +func fillPolyRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Shape byte, CoordinateMode byte, Points []Point) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Points) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 69 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + buf[b] = Shape + b += 1 + + buf[b] = CoordinateMode + b += 1 + + b += 2 // padding + + b += PointListBytes(buf[b:], Points) + + return buf +} + +// ForceScreenSaverCookie is a cookie used only for ForceScreenSaver requests. +type ForceScreenSaverCookie struct { + *xgb.Cookie +} + +// ForceScreenSaver sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ForceScreenSaver(c *xgb.Conn, Mode byte) ForceScreenSaverCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(forceScreenSaverRequest(c, Mode), cookie) + return ForceScreenSaverCookie{cookie} +} + +// ForceScreenSaverChecked sends a checked request. +// If an error occurs, it can be retrieved using ForceScreenSaverCookie.Check() +func ForceScreenSaverChecked(c *xgb.Conn, Mode byte) ForceScreenSaverCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(forceScreenSaverRequest(c, Mode), cookie) + return ForceScreenSaverCookie{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 ForceScreenSaverCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ForceScreenSaver +// forceScreenSaverRequest writes a ForceScreenSaver request to a byte slice. +func forceScreenSaverRequest(c *xgb.Conn, Mode byte) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 115 // request opcode + b += 1 + + buf[b] = Mode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// FreeColormapCookie is a cookie used only for FreeColormap requests. +type FreeColormapCookie struct { + *xgb.Cookie +} + +// FreeColormap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeColormap(c *xgb.Conn, Cmap Colormap) FreeColormapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freeColormapRequest(c, Cmap), cookie) + return FreeColormapCookie{cookie} +} + +// FreeColormapChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeColormapCookie.Check() +func FreeColormapChecked(c *xgb.Conn, Cmap Colormap) FreeColormapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freeColormapRequest(c, Cmap), cookie) + return FreeColormapCookie{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 FreeColormapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeColormap +// freeColormapRequest writes a FreeColormap request to a byte slice. +func freeColormapRequest(c *xgb.Conn, Cmap Colormap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 79 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + return buf +} + +// FreeColorsCookie is a cookie used only for FreeColors requests. +type FreeColorsCookie struct { + *xgb.Cookie +} + +// FreeColors sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeColors(c *xgb.Conn, Cmap Colormap, PlaneMask uint32, Pixels []uint32) FreeColorsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freeColorsRequest(c, Cmap, PlaneMask, Pixels), cookie) + return FreeColorsCookie{cookie} +} + +// FreeColorsChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeColorsCookie.Check() +func FreeColorsChecked(c *xgb.Conn, Cmap Colormap, PlaneMask uint32, Pixels []uint32) FreeColorsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freeColorsRequest(c, Cmap, PlaneMask, Pixels), cookie) + return FreeColorsCookie{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 FreeColorsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeColors +// freeColorsRequest writes a FreeColors request to a byte slice. +func freeColorsRequest(c *xgb.Conn, Cmap Colormap, PlaneMask uint32, Pixels []uint32) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Pixels) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 88 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put32(buf[b:], PlaneMask) + b += 4 + + for i := 0; i < int(len(Pixels)); i++ { + xgb.Put32(buf[b:], Pixels[i]) + b += 4 + } + + return buf +} + +// FreeCursorCookie is a cookie used only for FreeCursor requests. +type FreeCursorCookie struct { + *xgb.Cookie +} + +// FreeCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeCursor(c *xgb.Conn, Cursor Cursor) FreeCursorCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freeCursorRequest(c, Cursor), cookie) + return FreeCursorCookie{cookie} +} + +// FreeCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeCursorCookie.Check() +func FreeCursorChecked(c *xgb.Conn, Cursor Cursor) FreeCursorCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freeCursorRequest(c, Cursor), cookie) + return FreeCursorCookie{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 FreeCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeCursor +// freeCursorRequest writes a FreeCursor request to a byte slice. +func freeCursorRequest(c *xgb.Conn, Cursor Cursor) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 95 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + return buf +} + +// FreeGCCookie is a cookie used only for FreeGC requests. +type FreeGCCookie struct { + *xgb.Cookie +} + +// FreeGC sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreeGC(c *xgb.Conn, Gc Gcontext) FreeGCCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freeGCRequest(c, Gc), cookie) + return FreeGCCookie{cookie} +} + +// FreeGCChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeGCCookie.Check() +func FreeGCChecked(c *xgb.Conn, Gc Gcontext) FreeGCCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freeGCRequest(c, Gc), cookie) + return FreeGCCookie{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 FreeGCCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeGC +// freeGCRequest writes a FreeGC request to a byte slice. +func freeGCRequest(c *xgb.Conn, Gc Gcontext) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 60 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + return buf +} + +// FreePixmapCookie is a cookie used only for FreePixmap requests. +type FreePixmapCookie struct { + *xgb.Cookie +} + +// FreePixmap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func FreePixmap(c *xgb.Conn, Pixmap Pixmap) FreePixmapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freePixmapRequest(c, Pixmap), cookie) + return FreePixmapCookie{cookie} +} + +// FreePixmapChecked sends a checked request. +// If an error occurs, it can be retrieved using FreePixmapCookie.Check() +func FreePixmapChecked(c *xgb.Conn, Pixmap Pixmap) FreePixmapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freePixmapRequest(c, Pixmap), cookie) + return FreePixmapCookie{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 FreePixmapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreePixmap +// freePixmapRequest writes a FreePixmap request to a byte slice. +func freePixmapRequest(c *xgb.Conn, Pixmap Pixmap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 54 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Pixmap)) + b += 4 + + return buf +} + +// GetAtomNameCookie is a cookie used only for GetAtomName requests. +type GetAtomNameCookie struct { + *xgb.Cookie +} + +// GetAtomName sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetAtomNameCookie.Reply() +func GetAtomName(c *xgb.Conn, Atom Atom) GetAtomNameCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getAtomNameRequest(c, Atom), cookie) + return GetAtomNameCookie{cookie} +} + +// GetAtomNameUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetAtomNameUnchecked(c *xgb.Conn, Atom Atom) GetAtomNameCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getAtomNameRequest(c, Atom), cookie) + return GetAtomNameCookie{cookie} +} + +// GetAtomNameReply represents the data returned from a GetAtomName request. +type GetAtomNameReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NameLen uint16 + // padding: 22 bytes + Name string // size: xgb.Pad((int(NameLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetAtomName request. +func (cook GetAtomNameCookie) Reply() (*GetAtomNameReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getAtomNameReply(buf), nil +} + +// getAtomNameReply reads a byte slice into a GetAtomNameReply value. +func getAtomNameReply(buf []byte) *GetAtomNameReply { + v := new(GetAtomNameReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NameLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + { + byteString := make([]byte, v.NameLen) + copy(byteString[:v.NameLen], buf[b:]) + v.Name = string(byteString) + b += int(v.NameLen) + } + + return v +} + +// Write request to wire for GetAtomName +// getAtomNameRequest writes a GetAtomName request to a byte slice. +func getAtomNameRequest(c *xgb.Conn, Atom Atom) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 17 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Atom)) + b += 4 + + return buf +} + +// GetFontPathCookie is a cookie used only for GetFontPath requests. +type GetFontPathCookie struct { + *xgb.Cookie +} + +// GetFontPath sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetFontPathCookie.Reply() +func GetFontPath(c *xgb.Conn) GetFontPathCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getFontPathRequest(c), cookie) + return GetFontPathCookie{cookie} +} + +// GetFontPathUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetFontPathUnchecked(c *xgb.Conn) GetFontPathCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getFontPathRequest(c), cookie) + return GetFontPathCookie{cookie} +} + +// GetFontPathReply represents the data returned from a GetFontPath request. +type GetFontPathReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PathLen uint16 + // padding: 22 bytes + Path []Str // size: StrListSize(Path) +} + +// Reply blocks and returns the reply data for a GetFontPath request. +func (cook GetFontPathCookie) Reply() (*GetFontPathReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getFontPathReply(buf), nil +} + +// getFontPathReply reads a byte slice into a GetFontPathReply value. +func getFontPathReply(buf []byte) *GetFontPathReply { + v := new(GetFontPathReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PathLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Path = make([]Str, v.PathLen) + b += StrReadList(buf[b:], v.Path) + + return v +} + +// Write request to wire for GetFontPath +// getFontPathRequest writes a GetFontPath request to a byte slice. +func getFontPathRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 52 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetGeometryCookie is a cookie used only for GetGeometry requests. +type GetGeometryCookie struct { + *xgb.Cookie +} + +// GetGeometry sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetGeometryCookie.Reply() +func GetGeometry(c *xgb.Conn, Drawable Drawable) GetGeometryCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getGeometryRequest(c, Drawable), cookie) + return GetGeometryCookie{cookie} +} + +// GetGeometryUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetGeometryUnchecked(c *xgb.Conn, Drawable Drawable) GetGeometryCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getGeometryRequest(c, Drawable), cookie) + return GetGeometryCookie{cookie} +} + +// GetGeometryReply represents the data returned from a GetGeometry request. +type GetGeometryReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Depth byte + Root Window + X int16 + Y int16 + Width uint16 + Height uint16 + BorderWidth uint16 + // padding: 2 bytes +} + +// Reply blocks and returns the reply data for a GetGeometry request. +func (cook GetGeometryCookie) Reply() (*GetGeometryReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getGeometryReply(buf), nil +} + +// getGeometryReply reads a byte slice into a GetGeometryReply value. +func getGeometryReply(buf []byte) *GetGeometryReply { + v := new(GetGeometryReply) + b := 1 // skip reply determinant + + v.Depth = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.BorderWidth = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + return v +} + +// Write request to wire for GetGeometry +// getGeometryRequest writes a GetGeometry request to a byte slice. +func getGeometryRequest(c *xgb.Conn, Drawable Drawable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 14 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + return buf +} + +// GetImageCookie is a cookie used only for GetImage requests. +type GetImageCookie struct { + *xgb.Cookie +} + +// GetImage sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetImageCookie.Reply() +func GetImage(c *xgb.Conn, Format byte, Drawable Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) GetImageCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getImageRequest(c, Format, Drawable, X, Y, Width, Height, PlaneMask), cookie) + return GetImageCookie{cookie} +} + +// GetImageUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetImageUnchecked(c *xgb.Conn, Format byte, Drawable Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) GetImageCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getImageRequest(c, Format, Drawable, X, Y, Width, Height, PlaneMask), cookie) + return GetImageCookie{cookie} +} + +// GetImageReply represents the data returned from a GetImage request. +type GetImageReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Depth byte + Visual Visualid + // padding: 20 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a GetImage request. +func (cook GetImageCookie) Reply() (*GetImageReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getImageReply(buf), nil +} + +// getImageReply reads a byte slice into a GetImageReply value. +func getImageReply(buf []byte) *GetImageReply { + v := new(GetImageReply) + b := 1 // skip reply determinant + + v.Depth = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Visual = Visualid(xgb.Get32(buf[b:])) + b += 4 + + b += 20 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += int((int(v.Length) * 4)) + + return v +} + +// Write request to wire for GetImage +// getImageRequest writes a GetImage request to a byte slice. +func getImageRequest(c *xgb.Conn, Format byte, Drawable Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + buf[b] = 73 // request opcode + b += 1 + + buf[b] = Format + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put32(buf[b:], PlaneMask) + b += 4 + + return buf +} + +// GetInputFocusCookie is a cookie used only for GetInputFocus requests. +type GetInputFocusCookie struct { + *xgb.Cookie +} + +// GetInputFocus sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetInputFocusCookie.Reply() +func GetInputFocus(c *xgb.Conn) GetInputFocusCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getInputFocusRequest(c), cookie) + return GetInputFocusCookie{cookie} +} + +// GetInputFocusUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetInputFocusUnchecked(c *xgb.Conn) GetInputFocusCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getInputFocusRequest(c), cookie) + return GetInputFocusCookie{cookie} +} + +// GetInputFocusReply represents the data returned from a GetInputFocus request. +type GetInputFocusReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + RevertTo byte + Focus Window +} + +// Reply blocks and returns the reply data for a GetInputFocus request. +func (cook GetInputFocusCookie) Reply() (*GetInputFocusReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getInputFocusReply(buf), nil +} + +// getInputFocusReply reads a byte slice into a GetInputFocusReply value. +func getInputFocusReply(buf []byte) *GetInputFocusReply { + v := new(GetInputFocusReply) + b := 1 // skip reply determinant + + v.RevertTo = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Focus = Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetInputFocus +// getInputFocusRequest writes a GetInputFocus request to a byte slice. +func getInputFocusRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 43 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetKeyboardControlCookie is a cookie used only for GetKeyboardControl requests. +type GetKeyboardControlCookie struct { + *xgb.Cookie +} + +// GetKeyboardControl sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetKeyboardControlCookie.Reply() +func GetKeyboardControl(c *xgb.Conn) GetKeyboardControlCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getKeyboardControlRequest(c), cookie) + return GetKeyboardControlCookie{cookie} +} + +// GetKeyboardControlUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetKeyboardControlUnchecked(c *xgb.Conn) GetKeyboardControlCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getKeyboardControlRequest(c), cookie) + return GetKeyboardControlCookie{cookie} +} + +// GetKeyboardControlReply represents the data returned from a GetKeyboardControl request. +type GetKeyboardControlReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + GlobalAutoRepeat byte + LedMask uint32 + KeyClickPercent byte + BellPercent byte + BellPitch uint16 + BellDuration uint16 + // padding: 2 bytes + AutoRepeats []byte // size: 32 +} + +// Reply blocks and returns the reply data for a GetKeyboardControl request. +func (cook GetKeyboardControlCookie) Reply() (*GetKeyboardControlReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getKeyboardControlReply(buf), nil +} + +// getKeyboardControlReply reads a byte slice into a GetKeyboardControlReply value. +func getKeyboardControlReply(buf []byte) *GetKeyboardControlReply { + v := new(GetKeyboardControlReply) + b := 1 // skip reply determinant + + v.GlobalAutoRepeat = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.LedMask = xgb.Get32(buf[b:]) + b += 4 + + v.KeyClickPercent = buf[b] + b += 1 + + v.BellPercent = buf[b] + b += 1 + + v.BellPitch = xgb.Get16(buf[b:]) + b += 2 + + v.BellDuration = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.AutoRepeats = make([]byte, 32) + copy(v.AutoRepeats[:32], buf[b:]) + b += int(32) + + return v +} + +// Write request to wire for GetKeyboardControl +// getKeyboardControlRequest writes a GetKeyboardControl request to a byte slice. +func getKeyboardControlRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 103 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetKeyboardMappingCookie is a cookie used only for GetKeyboardMapping requests. +type GetKeyboardMappingCookie struct { + *xgb.Cookie +} + +// GetKeyboardMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetKeyboardMappingCookie.Reply() +func GetKeyboardMapping(c *xgb.Conn, FirstKeycode Keycode, Count byte) GetKeyboardMappingCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getKeyboardMappingRequest(c, FirstKeycode, Count), cookie) + return GetKeyboardMappingCookie{cookie} +} + +// GetKeyboardMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetKeyboardMappingUnchecked(c *xgb.Conn, FirstKeycode Keycode, Count byte) GetKeyboardMappingCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getKeyboardMappingRequest(c, FirstKeycode, Count), cookie) + return GetKeyboardMappingCookie{cookie} +} + +// GetKeyboardMappingReply represents the data returned from a GetKeyboardMapping request. +type GetKeyboardMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + KeysymsPerKeycode byte + // padding: 24 bytes + Keysyms []Keysym // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a GetKeyboardMapping request. +func (cook GetKeyboardMappingCookie) Reply() (*GetKeyboardMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getKeyboardMappingReply(buf), nil +} + +// getKeyboardMappingReply reads a byte slice into a GetKeyboardMappingReply value. +func getKeyboardMappingReply(buf []byte) *GetKeyboardMappingReply { + v := new(GetKeyboardMappingReply) + b := 1 // skip reply determinant + + v.KeysymsPerKeycode = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Keysyms = make([]Keysym, v.Length) + for i := 0; i < int(v.Length); i++ { + v.Keysyms[i] = Keysym(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for GetKeyboardMapping +// getKeyboardMappingRequest writes a GetKeyboardMapping request to a byte slice. +func getKeyboardMappingRequest(c *xgb.Conn, FirstKeycode Keycode, Count byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 101 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = byte(FirstKeycode) + b += 1 + + buf[b] = Count + b += 1 + + return buf +} + +// GetModifierMappingCookie is a cookie used only for GetModifierMapping requests. +type GetModifierMappingCookie struct { + *xgb.Cookie +} + +// GetModifierMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetModifierMappingCookie.Reply() +func GetModifierMapping(c *xgb.Conn) GetModifierMappingCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getModifierMappingRequest(c), cookie) + return GetModifierMappingCookie{cookie} +} + +// GetModifierMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetModifierMappingUnchecked(c *xgb.Conn) GetModifierMappingCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getModifierMappingRequest(c), cookie) + return GetModifierMappingCookie{cookie} +} + +// GetModifierMappingReply represents the data returned from a GetModifierMapping request. +type GetModifierMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + KeycodesPerModifier byte + // padding: 24 bytes + Keycodes []Keycode // size: xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)) +} + +// Reply blocks and returns the reply data for a GetModifierMapping request. +func (cook GetModifierMappingCookie) Reply() (*GetModifierMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getModifierMappingReply(buf), nil +} + +// getModifierMappingReply reads a byte slice into a GetModifierMappingReply value. +func getModifierMappingReply(buf []byte) *GetModifierMappingReply { + v := new(GetModifierMappingReply) + b := 1 // skip reply determinant + + v.KeycodesPerModifier = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Keycodes = make([]Keycode, (int(v.KeycodesPerModifier) * 8)) + for i := 0; i < int((int(v.KeycodesPerModifier) * 8)); i++ { + v.Keycodes[i] = Keycode(buf[b]) + b += 1 + } + + return v +} + +// Write request to wire for GetModifierMapping +// getModifierMappingRequest writes a GetModifierMapping request to a byte slice. +func getModifierMappingRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 119 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetMotionEventsCookie is a cookie used only for GetMotionEvents requests. +type GetMotionEventsCookie struct { + *xgb.Cookie +} + +// GetMotionEvents sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMotionEventsCookie.Reply() +func GetMotionEvents(c *xgb.Conn, Window Window, Start Timestamp, Stop Timestamp) GetMotionEventsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getMotionEventsRequest(c, Window, Start, Stop), cookie) + return GetMotionEventsCookie{cookie} +} + +// GetMotionEventsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMotionEventsUnchecked(c *xgb.Conn, Window Window, Start Timestamp, Stop Timestamp) GetMotionEventsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getMotionEventsRequest(c, Window, Start, Stop), cookie) + return GetMotionEventsCookie{cookie} +} + +// GetMotionEventsReply represents the data returned from a GetMotionEvents request. +type GetMotionEventsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + EventsLen uint32 + // padding: 20 bytes + Events []Timecoord // size: xgb.Pad((int(EventsLen) * 8)) +} + +// Reply blocks and returns the reply data for a GetMotionEvents request. +func (cook GetMotionEventsCookie) Reply() (*GetMotionEventsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMotionEventsReply(buf), nil +} + +// getMotionEventsReply reads a byte slice into a GetMotionEventsReply value. +func getMotionEventsReply(buf []byte) *GetMotionEventsReply { + v := new(GetMotionEventsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.EventsLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Events = make([]Timecoord, v.EventsLen) + b += TimecoordReadList(buf[b:], v.Events) + + return v +} + +// Write request to wire for GetMotionEvents +// getMotionEventsRequest writes a GetMotionEvents request to a byte slice. +func getMotionEventsRequest(c *xgb.Conn, Window Window, Start Timestamp, Stop Timestamp) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 39 // request opcode + b += 1 + + b += 1 // padding + + 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(Start)) + b += 4 + + xgb.Put32(buf[b:], uint32(Stop)) + b += 4 + + return buf +} + +// GetPointerControlCookie is a cookie used only for GetPointerControl requests. +type GetPointerControlCookie struct { + *xgb.Cookie +} + +// GetPointerControl sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPointerControlCookie.Reply() +func GetPointerControl(c *xgb.Conn) GetPointerControlCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getPointerControlRequest(c), cookie) + return GetPointerControlCookie{cookie} +} + +// GetPointerControlUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPointerControlUnchecked(c *xgb.Conn) GetPointerControlCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getPointerControlRequest(c), cookie) + return GetPointerControlCookie{cookie} +} + +// GetPointerControlReply represents the data returned from a GetPointerControl request. +type GetPointerControlReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + AccelerationNumerator uint16 + AccelerationDenominator uint16 + Threshold uint16 + // padding: 18 bytes +} + +// Reply blocks and returns the reply data for a GetPointerControl request. +func (cook GetPointerControlCookie) Reply() (*GetPointerControlReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPointerControlReply(buf), nil +} + +// getPointerControlReply reads a byte slice into a GetPointerControlReply value. +func getPointerControlReply(buf []byte) *GetPointerControlReply { + v := new(GetPointerControlReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.AccelerationNumerator = xgb.Get16(buf[b:]) + b += 2 + + v.AccelerationDenominator = xgb.Get16(buf[b:]) + b += 2 + + v.Threshold = xgb.Get16(buf[b:]) + b += 2 + + b += 18 // padding + + return v +} + +// Write request to wire for GetPointerControl +// getPointerControlRequest writes a GetPointerControl request to a byte slice. +func getPointerControlRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 106 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetPointerMappingCookie is a cookie used only for GetPointerMapping requests. +type GetPointerMappingCookie struct { + *xgb.Cookie +} + +// GetPointerMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPointerMappingCookie.Reply() +func GetPointerMapping(c *xgb.Conn) GetPointerMappingCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getPointerMappingRequest(c), cookie) + return GetPointerMappingCookie{cookie} +} + +// GetPointerMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPointerMappingUnchecked(c *xgb.Conn) GetPointerMappingCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getPointerMappingRequest(c), cookie) + return GetPointerMappingCookie{cookie} +} + +// GetPointerMappingReply represents the data returned from a GetPointerMapping request. +type GetPointerMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + MapLen byte + // padding: 24 bytes + Map []byte // size: xgb.Pad((int(MapLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetPointerMapping request. +func (cook GetPointerMappingCookie) Reply() (*GetPointerMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPointerMappingReply(buf), nil +} + +// getPointerMappingReply reads a byte slice into a GetPointerMappingReply value. +func getPointerMappingReply(buf []byte) *GetPointerMappingReply { + v := new(GetPointerMappingReply) + b := 1 // skip reply determinant + + v.MapLen = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Map = make([]byte, v.MapLen) + copy(v.Map[:v.MapLen], buf[b:]) + b += int(v.MapLen) + + return v +} + +// Write request to wire for GetPointerMapping +// getPointerMappingRequest writes a GetPointerMapping request to a byte slice. +func getPointerMappingRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 117 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetPropertyCookie is a cookie used only for GetProperty requests. +type GetPropertyCookie struct { + *xgb.Cookie +} + +// GetProperty sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPropertyCookie.Reply() +func GetProperty(c *xgb.Conn, Delete bool, Window Window, Property Atom, Type Atom, LongOffset uint32, LongLength uint32) GetPropertyCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getPropertyRequest(c, Delete, Window, Property, Type, LongOffset, LongLength), cookie) + return GetPropertyCookie{cookie} +} + +// GetPropertyUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPropertyUnchecked(c *xgb.Conn, Delete bool, Window Window, Property Atom, Type Atom, LongOffset uint32, LongLength uint32) GetPropertyCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getPropertyRequest(c, Delete, Window, Property, Type, LongOffset, LongLength), cookie) + return GetPropertyCookie{cookie} +} + +// GetPropertyReply represents the data returned from a GetProperty request. +type GetPropertyReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Format byte + Type Atom + BytesAfter uint32 + ValueLen uint32 + // padding: 12 bytes + Value []byte // size: xgb.Pad(((int(ValueLen) * (int(Format) / 8)) * 1)) +} + +// Reply blocks and returns the reply data for a GetProperty request. +func (cook GetPropertyCookie) Reply() (*GetPropertyReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPropertyReply(buf), nil +} + +// getPropertyReply reads a byte slice into a GetPropertyReply value. +func getPropertyReply(buf []byte) *GetPropertyReply { + v := new(GetPropertyReply) + b := 1 // skip reply determinant + + v.Format = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Type = Atom(xgb.Get32(buf[b:])) + b += 4 + + v.BytesAfter = xgb.Get32(buf[b:]) + b += 4 + + v.ValueLen = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Value = make([]byte, (int(v.ValueLen) * (int(v.Format) / 8))) + copy(v.Value[:(int(v.ValueLen)*(int(v.Format)/8))], buf[b:]) + b += int((int(v.ValueLen) * (int(v.Format) / 8))) + + return v +} + +// Write request to wire for GetProperty +// getPropertyRequest writes a GetProperty request to a byte slice. +func getPropertyRequest(c *xgb.Conn, Delete bool, Window Window, Property Atom, Type Atom, LongOffset uint32, LongLength uint32) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + buf[b] = 20 // request opcode + b += 1 + + if Delete { + buf[b] = 1 + } else { + buf[b] = 0 + } + 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(Property)) + b += 4 + + xgb.Put32(buf[b:], uint32(Type)) + b += 4 + + xgb.Put32(buf[b:], LongOffset) + b += 4 + + xgb.Put32(buf[b:], LongLength) + b += 4 + + return buf +} + +// GetScreenSaverCookie is a cookie used only for GetScreenSaver requests. +type GetScreenSaverCookie struct { + *xgb.Cookie +} + +// GetScreenSaver sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetScreenSaverCookie.Reply() +func GetScreenSaver(c *xgb.Conn) GetScreenSaverCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getScreenSaverRequest(c), cookie) + return GetScreenSaverCookie{cookie} +} + +// GetScreenSaverUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetScreenSaverUnchecked(c *xgb.Conn) GetScreenSaverCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getScreenSaverRequest(c), cookie) + return GetScreenSaverCookie{cookie} +} + +// GetScreenSaverReply represents the data returned from a GetScreenSaver request. +type GetScreenSaverReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timeout uint16 + Interval uint16 + PreferBlanking byte + AllowExposures byte + // padding: 18 bytes +} + +// Reply blocks and returns the reply data for a GetScreenSaver request. +func (cook GetScreenSaverCookie) Reply() (*GetScreenSaverReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getScreenSaverReply(buf), nil +} + +// getScreenSaverReply reads a byte slice into a GetScreenSaverReply value. +func getScreenSaverReply(buf []byte) *GetScreenSaverReply { + v := new(GetScreenSaverReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Timeout = xgb.Get16(buf[b:]) + b += 2 + + v.Interval = xgb.Get16(buf[b:]) + b += 2 + + v.PreferBlanking = buf[b] + b += 1 + + v.AllowExposures = buf[b] + b += 1 + + b += 18 // padding + + return v +} + +// Write request to wire for GetScreenSaver +// getScreenSaverRequest writes a GetScreenSaver request to a byte slice. +func getScreenSaverRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 108 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetSelectionOwnerCookie is a cookie used only for GetSelectionOwner requests. +type GetSelectionOwnerCookie struct { + *xgb.Cookie +} + +// GetSelectionOwner sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectionOwnerCookie.Reply() +func GetSelectionOwner(c *xgb.Conn, Selection Atom) GetSelectionOwnerCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectionOwnerRequest(c, Selection), cookie) + return GetSelectionOwnerCookie{cookie} +} + +// GetSelectionOwnerUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectionOwnerUnchecked(c *xgb.Conn, Selection Atom) GetSelectionOwnerCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectionOwnerRequest(c, Selection), cookie) + return GetSelectionOwnerCookie{cookie} +} + +// GetSelectionOwnerReply represents the data returned from a GetSelectionOwner request. +type GetSelectionOwnerReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Owner Window +} + +// Reply blocks and returns the reply data for a GetSelectionOwner request. +func (cook GetSelectionOwnerCookie) Reply() (*GetSelectionOwnerReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectionOwnerReply(buf), nil +} + +// getSelectionOwnerReply reads a byte slice into a GetSelectionOwnerReply value. +func getSelectionOwnerReply(buf []byte) *GetSelectionOwnerReply { + v := new(GetSelectionOwnerReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Owner = Window(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetSelectionOwner +// getSelectionOwnerRequest writes a GetSelectionOwner request to a byte slice. +func getSelectionOwnerRequest(c *xgb.Conn, Selection Atom) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 23 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Selection)) + b += 4 + + return buf +} + +// GetWindowAttributesCookie is a cookie used only for GetWindowAttributes requests. +type GetWindowAttributesCookie struct { + *xgb.Cookie +} + +// GetWindowAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetWindowAttributesCookie.Reply() +func GetWindowAttributes(c *xgb.Conn, Window Window) GetWindowAttributesCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getWindowAttributesRequest(c, Window), cookie) + return GetWindowAttributesCookie{cookie} +} + +// GetWindowAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetWindowAttributesUnchecked(c *xgb.Conn, Window Window) GetWindowAttributesCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getWindowAttributesRequest(c, Window), cookie) + return GetWindowAttributesCookie{cookie} +} + +// GetWindowAttributesReply represents the data returned from a GetWindowAttributes request. +type GetWindowAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + BackingStore byte + Visual Visualid + Class uint16 + BitGravity byte + WinGravity byte + BackingPlanes uint32 + BackingPixel uint32 + SaveUnder bool + MapIsInstalled bool + MapState byte + OverrideRedirect bool + Colormap Colormap + AllEventMasks uint32 + YourEventMask uint32 + DoNotPropagateMask uint16 + // padding: 2 bytes +} + +// Reply blocks and returns the reply data for a GetWindowAttributes request. +func (cook GetWindowAttributesCookie) Reply() (*GetWindowAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getWindowAttributesReply(buf), nil +} + +// getWindowAttributesReply reads a byte slice into a GetWindowAttributesReply value. +func getWindowAttributesReply(buf []byte) *GetWindowAttributesReply { + v := new(GetWindowAttributesReply) + b := 1 // skip reply determinant + + v.BackingStore = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Visual = Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.Class = xgb.Get16(buf[b:]) + b += 2 + + v.BitGravity = buf[b] + b += 1 + + v.WinGravity = buf[b] + b += 1 + + v.BackingPlanes = xgb.Get32(buf[b:]) + b += 4 + + v.BackingPixel = xgb.Get32(buf[b:]) + b += 4 + + if buf[b] == 1 { + v.SaveUnder = true + } else { + v.SaveUnder = false + } + b += 1 + + if buf[b] == 1 { + v.MapIsInstalled = true + } else { + v.MapIsInstalled = false + } + b += 1 + + v.MapState = buf[b] + b += 1 + + if buf[b] == 1 { + v.OverrideRedirect = true + } else { + v.OverrideRedirect = false + } + b += 1 + + v.Colormap = Colormap(xgb.Get32(buf[b:])) + b += 4 + + v.AllEventMasks = xgb.Get32(buf[b:]) + b += 4 + + v.YourEventMask = xgb.Get32(buf[b:]) + b += 4 + + v.DoNotPropagateMask = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + return v +} + +// Write request to wire for GetWindowAttributes +// getWindowAttributesRequest writes a GetWindowAttributes request to a byte slice. +func getWindowAttributesRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 3 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// GrabButtonCookie is a cookie used only for GrabButton requests. +type GrabButtonCookie struct { + *xgb.Cookie +} + +// GrabButton sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabButton(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Button byte, Modifiers uint16) GrabButtonCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(grabButtonRequest(c, OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Button, Modifiers), cookie) + return GrabButtonCookie{cookie} +} + +// GrabButtonChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabButtonCookie.Check() +func GrabButtonChecked(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Button byte, Modifiers uint16) GrabButtonCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(grabButtonRequest(c, OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Button, Modifiers), cookie) + return GrabButtonCookie{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 GrabButtonCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GrabButton +// grabButtonRequest writes a GrabButton request to a byte slice. +func grabButtonRequest(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Button byte, Modifiers uint16) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + buf[b] = 28 // request opcode + b += 1 + + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], EventMask) + b += 2 + + buf[b] = PointerMode + b += 1 + + buf[b] = KeyboardMode + b += 1 + + xgb.Put32(buf[b:], uint32(ConfineTo)) + b += 4 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + buf[b] = Button + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], Modifiers) + b += 2 + + return buf +} + +// GrabKeyCookie is a cookie used only for GrabKey requests. +type GrabKeyCookie struct { + *xgb.Cookie +} + +// GrabKey sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabKey(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) GrabKeyCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(grabKeyRequest(c, OwnerEvents, GrabWindow, Modifiers, Key, PointerMode, KeyboardMode), cookie) + return GrabKeyCookie{cookie} +} + +// GrabKeyChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabKeyCookie.Check() +func GrabKeyChecked(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) GrabKeyCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(grabKeyRequest(c, OwnerEvents, GrabWindow, Modifiers, Key, PointerMode, KeyboardMode), cookie) + return GrabKeyCookie{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 GrabKeyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GrabKey +// grabKeyRequest writes a GrabKey request to a byte slice. +func grabKeyRequest(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 33 // request opcode + b += 1 + + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], Modifiers) + b += 2 + + buf[b] = byte(Key) + b += 1 + + buf[b] = PointerMode + b += 1 + + buf[b] = KeyboardMode + b += 1 + + b += 3 // padding + + return buf +} + +// GrabKeyboardCookie is a cookie used only for GrabKeyboard requests. +type GrabKeyboardCookie struct { + *xgb.Cookie +} + +// GrabKeyboard sends a checked request. +// If an error occurs, it will be returned with the reply by calling GrabKeyboardCookie.Reply() +func GrabKeyboard(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Time Timestamp, PointerMode byte, KeyboardMode byte) GrabKeyboardCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(grabKeyboardRequest(c, OwnerEvents, GrabWindow, Time, PointerMode, KeyboardMode), cookie) + return GrabKeyboardCookie{cookie} +} + +// GrabKeyboardUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabKeyboardUnchecked(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Time Timestamp, PointerMode byte, KeyboardMode byte) GrabKeyboardCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(grabKeyboardRequest(c, OwnerEvents, GrabWindow, Time, PointerMode, KeyboardMode), cookie) + return GrabKeyboardCookie{cookie} +} + +// GrabKeyboardReply represents the data returned from a GrabKeyboard request. +type GrabKeyboardReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte +} + +// Reply blocks and returns the reply data for a GrabKeyboard request. +func (cook GrabKeyboardCookie) Reply() (*GrabKeyboardReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return grabKeyboardReply(buf), nil +} + +// grabKeyboardReply reads a byte slice into a GrabKeyboardReply value. +func grabKeyboardReply(buf []byte) *GrabKeyboardReply { + v := new(GrabKeyboardReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + 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 GrabKeyboard +// grabKeyboardRequest writes a GrabKeyboard request to a byte slice. +func grabKeyboardRequest(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, Time Timestamp, PointerMode byte, KeyboardMode byte) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 31 // request opcode + b += 1 + + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + buf[b] = PointerMode + b += 1 + + buf[b] = KeyboardMode + b += 1 + + b += 2 // padding + + return buf +} + +// GrabPointerCookie is a cookie used only for GrabPointer requests. +type GrabPointerCookie struct { + *xgb.Cookie +} + +// GrabPointer sends a checked request. +// If an error occurs, it will be returned with the reply by calling GrabPointerCookie.Reply() +func GrabPointer(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Time Timestamp) GrabPointerCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(grabPointerRequest(c, OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Time), cookie) + return GrabPointerCookie{cookie} +} + +// GrabPointerUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabPointerUnchecked(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Time Timestamp) GrabPointerCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(grabPointerRequest(c, OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Time), cookie) + return GrabPointerCookie{cookie} +} + +// GrabPointerReply represents the data returned from a GrabPointer request. +type GrabPointerReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte +} + +// Reply blocks and returns the reply data for a GrabPointer request. +func (cook GrabPointerCookie) Reply() (*GrabPointerReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return grabPointerReply(buf), nil +} + +// grabPointerReply reads a byte slice into a GrabPointerReply value. +func grabPointerReply(buf []byte) *GrabPointerReply { + v := new(GrabPointerReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + 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 GrabPointer +// grabPointerRequest writes a GrabPointer request to a byte slice. +func grabPointerRequest(c *xgb.Conn, OwnerEvents bool, GrabWindow Window, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Window, Cursor Cursor, Time Timestamp) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + buf[b] = 26 // request opcode + b += 1 + + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], EventMask) + b += 2 + + buf[b] = PointerMode + b += 1 + + buf[b] = KeyboardMode + b += 1 + + xgb.Put32(buf[b:], uint32(ConfineTo)) + b += 4 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// GrabServerCookie is a cookie used only for GrabServer requests. +type GrabServerCookie struct { + *xgb.Cookie +} + +// GrabServer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabServer(c *xgb.Conn) GrabServerCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(grabServerRequest(c), cookie) + return GrabServerCookie{cookie} +} + +// GrabServerChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabServerCookie.Check() +func GrabServerChecked(c *xgb.Conn) GrabServerCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(grabServerRequest(c), cookie) + return GrabServerCookie{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 GrabServerCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GrabServer +// grabServerRequest writes a GrabServer request to a byte slice. +func grabServerRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 36 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ImageText16Cookie is a cookie used only for ImageText16 requests. +type ImageText16Cookie struct { + *xgb.Cookie +} + +// ImageText16 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ImageText16(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String []Char2b) ImageText16Cookie { + cookie := c.NewCookie(false, false) + c.NewRequest(imageText16Request(c, StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText16Cookie{cookie} +} + +// ImageText16Checked sends a checked request. +// If an error occurs, it can be retrieved using ImageText16Cookie.Check() +func ImageText16Checked(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String []Char2b) ImageText16Cookie { + cookie := c.NewCookie(true, false) + c.NewRequest(imageText16Request(c, StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText16Cookie{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 ImageText16Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ImageText16 +// imageText16Request writes a ImageText16 request to a byte slice. +func imageText16Request(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String []Char2b) []byte { + size := xgb.Pad((16 + xgb.Pad((int(StringLen) * 2)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 77 // request opcode + b += 1 + + buf[b] = StringLen + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + b += Char2bListBytes(buf[b:], String) + + return buf +} + +// ImageText8Cookie is a cookie used only for ImageText8 requests. +type ImageText8Cookie struct { + *xgb.Cookie +} + +// ImageText8 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ImageText8(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String string) ImageText8Cookie { + cookie := c.NewCookie(false, false) + c.NewRequest(imageText8Request(c, StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText8Cookie{cookie} +} + +// ImageText8Checked sends a checked request. +// If an error occurs, it can be retrieved using ImageText8Cookie.Check() +func ImageText8Checked(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String string) ImageText8Cookie { + cookie := c.NewCookie(true, false) + c.NewRequest(imageText8Request(c, StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText8Cookie{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 ImageText8Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ImageText8 +// imageText8Request writes a ImageText8 request to a byte slice. +func imageText8Request(c *xgb.Conn, StringLen byte, Drawable Drawable, Gc Gcontext, X int16, Y int16, String string) []byte { + size := xgb.Pad((16 + xgb.Pad((int(StringLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 76 // request opcode + b += 1 + + buf[b] = StringLen + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + copy(buf[b:], String[:StringLen]) + b += int(StringLen) + + return buf +} + +// InstallColormapCookie is a cookie used only for InstallColormap requests. +type InstallColormapCookie struct { + *xgb.Cookie +} + +// InstallColormap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func InstallColormap(c *xgb.Conn, Cmap Colormap) InstallColormapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(installColormapRequest(c, Cmap), cookie) + return InstallColormapCookie{cookie} +} + +// InstallColormapChecked sends a checked request. +// If an error occurs, it can be retrieved using InstallColormapCookie.Check() +func InstallColormapChecked(c *xgb.Conn, Cmap Colormap) InstallColormapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(installColormapRequest(c, Cmap), cookie) + return InstallColormapCookie{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 InstallColormapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for InstallColormap +// installColormapRequest writes a InstallColormap request to a byte slice. +func installColormapRequest(c *xgb.Conn, Cmap Colormap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 81 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + return buf +} + +// InternAtomCookie is a cookie used only for InternAtom requests. +type InternAtomCookie struct { + *xgb.Cookie +} + +// InternAtom sends a checked request. +// If an error occurs, it will be returned with the reply by calling InternAtomCookie.Reply() +func InternAtom(c *xgb.Conn, OnlyIfExists bool, NameLen uint16, Name string) InternAtomCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(internAtomRequest(c, OnlyIfExists, NameLen, Name), cookie) + return InternAtomCookie{cookie} +} + +// InternAtomUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func InternAtomUnchecked(c *xgb.Conn, OnlyIfExists bool, NameLen uint16, Name string) InternAtomCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(internAtomRequest(c, OnlyIfExists, NameLen, Name), cookie) + return InternAtomCookie{cookie} +} + +// InternAtomReply represents the data returned from a InternAtom request. +type InternAtomReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Atom Atom +} + +// Reply blocks and returns the reply data for a InternAtom request. +func (cook InternAtomCookie) Reply() (*InternAtomReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return internAtomReply(buf), nil +} + +// internAtomReply reads a byte slice into a InternAtomReply value. +func internAtomReply(buf []byte) *InternAtomReply { + v := new(InternAtomReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Atom = Atom(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for InternAtom +// internAtomRequest writes a InternAtom request to a byte slice. +func internAtomRequest(c *xgb.Conn, OnlyIfExists bool, NameLen uint16, Name string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 16 // request opcode + b += 1 + + if OnlyIfExists { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// KillClientCookie is a cookie used only for KillClient requests. +type KillClientCookie struct { + *xgb.Cookie +} + +// KillClient sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func KillClient(c *xgb.Conn, Resource uint32) KillClientCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(killClientRequest(c, Resource), cookie) + return KillClientCookie{cookie} +} + +// KillClientChecked sends a checked request. +// If an error occurs, it can be retrieved using KillClientCookie.Check() +func KillClientChecked(c *xgb.Conn, Resource uint32) KillClientCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(killClientRequest(c, Resource), cookie) + return KillClientCookie{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 KillClientCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for KillClient +// killClientRequest writes a KillClient request to a byte slice. +func killClientRequest(c *xgb.Conn, Resource uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 113 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Resource) + b += 4 + + return buf +} + +// ListExtensionsCookie is a cookie used only for ListExtensions requests. +type ListExtensionsCookie struct { + *xgb.Cookie +} + +// ListExtensions sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListExtensionsCookie.Reply() +func ListExtensions(c *xgb.Conn) ListExtensionsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listExtensionsRequest(c), cookie) + return ListExtensionsCookie{cookie} +} + +// ListExtensionsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListExtensionsUnchecked(c *xgb.Conn) ListExtensionsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listExtensionsRequest(c), cookie) + return ListExtensionsCookie{cookie} +} + +// ListExtensionsReply represents the data returned from a ListExtensions request. +type ListExtensionsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + NamesLen byte + // padding: 24 bytes + Names []Str // size: StrListSize(Names) +} + +// Reply blocks and returns the reply data for a ListExtensions request. +func (cook ListExtensionsCookie) Reply() (*ListExtensionsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listExtensionsReply(buf), nil +} + +// listExtensionsReply reads a byte slice into a ListExtensionsReply value. +func listExtensionsReply(buf []byte) *ListExtensionsReply { + v := new(ListExtensionsReply) + b := 1 // skip reply determinant + + v.NamesLen = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.Names = make([]Str, v.NamesLen) + b += StrReadList(buf[b:], v.Names) + + return v +} + +// Write request to wire for ListExtensions +// listExtensionsRequest writes a ListExtensions request to a byte slice. +func listExtensionsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 99 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ListFontsCookie is a cookie used only for ListFonts requests. +type ListFontsCookie struct { + *xgb.Cookie +} + +// ListFonts sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListFontsCookie.Reply() +func ListFonts(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) ListFontsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listFontsRequest(c, MaxNames, PatternLen, Pattern), cookie) + return ListFontsCookie{cookie} +} + +// ListFontsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListFontsUnchecked(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) ListFontsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listFontsRequest(c, MaxNames, PatternLen, Pattern), cookie) + return ListFontsCookie{cookie} +} + +// ListFontsReply represents the data returned from a ListFonts request. +type ListFontsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NamesLen uint16 + // padding: 22 bytes + Names []Str // size: StrListSize(Names) +} + +// Reply blocks and returns the reply data for a ListFonts request. +func (cook ListFontsCookie) Reply() (*ListFontsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listFontsReply(buf), nil +} + +// listFontsReply reads a byte slice into a ListFontsReply value. +func listFontsReply(buf []byte) *ListFontsReply { + v := new(ListFontsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NamesLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Names = make([]Str, v.NamesLen) + b += StrReadList(buf[b:], v.Names) + + return v +} + +// Write request to wire for ListFonts +// listFontsRequest writes a ListFonts request to a byte slice. +func listFontsRequest(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(PatternLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 49 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], MaxNames) + b += 2 + + xgb.Put16(buf[b:], PatternLen) + b += 2 + + copy(buf[b:], Pattern[:PatternLen]) + b += int(PatternLen) + + return buf +} + +// ListFontsWithInfoCookie is a cookie used only for ListFontsWithInfo requests. +type ListFontsWithInfoCookie struct { + *xgb.Cookie +} + +// ListFontsWithInfo sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListFontsWithInfoCookie.Reply() +func ListFontsWithInfo(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) ListFontsWithInfoCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listFontsWithInfoRequest(c, MaxNames, PatternLen, Pattern), cookie) + return ListFontsWithInfoCookie{cookie} +} + +// ListFontsWithInfoUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListFontsWithInfoUnchecked(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) ListFontsWithInfoCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listFontsWithInfoRequest(c, MaxNames, PatternLen, Pattern), cookie) + return ListFontsWithInfoCookie{cookie} +} + +// ListFontsWithInfoReply represents the data returned from a ListFontsWithInfo request. +type ListFontsWithInfoReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + NameLen byte + MinBounds Charinfo + // padding: 4 bytes + MaxBounds Charinfo + // padding: 4 bytes + MinCharOrByte2 uint16 + MaxCharOrByte2 uint16 + DefaultChar uint16 + PropertiesLen uint16 + DrawDirection byte + MinByte1 byte + MaxByte1 byte + AllCharsExist bool + FontAscent int16 + FontDescent int16 + RepliesHint uint32 + Properties []Fontprop // size: xgb.Pad((int(PropertiesLen) * 8)) + Name string // size: xgb.Pad((int(NameLen) * 1)) +} + +// Reply blocks and returns the reply data for a ListFontsWithInfo request. +func (cook ListFontsWithInfoCookie) Reply() (*ListFontsWithInfoReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listFontsWithInfoReply(buf), nil +} + +// listFontsWithInfoReply reads a byte slice into a ListFontsWithInfoReply value. +func listFontsWithInfoReply(buf []byte) *ListFontsWithInfoReply { + v := new(ListFontsWithInfoReply) + b := 1 // skip reply determinant + + v.NameLen = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MinBounds = Charinfo{} + b += CharinfoRead(buf[b:], &v.MinBounds) + + b += 4 // padding + + v.MaxBounds = Charinfo{} + b += CharinfoRead(buf[b:], &v.MaxBounds) + + b += 4 // padding + + v.MinCharOrByte2 = xgb.Get16(buf[b:]) + b += 2 + + v.MaxCharOrByte2 = xgb.Get16(buf[b:]) + b += 2 + + v.DefaultChar = xgb.Get16(buf[b:]) + b += 2 + + v.PropertiesLen = xgb.Get16(buf[b:]) + b += 2 + + v.DrawDirection = buf[b] + b += 1 + + v.MinByte1 = buf[b] + b += 1 + + v.MaxByte1 = buf[b] + b += 1 + + if buf[b] == 1 { + v.AllCharsExist = true + } else { + v.AllCharsExist = false + } + b += 1 + + v.FontAscent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.FontDescent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RepliesHint = xgb.Get32(buf[b:]) + b += 4 + + v.Properties = make([]Fontprop, v.PropertiesLen) + b += FontpropReadList(buf[b:], v.Properties) + + { + byteString := make([]byte, v.NameLen) + copy(byteString[:v.NameLen], buf[b:]) + v.Name = string(byteString) + b += int(v.NameLen) + } + + return v +} + +// Write request to wire for ListFontsWithInfo +// listFontsWithInfoRequest writes a ListFontsWithInfo request to a byte slice. +func listFontsWithInfoRequest(c *xgb.Conn, MaxNames uint16, PatternLen uint16, Pattern string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(PatternLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 50 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], MaxNames) + b += 2 + + xgb.Put16(buf[b:], PatternLen) + b += 2 + + copy(buf[b:], Pattern[:PatternLen]) + b += int(PatternLen) + + return buf +} + +// ListHostsCookie is a cookie used only for ListHosts requests. +type ListHostsCookie struct { + *xgb.Cookie +} + +// ListHosts sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListHostsCookie.Reply() +func ListHosts(c *xgb.Conn) ListHostsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listHostsRequest(c), cookie) + return ListHostsCookie{cookie} +} + +// ListHostsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListHostsUnchecked(c *xgb.Conn) ListHostsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listHostsRequest(c), cookie) + return ListHostsCookie{cookie} +} + +// ListHostsReply represents the data returned from a ListHosts request. +type ListHostsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Mode byte + HostsLen uint16 + // padding: 22 bytes + Hosts []Host // size: HostListSize(Hosts) +} + +// Reply blocks and returns the reply data for a ListHosts request. +func (cook ListHostsCookie) Reply() (*ListHostsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listHostsReply(buf), nil +} + +// listHostsReply reads a byte slice into a ListHostsReply value. +func listHostsReply(buf []byte) *ListHostsReply { + v := new(ListHostsReply) + b := 1 // skip reply determinant + + v.Mode = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.HostsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Hosts = make([]Host, v.HostsLen) + b += HostReadList(buf[b:], v.Hosts) + + return v +} + +// Write request to wire for ListHosts +// listHostsRequest writes a ListHosts request to a byte slice. +func listHostsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 110 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ListInstalledColormapsCookie is a cookie used only for ListInstalledColormaps requests. +type ListInstalledColormapsCookie struct { + *xgb.Cookie +} + +// ListInstalledColormaps sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListInstalledColormapsCookie.Reply() +func ListInstalledColormaps(c *xgb.Conn, Window Window) ListInstalledColormapsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listInstalledColormapsRequest(c, Window), cookie) + return ListInstalledColormapsCookie{cookie} +} + +// ListInstalledColormapsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListInstalledColormapsUnchecked(c *xgb.Conn, Window Window) ListInstalledColormapsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listInstalledColormapsRequest(c, Window), cookie) + return ListInstalledColormapsCookie{cookie} +} + +// ListInstalledColormapsReply represents the data returned from a ListInstalledColormaps request. +type ListInstalledColormapsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + CmapsLen uint16 + // padding: 22 bytes + Cmaps []Colormap // size: xgb.Pad((int(CmapsLen) * 4)) +} + +// Reply blocks and returns the reply data for a ListInstalledColormaps request. +func (cook ListInstalledColormapsCookie) Reply() (*ListInstalledColormapsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listInstalledColormapsReply(buf), nil +} + +// listInstalledColormapsReply reads a byte slice into a ListInstalledColormapsReply value. +func listInstalledColormapsReply(buf []byte) *ListInstalledColormapsReply { + v := new(ListInstalledColormapsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.CmapsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Cmaps = make([]Colormap, v.CmapsLen) + for i := 0; i < int(v.CmapsLen); i++ { + v.Cmaps[i] = Colormap(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for ListInstalledColormaps +// listInstalledColormapsRequest writes a ListInstalledColormaps request to a byte slice. +func listInstalledColormapsRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 83 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// ListPropertiesCookie is a cookie used only for ListProperties requests. +type ListPropertiesCookie struct { + *xgb.Cookie +} + +// ListProperties sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListPropertiesCookie.Reply() +func ListProperties(c *xgb.Conn, Window Window) ListPropertiesCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(listPropertiesRequest(c, Window), cookie) + return ListPropertiesCookie{cookie} +} + +// ListPropertiesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListPropertiesUnchecked(c *xgb.Conn, Window Window) ListPropertiesCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(listPropertiesRequest(c, Window), cookie) + return ListPropertiesCookie{cookie} +} + +// ListPropertiesReply represents the data returned from a ListProperties request. +type ListPropertiesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + AtomsLen uint16 + // padding: 22 bytes + Atoms []Atom // size: xgb.Pad((int(AtomsLen) * 4)) +} + +// Reply blocks and returns the reply data for a ListProperties request. +func (cook ListPropertiesCookie) Reply() (*ListPropertiesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listPropertiesReply(buf), nil +} + +// listPropertiesReply reads a byte slice into a ListPropertiesReply value. +func listPropertiesReply(buf []byte) *ListPropertiesReply { + v := new(ListPropertiesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.AtomsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Atoms = make([]Atom, v.AtomsLen) + for i := 0; i < int(v.AtomsLen); i++ { + v.Atoms[i] = Atom(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for ListProperties +// listPropertiesRequest writes a ListProperties request to a byte slice. +func listPropertiesRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 21 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// LookupColorCookie is a cookie used only for LookupColor requests. +type LookupColorCookie struct { + *xgb.Cookie +} + +// LookupColor sends a checked request. +// If an error occurs, it will be returned with the reply by calling LookupColorCookie.Reply() +func LookupColor(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) LookupColorCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(lookupColorRequest(c, Cmap, NameLen, Name), cookie) + return LookupColorCookie{cookie} +} + +// LookupColorUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func LookupColorUnchecked(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) LookupColorCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(lookupColorRequest(c, Cmap, NameLen, Name), cookie) + return LookupColorCookie{cookie} +} + +// LookupColorReply represents the data returned from a LookupColor request. +type LookupColorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ExactRed uint16 + ExactGreen uint16 + ExactBlue uint16 + VisualRed uint16 + VisualGreen uint16 + VisualBlue uint16 +} + +// Reply blocks and returns the reply data for a LookupColor request. +func (cook LookupColorCookie) Reply() (*LookupColorReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return lookupColorReply(buf), nil +} + +// lookupColorReply reads a byte slice into a LookupColorReply value. +func lookupColorReply(buf []byte) *LookupColorReply { + v := new(LookupColorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ExactRed = xgb.Get16(buf[b:]) + b += 2 + + v.ExactGreen = xgb.Get16(buf[b:]) + b += 2 + + v.ExactBlue = xgb.Get16(buf[b:]) + b += 2 + + v.VisualRed = xgb.Get16(buf[b:]) + b += 2 + + v.VisualGreen = xgb.Get16(buf[b:]) + b += 2 + + v.VisualBlue = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for LookupColor +// lookupColorRequest writes a LookupColor request to a byte slice. +func lookupColorRequest(c *xgb.Conn, Cmap Colormap, NameLen uint16, Name string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 92 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// MapSubwindowsCookie is a cookie used only for MapSubwindows requests. +type MapSubwindowsCookie struct { + *xgb.Cookie +} + +// MapSubwindows sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func MapSubwindows(c *xgb.Conn, Window Window) MapSubwindowsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(mapSubwindowsRequest(c, Window), cookie) + return MapSubwindowsCookie{cookie} +} + +// MapSubwindowsChecked sends a checked request. +// If an error occurs, it can be retrieved using MapSubwindowsCookie.Check() +func MapSubwindowsChecked(c *xgb.Conn, Window Window) MapSubwindowsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(mapSubwindowsRequest(c, Window), cookie) + return MapSubwindowsCookie{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 MapSubwindowsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for MapSubwindows +// mapSubwindowsRequest writes a MapSubwindows request to a byte slice. +func mapSubwindowsRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 9 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// MapWindowCookie is a cookie used only for MapWindow requests. +type MapWindowCookie struct { + *xgb.Cookie +} + +// MapWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func MapWindow(c *xgb.Conn, Window Window) MapWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(mapWindowRequest(c, Window), cookie) + return MapWindowCookie{cookie} +} + +// MapWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using MapWindowCookie.Check() +func MapWindowChecked(c *xgb.Conn, Window Window) MapWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(mapWindowRequest(c, Window), cookie) + return MapWindowCookie{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 MapWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for MapWindow +// mapWindowRequest writes a MapWindow request to a byte slice. +func mapWindowRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 8 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// NoOperationCookie is a cookie used only for NoOperation requests. +type NoOperationCookie struct { + *xgb.Cookie +} + +// NoOperation sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func NoOperation(c *xgb.Conn) NoOperationCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(noOperationRequest(c), cookie) + return NoOperationCookie{cookie} +} + +// NoOperationChecked sends a checked request. +// If an error occurs, it can be retrieved using NoOperationCookie.Check() +func NoOperationChecked(c *xgb.Conn) NoOperationCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(noOperationRequest(c), cookie) + return NoOperationCookie{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 NoOperationCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for NoOperation +// noOperationRequest writes a NoOperation request to a byte slice. +func noOperationRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 127 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// OpenFontCookie is a cookie used only for OpenFont requests. +type OpenFontCookie struct { + *xgb.Cookie +} + +// OpenFont sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func OpenFont(c *xgb.Conn, Fid Font, NameLen uint16, Name string) OpenFontCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(openFontRequest(c, Fid, NameLen, Name), cookie) + return OpenFontCookie{cookie} +} + +// OpenFontChecked sends a checked request. +// If an error occurs, it can be retrieved using OpenFontCookie.Check() +func OpenFontChecked(c *xgb.Conn, Fid Font, NameLen uint16, Name string) OpenFontCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(openFontRequest(c, Fid, NameLen, Name), cookie) + return OpenFontCookie{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 OpenFontCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for OpenFont +// openFontRequest writes a OpenFont request to a byte slice. +func openFontRequest(c *xgb.Conn, Fid Font, NameLen uint16, Name string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 45 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Fid)) + b += 4 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// PolyArcCookie is a cookie used only for PolyArc requests. +type PolyArcCookie struct { + *xgb.Cookie +} + +// PolyArc sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyArc(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) PolyArcCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyArcRequest(c, Drawable, Gc, Arcs), cookie) + return PolyArcCookie{cookie} +} + +// PolyArcChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyArcCookie.Check() +func PolyArcChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) PolyArcCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyArcRequest(c, Drawable, Gc, Arcs), cookie) + return PolyArcCookie{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 PolyArcCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyArc +// polyArcRequest writes a PolyArc request to a byte slice. +func polyArcRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Arcs) * 12)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 68 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += ArcListBytes(buf[b:], Arcs) + + return buf +} + +// PolyFillArcCookie is a cookie used only for PolyFillArc requests. +type PolyFillArcCookie struct { + *xgb.Cookie +} + +// PolyFillArc sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyFillArc(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) PolyFillArcCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyFillArcRequest(c, Drawable, Gc, Arcs), cookie) + return PolyFillArcCookie{cookie} +} + +// PolyFillArcChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyFillArcCookie.Check() +func PolyFillArcChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) PolyFillArcCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyFillArcRequest(c, Drawable, Gc, Arcs), cookie) + return PolyFillArcCookie{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 PolyFillArcCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyFillArc +// polyFillArcRequest writes a PolyFillArc request to a byte slice. +func polyFillArcRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Arcs []Arc) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Arcs) * 12)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 71 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += ArcListBytes(buf[b:], Arcs) + + return buf +} + +// PolyFillRectangleCookie is a cookie used only for PolyFillRectangle requests. +type PolyFillRectangleCookie struct { + *xgb.Cookie +} + +// PolyFillRectangle sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyFillRectangle(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) PolyFillRectangleCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyFillRectangleRequest(c, Drawable, Gc, Rectangles), cookie) + return PolyFillRectangleCookie{cookie} +} + +// PolyFillRectangleChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyFillRectangleCookie.Check() +func PolyFillRectangleChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) PolyFillRectangleCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyFillRectangleRequest(c, Drawable, Gc, Rectangles), cookie) + return PolyFillRectangleCookie{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 PolyFillRectangleCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyFillRectangle +// polyFillRectangleRequest writes a PolyFillRectangle request to a byte slice. +func polyFillRectangleRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 70 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// PolyLineCookie is a cookie used only for PolyLine requests. +type PolyLineCookie struct { + *xgb.Cookie +} + +// PolyLine sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyLine(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) PolyLineCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyLineRequest(c, CoordinateMode, Drawable, Gc, Points), cookie) + return PolyLineCookie{cookie} +} + +// PolyLineChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyLineCookie.Check() +func PolyLineChecked(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) PolyLineCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyLineRequest(c, CoordinateMode, Drawable, Gc, Points), cookie) + return PolyLineCookie{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 PolyLineCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyLine +// polyLineRequest writes a PolyLine request to a byte slice. +func polyLineRequest(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Points) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 65 // request opcode + b += 1 + + buf[b] = CoordinateMode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += PointListBytes(buf[b:], Points) + + return buf +} + +// PolyPointCookie is a cookie used only for PolyPoint requests. +type PolyPointCookie struct { + *xgb.Cookie +} + +// PolyPoint sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyPoint(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) PolyPointCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyPointRequest(c, CoordinateMode, Drawable, Gc, Points), cookie) + return PolyPointCookie{cookie} +} + +// PolyPointChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyPointCookie.Check() +func PolyPointChecked(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) PolyPointCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyPointRequest(c, CoordinateMode, Drawable, Gc, Points), cookie) + return PolyPointCookie{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 PolyPointCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyPoint +// polyPointRequest writes a PolyPoint request to a byte slice. +func polyPointRequest(c *xgb.Conn, CoordinateMode byte, Drawable Drawable, Gc Gcontext, Points []Point) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Points) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 64 // request opcode + b += 1 + + buf[b] = CoordinateMode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += PointListBytes(buf[b:], Points) + + return buf +} + +// PolyRectangleCookie is a cookie used only for PolyRectangle requests. +type PolyRectangleCookie struct { + *xgb.Cookie +} + +// PolyRectangle sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyRectangle(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) PolyRectangleCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyRectangleRequest(c, Drawable, Gc, Rectangles), cookie) + return PolyRectangleCookie{cookie} +} + +// PolyRectangleChecked sends a checked request. +// If an error occurs, it can be retrieved using PolyRectangleCookie.Check() +func PolyRectangleChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) PolyRectangleCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyRectangleRequest(c, Drawable, Gc, Rectangles), cookie) + return PolyRectangleCookie{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 PolyRectangleCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyRectangle +// polyRectangleRequest writes a PolyRectangle request to a byte slice. +func polyRectangleRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Rectangles []Rectangle) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 67 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// PolySegmentCookie is a cookie used only for PolySegment requests. +type PolySegmentCookie struct { + *xgb.Cookie +} + +// PolySegment sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolySegment(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Segments []Segment) PolySegmentCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polySegmentRequest(c, Drawable, Gc, Segments), cookie) + return PolySegmentCookie{cookie} +} + +// PolySegmentChecked sends a checked request. +// If an error occurs, it can be retrieved using PolySegmentCookie.Check() +func PolySegmentChecked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Segments []Segment) PolySegmentCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polySegmentRequest(c, Drawable, Gc, Segments), cookie) + return PolySegmentCookie{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 PolySegmentCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolySegment +// polySegmentRequest writes a PolySegment request to a byte slice. +func polySegmentRequest(c *xgb.Conn, Drawable Drawable, Gc Gcontext, Segments []Segment) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Segments) * 8)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 66 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + b += SegmentListBytes(buf[b:], Segments) + + return buf +} + +// PolyText16Cookie is a cookie used only for PolyText16 requests. +type PolyText16Cookie struct { + *xgb.Cookie +} + +// PolyText16 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyText16(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) PolyText16Cookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyText16Request(c, Drawable, Gc, X, Y, Items), cookie) + return PolyText16Cookie{cookie} +} + +// PolyText16Checked sends a checked request. +// If an error occurs, it can be retrieved using PolyText16Cookie.Check() +func PolyText16Checked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) PolyText16Cookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyText16Request(c, Drawable, Gc, X, Y, Items), cookie) + return PolyText16Cookie{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 PolyText16Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyText16 +// polyText16Request writes a PolyText16 request to a byte slice. +func polyText16Request(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Items) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 75 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + copy(buf[b:], Items[:len(Items)]) + b += int(len(Items)) + + return buf +} + +// PolyText8Cookie is a cookie used only for PolyText8 requests. +type PolyText8Cookie struct { + *xgb.Cookie +} + +// PolyText8 sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PolyText8(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) PolyText8Cookie { + cookie := c.NewCookie(false, false) + c.NewRequest(polyText8Request(c, Drawable, Gc, X, Y, Items), cookie) + return PolyText8Cookie{cookie} +} + +// PolyText8Checked sends a checked request. +// If an error occurs, it can be retrieved using PolyText8Cookie.Check() +func PolyText8Checked(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) PolyText8Cookie { + cookie := c.NewCookie(true, false) + c.NewRequest(polyText8Request(c, Drawable, Gc, X, Y, Items), cookie) + return PolyText8Cookie{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 PolyText8Cookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PolyText8 +// polyText8Request writes a PolyText8 request to a byte slice. +func polyText8Request(c *xgb.Conn, Drawable Drawable, Gc Gcontext, X int16, Y int16, Items []byte) []byte { + size := xgb.Pad((16 + xgb.Pad((len(Items) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 74 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + copy(buf[b:], Items[:len(Items)]) + b += int(len(Items)) + + return buf +} + +// PutImageCookie is a cookie used only for PutImage requests. +type PutImageCookie struct { + *xgb.Cookie +} + +// PutImage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PutImage(c *xgb.Conn, Format byte, Drawable Drawable, Gc Gcontext, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) PutImageCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(putImageRequest(c, Format, Drawable, Gc, Width, Height, DstX, DstY, LeftPad, Depth, Data), cookie) + return PutImageCookie{cookie} +} + +// PutImageChecked sends a checked request. +// If an error occurs, it can be retrieved using PutImageCookie.Check() +func PutImageChecked(c *xgb.Conn, Format byte, Drawable Drawable, Gc Gcontext, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) PutImageCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(putImageRequest(c, Format, Drawable, Gc, Width, Height, DstX, DstY, LeftPad, Depth, Data), cookie) + return PutImageCookie{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 PutImageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PutImage +// putImageRequest writes a PutImage request to a byte slice. +func putImageRequest(c *xgb.Conn, Format byte, Drawable Drawable, Gc Gcontext, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) []byte { + size := xgb.Pad((24 + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 72 // request opcode + b += 1 + + buf[b] = Format + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + buf[b] = LeftPad + b += 1 + + buf[b] = Depth + b += 1 + + b += 2 // padding + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// QueryBestSizeCookie is a cookie used only for QueryBestSize requests. +type QueryBestSizeCookie struct { + *xgb.Cookie +} + +// QueryBestSize sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryBestSizeCookie.Reply() +func QueryBestSize(c *xgb.Conn, Class byte, Drawable Drawable, Width uint16, Height uint16) QueryBestSizeCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryBestSizeRequest(c, Class, Drawable, Width, Height), cookie) + return QueryBestSizeCookie{cookie} +} + +// QueryBestSizeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryBestSizeUnchecked(c *xgb.Conn, Class byte, Drawable Drawable, Width uint16, Height uint16) QueryBestSizeCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryBestSizeRequest(c, Class, Drawable, Width, Height), cookie) + return QueryBestSizeCookie{cookie} +} + +// QueryBestSizeReply represents the data returned from a QueryBestSize request. +type QueryBestSizeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Width uint16 + Height uint16 +} + +// Reply blocks and returns the reply data for a QueryBestSize request. +func (cook QueryBestSizeCookie) Reply() (*QueryBestSizeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryBestSizeReply(buf), nil +} + +// queryBestSizeReply reads a byte slice into a QueryBestSizeReply value. +func queryBestSizeReply(buf []byte) *QueryBestSizeReply { + v := new(QueryBestSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryBestSize +// queryBestSizeRequest writes a QueryBestSize request to a byte slice. +func queryBestSizeRequest(c *xgb.Conn, Class byte, Drawable Drawable, Width uint16, Height uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 97 // request opcode + b += 1 + + buf[b] = Class + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// QueryColorsCookie is a cookie used only for QueryColors requests. +type QueryColorsCookie struct { + *xgb.Cookie +} + +// QueryColors sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryColorsCookie.Reply() +func QueryColors(c *xgb.Conn, Cmap Colormap, Pixels []uint32) QueryColorsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryColorsRequest(c, Cmap, Pixels), cookie) + return QueryColorsCookie{cookie} +} + +// QueryColorsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryColorsUnchecked(c *xgb.Conn, Cmap Colormap, Pixels []uint32) QueryColorsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryColorsRequest(c, Cmap, Pixels), cookie) + return QueryColorsCookie{cookie} +} + +// QueryColorsReply represents the data returned from a QueryColors request. +type QueryColorsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ColorsLen uint16 + // padding: 22 bytes + Colors []Rgb // size: xgb.Pad((int(ColorsLen) * 8)) +} + +// Reply blocks and returns the reply data for a QueryColors request. +func (cook QueryColorsCookie) Reply() (*QueryColorsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryColorsReply(buf), nil +} + +// queryColorsReply reads a byte slice into a QueryColorsReply value. +func queryColorsReply(buf []byte) *QueryColorsReply { + v := new(QueryColorsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ColorsLen = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Colors = make([]Rgb, v.ColorsLen) + b += RgbReadList(buf[b:], v.Colors) + + return v +} + +// Write request to wire for QueryColors +// queryColorsRequest writes a QueryColors request to a byte slice. +func queryColorsRequest(c *xgb.Conn, Cmap Colormap, Pixels []uint32) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Pixels) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 91 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + for i := 0; i < int(len(Pixels)); i++ { + xgb.Put32(buf[b:], Pixels[i]) + b += 4 + } + + return buf +} + +// QueryExtensionCookie is a cookie used only for QueryExtension requests. +type QueryExtensionCookie struct { + *xgb.Cookie +} + +// QueryExtension sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryExtensionCookie.Reply() +func QueryExtension(c *xgb.Conn, NameLen uint16, Name string) QueryExtensionCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryExtensionRequest(c, NameLen, Name), cookie) + return QueryExtensionCookie{cookie} +} + +// QueryExtensionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryExtensionUnchecked(c *xgb.Conn, NameLen uint16, Name string) QueryExtensionCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryExtensionRequest(c, NameLen, Name), cookie) + return QueryExtensionCookie{cookie} +} + +// QueryExtensionReply represents the data returned from a QueryExtension request. +type QueryExtensionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Present bool + MajorOpcode byte + FirstEvent byte + FirstError byte +} + +// Reply blocks and returns the reply data for a QueryExtension request. +func (cook QueryExtensionCookie) Reply() (*QueryExtensionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryExtensionReply(buf), nil +} + +// queryExtensionReply reads a byte slice into a QueryExtensionReply value. +func queryExtensionReply(buf []byte) *QueryExtensionReply { + v := new(QueryExtensionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + if buf[b] == 1 { + v.Present = true + } else { + v.Present = false + } + b += 1 + + v.MajorOpcode = buf[b] + b += 1 + + v.FirstEvent = buf[b] + b += 1 + + v.FirstError = buf[b] + b += 1 + + return v +} + +// Write request to wire for QueryExtension +// queryExtensionRequest writes a QueryExtension request to a byte slice. +func queryExtensionRequest(c *xgb.Conn, NameLen uint16, Name string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 98 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// QueryFontCookie is a cookie used only for QueryFont requests. +type QueryFontCookie struct { + *xgb.Cookie +} + +// QueryFont sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryFontCookie.Reply() +func QueryFont(c *xgb.Conn, Font Fontable) QueryFontCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryFontRequest(c, Font), cookie) + return QueryFontCookie{cookie} +} + +// QueryFontUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryFontUnchecked(c *xgb.Conn, Font Fontable) QueryFontCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryFontRequest(c, Font), cookie) + return QueryFontCookie{cookie} +} + +// QueryFontReply represents the data returned from a QueryFont request. +type QueryFontReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MinBounds Charinfo + // padding: 4 bytes + MaxBounds Charinfo + // padding: 4 bytes + MinCharOrByte2 uint16 + MaxCharOrByte2 uint16 + DefaultChar uint16 + PropertiesLen uint16 + DrawDirection byte + MinByte1 byte + MaxByte1 byte + AllCharsExist bool + FontAscent int16 + FontDescent int16 + CharInfosLen uint32 + Properties []Fontprop // size: xgb.Pad((int(PropertiesLen) * 8)) + CharInfos []Charinfo // size: xgb.Pad((int(CharInfosLen) * 12)) +} + +// Reply blocks and returns the reply data for a QueryFont request. +func (cook QueryFontCookie) Reply() (*QueryFontReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryFontReply(buf), nil +} + +// queryFontReply reads a byte slice into a QueryFontReply value. +func queryFontReply(buf []byte) *QueryFontReply { + v := new(QueryFontReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MinBounds = Charinfo{} + b += CharinfoRead(buf[b:], &v.MinBounds) + + b += 4 // padding + + v.MaxBounds = Charinfo{} + b += CharinfoRead(buf[b:], &v.MaxBounds) + + b += 4 // padding + + v.MinCharOrByte2 = xgb.Get16(buf[b:]) + b += 2 + + v.MaxCharOrByte2 = xgb.Get16(buf[b:]) + b += 2 + + v.DefaultChar = xgb.Get16(buf[b:]) + b += 2 + + v.PropertiesLen = xgb.Get16(buf[b:]) + b += 2 + + v.DrawDirection = buf[b] + b += 1 + + v.MinByte1 = buf[b] + b += 1 + + v.MaxByte1 = buf[b] + b += 1 + + if buf[b] == 1 { + v.AllCharsExist = true + } else { + v.AllCharsExist = false + } + b += 1 + + v.FontAscent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.FontDescent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.CharInfosLen = xgb.Get32(buf[b:]) + b += 4 + + v.Properties = make([]Fontprop, v.PropertiesLen) + b += FontpropReadList(buf[b:], v.Properties) + + v.CharInfos = make([]Charinfo, v.CharInfosLen) + b += CharinfoReadList(buf[b:], v.CharInfos) + + return v +} + +// Write request to wire for QueryFont +// queryFontRequest writes a QueryFont request to a byte slice. +func queryFontRequest(c *xgb.Conn, Font Fontable) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 47 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Font)) + b += 4 + + return buf +} + +// QueryKeymapCookie is a cookie used only for QueryKeymap requests. +type QueryKeymapCookie struct { + *xgb.Cookie +} + +// QueryKeymap sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryKeymapCookie.Reply() +func QueryKeymap(c *xgb.Conn) QueryKeymapCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryKeymapRequest(c), cookie) + return QueryKeymapCookie{cookie} +} + +// QueryKeymapUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryKeymapUnchecked(c *xgb.Conn) QueryKeymapCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryKeymapRequest(c), cookie) + return QueryKeymapCookie{cookie} +} + +// QueryKeymapReply represents the data returned from a QueryKeymap request. +type QueryKeymapReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Keys []byte // size: 32 +} + +// Reply blocks and returns the reply data for a QueryKeymap request. +func (cook QueryKeymapCookie) Reply() (*QueryKeymapReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryKeymapReply(buf), nil +} + +// queryKeymapReply reads a byte slice into a QueryKeymapReply value. +func queryKeymapReply(buf []byte) *QueryKeymapReply { + v := new(QueryKeymapReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Keys = make([]byte, 32) + copy(v.Keys[:32], buf[b:]) + b += int(32) + + return v +} + +// Write request to wire for QueryKeymap +// queryKeymapRequest writes a QueryKeymap request to a byte slice. +func queryKeymapRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 44 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// QueryPointerCookie is a cookie used only for QueryPointer requests. +type QueryPointerCookie struct { + *xgb.Cookie +} + +// QueryPointer sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryPointerCookie.Reply() +func QueryPointer(c *xgb.Conn, Window Window) QueryPointerCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryPointerRequest(c, Window), cookie) + return QueryPointerCookie{cookie} +} + +// QueryPointerUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryPointerUnchecked(c *xgb.Conn, Window Window) QueryPointerCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryPointerRequest(c, Window), cookie) + return QueryPointerCookie{cookie} +} + +// QueryPointerReply represents the data returned from a QueryPointer request. +type QueryPointerReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + SameScreen bool + Root Window + Child Window + RootX int16 + RootY int16 + WinX int16 + WinY int16 + Mask uint16 + // padding: 2 bytes +} + +// Reply blocks and returns the reply data for a QueryPointer request. +func (cook QueryPointerCookie) Reply() (*QueryPointerReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryPointerReply(buf), nil +} + +// queryPointerReply reads a byte slice into a QueryPointerReply value. +func queryPointerReply(buf []byte) *QueryPointerReply { + v := new(QueryPointerReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.WinX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.WinY = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Mask = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + return v +} + +// Write request to wire for QueryPointer +// queryPointerRequest writes a QueryPointer request to a byte slice. +func queryPointerRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 38 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// QueryTextExtentsCookie is a cookie used only for QueryTextExtents requests. +type QueryTextExtentsCookie struct { + *xgb.Cookie +} + +// QueryTextExtents sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryTextExtentsCookie.Reply() +func QueryTextExtents(c *xgb.Conn, Font Fontable, String []Char2b, StringLen uint16) QueryTextExtentsCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryTextExtentsRequest(c, Font, String, StringLen), cookie) + return QueryTextExtentsCookie{cookie} +} + +// QueryTextExtentsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryTextExtentsUnchecked(c *xgb.Conn, Font Fontable, String []Char2b, StringLen uint16) QueryTextExtentsCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryTextExtentsRequest(c, Font, String, StringLen), cookie) + return QueryTextExtentsCookie{cookie} +} + +// QueryTextExtentsReply represents the data returned from a QueryTextExtents request. +type QueryTextExtentsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + DrawDirection byte + FontAscent int16 + FontDescent int16 + OverallAscent int16 + OverallDescent int16 + OverallWidth int32 + OverallLeft int32 + OverallRight int32 +} + +// Reply blocks and returns the reply data for a QueryTextExtents request. +func (cook QueryTextExtentsCookie) Reply() (*QueryTextExtentsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryTextExtentsReply(buf), nil +} + +// queryTextExtentsReply reads a byte slice into a QueryTextExtentsReply value. +func queryTextExtentsReply(buf []byte) *QueryTextExtentsReply { + v := new(QueryTextExtentsReply) + b := 1 // skip reply determinant + + v.DrawDirection = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.FontAscent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.FontDescent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.OverallAscent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.OverallDescent = int16(xgb.Get16(buf[b:])) + b += 2 + + v.OverallWidth = int32(xgb.Get32(buf[b:])) + b += 4 + + v.OverallLeft = int32(xgb.Get32(buf[b:])) + b += 4 + + v.OverallRight = int32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for QueryTextExtents +// queryTextExtentsRequest writes a QueryTextExtents request to a byte slice. +func queryTextExtentsRequest(c *xgb.Conn, Font Fontable, String []Char2b, StringLen uint16) []byte { + size := xgb.Pad((8 + xgb.Pad((len(String) * 2)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 48 // request opcode + b += 1 + + buf[b] = byte((int(StringLen) & 1)) + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Font)) + b += 4 + + b += Char2bListBytes(buf[b:], String) + + // skip writing local field: StringLen (2) :: uint16 + + return buf +} + +// QueryTreeCookie is a cookie used only for QueryTree requests. +type QueryTreeCookie struct { + *xgb.Cookie +} + +// QueryTree sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryTreeCookie.Reply() +func QueryTree(c *xgb.Conn, Window Window) QueryTreeCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryTreeRequest(c, Window), cookie) + return QueryTreeCookie{cookie} +} + +// QueryTreeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryTreeUnchecked(c *xgb.Conn, Window Window) QueryTreeCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryTreeRequest(c, Window), cookie) + return QueryTreeCookie{cookie} +} + +// QueryTreeReply represents the data returned from a QueryTree request. +type QueryTreeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Root Window + Parent Window + ChildrenLen uint16 + // padding: 14 bytes + Children []Window // size: xgb.Pad((int(ChildrenLen) * 4)) +} + +// Reply blocks and returns the reply data for a QueryTree request. +func (cook QueryTreeCookie) Reply() (*QueryTreeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryTreeReply(buf), nil +} + +// queryTreeReply reads a byte slice into a QueryTreeReply value. +func queryTreeReply(buf []byte) *QueryTreeReply { + v := new(QueryTreeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Root = Window(xgb.Get32(buf[b:])) + b += 4 + + v.Parent = Window(xgb.Get32(buf[b:])) + b += 4 + + v.ChildrenLen = xgb.Get16(buf[b:]) + b += 2 + + b += 14 // padding + + v.Children = make([]Window, v.ChildrenLen) + for i := 0; i < int(v.ChildrenLen); i++ { + v.Children[i] = Window(xgb.Get32(buf[b:])) + b += 4 + } + + return v +} + +// Write request to wire for QueryTree +// queryTreeRequest writes a QueryTree request to a byte slice. +func queryTreeRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 15 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// RecolorCursorCookie is a cookie used only for RecolorCursor requests. +type RecolorCursorCookie struct { + *xgb.Cookie +} + +// RecolorCursor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RecolorCursor(c *xgb.Conn, Cursor Cursor, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) RecolorCursorCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(recolorCursorRequest(c, Cursor, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return RecolorCursorCookie{cookie} +} + +// RecolorCursorChecked sends a checked request. +// If an error occurs, it can be retrieved using RecolorCursorCookie.Check() +func RecolorCursorChecked(c *xgb.Conn, Cursor Cursor, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) RecolorCursorCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(recolorCursorRequest(c, Cursor, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return RecolorCursorCookie{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 RecolorCursorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RecolorCursor +// recolorCursorRequest writes a RecolorCursor request to a byte slice. +func recolorCursorRequest(c *xgb.Conn, Cursor Cursor, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + buf[b] = 96 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cursor)) + b += 4 + + xgb.Put16(buf[b:], ForeRed) + b += 2 + + xgb.Put16(buf[b:], ForeGreen) + b += 2 + + xgb.Put16(buf[b:], ForeBlue) + b += 2 + + xgb.Put16(buf[b:], BackRed) + b += 2 + + xgb.Put16(buf[b:], BackGreen) + b += 2 + + xgb.Put16(buf[b:], BackBlue) + b += 2 + + return buf +} + +// ReparentWindowCookie is a cookie used only for ReparentWindow requests. +type ReparentWindowCookie struct { + *xgb.Cookie +} + +// ReparentWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ReparentWindow(c *xgb.Conn, Window Window, Parent Window, X int16, Y int16) ReparentWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(reparentWindowRequest(c, Window, Parent, X, Y), cookie) + return ReparentWindowCookie{cookie} +} + +// ReparentWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using ReparentWindowCookie.Check() +func ReparentWindowChecked(c *xgb.Conn, Window Window, Parent Window, X int16, Y int16) ReparentWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(reparentWindowRequest(c, Window, Parent, X, Y), cookie) + return ReparentWindowCookie{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 ReparentWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ReparentWindow +// reparentWindowRequest writes a ReparentWindow request to a byte slice. +func reparentWindowRequest(c *xgb.Conn, Window Window, Parent Window, X int16, Y int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 7 // request opcode + b += 1 + + b += 1 // padding + + 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(Parent)) + b += 4 + + xgb.Put16(buf[b:], uint16(X)) + b += 2 + + xgb.Put16(buf[b:], uint16(Y)) + b += 2 + + return buf +} + +// RotatePropertiesCookie is a cookie used only for RotateProperties requests. +type RotatePropertiesCookie struct { + *xgb.Cookie +} + +// RotateProperties sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func RotateProperties(c *xgb.Conn, Window Window, AtomsLen uint16, Delta int16, Atoms []Atom) RotatePropertiesCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(rotatePropertiesRequest(c, Window, AtomsLen, Delta, Atoms), cookie) + return RotatePropertiesCookie{cookie} +} + +// RotatePropertiesChecked sends a checked request. +// If an error occurs, it can be retrieved using RotatePropertiesCookie.Check() +func RotatePropertiesChecked(c *xgb.Conn, Window Window, AtomsLen uint16, Delta int16, Atoms []Atom) RotatePropertiesCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(rotatePropertiesRequest(c, Window, AtomsLen, Delta, Atoms), cookie) + return RotatePropertiesCookie{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 RotatePropertiesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RotateProperties +// rotatePropertiesRequest writes a RotateProperties request to a byte slice. +func rotatePropertiesRequest(c *xgb.Conn, Window Window, AtomsLen uint16, Delta int16, Atoms []Atom) []byte { + size := xgb.Pad((12 + xgb.Pad((int(AtomsLen) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 114 // request opcode + b += 1 + + b += 1 // padding + + 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.Put16(buf[b:], AtomsLen) + b += 2 + + xgb.Put16(buf[b:], uint16(Delta)) + b += 2 + + for i := 0; i < int(AtomsLen); i++ { + xgb.Put32(buf[b:], uint32(Atoms[i])) + b += 4 + } + + return buf +} + +// SendEventCookie is a cookie used only for SendEvent requests. +type SendEventCookie struct { + *xgb.Cookie +} + +// SendEvent sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SendEvent(c *xgb.Conn, Propagate bool, Destination Window, EventMask uint32, Event string) SendEventCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(sendEventRequest(c, Propagate, Destination, EventMask, Event), cookie) + return SendEventCookie{cookie} +} + +// SendEventChecked sends a checked request. +// If an error occurs, it can be retrieved using SendEventCookie.Check() +func SendEventChecked(c *xgb.Conn, Propagate bool, Destination Window, EventMask uint32, Event string) SendEventCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(sendEventRequest(c, Propagate, Destination, EventMask, Event), cookie) + return SendEventCookie{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 SendEventCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SendEvent +// sendEventRequest writes a SendEvent request to a byte slice. +func sendEventRequest(c *xgb.Conn, Propagate bool, Destination Window, EventMask uint32, Event string) []byte { + size := 44 + b := 0 + buf := make([]byte, size) + + buf[b] = 25 // request opcode + b += 1 + + if Propagate { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + + xgb.Put32(buf[b:], EventMask) + b += 4 + + copy(buf[b:], Event[:32]) + b += int(32) + + return buf +} + +// SetAccessControlCookie is a cookie used only for SetAccessControl requests. +type SetAccessControlCookie struct { + *xgb.Cookie +} + +// SetAccessControl sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetAccessControl(c *xgb.Conn, Mode byte) SetAccessControlCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setAccessControlRequest(c, Mode), cookie) + return SetAccessControlCookie{cookie} +} + +// SetAccessControlChecked sends a checked request. +// If an error occurs, it can be retrieved using SetAccessControlCookie.Check() +func SetAccessControlChecked(c *xgb.Conn, Mode byte) SetAccessControlCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setAccessControlRequest(c, Mode), cookie) + return SetAccessControlCookie{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 SetAccessControlCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetAccessControl +// setAccessControlRequest writes a SetAccessControl request to a byte slice. +func setAccessControlRequest(c *xgb.Conn, Mode byte) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 111 // request opcode + b += 1 + + buf[b] = Mode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// SetClipRectanglesCookie is a cookie used only for SetClipRectangles requests. +type SetClipRectanglesCookie struct { + *xgb.Cookie +} + +// SetClipRectangles sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetClipRectangles(c *xgb.Conn, Ordering byte, Gc Gcontext, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) SetClipRectanglesCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setClipRectanglesRequest(c, Ordering, Gc, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetClipRectanglesCookie{cookie} +} + +// SetClipRectanglesChecked sends a checked request. +// If an error occurs, it can be retrieved using SetClipRectanglesCookie.Check() +func SetClipRectanglesChecked(c *xgb.Conn, Ordering byte, Gc Gcontext, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) SetClipRectanglesCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setClipRectanglesRequest(c, Ordering, Gc, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetClipRectanglesCookie{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 SetClipRectanglesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetClipRectangles +// setClipRectanglesRequest writes a SetClipRectangles request to a byte slice. +func setClipRectanglesRequest(c *xgb.Conn, Ordering byte, Gc Gcontext, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) []byte { + size := xgb.Pad((12 + xgb.Pad((len(Rectangles) * 8)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 59 // request opcode + b += 1 + + buf[b] = Ordering + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(ClipXOrigin)) + b += 2 + + xgb.Put16(buf[b:], uint16(ClipYOrigin)) + b += 2 + + b += RectangleListBytes(buf[b:], Rectangles) + + return buf +} + +// SetCloseDownModeCookie is a cookie used only for SetCloseDownMode requests. +type SetCloseDownModeCookie struct { + *xgb.Cookie +} + +// SetCloseDownMode sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetCloseDownMode(c *xgb.Conn, Mode byte) SetCloseDownModeCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setCloseDownModeRequest(c, Mode), cookie) + return SetCloseDownModeCookie{cookie} +} + +// SetCloseDownModeChecked sends a checked request. +// If an error occurs, it can be retrieved using SetCloseDownModeCookie.Check() +func SetCloseDownModeChecked(c *xgb.Conn, Mode byte) SetCloseDownModeCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setCloseDownModeRequest(c, Mode), cookie) + return SetCloseDownModeCookie{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 SetCloseDownModeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetCloseDownMode +// setCloseDownModeRequest writes a SetCloseDownMode request to a byte slice. +func setCloseDownModeRequest(c *xgb.Conn, Mode byte) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 112 // request opcode + b += 1 + + buf[b] = Mode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// SetDashesCookie is a cookie used only for SetDashes requests. +type SetDashesCookie struct { + *xgb.Cookie +} + +// SetDashes sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetDashes(c *xgb.Conn, Gc Gcontext, DashOffset uint16, DashesLen uint16, Dashes []byte) SetDashesCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setDashesRequest(c, Gc, DashOffset, DashesLen, Dashes), cookie) + return SetDashesCookie{cookie} +} + +// SetDashesChecked sends a checked request. +// If an error occurs, it can be retrieved using SetDashesCookie.Check() +func SetDashesChecked(c *xgb.Conn, Gc Gcontext, DashOffset uint16, DashesLen uint16, Dashes []byte) SetDashesCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setDashesRequest(c, Gc, DashOffset, DashesLen, Dashes), cookie) + return SetDashesCookie{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 SetDashesCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetDashes +// setDashesRequest writes a SetDashes request to a byte slice. +func setDashesRequest(c *xgb.Conn, Gc Gcontext, DashOffset uint16, DashesLen uint16, Dashes []byte) []byte { + size := xgb.Pad((12 + xgb.Pad((int(DashesLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 58 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], DashOffset) + b += 2 + + xgb.Put16(buf[b:], DashesLen) + b += 2 + + copy(buf[b:], Dashes[:DashesLen]) + b += int(DashesLen) + + return buf +} + +// SetFontPathCookie is a cookie used only for SetFontPath requests. +type SetFontPathCookie struct { + *xgb.Cookie +} + +// SetFontPath sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetFontPath(c *xgb.Conn, FontQty uint16, Font []Str) SetFontPathCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setFontPathRequest(c, FontQty, Font), cookie) + return SetFontPathCookie{cookie} +} + +// SetFontPathChecked sends a checked request. +// If an error occurs, it can be retrieved using SetFontPathCookie.Check() +func SetFontPathChecked(c *xgb.Conn, FontQty uint16, Font []Str) SetFontPathCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setFontPathRequest(c, FontQty, Font), cookie) + return SetFontPathCookie{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 SetFontPathCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetFontPath +// setFontPathRequest writes a SetFontPath request to a byte slice. +func setFontPathRequest(c *xgb.Conn, FontQty uint16, Font []Str) []byte { + size := xgb.Pad((8 + StrListSize(Font))) + b := 0 + buf := make([]byte, size) + + buf[b] = 51 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], FontQty) + b += 2 + + b += 2 // padding + + b += StrListBytes(buf[b:], Font) + + return buf +} + +// SetInputFocusCookie is a cookie used only for SetInputFocus requests. +type SetInputFocusCookie struct { + *xgb.Cookie +} + +// SetInputFocus sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetInputFocus(c *xgb.Conn, RevertTo byte, Focus Window, Time Timestamp) SetInputFocusCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setInputFocusRequest(c, RevertTo, Focus, Time), cookie) + return SetInputFocusCookie{cookie} +} + +// SetInputFocusChecked sends a checked request. +// If an error occurs, it can be retrieved using SetInputFocusCookie.Check() +func SetInputFocusChecked(c *xgb.Conn, RevertTo byte, Focus Window, Time Timestamp) SetInputFocusCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setInputFocusRequest(c, RevertTo, Focus, Time), cookie) + return SetInputFocusCookie{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 SetInputFocusCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetInputFocus +// setInputFocusRequest writes a SetInputFocus request to a byte slice. +func setInputFocusRequest(c *xgb.Conn, RevertTo byte, Focus Window, Time Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 42 // request opcode + b += 1 + + buf[b] = RevertTo + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Focus)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// SetModifierMappingCookie is a cookie used only for SetModifierMapping requests. +type SetModifierMappingCookie struct { + *xgb.Cookie +} + +// SetModifierMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetModifierMappingCookie.Reply() +func SetModifierMapping(c *xgb.Conn, KeycodesPerModifier byte, Keycodes []Keycode) SetModifierMappingCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(setModifierMappingRequest(c, KeycodesPerModifier, Keycodes), cookie) + return SetModifierMappingCookie{cookie} +} + +// SetModifierMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetModifierMappingUnchecked(c *xgb.Conn, KeycodesPerModifier byte, Keycodes []Keycode) SetModifierMappingCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(setModifierMappingRequest(c, KeycodesPerModifier, Keycodes), cookie) + return SetModifierMappingCookie{cookie} +} + +// SetModifierMappingReply represents the data returned from a SetModifierMapping request. +type SetModifierMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte +} + +// Reply blocks and returns the reply data for a SetModifierMapping request. +func (cook SetModifierMappingCookie) Reply() (*SetModifierMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return setModifierMappingReply(buf), nil +} + +// setModifierMappingReply reads a byte slice into a SetModifierMappingReply value. +func setModifierMappingReply(buf []byte) *SetModifierMappingReply { + v := new(SetModifierMappingReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + 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 SetModifierMapping +// setModifierMappingRequest writes a SetModifierMapping request to a byte slice. +func setModifierMappingRequest(c *xgb.Conn, KeycodesPerModifier byte, Keycodes []Keycode) []byte { + size := xgb.Pad((4 + xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 118 // request opcode + b += 1 + + buf[b] = KeycodesPerModifier + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + for i := 0; i < int((int(KeycodesPerModifier) * 8)); i++ { + buf[b] = byte(Keycodes[i]) + b += 1 + } + + return buf +} + +// SetPointerMappingCookie is a cookie used only for SetPointerMapping requests. +type SetPointerMappingCookie struct { + *xgb.Cookie +} + +// SetPointerMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetPointerMappingCookie.Reply() +func SetPointerMapping(c *xgb.Conn, MapLen byte, Map []byte) SetPointerMappingCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(setPointerMappingRequest(c, MapLen, Map), cookie) + return SetPointerMappingCookie{cookie} +} + +// SetPointerMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPointerMappingUnchecked(c *xgb.Conn, MapLen byte, Map []byte) SetPointerMappingCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(setPointerMappingRequest(c, MapLen, Map), cookie) + return SetPointerMappingCookie{cookie} +} + +// SetPointerMappingReply represents the data returned from a SetPointerMapping request. +type SetPointerMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Status byte +} + +// Reply blocks and returns the reply data for a SetPointerMapping request. +func (cook SetPointerMappingCookie) Reply() (*SetPointerMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return setPointerMappingReply(buf), nil +} + +// setPointerMappingReply reads a byte slice into a SetPointerMappingReply value. +func setPointerMappingReply(buf []byte) *SetPointerMappingReply { + v := new(SetPointerMappingReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + 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 SetPointerMapping +// setPointerMappingRequest writes a SetPointerMapping request to a byte slice. +func setPointerMappingRequest(c *xgb.Conn, MapLen byte, Map []byte) []byte { + size := xgb.Pad((4 + xgb.Pad((int(MapLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 116 // request opcode + b += 1 + + buf[b] = MapLen + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + copy(buf[b:], Map[:MapLen]) + b += int(MapLen) + + return buf +} + +// SetScreenSaverCookie is a cookie used only for SetScreenSaver requests. +type SetScreenSaverCookie struct { + *xgb.Cookie +} + +// SetScreenSaver sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetScreenSaver(c *xgb.Conn, Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) SetScreenSaverCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setScreenSaverRequest(c, Timeout, Interval, PreferBlanking, AllowExposures), cookie) + return SetScreenSaverCookie{cookie} +} + +// SetScreenSaverChecked sends a checked request. +// If an error occurs, it can be retrieved using SetScreenSaverCookie.Check() +func SetScreenSaverChecked(c *xgb.Conn, Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) SetScreenSaverCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setScreenSaverRequest(c, Timeout, Interval, PreferBlanking, AllowExposures), cookie) + return SetScreenSaverCookie{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 SetScreenSaverCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetScreenSaver +// setScreenSaverRequest writes a SetScreenSaver request to a byte slice. +func setScreenSaverRequest(c *xgb.Conn, Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 107 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], uint16(Timeout)) + b += 2 + + xgb.Put16(buf[b:], uint16(Interval)) + b += 2 + + buf[b] = PreferBlanking + b += 1 + + buf[b] = AllowExposures + b += 1 + + return buf +} + +// SetSelectionOwnerCookie is a cookie used only for SetSelectionOwner requests. +type SetSelectionOwnerCookie struct { + *xgb.Cookie +} + +// SetSelectionOwner sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetSelectionOwner(c *xgb.Conn, Owner Window, Selection Atom, Time Timestamp) SetSelectionOwnerCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(setSelectionOwnerRequest(c, Owner, Selection, Time), cookie) + return SetSelectionOwnerCookie{cookie} +} + +// SetSelectionOwnerChecked sends a checked request. +// If an error occurs, it can be retrieved using SetSelectionOwnerCookie.Check() +func SetSelectionOwnerChecked(c *xgb.Conn, Owner Window, Selection Atom, Time Timestamp) SetSelectionOwnerCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(setSelectionOwnerRequest(c, Owner, Selection, Time), cookie) + return SetSelectionOwnerCookie{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 SetSelectionOwnerCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetSelectionOwner +// setSelectionOwnerRequest writes a SetSelectionOwner request to a byte slice. +func setSelectionOwnerRequest(c *xgb.Conn, Owner Window, Selection Atom, Time Timestamp) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 22 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Owner)) + b += 4 + + xgb.Put32(buf[b:], uint32(Selection)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// StoreColorsCookie is a cookie used only for StoreColors requests. +type StoreColorsCookie struct { + *xgb.Cookie +} + +// StoreColors sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func StoreColors(c *xgb.Conn, Cmap Colormap, Items []Coloritem) StoreColorsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(storeColorsRequest(c, Cmap, Items), cookie) + return StoreColorsCookie{cookie} +} + +// StoreColorsChecked sends a checked request. +// If an error occurs, it can be retrieved using StoreColorsCookie.Check() +func StoreColorsChecked(c *xgb.Conn, Cmap Colormap, Items []Coloritem) StoreColorsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(storeColorsRequest(c, Cmap, Items), cookie) + return StoreColorsCookie{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 StoreColorsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for StoreColors +// storeColorsRequest writes a StoreColors request to a byte slice. +func storeColorsRequest(c *xgb.Conn, Cmap Colormap, Items []Coloritem) []byte { + size := xgb.Pad((8 + xgb.Pad((len(Items) * 12)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 89 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + b += ColoritemListBytes(buf[b:], Items) + + return buf +} + +// StoreNamedColorCookie is a cookie used only for StoreNamedColor requests. +type StoreNamedColorCookie struct { + *xgb.Cookie +} + +// StoreNamedColor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func StoreNamedColor(c *xgb.Conn, Flags byte, Cmap Colormap, Pixel uint32, NameLen uint16, Name string) StoreNamedColorCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(storeNamedColorRequest(c, Flags, Cmap, Pixel, NameLen, Name), cookie) + return StoreNamedColorCookie{cookie} +} + +// StoreNamedColorChecked sends a checked request. +// If an error occurs, it can be retrieved using StoreNamedColorCookie.Check() +func StoreNamedColorChecked(c *xgb.Conn, Flags byte, Cmap Colormap, Pixel uint32, NameLen uint16, Name string) StoreNamedColorCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(storeNamedColorRequest(c, Flags, Cmap, Pixel, NameLen, Name), cookie) + return StoreNamedColorCookie{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 StoreNamedColorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for StoreNamedColor +// storeNamedColorRequest writes a StoreNamedColor request to a byte slice. +func storeNamedColorRequest(c *xgb.Conn, Flags byte, Cmap Colormap, Pixel uint32, NameLen uint16, Name string) []byte { + size := xgb.Pad((16 + xgb.Pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 90 // request opcode + b += 1 + + buf[b] = Flags + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + xgb.Put32(buf[b:], Pixel) + b += 4 + + xgb.Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += int(NameLen) + + return buf +} + +// TranslateCoordinatesCookie is a cookie used only for TranslateCoordinates requests. +type TranslateCoordinatesCookie struct { + *xgb.Cookie +} + +// TranslateCoordinates sends a checked request. +// If an error occurs, it will be returned with the reply by calling TranslateCoordinatesCookie.Reply() +func TranslateCoordinates(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16) TranslateCoordinatesCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(translateCoordinatesRequest(c, SrcWindow, DstWindow, SrcX, SrcY), cookie) + return TranslateCoordinatesCookie{cookie} +} + +// TranslateCoordinatesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func TranslateCoordinatesUnchecked(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16) TranslateCoordinatesCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(translateCoordinatesRequest(c, SrcWindow, DstWindow, SrcX, SrcY), cookie) + return TranslateCoordinatesCookie{cookie} +} + +// TranslateCoordinatesReply represents the data returned from a TranslateCoordinates request. +type TranslateCoordinatesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + SameScreen bool + Child Window + DstX int16 + DstY int16 +} + +// Reply blocks and returns the reply data for a TranslateCoordinates request. +func (cook TranslateCoordinatesCookie) Reply() (*TranslateCoordinatesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return translateCoordinatesReply(buf), nil +} + +// translateCoordinatesReply reads a byte slice into a TranslateCoordinatesReply value. +func translateCoordinatesReply(buf []byte) *TranslateCoordinatesReply { + v := new(TranslateCoordinatesReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Child = Window(xgb.Get32(buf[b:])) + b += 4 + + v.DstX = int16(xgb.Get16(buf[b:])) + b += 2 + + v.DstY = int16(xgb.Get16(buf[b:])) + b += 2 + + return v +} + +// Write request to wire for TranslateCoordinates +// translateCoordinatesRequest writes a TranslateCoordinates request to a byte slice. +func translateCoordinatesRequest(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 40 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(SrcWindow)) + b += 4 + + xgb.Put32(buf[b:], uint32(DstWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + return buf +} + +// UngrabButtonCookie is a cookie used only for UngrabButton requests. +type UngrabButtonCookie struct { + *xgb.Cookie +} + +// UngrabButton sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabButton(c *xgb.Conn, Button byte, GrabWindow Window, Modifiers uint16) UngrabButtonCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabButtonRequest(c, Button, GrabWindow, Modifiers), cookie) + return UngrabButtonCookie{cookie} +} + +// UngrabButtonChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabButtonCookie.Check() +func UngrabButtonChecked(c *xgb.Conn, Button byte, GrabWindow Window, Modifiers uint16) UngrabButtonCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabButtonRequest(c, Button, GrabWindow, Modifiers), cookie) + return UngrabButtonCookie{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 UngrabButtonCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabButton +// ungrabButtonRequest writes a UngrabButton request to a byte slice. +func ungrabButtonRequest(c *xgb.Conn, Button byte, GrabWindow Window, Modifiers uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 29 // request opcode + b += 1 + + buf[b] = Button + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], Modifiers) + b += 2 + + b += 2 // padding + + return buf +} + +// UngrabKeyCookie is a cookie used only for UngrabKey requests. +type UngrabKeyCookie struct { + *xgb.Cookie +} + +// UngrabKey sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabKey(c *xgb.Conn, Key Keycode, GrabWindow Window, Modifiers uint16) UngrabKeyCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabKeyRequest(c, Key, GrabWindow, Modifiers), cookie) + return UngrabKeyCookie{cookie} +} + +// UngrabKeyChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabKeyCookie.Check() +func UngrabKeyChecked(c *xgb.Conn, Key Keycode, GrabWindow Window, Modifiers uint16) UngrabKeyCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabKeyRequest(c, Key, GrabWindow, Modifiers), cookie) + return UngrabKeyCookie{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 UngrabKeyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabKey +// ungrabKeyRequest writes a UngrabKey request to a byte slice. +func ungrabKeyRequest(c *xgb.Conn, Key Keycode, GrabWindow Window, Modifiers uint16) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = 34 // request opcode + b += 1 + + buf[b] = byte(Key) + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], Modifiers) + b += 2 + + b += 2 // padding + + return buf +} + +// UngrabKeyboardCookie is a cookie used only for UngrabKeyboard requests. +type UngrabKeyboardCookie struct { + *xgb.Cookie +} + +// UngrabKeyboard sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabKeyboard(c *xgb.Conn, Time Timestamp) UngrabKeyboardCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabKeyboardRequest(c, Time), cookie) + return UngrabKeyboardCookie{cookie} +} + +// UngrabKeyboardChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabKeyboardCookie.Check() +func UngrabKeyboardChecked(c *xgb.Conn, Time Timestamp) UngrabKeyboardCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabKeyboardRequest(c, Time), cookie) + return UngrabKeyboardCookie{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 UngrabKeyboardCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabKeyboard +// ungrabKeyboardRequest writes a UngrabKeyboard request to a byte slice. +func ungrabKeyboardRequest(c *xgb.Conn, Time Timestamp) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 32 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// UngrabPointerCookie is a cookie used only for UngrabPointer requests. +type UngrabPointerCookie struct { + *xgb.Cookie +} + +// UngrabPointer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabPointer(c *xgb.Conn, Time Timestamp) UngrabPointerCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabPointerRequest(c, Time), cookie) + return UngrabPointerCookie{cookie} +} + +// UngrabPointerChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabPointerCookie.Check() +func UngrabPointerChecked(c *xgb.Conn, Time Timestamp) UngrabPointerCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabPointerRequest(c, Time), cookie) + return UngrabPointerCookie{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 UngrabPointerCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabPointer +// ungrabPointerRequest writes a UngrabPointer request to a byte slice. +func ungrabPointerRequest(c *xgb.Conn, Time Timestamp) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 27 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// UngrabServerCookie is a cookie used only for UngrabServer requests. +type UngrabServerCookie struct { + *xgb.Cookie +} + +// UngrabServer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabServer(c *xgb.Conn) UngrabServerCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabServerRequest(c), cookie) + return UngrabServerCookie{cookie} +} + +// UngrabServerChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabServerCookie.Check() +func UngrabServerChecked(c *xgb.Conn) UngrabServerCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabServerRequest(c), cookie) + return UngrabServerCookie{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 UngrabServerCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabServer +// ungrabServerRequest writes a UngrabServer request to a byte slice. +func ungrabServerRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 37 // request opcode + b += 1 + + b += 1 // padding + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// UninstallColormapCookie is a cookie used only for UninstallColormap requests. +type UninstallColormapCookie struct { + *xgb.Cookie +} + +// UninstallColormap sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UninstallColormap(c *xgb.Conn, Cmap Colormap) UninstallColormapCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(uninstallColormapRequest(c, Cmap), cookie) + return UninstallColormapCookie{cookie} +} + +// UninstallColormapChecked sends a checked request. +// If an error occurs, it can be retrieved using UninstallColormapCookie.Check() +func UninstallColormapChecked(c *xgb.Conn, Cmap Colormap) UninstallColormapCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(uninstallColormapRequest(c, Cmap), cookie) + return UninstallColormapCookie{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 UninstallColormapCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UninstallColormap +// uninstallColormapRequest writes a UninstallColormap request to a byte slice. +func uninstallColormapRequest(c *xgb.Conn, Cmap Colormap) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 82 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Cmap)) + b += 4 + + return buf +} + +// UnmapSubwindowsCookie is a cookie used only for UnmapSubwindows requests. +type UnmapSubwindowsCookie struct { + *xgb.Cookie +} + +// UnmapSubwindows sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnmapSubwindows(c *xgb.Conn, Window Window) UnmapSubwindowsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(unmapSubwindowsRequest(c, Window), cookie) + return UnmapSubwindowsCookie{cookie} +} + +// UnmapSubwindowsChecked sends a checked request. +// If an error occurs, it can be retrieved using UnmapSubwindowsCookie.Check() +func UnmapSubwindowsChecked(c *xgb.Conn, Window Window) UnmapSubwindowsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(unmapSubwindowsRequest(c, Window), cookie) + return UnmapSubwindowsCookie{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 UnmapSubwindowsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnmapSubwindows +// unmapSubwindowsRequest writes a UnmapSubwindows request to a byte slice. +func unmapSubwindowsRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 11 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// UnmapWindowCookie is a cookie used only for UnmapWindow requests. +type UnmapWindowCookie struct { + *xgb.Cookie +} + +// UnmapWindow sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UnmapWindow(c *xgb.Conn, Window Window) UnmapWindowCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(unmapWindowRequest(c, Window), cookie) + return UnmapWindowCookie{cookie} +} + +// UnmapWindowChecked sends a checked request. +// If an error occurs, it can be retrieved using UnmapWindowCookie.Check() +func UnmapWindowChecked(c *xgb.Conn, Window Window) UnmapWindowCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(unmapWindowRequest(c, Window), cookie) + return UnmapWindowCookie{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 UnmapWindowCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnmapWindow +// unmapWindowRequest writes a UnmapWindow request to a byte slice. +func unmapWindowRequest(c *xgb.Conn, Window Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 10 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + return buf +} + +// WarpPointerCookie is a cookie used only for WarpPointer requests. +type WarpPointerCookie struct { + *xgb.Cookie +} + +// WarpPointer sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func WarpPointer(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) WarpPointerCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(warpPointerRequest(c, SrcWindow, DstWindow, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY), cookie) + return WarpPointerCookie{cookie} +} + +// WarpPointerChecked sends a checked request. +// If an error occurs, it can be retrieved using WarpPointerCookie.Check() +func WarpPointerChecked(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) WarpPointerCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(warpPointerRequest(c, SrcWindow, DstWindow, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY), cookie) + return WarpPointerCookie{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 WarpPointerCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for WarpPointer +// warpPointerRequest writes a WarpPointer request to a byte slice. +func warpPointerRequest(c *xgb.Conn, SrcWindow Window, DstWindow Window, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + buf[b] = 41 // request opcode + b += 1 + + b += 1 // padding + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(SrcWindow)) + b += 4 + + xgb.Put32(buf[b:], uint32(DstWindow)) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], SrcWidth) + b += 2 + + xgb.Put16(buf[b:], SrcHeight) + b += 2 + + xgb.Put16(buf[b:], uint16(DstX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DstY)) + b += 2 + + return buf +} diff --git a/nexgb/xproto/xproto_test.go b/nexgb/xproto/xproto_test.go new file mode 100644 index 0000000..a5bec71 --- /dev/null +++ b/nexgb/xproto/xproto_test.go @@ -0,0 +1,384 @@ +package xproto + +/* + Tests for XGB. + + These tests only test the core X protocol at the moment. It isn't even + close to complete coverage (and probably never will be), but it does test + a number of different corners: requests with no replies, requests without + replies, checked (i.e., synchronous) errors, unchecked (i.e., asynchronous) + errors, and sequence number wrapping. + + There are also a couple of benchmarks that show the difference between + correctly issuing lots of requests and gathering replies and + incorrectly doing the same. (This particular difference is one of the + claimed advantages of the XCB, and therefore XGB, family.) + + In sum, these tests are more focused on testing the core xgb package itself, + rather than whether xproto has properly implemented the core X client + protocol. +*/ + +import ( + "fmt" + "log" + "math/rand" + "testing" + "time" + + "github.com/BurntSushi/xgb" +) + +// The X connection used throughout testing. +var X *xgb.Conn + +// init initializes the X connection, seeds the RNG and starts waiting +// for events. +func init() { + var err error + + X, err = xgb.NewConn() + if err != nil { + log.Fatal(err) + } + + rand.Seed(time.Now().UnixNano()) + + go grabEvents() +} + +/******************************************************************************/ +// Tests +/******************************************************************************/ + +// TestSynchronousError purposefully causes a BadWindow error in a +// MapWindow request, and checks it synchronously. +func TestSynchronousError(t *testing.T) { + err := MapWindowChecked(X, 0).Check() // resource 0 is always invalid + if err == nil { + t.Fatalf("MapWindow: A MapWindow request that should return an " + + "error has returned a nil error.") + } + verifyMapWindowError(t, err) +} + +// TestAsynchronousError does the same thing as TestSynchronousError, but +// grabs the error asynchronously instead. +func TestAsynchronousError(t *testing.T) { + MapWindow(X, 0) // resource id 0 is always invalid + + evOrErr := waitForEvent(t, 5) + if evOrErr.ev != nil { + t.Fatalf("After issuing an erroneous MapWindow request, we have "+ + "received an event rather than an error: %s", evOrErr.ev) + } + verifyMapWindowError(t, evOrErr.err) +} + +// TestCookieBuffer issues (2^16) + n requets *without* replies to guarantee +// that the sequence number wraps and that the cookie buffer will have to +// flush itself (since there are no replies coming in to flush it). +// And just like TestSequenceWrap, we issue another request with a reply +// at the end to make sure XGB is still working properly. +func TestCookieBuffer(t *testing.T) { + n := (1 << 16) + 10 + for i := 0; i < n; i++ { + NoOperation(X) + } + TestProperty(t) +} + +// TestSequenceWrap issues (2^16) + n requests w/ replies to guarantee that the +// sequence number (which is a 16 bit integer) will wrap. It then issues one +// final request to ensure things still work properly. +func TestSequenceWrap(t *testing.T) { + n := (1 << 16) + 10 + for i := 0; i < n; i++ { + _, err := InternAtom(X, false, 5, "RANDO").Reply() + if err != nil { + t.Fatalf("InternAtom: %s", err) + } + } + TestProperty(t) +} + +// TestProperty tests whether a random value can be set and read. +func TestProperty(t *testing.T) { + propName := randString(20) // whatevs + writeVal := randString(20) + readVal, err := changeAndGetProp(propName, writeVal) + if err != nil { + t.Error(err) + } + + if readVal != writeVal { + t.Errorf("The value written, '%s', is not the same as the "+ + "value read '%s'.", writeVal, readVal) + } +} + +// TestWindowEvents creates a window, maps it, listens for configure notify +// events, issues a configure request, and checks for the appropriate +// configure notify event. +// This probably violates the notion of "test one thing and test it well," +// but testing X stuff is unique since it involves so much state. +// Each request is checked to make sure there are no errors returned. If there +// is an error, the test is failed. +// You may see a window appear quickly and then disappear. Do not be alarmed :P +// It's possible that this test will yield a false negative because we cannot +// control our environment. That is, the window manager could override the +// placement set. However, we set override redirect on the window, so the +// window manager *shouldn't* touch our window if it is well-behaved. +func TestWindowEvents(t *testing.T) { + // The geometry to set the window. + gx, gy, gw, gh := 200, 400, 1000, 300 + + wid, err := NewWindowId(X) + if err != nil { + t.Fatalf("NewId: %s", err) + } + + screen := Setup(X).DefaultScreen(X) // alias + err = CreateWindowChecked(X, screen.RootDepth, wid, screen.Root, + 0, 0, 500, 500, 0, + WindowClassInputOutput, screen.RootVisual, + CwBackPixel|CwOverrideRedirect, []uint32{0xffffffff, 1}).Check() + if err != nil { + t.Fatalf("CreateWindow: %s", err) + } + + err = MapWindowChecked(X, wid).Check() + if err != nil { + t.Fatalf("MapWindow: %s", err) + } + + // We don't listen in the CreateWindow request so that we don't get + // a MapNotify event. + err = ChangeWindowAttributesChecked(X, wid, + CwEventMask, []uint32{EventMaskStructureNotify}).Check() + if err != nil { + t.Fatalf("ChangeWindowAttributes: %s", err) + } + + err = ConfigureWindowChecked(X, wid, + ConfigWindowX|ConfigWindowY| + ConfigWindowWidth|ConfigWindowHeight, + []uint32{uint32(gx), uint32(gy), uint32(gw), uint32(gh)}).Check() + if err != nil { + t.Fatalf("ConfigureWindow: %s", err) + } + + evOrErr := waitForEvent(t, 5) + switch event := evOrErr.ev.(type) { + case ConfigureNotifyEvent: + if event.X != int16(gx) { + t.Fatalf("x was set to %d but ConfigureNotify reports %d", + gx, event.X) + } + if event.Y != int16(gy) { + t.Fatalf("y was set to %d but ConfigureNotify reports %d", + gy, event.Y) + } + if event.Width != uint16(gw) { + t.Fatalf("width was set to %d but ConfigureNotify reports %d", + gw, event.Width) + } + if event.Height != uint16(gh) { + t.Fatalf("height was set to %d but ConfigureNotify reports %d", + gh, event.Height) + } + default: + t.Fatalf("Expected a ConfigureNotifyEvent but got %T instead.", event) + } + + // Okay, clean up! + err = ChangeWindowAttributesChecked(X, wid, + CwEventMask, []uint32{0}).Check() + if err != nil { + t.Fatalf("ChangeWindowAttributes: %s", err) + } + + err = DestroyWindowChecked(X, wid).Check() + if err != nil { + t.Fatalf("DestroyWindow: %s", err) + } +} + +// Calls GetFontPath function, Issue #12 +func TestGetFontPath(t *testing.T) { + fontPathReply, err := GetFontPath(X).Reply() + if err != nil { + t.Fatalf("GetFontPath: %v", err) + } + _ = fontPathReply +} + +func TestListFonts(t *testing.T) { + listFontsReply, err := ListFonts(X, 10, 1, "*").Reply() + if err != nil { + t.Fatalf("ListFonts: %v", err) + } + _ = listFontsReply +} + +/******************************************************************************/ +// Benchmarks +/******************************************************************************/ + +// 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 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. +func BenchmarkInternAtomsGood(b *testing.B) { + b.StopTimer() + names := seqNames(b.N) + + b.StartTimer() + cookies := make([]InternAtomCookie, b.N) + for i := 0; i < b.N; i++ { + cookies[i] = InternAtom(X, false, uint16(len(names[i])), names[i]) + } + for _, cookie := range cookies { + cookie.Reply() + } +} + +// BenchmarkInternAtomsBad shows how *not* to issue a lot of requests with +// replies. Namely, each subsequent request isn't issued *until* the last +// reply is made. This implies a round trip to the X server for every +// iteration. +func BenchmarkInternAtomsPoor(b *testing.B) { + b.StopTimer() + names := seqNames(b.N) + + b.StartTimer() + for i := 0; i < b.N; i++ { + InternAtom(X, false, uint16(len(names[i])), names[i]).Reply() + } +} + +/******************************************************************************/ +// Helper functions +/******************************************************************************/ + +// changeAndGetProp sets property 'prop' with value 'val'. +// It then gets the value of that property and returns it. +// (It's used to check that the 'val' going in is the same 'val' going out.) +// It tests both requests with and without replies (GetProperty and +// ChangeProperty respectively.) +func changeAndGetProp(prop, val string) (string, error) { + setup := Setup(X) + root := setup.DefaultScreen(X).Root + + propAtom, err := InternAtom(X, false, uint16(len(prop)), prop).Reply() + if err != nil { + return "", fmt.Errorf("InternAtom: %s", err) + } + + typName := "UTF8_STRING" + typAtom, err := InternAtom(X, false, uint16(len(typName)), typName).Reply() + if err != nil { + return "", fmt.Errorf("InternAtom: %s", err) + } + + err = ChangePropertyChecked(X, PropModeReplace, root, propAtom.Atom, + typAtom.Atom, 8, uint32(len(val)), []byte(val)).Check() + if err != nil { + return "", fmt.Errorf("ChangeProperty: %s", err) + } + + reply, err := GetProperty(X, false, root, propAtom.Atom, + GetPropertyTypeAny, 0, (1<<32)-1).Reply() + if err != nil { + return "", fmt.Errorf("GetProperty: %s", err) + } + if reply.Format != 8 { + return "", fmt.Errorf("Property reply format is %d but it should be 8.", + reply.Format) + } + + return string(reply.Value), nil +} + +// verifyMapWindowError takes an error that is returned with an invalid +// MapWindow request with a window Id of 0 and makes sure the error is the +// right type and contains the correct values. +func verifyMapWindowError(t *testing.T, err error) { + switch e := err.(type) { + case WindowError: + if e.BadValue != 0 { + t.Fatalf("WindowError should report a bad value of 0 but "+ + "it reports %d instead.", e.BadValue) + } + if e.MajorOpcode != 8 { + t.Fatalf("WindowError should report a major opcode of 8 "+ + "(which is a MapWindow request), but it reports %d instead.", + e.MajorOpcode) + } + default: + t.Fatalf("Expected a WindowError but got %T instead.", e) + } +} + +// randString generates a random string of length n. +func randString(n int) string { + byts := make([]byte, n) + for i := 0; i < n; i++ { + rando := rand.Intn(53) + switch { + case rando <= 25: + byts[i] = byte(65 + rando) + case rando <= 51: + byts[i] = byte(97 + rando - 26) + default: + byts[i] = ' ' + } + } + return string(byts) +} + +// seqNames creates a slice of NAME0, NAME1, ..., NAMEN. +func seqNames(n int) []string { + names := make([]string, n) + for i := range names { + names[i] = fmt.Sprintf("NAME%d", i) + } + return names +} + +// evErr represents a value that is either an event or an error. +type evErr struct { + ev xgb.Event + err xgb.Error +} + +// channel used to pass evErrs. +var evOrErrChan = make(chan evErr, 0) + +// grabEvents is a goroutine that reads events off the wire. +// We used this instead of WaitForEvent directly in our tests so that +// we can timeout and fail a test. +func grabEvents() { + for { + ev, err := X.WaitForEvent() + evOrErrChan <- evErr{ev, err} + } +} + +// waitForEvent asks the evOrErrChan channel for an event. +// If it doesn't get an event in 'n' seconds, the current test is failed. +func waitForEvent(t *testing.T, n int) evErr { + var evOrErr evErr + + select { + case evOrErr = <-evOrErrChan: + case <-time.After(time.Second * 5): + t.Fatalf("After waiting 5 seconds for an event or an error, " + + "we have timed out.") + } + + return evOrErr +} diff --git a/nexgb/xselinux/xselinux.go b/nexgb/xselinux/xselinux.go new file mode 100644 index 0000000..c237857 --- /dev/null +++ b/nexgb/xselinux/xselinux.go @@ -0,0 +1,2267 @@ +// Package xselinux is the X client API for the SELinux extension. +package xselinux + +// This file is automatically generated from xselinux.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the SELinux extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 7, "SELinux").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named SELinux could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["SELinux"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["SELinux"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["SELinux"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["SELinux"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["SELinux"] = make(map[int]xgb.NewErrorFun) +} + +type ListItem struct { + Name xproto.Atom + ObjectContextLen uint32 + DataContextLen uint32 + ObjectContext string // size: xgb.Pad((int(ObjectContextLen) * 1)) + // alignment gap to multiple of 4 + DataContext string // size: xgb.Pad((int(DataContextLen) * 1)) + // alignment gap to multiple of 4 +} + +// ListItemRead reads a byte slice into a ListItem value. +func ListItemRead(buf []byte, v *ListItem) int { + b := 0 + + v.Name = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.ObjectContextLen = xgb.Get32(buf[b:]) + b += 4 + + v.DataContextLen = xgb.Get32(buf[b:]) + b += 4 + + { + byteString := make([]byte, v.ObjectContextLen) + copy(byteString[:v.ObjectContextLen], buf[b:]) + v.ObjectContext = string(byteString) + b += int(v.ObjectContextLen) + } + + b = (b + 3) & ^3 // alignment gap + + { + byteString := make([]byte, v.DataContextLen) + copy(byteString[:v.DataContextLen], buf[b:]) + v.DataContext = string(byteString) + b += int(v.DataContextLen) + } + + b = (b + 3) & ^3 // alignment gap + + return b +} + +// ListItemReadList reads a byte slice into a list of ListItem values. +func ListItemReadList(buf []byte, dest []ListItem) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ListItem{} + b += ListItemRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ListItem value to a byte slice. +func (v ListItem) Bytes() []byte { + buf := make([]byte, ((((12 + xgb.Pad((int(v.ObjectContextLen) * 1))) + 4) + xgb.Pad((int(v.DataContextLen) * 1))) + 4)) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Name)) + b += 4 + + xgb.Put32(buf[b:], v.ObjectContextLen) + b += 4 + + xgb.Put32(buf[b:], v.DataContextLen) + b += 4 + + copy(buf[b:], v.ObjectContext[:v.ObjectContextLen]) + b += int(v.ObjectContextLen) + + b = (b + 3) & ^3 // alignment gap + + copy(buf[b:], v.DataContext[:v.DataContextLen]) + b += int(v.DataContextLen) + + b = (b + 3) & ^3 // alignment gap + + return buf[:b] +} + +// ListItemListBytes writes a list of ListItem values to a byte slice. +func ListItemListBytes(buf []byte, list []ListItem) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ListItemListSize computes the size (bytes) of a list of ListItem values. +func ListItemListSize(list []ListItem) int { + size := 0 + for _, item := range list { + size += ((((12 + xgb.Pad((int(item.ObjectContextLen) * 1))) + 4) + xgb.Pad((int(item.DataContextLen) * 1))) + 4) + } + return size +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// GetClientContextCookie is a cookie used only for GetClientContext requests. +type GetClientContextCookie struct { + *xgb.Cookie +} + +// GetClientContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetClientContextCookie.Reply() +func GetClientContext(c *xgb.Conn, Resource uint32) GetClientContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getClientContextRequest(c, Resource), cookie) + return GetClientContextCookie{cookie} +} + +// GetClientContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetClientContextUnchecked(c *xgb.Conn, Resource uint32) GetClientContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getClientContextRequest(c, Resource), cookie) + return GetClientContextCookie{cookie} +} + +// GetClientContextReply represents the data returned from a GetClientContext request. +type GetClientContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetClientContext request. +func (cook GetClientContextCookie) Reply() (*GetClientContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getClientContextReply(buf), nil +} + +// getClientContextReply reads a byte slice into a GetClientContextReply value. +func getClientContextReply(buf []byte) *GetClientContextReply { + v := new(GetClientContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetClientContext +// getClientContextRequest writes a GetClientContext request to a byte slice. +func getClientContextRequest(c *xgb.Conn, Resource uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 22 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Resource) + b += 4 + + return buf +} + +// GetDeviceContextCookie is a cookie used only for GetDeviceContext requests. +type GetDeviceContextCookie struct { + *xgb.Cookie +} + +// GetDeviceContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceContextCookie.Reply() +func GetDeviceContext(c *xgb.Conn, Device uint32) GetDeviceContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDeviceContextRequest(c, Device), cookie) + return GetDeviceContextCookie{cookie} +} + +// GetDeviceContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDeviceContextUnchecked(c *xgb.Conn, Device uint32) GetDeviceContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDeviceContextRequest(c, Device), cookie) + return GetDeviceContextCookie{cookie} +} + +// GetDeviceContextReply represents the data returned from a GetDeviceContext request. +type GetDeviceContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetDeviceContext request. +func (cook GetDeviceContextCookie) Reply() (*GetDeviceContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDeviceContextReply(buf), nil +} + +// getDeviceContextReply reads a byte slice into a GetDeviceContextReply value. +func getDeviceContextReply(buf []byte) *GetDeviceContextReply { + v := new(GetDeviceContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetDeviceContext +// getDeviceContextRequest writes a GetDeviceContext request to a byte slice. +func getDeviceContextRequest(c *xgb.Conn, Device uint32) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], Device) + b += 4 + + return buf +} + +// GetDeviceCreateContextCookie is a cookie used only for GetDeviceCreateContext requests. +type GetDeviceCreateContextCookie struct { + *xgb.Cookie +} + +// GetDeviceCreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceCreateContextCookie.Reply() +func GetDeviceCreateContext(c *xgb.Conn) GetDeviceCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getDeviceCreateContextRequest(c), cookie) + return GetDeviceCreateContextCookie{cookie} +} + +// GetDeviceCreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDeviceCreateContextUnchecked(c *xgb.Conn) GetDeviceCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDeviceCreateContextRequest(c), cookie) + return GetDeviceCreateContextCookie{cookie} +} + +// GetDeviceCreateContextReply represents the data returned from a GetDeviceCreateContext request. +type GetDeviceCreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetDeviceCreateContext request. +func (cook GetDeviceCreateContextCookie) Reply() (*GetDeviceCreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getDeviceCreateContextReply(buf), nil +} + +// getDeviceCreateContextReply reads a byte slice into a GetDeviceCreateContextReply value. +func getDeviceCreateContextReply(buf []byte) *GetDeviceCreateContextReply { + v := new(GetDeviceCreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetDeviceCreateContext +// getDeviceCreateContextRequest writes a GetDeviceCreateContext request to a byte slice. +func getDeviceCreateContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// GetPropertyContextCookie is a cookie used only for GetPropertyContext requests. +type GetPropertyContextCookie struct { + *xgb.Cookie +} + +// GetPropertyContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPropertyContextCookie.Reply() +func GetPropertyContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie) + return GetPropertyContextCookie{cookie} +} + +// GetPropertyContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPropertyContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie) + return GetPropertyContextCookie{cookie} +} + +// GetPropertyContextReply represents the data returned from a GetPropertyContext request. +type GetPropertyContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetPropertyContext request. +func (cook GetPropertyContextCookie) Reply() (*GetPropertyContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPropertyContextReply(buf), nil +} + +// getPropertyContextReply reads a byte slice into a GetPropertyContextReply value. +func getPropertyContextReply(buf []byte) *GetPropertyContextReply { + v := new(GetPropertyContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetPropertyContext +// getPropertyContextRequest writes a GetPropertyContext request to a byte slice. +func getPropertyContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Property)) + b += 4 + + return buf +} + +// GetPropertyCreateContextCookie is a cookie used only for GetPropertyCreateContext requests. +type GetPropertyCreateContextCookie struct { + *xgb.Cookie +} + +// GetPropertyCreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPropertyCreateContextCookie.Reply() +func GetPropertyCreateContext(c *xgb.Conn) GetPropertyCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPropertyCreateContextRequest(c), cookie) + return GetPropertyCreateContextCookie{cookie} +} + +// GetPropertyCreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPropertyCreateContextUnchecked(c *xgb.Conn) GetPropertyCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPropertyCreateContextRequest(c), cookie) + return GetPropertyCreateContextCookie{cookie} +} + +// GetPropertyCreateContextReply represents the data returned from a GetPropertyCreateContext request. +type GetPropertyCreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetPropertyCreateContext request. +func (cook GetPropertyCreateContextCookie) Reply() (*GetPropertyCreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPropertyCreateContextReply(buf), nil +} + +// getPropertyCreateContextReply reads a byte slice into a GetPropertyCreateContextReply value. +func getPropertyCreateContextReply(buf []byte) *GetPropertyCreateContextReply { + v := new(GetPropertyCreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetPropertyCreateContext +// getPropertyCreateContextRequest writes a GetPropertyCreateContext request to a byte slice. +func getPropertyCreateContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetPropertyDataContextCookie is a cookie used only for GetPropertyDataContext requests. +type GetPropertyDataContextCookie struct { + *xgb.Cookie +} + +// GetPropertyDataContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPropertyDataContextCookie.Reply() +func GetPropertyDataContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie) + return GetPropertyDataContextCookie{cookie} +} + +// GetPropertyDataContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPropertyDataContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie) + return GetPropertyDataContextCookie{cookie} +} + +// GetPropertyDataContextReply represents the data returned from a GetPropertyDataContext request. +type GetPropertyDataContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetPropertyDataContext request. +func (cook GetPropertyDataContextCookie) Reply() (*GetPropertyDataContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPropertyDataContextReply(buf), nil +} + +// getPropertyDataContextReply reads a byte slice into a GetPropertyDataContextReply value. +func getPropertyDataContextReply(buf []byte) *GetPropertyDataContextReply { + v := new(GetPropertyDataContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetPropertyDataContext +// getPropertyDataContextRequest writes a GetPropertyDataContext request to a byte slice. +func getPropertyDataContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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(Property)) + b += 4 + + return buf +} + +// GetPropertyUseContextCookie is a cookie used only for GetPropertyUseContext requests. +type GetPropertyUseContextCookie struct { + *xgb.Cookie +} + +// GetPropertyUseContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPropertyUseContextCookie.Reply() +func GetPropertyUseContext(c *xgb.Conn) GetPropertyUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPropertyUseContextRequest(c), cookie) + return GetPropertyUseContextCookie{cookie} +} + +// GetPropertyUseContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPropertyUseContextUnchecked(c *xgb.Conn) GetPropertyUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPropertyUseContextRequest(c), cookie) + return GetPropertyUseContextCookie{cookie} +} + +// GetPropertyUseContextReply represents the data returned from a GetPropertyUseContext request. +type GetPropertyUseContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetPropertyUseContext request. +func (cook GetPropertyUseContextCookie) Reply() (*GetPropertyUseContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPropertyUseContextReply(buf), nil +} + +// getPropertyUseContextReply reads a byte slice into a GetPropertyUseContextReply value. +func getPropertyUseContextReply(buf []byte) *GetPropertyUseContextReply { + v := new(GetPropertyUseContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetPropertyUseContext +// getPropertyUseContextRequest writes a GetPropertyUseContext request to a byte slice. +func getPropertyUseContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetSelectionContextCookie is a cookie used only for GetSelectionContext requests. +type GetSelectionContextCookie struct { + *xgb.Cookie +} + +// GetSelectionContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectionContextCookie.Reply() +func GetSelectionContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectionContextRequest(c, Selection), cookie) + return GetSelectionContextCookie{cookie} +} + +// GetSelectionContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectionContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectionContextRequest(c, Selection), cookie) + return GetSelectionContextCookie{cookie} +} + +// GetSelectionContextReply represents the data returned from a GetSelectionContext request. +type GetSelectionContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetSelectionContext request. +func (cook GetSelectionContextCookie) Reply() (*GetSelectionContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectionContextReply(buf), nil +} + +// getSelectionContextReply reads a byte slice into a GetSelectionContextReply value. +func getSelectionContextReply(buf []byte) *GetSelectionContextReply { + v := new(GetSelectionContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetSelectionContext +// getSelectionContextRequest writes a GetSelectionContext request to a byte slice. +func getSelectionContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Selection)) + b += 4 + + return buf +} + +// GetSelectionCreateContextCookie is a cookie used only for GetSelectionCreateContext requests. +type GetSelectionCreateContextCookie struct { + *xgb.Cookie +} + +// GetSelectionCreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectionCreateContextCookie.Reply() +func GetSelectionCreateContext(c *xgb.Conn) GetSelectionCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectionCreateContextRequest(c), cookie) + return GetSelectionCreateContextCookie{cookie} +} + +// GetSelectionCreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectionCreateContextUnchecked(c *xgb.Conn) GetSelectionCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectionCreateContextRequest(c), cookie) + return GetSelectionCreateContextCookie{cookie} +} + +// GetSelectionCreateContextReply represents the data returned from a GetSelectionCreateContext request. +type GetSelectionCreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetSelectionCreateContext request. +func (cook GetSelectionCreateContextCookie) Reply() (*GetSelectionCreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectionCreateContextReply(buf), nil +} + +// getSelectionCreateContextReply reads a byte slice into a GetSelectionCreateContextReply value. +func getSelectionCreateContextReply(buf []byte) *GetSelectionCreateContextReply { + v := new(GetSelectionCreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetSelectionCreateContext +// getSelectionCreateContextRequest writes a GetSelectionCreateContext request to a byte slice. +func getSelectionCreateContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetSelectionDataContextCookie is a cookie used only for GetSelectionDataContext requests. +type GetSelectionDataContextCookie struct { + *xgb.Cookie +} + +// GetSelectionDataContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectionDataContextCookie.Reply() +func GetSelectionDataContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie) + return GetSelectionDataContextCookie{cookie} +} + +// GetSelectionDataContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectionDataContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie) + return GetSelectionDataContextCookie{cookie} +} + +// GetSelectionDataContextReply represents the data returned from a GetSelectionDataContext request. +type GetSelectionDataContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetSelectionDataContext request. +func (cook GetSelectionDataContextCookie) Reply() (*GetSelectionDataContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectionDataContextReply(buf), nil +} + +// getSelectionDataContextReply reads a byte slice into a GetSelectionDataContextReply value. +func getSelectionDataContextReply(buf []byte) *GetSelectionDataContextReply { + v := new(GetSelectionDataContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetSelectionDataContext +// getSelectionDataContextRequest writes a GetSelectionDataContext request to a byte slice. +func getSelectionDataContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 20 // 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(Selection)) + b += 4 + + return buf +} + +// GetSelectionUseContextCookie is a cookie used only for GetSelectionUseContext requests. +type GetSelectionUseContextCookie struct { + *xgb.Cookie +} + +// GetSelectionUseContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectionUseContextCookie.Reply() +func GetSelectionUseContext(c *xgb.Conn) GetSelectionUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectionUseContextRequest(c), cookie) + return GetSelectionUseContextCookie{cookie} +} + +// GetSelectionUseContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectionUseContextUnchecked(c *xgb.Conn) GetSelectionUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectionUseContextRequest(c), cookie) + return GetSelectionUseContextCookie{cookie} +} + +// GetSelectionUseContextReply represents the data returned from a GetSelectionUseContext request. +type GetSelectionUseContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetSelectionUseContext request. +func (cook GetSelectionUseContextCookie) Reply() (*GetSelectionUseContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectionUseContextReply(buf), nil +} + +// getSelectionUseContextReply reads a byte slice into a GetSelectionUseContextReply value. +func getSelectionUseContextReply(buf []byte) *GetSelectionUseContextReply { + v := new(GetSelectionUseContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetSelectionUseContext +// getSelectionUseContextRequest writes a GetSelectionUseContext request to a byte slice. +func getSelectionUseContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// GetWindowContextCookie is a cookie used only for GetWindowContext requests. +type GetWindowContextCookie struct { + *xgb.Cookie +} + +// GetWindowContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetWindowContextCookie.Reply() +func GetWindowContext(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getWindowContextRequest(c, Window), cookie) + return GetWindowContextCookie{cookie} +} + +// GetWindowContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetWindowContextUnchecked(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getWindowContextRequest(c, Window), cookie) + return GetWindowContextCookie{cookie} +} + +// GetWindowContextReply represents the data returned from a GetWindowContext request. +type GetWindowContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetWindowContext request. +func (cook GetWindowContextCookie) Reply() (*GetWindowContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getWindowContextReply(buf), nil +} + +// getWindowContextReply reads a byte slice into a GetWindowContextReply value. +func getWindowContextReply(buf []byte) *GetWindowContextReply { + v := new(GetWindowContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetWindowContext +// getWindowContextRequest writes a GetWindowContext request to a byte slice. +func getWindowContextRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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 + + return buf +} + +// GetWindowCreateContextCookie is a cookie used only for GetWindowCreateContext requests. +type GetWindowCreateContextCookie struct { + *xgb.Cookie +} + +// GetWindowCreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetWindowCreateContextCookie.Reply() +func GetWindowCreateContext(c *xgb.Conn) GetWindowCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getWindowCreateContextRequest(c), cookie) + return GetWindowCreateContextCookie{cookie} +} + +// GetWindowCreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetWindowCreateContextUnchecked(c *xgb.Conn) GetWindowCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getWindowCreateContextRequest(c), cookie) + return GetWindowCreateContextCookie{cookie} +} + +// GetWindowCreateContextReply represents the data returned from a GetWindowCreateContext request. +type GetWindowCreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ContextLen uint32 + // padding: 20 bytes + Context string // size: xgb.Pad((int(ContextLen) * 1)) +} + +// Reply blocks and returns the reply data for a GetWindowCreateContext request. +func (cook GetWindowCreateContextCookie) Reply() (*GetWindowCreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getWindowCreateContextReply(buf), nil +} + +// getWindowCreateContextReply reads a byte slice into a GetWindowCreateContextReply value. +func getWindowCreateContextReply(buf []byte) *GetWindowCreateContextReply { + v := new(GetWindowCreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ContextLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + { + byteString := make([]byte, v.ContextLen) + copy(byteString[:v.ContextLen], buf[b:]) + v.Context = string(byteString) + b += int(v.ContextLen) + } + + return v +} + +// Write request to wire for GetWindowCreateContext +// getWindowCreateContextRequest writes a GetWindowCreateContext request to a byte slice. +func getWindowCreateContextRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// ListPropertiesCookie is a cookie used only for ListProperties requests. +type ListPropertiesCookie struct { + *xgb.Cookie +} + +// ListProperties sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListPropertiesCookie.Reply() +func ListProperties(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listPropertiesRequest(c, Window), cookie) + return ListPropertiesCookie{cookie} +} + +// ListPropertiesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListPropertiesUnchecked(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listPropertiesRequest(c, Window), cookie) + return ListPropertiesCookie{cookie} +} + +// ListPropertiesReply represents the data returned from a ListProperties request. +type ListPropertiesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + PropertiesLen uint32 + // padding: 20 bytes + Properties []ListItem // size: ListItemListSize(Properties) +} + +// Reply blocks and returns the reply data for a ListProperties request. +func (cook ListPropertiesCookie) Reply() (*ListPropertiesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listPropertiesReply(buf), nil +} + +// listPropertiesReply reads a byte slice into a ListPropertiesReply value. +func listPropertiesReply(buf []byte) *ListPropertiesReply { + v := new(ListPropertiesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.PropertiesLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Properties = make([]ListItem, v.PropertiesLen) + b += ListItemReadList(buf[b:], v.Properties) + + return v +} + +// Write request to wire for ListProperties +// listPropertiesRequest writes a ListProperties request to a byte slice. +func listPropertiesRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // 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 + + return buf +} + +// ListSelectionsCookie is a cookie used only for ListSelections requests. +type ListSelectionsCookie struct { + *xgb.Cookie +} + +// ListSelections sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListSelectionsCookie.Reply() +func ListSelections(c *xgb.Conn) ListSelectionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listSelectionsRequest(c), cookie) + return ListSelectionsCookie{cookie} +} + +// ListSelectionsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListSelectionsUnchecked(c *xgb.Conn) ListSelectionsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listSelectionsRequest(c), cookie) + return ListSelectionsCookie{cookie} +} + +// ListSelectionsReply represents the data returned from a ListSelections request. +type ListSelectionsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + SelectionsLen uint32 + // padding: 20 bytes + Selections []ListItem // size: ListItemListSize(Selections) +} + +// Reply blocks and returns the reply data for a ListSelections request. +func (cook ListSelectionsCookie) Reply() (*ListSelectionsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listSelectionsReply(buf), nil +} + +// listSelectionsReply reads a byte slice into a ListSelectionsReply value. +func listSelectionsReply(buf []byte) *ListSelectionsReply { + v := new(ListSelectionsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.SelectionsLen = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Selections = make([]ListItem, v.SelectionsLen) + b += ListItemReadList(buf[b:], v.Selections) + + return v +} + +// Write request to wire for ListSelections +// listSelectionsRequest writes a ListSelections request to a byte slice. +func listSelectionsRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 21 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ServerMajor uint16 + ServerMinor uint16 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ServerMajor = xgb.Get16(buf[b:]) + b += 2 + + v.ServerMinor = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, ClientMajor byte, ClientMinor byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + 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] = ClientMajor + b += 1 + + buf[b] = ClientMinor + b += 1 + + return buf +} + +// SetDeviceContextCookie is a cookie used only for SetDeviceContext requests. +type SetDeviceContextCookie struct { + *xgb.Cookie +} + +// SetDeviceContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetDeviceContext(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie) + return SetDeviceContextCookie{cookie} +} + +// SetDeviceContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetDeviceContextCookie.Check() +func SetDeviceContextChecked(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie) + return SetDeviceContextCookie{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 SetDeviceContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetDeviceContext +// setDeviceContextRequest writes a SetDeviceContext request to a byte slice. +func setDeviceContextRequest(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) []byte { + size := xgb.Pad((12 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], Device) + b += 4 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetDeviceCreateContextCookie is a cookie used only for SetDeviceCreateContext requests. +type SetDeviceCreateContextCookie struct { + *xgb.Cookie +} + +// SetDeviceCreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetDeviceCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie) + return SetDeviceCreateContextCookie{cookie} +} + +// SetDeviceCreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetDeviceCreateContextCookie.Check() +func SetDeviceCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie) + return SetDeviceCreateContextCookie{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 SetDeviceCreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetDeviceCreateContext +// setDeviceCreateContextRequest writes a SetDeviceCreateContext request to a byte slice. +func setDeviceCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + 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:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetPropertyCreateContextCookie is a cookie used only for SetPropertyCreateContext requests. +type SetPropertyCreateContextCookie struct { + *xgb.Cookie +} + +// SetPropertyCreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPropertyCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie) + return SetPropertyCreateContextCookie{cookie} +} + +// SetPropertyCreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPropertyCreateContextCookie.Check() +func SetPropertyCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie) + return SetPropertyCreateContextCookie{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 SetPropertyCreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPropertyCreateContext +// setPropertyCreateContextRequest writes a SetPropertyCreateContext request to a byte slice. +func setPropertyCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetPropertyUseContextCookie is a cookie used only for SetPropertyUseContext requests. +type SetPropertyUseContextCookie struct { + *xgb.Cookie +} + +// SetPropertyUseContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPropertyUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie) + return SetPropertyUseContextCookie{cookie} +} + +// SetPropertyUseContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPropertyUseContextCookie.Check() +func SetPropertyUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie) + return SetPropertyUseContextCookie{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 SetPropertyUseContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPropertyUseContext +// setPropertyUseContextRequest writes a SetPropertyUseContext request to a byte slice. +func setPropertyUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetSelectionCreateContextCookie is a cookie used only for SetSelectionCreateContext requests. +type SetSelectionCreateContextCookie struct { + *xgb.Cookie +} + +// SetSelectionCreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetSelectionCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie) + return SetSelectionCreateContextCookie{cookie} +} + +// SetSelectionCreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetSelectionCreateContextCookie.Check() +func SetSelectionCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie) + return SetSelectionCreateContextCookie{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 SetSelectionCreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetSelectionCreateContext +// setSelectionCreateContextRequest writes a SetSelectionCreateContext request to a byte slice. +func setSelectionCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetSelectionUseContextCookie is a cookie used only for SetSelectionUseContext requests. +type SetSelectionUseContextCookie struct { + *xgb.Cookie +} + +// SetSelectionUseContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetSelectionUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie) + return SetSelectionUseContextCookie{cookie} +} + +// SetSelectionUseContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetSelectionUseContextCookie.Check() +func SetSelectionUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie) + return SetSelectionUseContextCookie{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 SetSelectionUseContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetSelectionUseContext +// setSelectionUseContextRequest writes a SetSelectionUseContext request to a byte slice. +func setSelectionUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} + +// SetWindowCreateContextCookie is a cookie used only for SetWindowCreateContext requests. +type SetWindowCreateContextCookie struct { + *xgb.Cookie +} + +// SetWindowCreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetWindowCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie) + return SetWindowCreateContextCookie{cookie} +} + +// SetWindowCreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using SetWindowCreateContextCookie.Check() +func SetWindowCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["SELinux"]; !ok { + panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie) + return SetWindowCreateContextCookie{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 SetWindowCreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetWindowCreateContext +// setWindowCreateContextRequest writes a SetWindowCreateContext request to a byte slice. +func setWindowCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["SELinux"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], ContextLen) + b += 4 + + copy(buf[b:], Context[:ContextLen]) + b += int(ContextLen) + + return buf +} diff --git a/nexgb/xtest/xtest.go b/nexgb/xtest/xtest.go new file mode 100644 index 0000000..182760e --- /dev/null +++ b/nexgb/xtest/xtest.go @@ -0,0 +1,416 @@ +// Package xtest is the X client API for the XTEST extension. +package xtest + +// This file is automatically generated from xtest.xml. 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.") + } + + 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 + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XTEST"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XTEST"] = make(map[int]xgb.NewErrorFun) +} + +const ( + CursorNone = 0 + CursorCurrent = 1 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// 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 { + 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.") + } + 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 { + 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.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(compareCursorRequest(c, Window, Cursor), cookie) + return CompareCursorCookie{cookie} +} + +// CompareCursorReply represents the data returned from a CompareCursor request. +type CompareCursorReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Same bool +} + +// 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 { + return nil, err + } + if buf == nil { + return nil, nil + } + return compareCursorReply(buf), nil +} + +// compareCursorReply reads a byte slice into a CompareCursorReply value. +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 +// 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 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() + 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 +} + +// FakeInputCookie is a cookie used only for FakeInput requests. +type FakeInputCookie struct { + *xgb.Cookie +} + +// 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.") + } + 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 { + 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.") + } + 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 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() + 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 +} + +// 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 { + 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.") + } + 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 { + 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.") + } + 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) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() + 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 +} + +// 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.") + } + 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 { + 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.") + } + 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 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XTEST"] + c.ExtLock.RUnlock() + 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 +} diff --git a/nexgb/xv/xv.go b/nexgb/xv/xv.go new file mode 100644 index 0000000..69a0549 --- /dev/null +++ b/nexgb/xv/xv.go @@ -0,0 +1,3063 @@ +// Package xv is the X client API for the XVideo extension. +package xv + +// This file is automatically generated from xv.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/shm" + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the XVideo extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "XVideo").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XVideo could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XVideo"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XVideo"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XVideo"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XVideo"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XVideo"] = make(map[int]xgb.NewErrorFun) +} + +type AdaptorInfo struct { + BaseId Port + NameSize uint16 + NumPorts uint16 + NumFormats uint16 + Type byte + // padding: 1 bytes + Name string // size: xgb.Pad((int(NameSize) * 1)) + // alignment gap to multiple of 4 + Formats []Format // size: xgb.Pad((int(NumFormats) * 8)) +} + +// AdaptorInfoRead reads a byte slice into a AdaptorInfo value. +func AdaptorInfoRead(buf []byte, v *AdaptorInfo) int { + b := 0 + + v.BaseId = Port(xgb.Get32(buf[b:])) + b += 4 + + v.NameSize = xgb.Get16(buf[b:]) + b += 2 + + v.NumPorts = xgb.Get16(buf[b:]) + b += 2 + + v.NumFormats = xgb.Get16(buf[b:]) + b += 2 + + v.Type = buf[b] + b += 1 + + b += 1 // padding + + { + byteString := make([]byte, v.NameSize) + copy(byteString[:v.NameSize], buf[b:]) + v.Name = string(byteString) + b += int(v.NameSize) + } + + b = (b + 3) & ^3 // alignment gap + + v.Formats = make([]Format, v.NumFormats) + b += FormatReadList(buf[b:], v.Formats) + + return b +} + +// AdaptorInfoReadList reads a byte slice into a list of AdaptorInfo values. +func AdaptorInfoReadList(buf []byte, dest []AdaptorInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = AdaptorInfo{} + b += AdaptorInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a AdaptorInfo value to a byte slice. +func (v AdaptorInfo) Bytes() []byte { + buf := make([]byte, (((12 + xgb.Pad((int(v.NameSize) * 1))) + 4) + xgb.Pad((int(v.NumFormats) * 8)))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.BaseId)) + b += 4 + + xgb.Put16(buf[b:], v.NameSize) + b += 2 + + xgb.Put16(buf[b:], v.NumPorts) + b += 2 + + xgb.Put16(buf[b:], v.NumFormats) + b += 2 + + buf[b] = v.Type + b += 1 + + b += 1 // padding + + copy(buf[b:], v.Name[:v.NameSize]) + b += int(v.NameSize) + + b = (b + 3) & ^3 // alignment gap + + b += FormatListBytes(buf[b:], v.Formats) + + return buf[:b] +} + +// AdaptorInfoListBytes writes a list of AdaptorInfo values to a byte slice. +func AdaptorInfoListBytes(buf []byte, list []AdaptorInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// AdaptorInfoListSize computes the size (bytes) of a list of AdaptorInfo values. +func AdaptorInfoListSize(list []AdaptorInfo) int { + size := 0 + for _, item := range list { + size += (((12 + xgb.Pad((int(item.NameSize) * 1))) + 4) + xgb.Pad((int(item.NumFormats) * 8))) + } + return size +} + +const ( + AttributeFlagGettable = 1 + AttributeFlagSettable = 2 +) + +type AttributeInfo struct { + Flags uint32 + Min int32 + Max int32 + Size uint32 + Name string // size: xgb.Pad((int(Size) * 1)) + // alignment gap to multiple of 4 +} + +// AttributeInfoRead reads a byte slice into a AttributeInfo value. +func AttributeInfoRead(buf []byte, v *AttributeInfo) int { + b := 0 + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + v.Min = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Max = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Size = xgb.Get32(buf[b:]) + b += 4 + + { + byteString := make([]byte, v.Size) + copy(byteString[:v.Size], buf[b:]) + v.Name = string(byteString) + b += int(v.Size) + } + + b = (b + 3) & ^3 // alignment gap + + return b +} + +// AttributeInfoReadList reads a byte slice into a list of AttributeInfo values. +func AttributeInfoReadList(buf []byte, dest []AttributeInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = AttributeInfo{} + b += AttributeInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a AttributeInfo value to a byte slice. +func (v AttributeInfo) Bytes() []byte { + buf := make([]byte, ((16 + xgb.Pad((int(v.Size) * 1))) + 4)) + b := 0 + + xgb.Put32(buf[b:], v.Flags) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Min)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Max)) + b += 4 + + xgb.Put32(buf[b:], v.Size) + b += 4 + + copy(buf[b:], v.Name[:v.Size]) + b += int(v.Size) + + b = (b + 3) & ^3 // alignment gap + + return buf[:b] +} + +// AttributeInfoListBytes writes a list of AttributeInfo values to a byte slice. +func AttributeInfoListBytes(buf []byte, list []AttributeInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// AttributeInfoListSize computes the size (bytes) of a list of AttributeInfo values. +func AttributeInfoListSize(list []AttributeInfo) int { + size := 0 + for _, item := range list { + size += ((16 + xgb.Pad((int(item.Size) * 1))) + 4) + } + return size +} + +// BadBadControl is the error number for a BadBadControl. +const BadBadControl = 2 + +type BadControlError struct { + Sequence uint16 + NiceName string +} + +// BadControlErrorNew constructs a BadControlError value that implements xgb.Error from a byte slice. +func BadControlErrorNew(buf []byte) xgb.Error { + v := BadControlError{} + v.NiceName = "BadControl" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadControl error. +// This is mostly used internally. +func (err BadControlError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadControl error. If no bad value exists, 0 is returned. +func (err BadControlError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadControl error. + +func (err BadControlError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadControl {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XVideo"][2] = BadControlErrorNew +} + +// BadBadEncoding is the error number for a BadBadEncoding. +const BadBadEncoding = 1 + +type BadEncodingError struct { + Sequence uint16 + NiceName string +} + +// BadEncodingErrorNew constructs a BadEncodingError value that implements xgb.Error from a byte slice. +func BadEncodingErrorNew(buf []byte) xgb.Error { + v := BadEncodingError{} + v.NiceName = "BadEncoding" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadEncoding error. +// This is mostly used internally. +func (err BadEncodingError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadEncoding error. If no bad value exists, 0 is returned. +func (err BadEncodingError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadEncoding error. + +func (err BadEncodingError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadEncoding {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XVideo"][1] = BadEncodingErrorNew +} + +// BadBadPort is the error number for a BadBadPort. +const BadBadPort = 0 + +type BadPortError struct { + Sequence uint16 + NiceName string +} + +// BadPortErrorNew constructs a BadPortError value that implements xgb.Error from a byte slice. +func BadPortErrorNew(buf []byte) xgb.Error { + v := BadPortError{} + v.NiceName = "BadPort" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// SequenceId returns the sequence id attached to the BadBadPort error. +// This is mostly used internally. +func (err BadPortError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadBadPort error. If no bad value exists, 0 is returned. +func (err BadPortError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadBadPort error. + +func (err BadPortError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadBadPort {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XVideo"][0] = BadPortErrorNew +} + +type Encoding uint32 + +func NewEncodingId(c *xgb.Conn) (Encoding, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Encoding(id), nil +} + +type EncodingInfo struct { + Encoding Encoding + NameSize uint16 + Width uint16 + Height uint16 + // padding: 2 bytes + Rate Rational + Name string // size: xgb.Pad((int(NameSize) * 1)) + // alignment gap to multiple of 4 +} + +// EncodingInfoRead reads a byte slice into a EncodingInfo value. +func EncodingInfoRead(buf []byte, v *EncodingInfo) int { + b := 0 + + v.Encoding = Encoding(xgb.Get32(buf[b:])) + b += 4 + + v.NameSize = xgb.Get16(buf[b:]) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Rate = Rational{} + b += RationalRead(buf[b:], &v.Rate) + + { + byteString := make([]byte, v.NameSize) + copy(byteString[:v.NameSize], buf[b:]) + v.Name = string(byteString) + b += int(v.NameSize) + } + + b = (b + 3) & ^3 // alignment gap + + return b +} + +// EncodingInfoReadList reads a byte slice into a list of EncodingInfo values. +func EncodingInfoReadList(buf []byte, dest []EncodingInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = EncodingInfo{} + b += EncodingInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a EncodingInfo value to a byte slice. +func (v EncodingInfo) Bytes() []byte { + buf := make([]byte, ((20 + xgb.Pad((int(v.NameSize) * 1))) + 4)) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Encoding)) + b += 4 + + xgb.Put16(buf[b:], v.NameSize) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + b += 2 // padding + + { + structBytes := v.Rate.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + copy(buf[b:], v.Name[:v.NameSize]) + b += int(v.NameSize) + + b = (b + 3) & ^3 // alignment gap + + return buf[:b] +} + +// EncodingInfoListBytes writes a list of EncodingInfo values to a byte slice. +func EncodingInfoListBytes(buf []byte, list []EncodingInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// EncodingInfoListSize computes the size (bytes) of a list of EncodingInfo values. +func EncodingInfoListSize(list []EncodingInfo) int { + size := 0 + for _, item := range list { + size += ((20 + xgb.Pad((int(item.NameSize) * 1))) + 4) + } + return size +} + +type Format struct { + Visual xproto.Visualid + Depth byte + // padding: 3 bytes +} + +// FormatRead reads a byte slice into a Format value. +func FormatRead(buf []byte, v *Format) int { + b := 0 + + v.Visual = xproto.Visualid(xgb.Get32(buf[b:])) + b += 4 + + v.Depth = buf[b] + b += 1 + + b += 3 // padding + + return b +} + +// FormatReadList reads a byte slice into a list of Format values. +func FormatReadList(buf []byte, dest []Format) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Format{} + b += FormatRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Format value to a byte slice. +func (v Format) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Visual)) + b += 4 + + buf[b] = v.Depth + b += 1 + + b += 3 // padding + + return buf[:b] +} + +// FormatListBytes writes a list of Format values to a byte slice. +func FormatListBytes(buf []byte, list []Format) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + GrabPortStatusSuccess = 0 + GrabPortStatusBadExtension = 1 + GrabPortStatusAlreadyGrabbed = 2 + GrabPortStatusInvalidTime = 3 + GrabPortStatusBadReply = 4 + GrabPortStatusBadAlloc = 5 +) + +type Image struct { + Id uint32 + Width uint16 + Height uint16 + DataSize uint32 + NumPlanes uint32 + Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) + Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) + Data []byte // size: xgb.Pad((int(DataSize) * 1)) +} + +// ImageRead reads a byte slice into a Image value. +func ImageRead(buf []byte, v *Image) int { + b := 0 + + v.Id = xgb.Get32(buf[b:]) + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.DataSize = xgb.Get32(buf[b:]) + b += 4 + + v.NumPlanes = xgb.Get32(buf[b:]) + b += 4 + + v.Pitches = make([]uint32, v.NumPlanes) + for i := 0; i < int(v.NumPlanes); i++ { + v.Pitches[i] = xgb.Get32(buf[b:]) + b += 4 + } + + v.Offsets = make([]uint32, v.NumPlanes) + for i := 0; i < int(v.NumPlanes); i++ { + v.Offsets[i] = xgb.Get32(buf[b:]) + b += 4 + } + + v.Data = make([]byte, v.DataSize) + copy(v.Data[:v.DataSize], buf[b:]) + b += int(v.DataSize) + + return b +} + +// ImageReadList reads a byte slice into a list of Image values. +func ImageReadList(buf []byte, dest []Image) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Image{} + b += ImageRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Image value to a byte slice. +func (v Image) Bytes() []byte { + buf := make([]byte, (((16 + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.DataSize) * 1)))) + b := 0 + + xgb.Put32(buf[b:], v.Id) + b += 4 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put32(buf[b:], v.DataSize) + b += 4 + + xgb.Put32(buf[b:], v.NumPlanes) + b += 4 + + for i := 0; i < int(v.NumPlanes); i++ { + xgb.Put32(buf[b:], v.Pitches[i]) + b += 4 + } + + for i := 0; i < int(v.NumPlanes); i++ { + xgb.Put32(buf[b:], v.Offsets[i]) + b += 4 + } + + copy(buf[b:], v.Data[:v.DataSize]) + b += int(v.DataSize) + + return buf[:b] +} + +// ImageListBytes writes a list of Image values to a byte slice. +func ImageListBytes(buf []byte, list []Image) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ImageListSize computes the size (bytes) of a list of Image values. +func ImageListSize(list []Image) int { + size := 0 + for _, item := range list { + size += (((16 + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.DataSize) * 1))) + } + return size +} + +type ImageFormatInfo struct { + Id uint32 + Type byte + ByteOrder byte + // padding: 2 bytes + Guid []byte // size: 16 + Bpp byte + NumPlanes byte + // padding: 2 bytes + Depth byte + // padding: 3 bytes + RedMask uint32 + GreenMask uint32 + BlueMask uint32 + Format byte + // padding: 3 bytes + YSampleBits uint32 + USampleBits uint32 + VSampleBits uint32 + VhorzYPeriod uint32 + VhorzUPeriod uint32 + VhorzVPeriod uint32 + VvertYPeriod uint32 + VvertUPeriod uint32 + VvertVPeriod uint32 + VcompOrder []byte // size: 32 + VscanlineOrder byte + // padding: 11 bytes +} + +// ImageFormatInfoRead reads a byte slice into a ImageFormatInfo value. +func ImageFormatInfoRead(buf []byte, v *ImageFormatInfo) int { + b := 0 + + v.Id = xgb.Get32(buf[b:]) + b += 4 + + v.Type = buf[b] + b += 1 + + v.ByteOrder = buf[b] + b += 1 + + b += 2 // padding + + v.Guid = make([]byte, 16) + copy(v.Guid[:16], buf[b:]) + b += int(16) + + v.Bpp = buf[b] + b += 1 + + v.NumPlanes = buf[b] + b += 1 + + b += 2 // padding + + v.Depth = buf[b] + b += 1 + + b += 3 // padding + + v.RedMask = xgb.Get32(buf[b:]) + b += 4 + + v.GreenMask = xgb.Get32(buf[b:]) + b += 4 + + v.BlueMask = xgb.Get32(buf[b:]) + b += 4 + + v.Format = buf[b] + b += 1 + + b += 3 // padding + + v.YSampleBits = xgb.Get32(buf[b:]) + b += 4 + + v.USampleBits = xgb.Get32(buf[b:]) + b += 4 + + v.VSampleBits = xgb.Get32(buf[b:]) + b += 4 + + v.VhorzYPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VhorzUPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VhorzVPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VvertYPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VvertUPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VvertVPeriod = xgb.Get32(buf[b:]) + b += 4 + + v.VcompOrder = make([]byte, 32) + copy(v.VcompOrder[:32], buf[b:]) + b += int(32) + + v.VscanlineOrder = buf[b] + b += 1 + + b += 11 // padding + + return b +} + +// ImageFormatInfoReadList reads a byte slice into a list of ImageFormatInfo values. +func ImageFormatInfoReadList(buf []byte, dest []ImageFormatInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ImageFormatInfo{} + b += ImageFormatInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a ImageFormatInfo value to a byte slice. +func (v ImageFormatInfo) Bytes() []byte { + buf := make([]byte, 128) + b := 0 + + xgb.Put32(buf[b:], v.Id) + b += 4 + + buf[b] = v.Type + b += 1 + + buf[b] = v.ByteOrder + b += 1 + + b += 2 // padding + + copy(buf[b:], v.Guid[:16]) + b += int(16) + + buf[b] = v.Bpp + b += 1 + + buf[b] = v.NumPlanes + b += 1 + + b += 2 // padding + + buf[b] = v.Depth + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], v.RedMask) + b += 4 + + xgb.Put32(buf[b:], v.GreenMask) + b += 4 + + xgb.Put32(buf[b:], v.BlueMask) + b += 4 + + buf[b] = v.Format + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], v.YSampleBits) + b += 4 + + xgb.Put32(buf[b:], v.USampleBits) + b += 4 + + xgb.Put32(buf[b:], v.VSampleBits) + b += 4 + + xgb.Put32(buf[b:], v.VhorzYPeriod) + b += 4 + + xgb.Put32(buf[b:], v.VhorzUPeriod) + b += 4 + + xgb.Put32(buf[b:], v.VhorzVPeriod) + b += 4 + + xgb.Put32(buf[b:], v.VvertYPeriod) + b += 4 + + xgb.Put32(buf[b:], v.VvertUPeriod) + b += 4 + + xgb.Put32(buf[b:], v.VvertVPeriod) + b += 4 + + copy(buf[b:], v.VcompOrder[:32]) + b += int(32) + + buf[b] = v.VscanlineOrder + b += 1 + + b += 11 // padding + + return buf[:b] +} + +// ImageFormatInfoListBytes writes a list of ImageFormatInfo values to a byte slice. +func ImageFormatInfoListBytes(buf []byte, list []ImageFormatInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// ImageFormatInfoListSize computes the size (bytes) of a list of ImageFormatInfo values. +func ImageFormatInfoListSize(list []ImageFormatInfo) int { + size := 0 + for _ = range list { + size += 128 + } + return size +} + +const ( + ImageFormatInfoFormatPacked = 0 + ImageFormatInfoFormatPlanar = 1 +) + +const ( + ImageFormatInfoTypeRgb = 0 + ImageFormatInfoTypeYuv = 1 +) + +type Port uint32 + +func NewPortId(c *xgb.Conn) (Port, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Port(id), nil +} + +// PortNotify is the event number for a PortNotifyEvent. +const PortNotify = 1 + +type PortNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Time xproto.Timestamp + Port Port + Attribute xproto.Atom + Value int32 +} + +// PortNotifyEventNew constructs a PortNotifyEvent value that implements xgb.Event from a byte slice. +func PortNotifyEventNew(buf []byte) xgb.Event { + v := PortNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Port = Port(xgb.Get32(buf[b:])) + b += 4 + + v.Attribute = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + v.Value = int32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a PortNotifyEvent value to a byte slice. +func (v PortNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 1 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Attribute)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Value)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the PortNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v PortNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of PortNotifyEvent. +func (v PortNotifyEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Port: %d", v.Port)) + fieldVals = append(fieldVals, xgb.Sprintf("Attribute: %d", v.Attribute)) + fieldVals = append(fieldVals, xgb.Sprintf("Value: %d", v.Value)) + return "PortNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XVideo"][1] = PortNotifyEventNew +} + +type Rational struct { + Numerator int32 + Denominator int32 +} + +// RationalRead reads a byte slice into a Rational value. +func RationalRead(buf []byte, v *Rational) int { + b := 0 + + v.Numerator = int32(xgb.Get32(buf[b:])) + b += 4 + + v.Denominator = int32(xgb.Get32(buf[b:])) + b += 4 + + return b +} + +// RationalReadList reads a byte slice into a list of Rational values. +func RationalReadList(buf []byte, dest []Rational) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Rational{} + b += RationalRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a Rational value to a byte slice. +func (v Rational) Bytes() []byte { + buf := make([]byte, 8) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Numerator)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Denominator)) + b += 4 + + return buf[:b] +} + +// RationalListBytes writes a list of Rational values to a byte slice. +func RationalListBytes(buf []byte, list []Rational) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +const ( + ScanlineOrderTopToBottom = 0 + ScanlineOrderBottomToTop = 1 +) + +const ( + TypeInputMask = 1 + TypeOutputMask = 2 + TypeVideoMask = 4 + TypeStillMask = 8 + TypeImageMask = 16 +) + +// VideoNotify is the event number for a VideoNotifyEvent. +const VideoNotify = 0 + +type VideoNotifyEvent struct { + Sequence uint16 + Reason byte + Time xproto.Timestamp + Drawable xproto.Drawable + Port Port +} + +// VideoNotifyEventNew constructs a VideoNotifyEvent value that implements xgb.Event from a byte slice. +func VideoNotifyEventNew(buf []byte) xgb.Event { + v := VideoNotifyEvent{} + b := 1 // don't read event number + + v.Reason = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) + b += 4 + + v.Port = Port(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Bytes writes a VideoNotifyEvent value to a byte slice. +func (v VideoNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 0 + b += 1 + + buf[b] = v.Reason + b += 1 + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.Port)) + b += 4 + + return buf +} + +// SequenceId returns the sequence id attached to the VideoNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v VideoNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of VideoNotifyEvent. +func (v VideoNotifyEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Reason: %d", v.Reason)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) + fieldVals = append(fieldVals, xgb.Sprintf("Port: %d", v.Port)) + return "VideoNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XVideo"][0] = VideoNotifyEventNew +} + +const ( + VideoNotifyReasonStarted = 0 + VideoNotifyReasonStopped = 1 + VideoNotifyReasonBusy = 2 + VideoNotifyReasonPreempted = 3 + VideoNotifyReasonHardError = 4 +) + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// GetPortAttributeCookie is a cookie used only for GetPortAttribute requests. +type GetPortAttributeCookie struct { + *xgb.Cookie +} + +// GetPortAttribute sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetPortAttributeCookie.Reply() +func GetPortAttribute(c *xgb.Conn, Port Port, Attribute xproto.Atom) GetPortAttributeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getPortAttributeRequest(c, Port, Attribute), cookie) + return GetPortAttributeCookie{cookie} +} + +// GetPortAttributeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetPortAttributeUnchecked(c *xgb.Conn, Port Port, Attribute xproto.Atom) GetPortAttributeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getPortAttributeRequest(c, Port, Attribute), cookie) + return GetPortAttributeCookie{cookie} +} + +// GetPortAttributeReply represents the data returned from a GetPortAttribute request. +type GetPortAttributeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Value int32 +} + +// Reply blocks and returns the reply data for a GetPortAttribute request. +func (cook GetPortAttributeCookie) Reply() (*GetPortAttributeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getPortAttributeReply(buf), nil +} + +// getPortAttributeReply reads a byte slice into a GetPortAttributeReply value. +func getPortAttributeReply(buf []byte) *GetPortAttributeReply { + v := new(GetPortAttributeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Value = int32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for GetPortAttribute +// getPortAttributeRequest writes a GetPortAttribute request to a byte slice. +func getPortAttributeRequest(c *xgb.Conn, Port Port, Attribute xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 14 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Attribute)) + b += 4 + + return buf +} + +// GetStillCookie is a cookie used only for GetStill requests. +type GetStillCookie struct { + *xgb.Cookie +} + +// GetStill sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetStill(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetStillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(getStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return GetStillCookie{cookie} +} + +// GetStillChecked sends a checked request. +// If an error occurs, it can be retrieved using GetStillCookie.Check() +func GetStillChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetStillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(getStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return GetStillCookie{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 GetStillCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GetStill +// getStillRequest writes a GetStill request to a byte slice. +func getStillRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(VidX)) + b += 2 + + xgb.Put16(buf[b:], uint16(VidY)) + b += 2 + + xgb.Put16(buf[b:], VidW) + b += 2 + + xgb.Put16(buf[b:], VidH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + return buf +} + +// GetVideoCookie is a cookie used only for GetVideo requests. +type GetVideoCookie struct { + *xgb.Cookie +} + +// GetVideo sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(getVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return GetVideoCookie{cookie} +} + +// GetVideoChecked sends a checked request. +// If an error occurs, it can be retrieved using GetVideoCookie.Check() +func GetVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GetVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(getVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return GetVideoCookie{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 GetVideoCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for GetVideo +// getVideoRequest writes a GetVideo request to a byte slice. +func getVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(VidX)) + b += 2 + + xgb.Put16(buf[b:], uint16(VidY)) + b += 2 + + xgb.Put16(buf[b:], VidW) + b += 2 + + xgb.Put16(buf[b:], VidH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + return buf +} + +// GrabPortCookie is a cookie used only for GrabPort requests. +type GrabPortCookie struct { + *xgb.Cookie +} + +// GrabPort sends a checked request. +// If an error occurs, it will be returned with the reply by calling GrabPortCookie.Reply() +func GrabPort(c *xgb.Conn, Port Port, Time xproto.Timestamp) GrabPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(grabPortRequest(c, Port, Time), cookie) + return GrabPortCookie{cookie} +} + +// GrabPortUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabPortUnchecked(c *xgb.Conn, Port Port, Time xproto.Timestamp) GrabPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'GrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(grabPortRequest(c, Port, Time), cookie) + return GrabPortCookie{cookie} +} + +// GrabPortReply represents the data returned from a GrabPort request. +type GrabPortReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Result byte +} + +// Reply blocks and returns the reply data for a GrabPort request. +func (cook GrabPortCookie) Reply() (*GrabPortReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return grabPortReply(buf), nil +} + +// grabPortReply reads a byte slice into a GrabPortReply value. +func grabPortReply(buf []byte) *GrabPortReply { + v := new(GrabPortReply) + b := 1 // skip reply determinant + + v.Result = buf[b] + 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 GrabPort +// grabPortRequest writes a GrabPort request to a byte slice. +func grabPortRequest(c *xgb.Conn, Port Port, Time xproto.Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} + +// ListImageFormatsCookie is a cookie used only for ListImageFormats requests. +type ListImageFormatsCookie struct { + *xgb.Cookie +} + +// ListImageFormats sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListImageFormatsCookie.Reply() +func ListImageFormats(c *xgb.Conn, Port Port) ListImageFormatsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'ListImageFormats' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listImageFormatsRequest(c, Port), cookie) + return ListImageFormatsCookie{cookie} +} + +// ListImageFormatsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListImageFormatsUnchecked(c *xgb.Conn, Port Port) ListImageFormatsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'ListImageFormats' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listImageFormatsRequest(c, Port), cookie) + return ListImageFormatsCookie{cookie} +} + +// ListImageFormatsReply represents the data returned from a ListImageFormats request. +type ListImageFormatsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumFormats uint32 + // padding: 20 bytes + Format []ImageFormatInfo // size: ImageFormatInfoListSize(Format) +} + +// Reply blocks and returns the reply data for a ListImageFormats request. +func (cook ListImageFormatsCookie) Reply() (*ListImageFormatsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listImageFormatsReply(buf), nil +} + +// listImageFormatsReply reads a byte slice into a ListImageFormatsReply value. +func listImageFormatsReply(buf []byte) *ListImageFormatsReply { + v := new(ListImageFormatsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumFormats = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Format = make([]ImageFormatInfo, v.NumFormats) + b += ImageFormatInfoReadList(buf[b:], v.Format) + + return v +} + +// Write request to wire for ListImageFormats +// listImageFormatsRequest writes a ListImageFormats request to a byte slice. +func listImageFormatsRequest(c *xgb.Conn, Port Port) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 16 // 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(Port)) + b += 4 + + return buf +} + +// PutImageCookie is a cookie used only for PutImage requests. +type PutImageCookie struct { + *xgb.Cookie +} + +// PutImage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PutImage(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) PutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(putImageRequest(c, Port, Drawable, Gc, Id, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, Data), cookie) + return PutImageCookie{cookie} +} + +// PutImageChecked sends a checked request. +// If an error occurs, it can be retrieved using PutImageCookie.Check() +func PutImageChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) PutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(putImageRequest(c, Port, Drawable, Gc, Id, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, Data), cookie) + return PutImageCookie{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 PutImageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PutImage +// putImageRequest writes a PutImage request to a byte slice. +func putImageRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) []byte { + size := xgb.Pad((40 + xgb.Pad((len(Data) * 1)))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 18 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], SrcW) + b += 2 + + xgb.Put16(buf[b:], SrcH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + copy(buf[b:], Data[:len(Data)]) + b += int(len(Data)) + + return buf +} + +// PutStillCookie is a cookie used only for PutStill requests. +type PutStillCookie struct { + *xgb.Cookie +} + +// PutStill sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PutStill(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutStillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(putStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return PutStillCookie{cookie} +} + +// PutStillChecked sends a checked request. +// If an error occurs, it can be retrieved using PutStillCookie.Check() +func PutStillChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutStillCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(putStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return PutStillCookie{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 PutStillCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PutStill +// putStillRequest writes a PutStill request to a byte slice. +func putStillRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(VidX)) + b += 2 + + xgb.Put16(buf[b:], uint16(VidY)) + b += 2 + + xgb.Put16(buf[b:], VidW) + b += 2 + + xgb.Put16(buf[b:], VidH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + return buf +} + +// PutVideoCookie is a cookie used only for PutVideo requests. +type PutVideoCookie struct { + *xgb.Cookie +} + +// PutVideo sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func PutVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(putVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return PutVideoCookie{cookie} +} + +// PutVideoChecked sends a checked request. +// If an error occurs, it can be retrieved using PutVideoCookie.Check() +func PutVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'PutVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(putVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) + return PutVideoCookie{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 PutVideoCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for PutVideo +// putVideoRequest writes a PutVideo request to a byte slice. +func putVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { + size := 32 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put16(buf[b:], uint16(VidX)) + b += 2 + + xgb.Put16(buf[b:], uint16(VidY)) + b += 2 + + xgb.Put16(buf[b:], VidW) + b += 2 + + xgb.Put16(buf[b:], VidH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + return buf +} + +// QueryAdaptorsCookie is a cookie used only for QueryAdaptors requests. +type QueryAdaptorsCookie struct { + *xgb.Cookie +} + +// QueryAdaptors sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryAdaptorsCookie.Reply() +func QueryAdaptors(c *xgb.Conn, Window xproto.Window) QueryAdaptorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryAdaptors' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryAdaptorsRequest(c, Window), cookie) + return QueryAdaptorsCookie{cookie} +} + +// QueryAdaptorsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryAdaptorsUnchecked(c *xgb.Conn, Window xproto.Window) QueryAdaptorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryAdaptors' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryAdaptorsRequest(c, Window), cookie) + return QueryAdaptorsCookie{cookie} +} + +// QueryAdaptorsReply represents the data returned from a QueryAdaptors request. +type QueryAdaptorsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAdaptors uint16 + // padding: 22 bytes + Info []AdaptorInfo // size: AdaptorInfoListSize(Info) +} + +// Reply blocks and returns the reply data for a QueryAdaptors request. +func (cook QueryAdaptorsCookie) Reply() (*QueryAdaptorsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryAdaptorsReply(buf), nil +} + +// queryAdaptorsReply reads a byte slice into a QueryAdaptorsReply value. +func queryAdaptorsReply(buf []byte) *QueryAdaptorsReply { + v := new(QueryAdaptorsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAdaptors = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Info = make([]AdaptorInfo, v.NumAdaptors) + b += AdaptorInfoReadList(buf[b:], v.Info) + + return v +} + +// Write request to wire for QueryAdaptors +// queryAdaptorsRequest writes a QueryAdaptors request to a byte slice. +func queryAdaptorsRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// QueryBestSizeCookie is a cookie used only for QueryBestSize requests. +type QueryBestSizeCookie struct { + *xgb.Cookie +} + +// QueryBestSize sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryBestSizeCookie.Reply() +func QueryBestSize(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) QueryBestSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryBestSize' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryBestSizeRequest(c, Port, VidW, VidH, DrwW, DrwH, Motion), cookie) + return QueryBestSizeCookie{cookie} +} + +// QueryBestSizeUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryBestSizeUnchecked(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) QueryBestSizeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryBestSize' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryBestSizeRequest(c, Port, VidW, VidH, DrwW, DrwH, Motion), cookie) + return QueryBestSizeCookie{cookie} +} + +// QueryBestSizeReply represents the data returned from a QueryBestSize request. +type QueryBestSizeReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ActualWidth uint16 + ActualHeight uint16 +} + +// Reply blocks and returns the reply data for a QueryBestSize request. +func (cook QueryBestSizeCookie) Reply() (*QueryBestSizeReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryBestSizeReply(buf), nil +} + +// queryBestSizeReply reads a byte slice into a QueryBestSizeReply value. +func queryBestSizeReply(buf []byte) *QueryBestSizeReply { + v := new(QueryBestSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ActualWidth = xgb.Get16(buf[b:]) + b += 2 + + v.ActualHeight = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryBestSize +// queryBestSizeRequest writes a QueryBestSize request to a byte slice. +func queryBestSizeRequest(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 12 // 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(Port)) + b += 4 + + xgb.Put16(buf[b:], VidW) + b += 2 + + xgb.Put16(buf[b:], VidH) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + if Motion { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// QueryEncodingsCookie is a cookie used only for QueryEncodings requests. +type QueryEncodingsCookie struct { + *xgb.Cookie +} + +// QueryEncodings sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryEncodingsCookie.Reply() +func QueryEncodings(c *xgb.Conn, Port Port) QueryEncodingsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryEncodings' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryEncodingsRequest(c, Port), cookie) + return QueryEncodingsCookie{cookie} +} + +// QueryEncodingsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryEncodingsUnchecked(c *xgb.Conn, Port Port) QueryEncodingsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryEncodings' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryEncodingsRequest(c, Port), cookie) + return QueryEncodingsCookie{cookie} +} + +// QueryEncodingsReply represents the data returned from a QueryEncodings request. +type QueryEncodingsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumEncodings uint16 + // padding: 22 bytes + Info []EncodingInfo // size: EncodingInfoListSize(Info) +} + +// Reply blocks and returns the reply data for a QueryEncodings request. +func (cook QueryEncodingsCookie) Reply() (*QueryEncodingsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryEncodingsReply(buf), nil +} + +// queryEncodingsReply reads a byte slice into a QueryEncodingsReply value. +func queryEncodingsReply(buf []byte) *QueryEncodingsReply { + v := new(QueryEncodingsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumEncodings = xgb.Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Info = make([]EncodingInfo, v.NumEncodings) + b += EncodingInfoReadList(buf[b:], v.Info) + + return v +} + +// Write request to wire for QueryEncodings +// queryEncodingsRequest writes a QueryEncodings request to a byte slice. +func queryEncodingsRequest(c *xgb.Conn, Port Port) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(Port)) + b += 4 + + return buf +} + +// QueryExtensionCookie is a cookie used only for QueryExtension requests. +type QueryExtensionCookie struct { + *xgb.Cookie +} + +// QueryExtension sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryExtensionCookie.Reply() +func QueryExtension(c *xgb.Conn) QueryExtensionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryExtension' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryExtensionRequest(c), cookie) + return QueryExtensionCookie{cookie} +} + +// QueryExtensionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryExtensionUnchecked(c *xgb.Conn) QueryExtensionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryExtension' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryExtensionRequest(c), cookie) + return QueryExtensionCookie{cookie} +} + +// QueryExtensionReply represents the data returned from a QueryExtension request. +type QueryExtensionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Major uint16 + Minor uint16 +} + +// Reply blocks and returns the reply data for a QueryExtension request. +func (cook QueryExtensionCookie) Reply() (*QueryExtensionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryExtensionReply(buf), nil +} + +// queryExtensionReply reads a byte slice into a QueryExtensionReply value. +func queryExtensionReply(buf []byte) *QueryExtensionReply { + v := new(QueryExtensionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Major = xgb.Get16(buf[b:]) + b += 2 + + v.Minor = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryExtension +// queryExtensionRequest writes a QueryExtension request to a byte slice. +func queryExtensionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + 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 + + return buf +} + +// QueryImageAttributesCookie is a cookie used only for QueryImageAttributes requests. +type QueryImageAttributesCookie struct { + *xgb.Cookie +} + +// QueryImageAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryImageAttributesCookie.Reply() +func QueryImageAttributes(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) QueryImageAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryImageAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryImageAttributesRequest(c, Port, Id, Width, Height), cookie) + return QueryImageAttributesCookie{cookie} +} + +// QueryImageAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryImageAttributesUnchecked(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) QueryImageAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryImageAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryImageAttributesRequest(c, Port, Id, Width, Height), cookie) + return QueryImageAttributesCookie{cookie} +} + +// QueryImageAttributesReply represents the data returned from a QueryImageAttributes request. +type QueryImageAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumPlanes uint32 + DataSize uint32 + Width uint16 + Height uint16 + // padding: 12 bytes + Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) + Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) +} + +// Reply blocks and returns the reply data for a QueryImageAttributes request. +func (cook QueryImageAttributesCookie) Reply() (*QueryImageAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryImageAttributesReply(buf), nil +} + +// queryImageAttributesReply reads a byte slice into a QueryImageAttributesReply value. +func queryImageAttributesReply(buf []byte) *QueryImageAttributesReply { + v := new(QueryImageAttributesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumPlanes = xgb.Get32(buf[b:]) + b += 4 + + v.DataSize = xgb.Get32(buf[b:]) + b += 4 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + b += 12 // padding + + v.Pitches = make([]uint32, v.NumPlanes) + for i := 0; i < int(v.NumPlanes); i++ { + v.Pitches[i] = xgb.Get32(buf[b:]) + b += 4 + } + + v.Offsets = make([]uint32, v.NumPlanes) + for i := 0; i < int(v.NumPlanes); i++ { + v.Offsets[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for QueryImageAttributes +// queryImageAttributesRequest writes a QueryImageAttributes request to a byte slice. +func queryImageAttributesRequest(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 17 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// QueryPortAttributesCookie is a cookie used only for QueryPortAttributes requests. +type QueryPortAttributesCookie struct { + *xgb.Cookie +} + +// QueryPortAttributes sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryPortAttributesCookie.Reply() +func QueryPortAttributes(c *xgb.Conn, Port Port) QueryPortAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryPortAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryPortAttributesRequest(c, Port), cookie) + return QueryPortAttributesCookie{cookie} +} + +// QueryPortAttributesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryPortAttributesUnchecked(c *xgb.Conn, Port Port) QueryPortAttributesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'QueryPortAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryPortAttributesRequest(c, Port), cookie) + return QueryPortAttributesCookie{cookie} +} + +// QueryPortAttributesReply represents the data returned from a QueryPortAttributes request. +type QueryPortAttributesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumAttributes uint32 + TextSize uint32 + // padding: 16 bytes + Attributes []AttributeInfo // size: AttributeInfoListSize(Attributes) +} + +// Reply blocks and returns the reply data for a QueryPortAttributes request. +func (cook QueryPortAttributesCookie) Reply() (*QueryPortAttributesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryPortAttributesReply(buf), nil +} + +// queryPortAttributesReply reads a byte slice into a QueryPortAttributesReply value. +func queryPortAttributesReply(buf []byte) *QueryPortAttributesReply { + v := new(QueryPortAttributesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.NumAttributes = xgb.Get32(buf[b:]) + b += 4 + + v.TextSize = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.Attributes = make([]AttributeInfo, v.NumAttributes) + b += AttributeInfoReadList(buf[b:], v.Attributes) + + return v +} + +// Write request to wire for QueryPortAttributes +// queryPortAttributesRequest writes a QueryPortAttributes request to a byte slice. +func queryPortAttributesRequest(c *xgb.Conn, Port Port) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 15 // 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(Port)) + b += 4 + + return buf +} + +// SelectPortNotifyCookie is a cookie used only for SelectPortNotify requests. +type SelectPortNotifyCookie struct { + *xgb.Cookie +} + +// SelectPortNotify sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectPortNotify(c *xgb.Conn, Port Port, Onoff bool) SelectPortNotifyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SelectPortNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectPortNotifyRequest(c, Port, Onoff), cookie) + return SelectPortNotifyCookie{cookie} +} + +// SelectPortNotifyChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectPortNotifyCookie.Check() +func SelectPortNotifyChecked(c *xgb.Conn, Port Port, Onoff bool) SelectPortNotifyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SelectPortNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectPortNotifyRequest(c, Port, Onoff), cookie) + return SelectPortNotifyCookie{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 SelectPortNotifyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectPortNotify +// selectPortNotifyRequest writes a SelectPortNotify request to a byte slice. +func selectPortNotifyRequest(c *xgb.Conn, Port Port, Onoff bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 11 // 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(Port)) + b += 4 + + if Onoff { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// SelectVideoNotifyCookie is a cookie used only for SelectVideoNotify requests. +type SelectVideoNotifyCookie struct { + *xgb.Cookie +} + +// SelectVideoNotify sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectVideoNotify(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) SelectVideoNotifyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SelectVideoNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(selectVideoNotifyRequest(c, Drawable, Onoff), cookie) + return SelectVideoNotifyCookie{cookie} +} + +// SelectVideoNotifyChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectVideoNotifyCookie.Check() +func SelectVideoNotifyChecked(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) SelectVideoNotifyCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SelectVideoNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(selectVideoNotifyRequest(c, Drawable, Onoff), cookie) + return SelectVideoNotifyCookie{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 SelectVideoNotifyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SelectVideoNotify +// selectVideoNotifyRequest writes a SelectVideoNotify request to a byte slice. +func selectVideoNotifyRequest(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 10 // 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(Drawable)) + b += 4 + + if Onoff { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + b += 3 // padding + + return buf +} + +// SetPortAttributeCookie is a cookie used only for SetPortAttribute requests. +type SetPortAttributeCookie struct { + *xgb.Cookie +} + +// SetPortAttribute sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetPortAttribute(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) SetPortAttributeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setPortAttributeRequest(c, Port, Attribute, Value), cookie) + return SetPortAttributeCookie{cookie} +} + +// SetPortAttributeChecked sends a checked request. +// If an error occurs, it can be retrieved using SetPortAttributeCookie.Check() +func SetPortAttributeChecked(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) SetPortAttributeCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'SetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setPortAttributeRequest(c, Port, Attribute, Value), cookie) + return SetPortAttributeCookie{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 SetPortAttributeCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetPortAttribute +// setPortAttributeRequest writes a SetPortAttribute request to a byte slice. +func setPortAttributeRequest(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 13 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Attribute)) + b += 4 + + xgb.Put32(buf[b:], uint32(Value)) + b += 4 + + return buf +} + +// ShmPutImageCookie is a cookie used only for ShmPutImage requests. +type ShmPutImageCookie struct { + *xgb.Cookie +} + +// ShmPutImage sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ShmPutImage(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) ShmPutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'ShmPutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(shmPutImageRequest(c, Port, Drawable, Gc, Shmseg, Id, Offset, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, SendEvent), cookie) + return ShmPutImageCookie{cookie} +} + +// ShmPutImageChecked sends a checked request. +// If an error occurs, it can be retrieved using ShmPutImageCookie.Check() +func ShmPutImageChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) ShmPutImageCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'ShmPutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(shmPutImageRequest(c, Port, Drawable, Gc, Shmseg, Id, Offset, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, SendEvent), cookie) + return ShmPutImageCookie{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 ShmPutImageCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for ShmPutImage +// shmPutImageRequest writes a ShmPutImage request to a byte slice. +func shmPutImageRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) []byte { + size := 52 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 19 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + xgb.Put32(buf[b:], uint32(Gc)) + b += 4 + + xgb.Put32(buf[b:], uint32(Shmseg)) + b += 4 + + xgb.Put32(buf[b:], Id) + b += 4 + + xgb.Put32(buf[b:], Offset) + b += 4 + + xgb.Put16(buf[b:], uint16(SrcX)) + b += 2 + + xgb.Put16(buf[b:], uint16(SrcY)) + b += 2 + + xgb.Put16(buf[b:], SrcW) + b += 2 + + xgb.Put16(buf[b:], SrcH) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwX)) + b += 2 + + xgb.Put16(buf[b:], uint16(DrwY)) + b += 2 + + xgb.Put16(buf[b:], DrwW) + b += 2 + + xgb.Put16(buf[b:], DrwH) + b += 2 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + buf[b] = SendEvent + b += 1 + + b += 3 // padding + + return buf +} + +// StopVideoCookie is a cookie used only for StopVideo requests. +type StopVideoCookie struct { + *xgb.Cookie +} + +// StopVideo sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func StopVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable) StopVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'StopVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(stopVideoRequest(c, Port, Drawable), cookie) + return StopVideoCookie{cookie} +} + +// StopVideoChecked sends a checked request. +// If an error occurs, it can be retrieved using StopVideoCookie.Check() +func StopVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable) StopVideoCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'StopVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(stopVideoRequest(c, Port, Drawable), cookie) + return StopVideoCookie{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 StopVideoCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for StopVideo +// stopVideoRequest writes a StopVideo request to a byte slice. +func stopVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 9 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Drawable)) + b += 4 + + return buf +} + +// UngrabPortCookie is a cookie used only for UngrabPort requests. +type UngrabPortCookie struct { + *xgb.Cookie +} + +// UngrabPort sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabPort(c *xgb.Conn, Port Port, Time xproto.Timestamp) UngrabPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'UngrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabPortRequest(c, Port, Time), cookie) + return UngrabPortCookie{cookie} +} + +// UngrabPortChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabPortCookie.Check() +func UngrabPortChecked(c *xgb.Conn, Port Port, Time xproto.Timestamp) UngrabPortCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo"]; !ok { + panic("Cannot issue request 'UngrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabPortRequest(c, Port, Time), cookie) + return UngrabPortCookie{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 UngrabPortCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabPort +// ungrabPortRequest writes a UngrabPort request to a byte slice. +func ungrabPortRequest(c *xgb.Conn, Port Port, Time xproto.Timestamp) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(Port)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + return buf +} diff --git a/nexgb/xvmc/xvmc.go b/nexgb/xvmc/xvmc.go new file mode 100644 index 0000000..b943fa0 --- /dev/null +++ b/nexgb/xvmc/xvmc.go @@ -0,0 +1,1041 @@ +// Package xvmc is the X client API for the XVideo-MotionCompensation extension. +package xvmc + +// This file is automatically generated from xvmc.xml. Edit at your peril! + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" + "github.com/BurntSushi/xgb/xv" +) + +// Init must be called before using the XVideo-MotionCompensation extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 25, "XVideo-MotionCompensation").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named XVideo-MotionCompensation could be found on on the server.") + } + + c.ExtLock.Lock() + c.Extensions["XVideo-MotionCompensation"] = reply.MajorOpcode + c.ExtLock.Unlock() + for evNum, fun := range xgb.NewExtEventFuncs["XVideo-MotionCompensation"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["XVideo-MotionCompensation"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + return nil +} + +func init() { + xgb.NewExtEventFuncs["XVideo-MotionCompensation"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["XVideo-MotionCompensation"] = make(map[int]xgb.NewErrorFun) +} + +type Context uint32 + +func NewContextId(c *xgb.Conn) (Context, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Context(id), nil +} + +type Subpicture uint32 + +func NewSubpictureId(c *xgb.Conn) (Subpicture, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Subpicture(id), nil +} + +type Surface uint32 + +func NewSurfaceId(c *xgb.Conn) (Surface, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Surface(id), nil +} + +type SurfaceInfo struct { + Id Surface + ChromaFormat uint16 + Pad0 uint16 + MaxWidth uint16 + MaxHeight uint16 + SubpictureMaxWidth uint16 + SubpictureMaxHeight uint16 + McType uint32 + Flags uint32 +} + +// SurfaceInfoRead reads a byte slice into a SurfaceInfo value. +func SurfaceInfoRead(buf []byte, v *SurfaceInfo) int { + b := 0 + + v.Id = Surface(xgb.Get32(buf[b:])) + b += 4 + + v.ChromaFormat = xgb.Get16(buf[b:]) + b += 2 + + v.Pad0 = xgb.Get16(buf[b:]) + b += 2 + + v.MaxWidth = xgb.Get16(buf[b:]) + b += 2 + + v.MaxHeight = xgb.Get16(buf[b:]) + b += 2 + + v.SubpictureMaxWidth = xgb.Get16(buf[b:]) + b += 2 + + v.SubpictureMaxHeight = xgb.Get16(buf[b:]) + b += 2 + + v.McType = xgb.Get32(buf[b:]) + b += 4 + + v.Flags = xgb.Get32(buf[b:]) + b += 4 + + return b +} + +// SurfaceInfoReadList reads a byte slice into a list of SurfaceInfo values. +func SurfaceInfoReadList(buf []byte, dest []SurfaceInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = SurfaceInfo{} + b += SurfaceInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a SurfaceInfo value to a byte slice. +func (v SurfaceInfo) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Id)) + b += 4 + + xgb.Put16(buf[b:], v.ChromaFormat) + b += 2 + + xgb.Put16(buf[b:], v.Pad0) + b += 2 + + xgb.Put16(buf[b:], v.MaxWidth) + b += 2 + + xgb.Put16(buf[b:], v.MaxHeight) + b += 2 + + xgb.Put16(buf[b:], v.SubpictureMaxWidth) + b += 2 + + xgb.Put16(buf[b:], v.SubpictureMaxHeight) + b += 2 + + xgb.Put32(buf[b:], v.McType) + b += 4 + + xgb.Put32(buf[b:], v.Flags) + b += 4 + + return buf[:b] +} + +// SurfaceInfoListBytes writes a list of SurfaceInfo values to a byte slice. +func SurfaceInfoListBytes(buf []byte, list []SurfaceInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Card8' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + +// CreateContextCookie is a cookie used only for CreateContext requests. +type CreateContextCookie struct { + *xgb.Cookie +} + +// CreateContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateContextCookie.Reply() +func CreateContext(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createContextRequest(c, ContextId, PortId, SurfaceId, Width, Height, Flags), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateContextUnchecked(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createContextRequest(c, ContextId, PortId, SurfaceId, Width, Height, Flags), cookie) + return CreateContextCookie{cookie} +} + +// CreateContextReply represents the data returned from a CreateContext request. +type CreateContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + WidthActual uint16 + HeightActual uint16 + FlagsReturn uint32 + // padding: 20 bytes + PrivData []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a CreateContext request. +func (cook CreateContextCookie) Reply() (*CreateContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createContextReply(buf), nil +} + +// createContextReply reads a byte slice into a CreateContextReply value. +func createContextReply(buf []byte) *CreateContextReply { + v := new(CreateContextReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.WidthActual = xgb.Get16(buf[b:]) + b += 2 + + v.HeightActual = xgb.Get16(buf[b:]) + b += 2 + + v.FlagsReturn = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.PrivData = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.PrivData[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. +func createContextRequest(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) []byte { + size := 24 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(ContextId)) + b += 4 + + xgb.Put32(buf[b:], uint32(PortId)) + b += 4 + + xgb.Put32(buf[b:], uint32(SurfaceId)) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + xgb.Put32(buf[b:], Flags) + b += 4 + + return buf +} + +// CreateSubpictureCookie is a cookie used only for CreateSubpicture requests. +type CreateSubpictureCookie struct { + *xgb.Cookie +} + +// CreateSubpicture sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateSubpictureCookie.Reply() +func CreateSubpicture(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) CreateSubpictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateSubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createSubpictureRequest(c, SubpictureId, Context, XvimageId, Width, Height), cookie) + return CreateSubpictureCookie{cookie} +} + +// CreateSubpictureUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateSubpictureUnchecked(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) CreateSubpictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateSubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createSubpictureRequest(c, SubpictureId, Context, XvimageId, Width, Height), cookie) + return CreateSubpictureCookie{cookie} +} + +// CreateSubpictureReply represents the data returned from a CreateSubpicture request. +type CreateSubpictureReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + WidthActual uint16 + HeightActual uint16 + NumPaletteEntries uint16 + EntryBytes uint16 + ComponentOrder []byte // size: 4 + // padding: 12 bytes + PrivData []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a CreateSubpicture request. +func (cook CreateSubpictureCookie) Reply() (*CreateSubpictureReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createSubpictureReply(buf), nil +} + +// createSubpictureReply reads a byte slice into a CreateSubpictureReply value. +func createSubpictureReply(buf []byte) *CreateSubpictureReply { + v := new(CreateSubpictureReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.WidthActual = xgb.Get16(buf[b:]) + b += 2 + + v.HeightActual = xgb.Get16(buf[b:]) + b += 2 + + v.NumPaletteEntries = xgb.Get16(buf[b:]) + b += 2 + + v.EntryBytes = xgb.Get16(buf[b:]) + b += 2 + + v.ComponentOrder = make([]byte, 4) + copy(v.ComponentOrder[:4], buf[b:]) + b += int(4) + + b += 12 // padding + + v.PrivData = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.PrivData[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for CreateSubpicture +// createSubpictureRequest writes a CreateSubpicture request to a byte slice. +func createSubpictureRequest(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) []byte { + size := 20 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 6 // 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(SubpictureId)) + b += 4 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + xgb.Put32(buf[b:], XvimageId) + b += 4 + + xgb.Put16(buf[b:], Width) + b += 2 + + xgb.Put16(buf[b:], Height) + b += 2 + + return buf +} + +// CreateSurfaceCookie is a cookie used only for CreateSurface requests. +type CreateSurfaceCookie struct { + *xgb.Cookie +} + +// CreateSurface sends a checked request. +// If an error occurs, it will be returned with the reply by calling CreateSurfaceCookie.Reply() +func CreateSurface(c *xgb.Conn, SurfaceId Surface, ContextId Context) CreateSurfaceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateSurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(createSurfaceRequest(c, SurfaceId, ContextId), cookie) + return CreateSurfaceCookie{cookie} +} + +// CreateSurfaceUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CreateSurfaceUnchecked(c *xgb.Conn, SurfaceId Surface, ContextId Context) CreateSurfaceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'CreateSurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(createSurfaceRequest(c, SurfaceId, ContextId), cookie) + return CreateSurfaceCookie{cookie} +} + +// CreateSurfaceReply represents the data returned from a CreateSurface request. +type CreateSurfaceReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + // padding: 24 bytes + PrivData []uint32 // size: xgb.Pad((int(Length) * 4)) +} + +// Reply blocks and returns the reply data for a CreateSurface request. +func (cook CreateSurfaceCookie) Reply() (*CreateSurfaceReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return createSurfaceReply(buf), nil +} + +// createSurfaceReply reads a byte slice into a CreateSurfaceReply value. +func createSurfaceReply(buf []byte) *CreateSurfaceReply { + v := new(CreateSurfaceReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + b += 24 // padding + + v.PrivData = make([]uint32, v.Length) + for i := 0; i < int(v.Length); i++ { + v.PrivData[i] = xgb.Get32(buf[b:]) + b += 4 + } + + return v +} + +// Write request to wire for CreateSurface +// createSurfaceRequest writes a CreateSurface request to a byte slice. +func createSurfaceRequest(c *xgb.Conn, SurfaceId Surface, ContextId Context) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 4 // 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(SurfaceId)) + b += 4 + + xgb.Put32(buf[b:], uint32(ContextId)) + b += 4 + + return buf +} + +// DestroyContextCookie is a cookie used only for DestroyContext requests. +type DestroyContextCookie struct { + *xgb.Cookie +} + +// DestroyContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroyContext(c *xgb.Conn, ContextId Context) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroyContextRequest(c, ContextId), cookie) + return DestroyContextCookie{cookie} +} + +// DestroyContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroyContextCookie.Check() +func DestroyContextChecked(c *xgb.Conn, ContextId Context) DestroyContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroyContextRequest(c, ContextId), cookie) + return DestroyContextCookie{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 DestroyContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroyContext +// destroyContextRequest writes a DestroyContext request to a byte slice. +func destroyContextRequest(c *xgb.Conn, ContextId Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + 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 + + xgb.Put32(buf[b:], uint32(ContextId)) + b += 4 + + return buf +} + +// DestroySubpictureCookie is a cookie used only for DestroySubpicture requests. +type DestroySubpictureCookie struct { + *xgb.Cookie +} + +// DestroySubpicture sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroySubpicture(c *xgb.Conn, SubpictureId Subpicture) DestroySubpictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroySubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroySubpictureRequest(c, SubpictureId), cookie) + return DestroySubpictureCookie{cookie} +} + +// DestroySubpictureChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroySubpictureCookie.Check() +func DestroySubpictureChecked(c *xgb.Conn, SubpictureId Subpicture) DestroySubpictureCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroySubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroySubpictureRequest(c, SubpictureId), cookie) + return DestroySubpictureCookie{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 DestroySubpictureCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroySubpicture +// destroySubpictureRequest writes a DestroySubpicture request to a byte slice. +func destroySubpictureRequest(c *xgb.Conn, SubpictureId Subpicture) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 7 // 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(SubpictureId)) + b += 4 + + return buf +} + +// DestroySurfaceCookie is a cookie used only for DestroySurface requests. +type DestroySurfaceCookie struct { + *xgb.Cookie +} + +// DestroySurface sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DestroySurface(c *xgb.Conn, SurfaceId Surface) DestroySurfaceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroySurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(destroySurfaceRequest(c, SurfaceId), cookie) + return DestroySurfaceCookie{cookie} +} + +// DestroySurfaceChecked sends a checked request. +// If an error occurs, it can be retrieved using DestroySurfaceCookie.Check() +func DestroySurfaceChecked(c *xgb.Conn, SurfaceId Surface) DestroySurfaceCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'DestroySurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(destroySurfaceRequest(c, SurfaceId), cookie) + return DestroySurfaceCookie{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 DestroySurfaceCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DestroySurface +// destroySurfaceRequest writes a DestroySurface request to a byte slice. +func destroySurfaceRequest(c *xgb.Conn, SurfaceId Surface) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 5 // 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(SurfaceId)) + b += 4 + + return buf +} + +// ListSubpictureTypesCookie is a cookie used only for ListSubpictureTypes requests. +type ListSubpictureTypesCookie struct { + *xgb.Cookie +} + +// ListSubpictureTypes sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListSubpictureTypesCookie.Reply() +func ListSubpictureTypes(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) ListSubpictureTypesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'ListSubpictureTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listSubpictureTypesRequest(c, PortId, SurfaceId), cookie) + return ListSubpictureTypesCookie{cookie} +} + +// ListSubpictureTypesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListSubpictureTypesUnchecked(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) ListSubpictureTypesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'ListSubpictureTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listSubpictureTypesRequest(c, PortId, SurfaceId), cookie) + return ListSubpictureTypesCookie{cookie} +} + +// ListSubpictureTypesReply represents the data returned from a ListSubpictureTypes request. +type ListSubpictureTypesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Num uint32 + // padding: 20 bytes + Types []xv.ImageFormatInfo // size: xv.ImageFormatInfoListSize(Types) +} + +// Reply blocks and returns the reply data for a ListSubpictureTypes request. +func (cook ListSubpictureTypesCookie) Reply() (*ListSubpictureTypesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listSubpictureTypesReply(buf), nil +} + +// listSubpictureTypesReply reads a byte slice into a ListSubpictureTypesReply value. +func listSubpictureTypesReply(buf []byte) *ListSubpictureTypesReply { + v := new(ListSubpictureTypesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Num = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Types = make([]xv.ImageFormatInfo, v.Num) + b += xv.ImageFormatInfoReadList(buf[b:], v.Types) + + return v +} + +// Write request to wire for ListSubpictureTypes +// listSubpictureTypesRequest writes a ListSubpictureTypes request to a byte slice. +func listSubpictureTypesRequest(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 8 // 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(PortId)) + b += 4 + + xgb.Put32(buf[b:], uint32(SurfaceId)) + b += 4 + + return buf +} + +// ListSurfaceTypesCookie is a cookie used only for ListSurfaceTypes requests. +type ListSurfaceTypesCookie struct { + *xgb.Cookie +} + +// ListSurfaceTypes sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListSurfaceTypesCookie.Reply() +func ListSurfaceTypes(c *xgb.Conn, PortId xv.Port) ListSurfaceTypesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'ListSurfaceTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(listSurfaceTypesRequest(c, PortId), cookie) + return ListSurfaceTypesCookie{cookie} +} + +// ListSurfaceTypesUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ListSurfaceTypesUnchecked(c *xgb.Conn, PortId xv.Port) ListSurfaceTypesCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'ListSurfaceTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(listSurfaceTypesRequest(c, PortId), cookie) + return ListSurfaceTypesCookie{cookie} +} + +// ListSurfaceTypesReply represents the data returned from a ListSurfaceTypes request. +type ListSurfaceTypesReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Num uint32 + // padding: 20 bytes + Surfaces []SurfaceInfo // size: xgb.Pad((int(Num) * 24)) +} + +// Reply blocks and returns the reply data for a ListSurfaceTypes request. +func (cook ListSurfaceTypesCookie) Reply() (*ListSurfaceTypesReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return listSurfaceTypesReply(buf), nil +} + +// listSurfaceTypesReply reads a byte slice into a ListSurfaceTypesReply value. +func listSurfaceTypesReply(buf []byte) *ListSurfaceTypesReply { + v := new(ListSurfaceTypesReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Num = xgb.Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Surfaces = make([]SurfaceInfo, v.Num) + b += SurfaceInfoReadList(buf[b:], v.Surfaces) + + return v +} + +// Write request to wire for ListSurfaceTypes +// listSurfaceTypesRequest writes a ListSurfaceTypes request to a byte slice. +func listSurfaceTypesRequest(c *xgb.Conn, PortId xv.Port) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + 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(PortId)) + b += 4 + + return buf +} + +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { + *xgb.Cookie +} + +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c), cookie) + return QueryVersionCookie{cookie} +} + +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Major uint32 + Minor uint32 +} + +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Major = xgb.Get32(buf[b:]) + b += 4 + + v.Minor = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["XVideo-MotionCompensation"] + c.ExtLock.RUnlock() + 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 + + return buf +} |