File: sync.go

package info (click to toggle)
golang-github-burntsushi-xgb 0.0~git20210121.deaf085-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,100 kB
  • sloc: makefile: 61
file content (29 lines) | stat: -rw-r--r-- 863 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
}