2012-05-11 02:06:22 +02:00
|
|
|
// Package shm is the X client API for the MIT-SHM extension.
|
2012-05-10 23:01:42 +02:00
|
|
|
package shm
|
|
|
|
|
2013-08-12 02:45:36 +02:00
|
|
|
// This file is automatically generated from shm.xml. Edit at your peril!
|
2012-05-10 23:01:42 +02:00
|
|
|
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
|
|
|
xgb.ExtLock.Lock()
|
|
|
|
c.Extensions["MIT-SHM"] = reply.MajorOpcode
|
|
|
|
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
|
|
|
|
}
|
|
|
|
xgb.ExtLock.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
xgb.NewExtEventFuncs["MIT-SHM"] = make(map[int]xgb.NewEventFun)
|
|
|
|
xgb.NewExtErrorFuncs["MIT-SHM"] = make(map[int]xgb.NewErrorFun)
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// BadBadSeg is the error number for a BadBadSeg.
|
|
|
|
const BadBadSeg = 0
|
2012-05-27 00:24:52 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
type BadSegError xproto.ValueError
|
2012-05-27 00:24:52 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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
|
|
|
|
}
|
2012-05-27 00:24:52 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// SequenceId returns the sequence id attached to the BadBadSeg error.
|
|
|
|
// This is mostly used internally.
|
|
|
|
func (err BadSegError) SequenceId() uint16 {
|
|
|
|
return err.Sequence
|
|
|
|
}
|
2012-05-27 00:24:52 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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
|
|
|
|
}
|
2012-05-27 00:24:52 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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, ", ") + "}"
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
func init() {
|
|
|
|
xgb.NewExtErrorFuncs["MIT-SHM"][0] = BadSegErrorNew
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Completion is the event number for a CompletionEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// CompletionEventNew constructs a CompletionEvent value that implements xgb.Event from a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Bytes writes a CompletionEvent value to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SequenceId returns the sequence id attached to the Completion event.
|
|
|
|
// Events without a sequence number (KeymapNotify) return 0.
|
|
|
|
// This is mostly used internally.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (v CompletionEvent) SequenceId() uint16 {
|
|
|
|
return v.Sequence
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// String is a rudimentary string representation of CompletionEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
type Seg uint32
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
func NewSegId(c *xgb.Conn) (Seg, error) {
|
|
|
|
id, err := c.NewId()
|
2012-05-10 23:01:42 +02:00
|
|
|
if err != nil {
|
2013-08-12 02:43:26 +02:00
|
|
|
return 0, err
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
2013-08-12 02:43:26 +02:00
|
|
|
return Seg(id), nil
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Bool'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Byte'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Card8'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Char'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Void'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Double'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Float'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Int16'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Int32'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Int8'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Card16'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Card32'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// AttachCookie is a cookie used only for Attach requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type AttachCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Attach sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func Attach(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
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.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie)
|
|
|
|
return AttachCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// AttachChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using AttachCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func AttachChecked(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
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.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie)
|
|
|
|
return AttachCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook AttachCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for Attach
|
2012-05-11 05:57:34 +02:00
|
|
|
// attachRequest writes a Attach request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func attachRequest(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) []byte {
|
|
|
|
size := 16
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// CreatePixmapCookie is a cookie used only for CreatePixmap requests.
|
|
|
|
type CreatePixmapCookie struct {
|
2012-05-10 23:01:42 +02:00
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// CreatePixmap sends an unchecked request.
|
2012-05-11 05:57:34 +02:00
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2013-08-12 02:43:26 +02:00
|
|
|
func CreatePixmap(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) CreatePixmapCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie)
|
|
|
|
return CreatePixmapCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie)
|
|
|
|
return CreatePixmapCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2013-08-12 02:43:26 +02:00
|
|
|
func (cook CreatePixmapCookie) Check() error {
|
2012-05-10 23:01:42 +02:00
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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
|
2012-05-10 23:01:42 +02:00
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
b += 1
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
buf[b] = 5 // request opcode
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put32(buf[b:], uint32(Pid))
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 4
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put32(buf[b:], uint32(Drawable))
|
|
|
|
b += 4
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put16(buf[b:], Width)
|
|
|
|
b += 2
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(detachRequest(c, Shmseg), cookie)
|
|
|
|
return DetachCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// DetachChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using DetachCookie.Check()
|
|
|
|
func DetachChecked(c *xgb.Conn, Shmseg Seg) DetachCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(detachRequest(c, Shmseg), cookie)
|
|
|
|
return DetachCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2013-08-12 02:43:26 +02:00
|
|
|
func (cook DetachCookie) Check() error {
|
2012-05-10 23:01:42 +02:00
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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
|
2012-05-10 23:01:42 +02:00
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
b += 1
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
buf[b] = 2 // request opcode
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetImageCookie is a cookie used only for GetImage requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetImageCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetImage sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetImageCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
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.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie)
|
|
|
|
return GetImageCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetImageUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
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.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie)
|
|
|
|
return GetImageCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetImageReply represents the data returned from a GetImage request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetImageReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
Depth byte
|
|
|
|
Visual xproto.Visualid
|
|
|
|
Size uint32
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetImage request.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getImageReply reads a byte slice into a GetImageReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
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
|
2012-05-11 05:57:34 +02:00
|
|
|
// getImageRequest writes a GetImage request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// PutImageCookie is a cookie used only for PutImage requests.
|
|
|
|
type PutImageCookie struct {
|
2012-05-10 23:01:42 +02:00
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// PutImage sends an unchecked request.
|
2012-05-11 05:57:34 +02:00
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2013-08-12 02:43:26 +02:00
|
|
|
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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie)
|
|
|
|
return PutImageCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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 {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["MIT-SHM"]; !ok {
|
2013-08-12 02:43:26 +02:00
|
|
|
panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
|
2012-05-12 05:58:52 +02:00
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
2013-08-12 02:43:26 +02:00
|
|
|
c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie)
|
|
|
|
return PutImageCookie{cookie}
|
2012-05-10 23:01:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2013-08-12 02:43:26 +02:00
|
|
|
func (cook PutImageCookie) Check() error {
|
2012-05-10 23:01:42 +02:00
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// 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
|
2012-05-10 23:01:42 +02:00
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
b += 1
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
buf[b] = 3 // request opcode
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put32(buf[b:], uint32(Drawable))
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 4
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put32(buf[b:], uint32(Gc))
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 4
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
xgb.Put16(buf[b:], TotalWidth)
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 2
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
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))
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 2
|
|
|
|
|
|
|
|
buf[b] = Depth
|
|
|
|
b += 1
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
buf[b] = Format
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = SendEvent
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
b += 1 // padding
|
2012-05-10 23:01:42 +02:00
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Shmseg))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], Offset)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
2013-08-12 02:43:26 +02:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
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 {
|
|
|
|
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)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["MIT-SHM"]
|
|
|
|
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
|
|
|
|
}
|