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) )
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)
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)
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)
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)
func Errorf(format string, v ...interface{}) error
Errorf is just a wrapper for fmt.Errorf. Exists for the same reason that 'stringsJoin' and 'sprintf' exists.
func Get16(buf []byte) uint16
Get16 constructs a 16 bit integer from the beginning of a byte slice.
func Get32(buf []byte) uint32
Get32 constructs a 32 bit integer from the beginning of a byte slice.
func Get64(buf []byte) uint64
Get64 constructs a 64 bit integer from the beginning of a byte slice.
func Pad(n int) int
Pad a length to align on 4 bytes.
func PopCount(mask0 int) int
PopCount counts the number of bits set in a value list mask.
func Put16(buf []byte, v uint16)
Put16 takes a 16 bit integer and copies it into a byte slice.
func Put32(buf []byte, v uint32)
Put32 takes a 32 bit integer and copies it into a byte slice.
func Put64(buf []byte, v uint64)
Put64 takes a 64 bit integer and copies it into a byte slice.
func Sprintf(format string, v ...interface{}) string
Sprintf is so we don't need to import 'fmt' in the generated Go files.
func StringsJoin(ss []string, sep string) string
StringsJoin is an alias to strings.Join. It allows us to avoid having to import 'strings' in each of the generated Go files.
A Conn represents a connection to an X server.
type Conn struct { DisplayNumber int DefaultScreen int SetupBytes []byte // 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 // contains filtered or unexported fields }
func NewConn() (*Conn, error)
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.) It is up to user to close connection with Close() method to finish all unfinished requests and clean up spawned goroutines. If the connection unexpectedly closes itself and WaitForEvent() returns "nil, nil", everything is cleaned by that moment, but nothing bad happens if you call Close() after.
func NewConnDisplay(display string) (*Conn, error)
NewConnDisplay is just like NewConn (see closing instructions), 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 NewConnNet(netConn net.Conn) (*Conn, error)
NewConnNet is just like NewConn (see closing instructions), but allows a specific net.Conn to be used.
func (c *Conn) Close()
Close gracefully closes the connection to the X server. When everything is cleaned up, the WaitForEvent method will return (nil, nil)
func (c *Conn) NewCookie(checked, reply bool) *Cookie
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) NewId() (uint32, error)
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. Returns (0, io.EOF) when the connection is closed.
func (c *Conn) NewRequest(buf []byte, cookie *Cookie)
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) PollForEvent() (Event, Error)
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) Sync()
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) WaitForEvent() (Event, Error)
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.
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 { Sequence uint16 // contains filtered or unexported fields }
func (c Cookie) Check() error
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. Returns io.EOF error when the connection is closed.
Unless you're building requests from bytes by hand, this method should not be used.
func (c Cookie) Reply() ([]byte, error)
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.
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 }
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 }
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
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
Name | Synopsis |
---|---|
.. | |
bigreq | Package bigreq is the X client API for the BIG-REQUESTS extension. |
composite | Package composite is the X client API for the Composite extension. |
damage | Package damage is the X client API for the DAMAGE extension. |
dpms | Package dpms is the X client API for the DPMS extension. |
dri2 | Package dri2 is the X client API for the DRI2 extension. |
examples | 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. |
atoms | |
create-window | 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). |
get-active-window | 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. |
randr | Example randr uses the randr protocol to get information about the active heads. |
shapes | The shapes example shows how to draw basic shapes into a window. |
xinerama | Example xinerama shows how to query the geometry of all active heads. |
ge | Package ge is the X client API for the Generic Event Extension extension. |
glx | Package glx is the X client API for the GLX extension. |
randr | Package randr is the X client API for the RANDR extension. |
record | Package record is the X client API for the RECORD extension. |
render | Package render is the X client API for the RENDER extension. |
res | Package res is the X client API for the X-Resource extension. |
screensaver | Package screensaver is the X client API for the MIT-SCREEN-SAVER extension. |
shape | Package shape is the X client API for the SHAPE extension. |
shm | Package shm is the X client API for the MIT-SHM extension. |
xcmisc | Package xcmisc is the X client API for the XC-MISC extension. |
xevie | Package xevie is the X client API for the XEVIE extension. |
xf86dri | Package xf86dri is the X client API for the XFree86-DRI extension. |
xf86vidmode | Package xf86vidmode is the X client API for the XFree86-VidModeExtension extension. |
xfixes | Package xfixes is the X client API for the XFIXES extension. |
xgbgen | xgbgen constructs Go source files from xproto XML description files. |
xinerama | Package xinerama is the X client API for the XINERAMA extension. |
xprint | Package xprint is the X client API for the XpExtension extension. |
xproto | Package xproto is the X client API for the extension. |
xselinux | Package xselinux is the X client API for the SELinux extension. |
xtest | Package xtest is the X client API for the XTEST extension. |
xv | Package xv is the X client API for the XVideo extension. |
xvmc | Package xvmc is the X client API for the XVideo-MotionCompensation extension. |