summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <git@peter.is-a-geek.org>2011-02-06 12:57:49 -0500
committerPeter Harris <git@peter.is-a-geek.org>2011-02-06 12:57:49 -0500
commit4ea5d43d29daf95edd57854598173ca71097cbe5 (patch)
tree3d40bd7f3a8d0d155984f9891d3ed290f2cbd279
parentb930ee5192550419ed423694797fc9b9396e033a (diff)
Cleanup: Automatic reformat
find . -name "*.go" | xargs gofmt -w
-rw-r--r--noop.go14
-rw-r--r--test.go26
-rw-r--r--xgob.go250
-rw-r--r--xgob/util/atom.go16
-rw-r--r--xgob/xproto.go54
-rw-r--r--xlsclients.go42
-rw-r--r--xmu.go6
7 files changed, 206 insertions, 202 deletions
diff --git a/noop.go b/noop.go
index ebe0e1c..1068f31 100644
--- a/noop.go
+++ b/noop.go
@@ -1,15 +1,15 @@
package main
import (
- "flag"
- "fmt"
- "xgob"
- )
+ "flag"
+ "fmt"
+ "xgob"
+)
var iter *uint = flag.Uint("iter", 1000000, "Number of noops to send to the server")
-var wait *bool = flag.Bool("wait", false, "Wait for server to process noops")
+var wait *bool = flag.Bool("wait", false, "Wait for server to process noops")
-func main () {
+func main() {
flag.Parse()
c, _ := xgob.Connect("")
@@ -34,7 +34,7 @@ func main () {
cookie := c.WriteReplyRequest(gifRequest)
c.Flush()
- <- cookie
+ <-cookie
fmt.Println("Done.")
}
diff --git a/test.go b/test.go
index e42733d..6182640 100644
--- a/test.go
+++ b/test.go
@@ -1,11 +1,11 @@
package main
import (
- "fmt"
- "xgob"
- )
+ "fmt"
+ "xgob"
+)
-func toUint32 (buf []byte) uint32 {
+func toUint32(buf []byte) uint32 {
rv := uint32(buf[0]) << 24
rv |= uint32(buf[1]) << 16
rv |= uint32(buf[2]) << 8
@@ -13,8 +13,8 @@ func toUint32 (buf []byte) uint32 {
return rv
}
-func decodeGif (in chan interface{}, out chan uint32, err chan xgob.Error) {
- r := <- in
+func decodeGif(in chan interface{}, out chan uint32, err chan xgob.Error) {
+ r := <-in
switch reply := r.(type) {
case xgob.Reply:
focus := toUint32(reply.Remainder[:4])
@@ -25,21 +25,21 @@ func decodeGif (in chan interface{}, out chan uint32, err chan xgob.Error) {
}
}
-func main () {
+func main() {
c, _ := xgob.Connect("")
error := make(chan xgob.Error)
var gifRequest [8]byte
- gifRequest[0] = 43 /* X_GetInputFocus */
- gifRequest[3] = 1 /* request length */
+ gifRequest[0] = 43 /* X_GetInputFocus */
+ gifRequest[3] = 1 /* request length */
done := make(chan uint32)
cookie1 := c.WriteReplyRequest(gifRequest[:4])
go decodeGif(cookie1, done, error)
- gifRequest[3] = 2 // bad length
+ gifRequest[3] = 2 // bad length
cookie2 := c.WriteReplyRequest(gifRequest[:])
go decodeGif(cookie2, done, error)
@@ -53,13 +53,13 @@ func main () {
var i int
for i < 2 {
select {
- case win := <- done:
+ case win := <-done:
if win < 0x80000000 {
fmt.Printf("Window with focus: 0x%X", win)
fmt.Println()
}
i++
- case e := <- error:
+ case e := <-error:
fmt.Printf("Error of type %d", e.Error)
fmt.Println()
fmt.Printf(" request %d.%d", e.Major, e.Minor)
@@ -68,7 +68,7 @@ func main () {
fmt.Println()
fmt.Printf(" value 0x%X (%d)", e.BadValue, e.BadValue)
fmt.Println()
- case event := <- c.Event:
+ case event := <-c.Event:
println("Unexpected event", event.EventType)
}
}
diff --git a/xgob.go b/xgob.go
index b5f01ab..eda3a1c 100644
--- a/xgob.go
+++ b/xgob.go
@@ -1,15 +1,15 @@
package xgob
import (
- "bufio"
- "bytes"
- "io"
- "net"
- "os"
- "strconv"
- "strings"
- "sync"
- )
+ "bufio"
+ "bytes"
+ "io"
+ "net"
+ "os"
+ "strconv"
+ "strings"
+ "sync"
+)
const X_TCP_PORT = 6000
@@ -23,104 +23,104 @@ type Format struct {
}
type VisualType struct {
- VisualID uint32
- Class uint8
+ VisualID uint32
+ Class uint8
BitsPerRGBValue uint8
ColormapEntries uint16
- RedMask uint32
- GreenMask uint32
- BlueMask uint32
+ RedMask uint32
+ GreenMask uint32
+ BlueMask uint32
}
type Depth struct {
- Depth uint8
+ Depth uint8
Visuals []VisualType
}
type Screen struct {
- Root uint32
- DefaultColormap uint32
- WhitePixel uint32
- BlackPixel uint32
- CurrentInputMasks uint32
- WidthInPixels uint16
- HeightInPixels uint16
- WidthInMillimeters uint16
+ Root uint32
+ DefaultColormap uint32
+ WhitePixel uint32
+ BlackPixel uint32
+ CurrentInputMasks uint32
+ WidthInPixels uint16
+ HeightInPixels uint16
+ WidthInMillimeters uint16
HeightInMillimeters uint16
- MinInstalledMaps uint16
- MaxInstalledMaps uint16
- RootVisual uint32
- BackingStores uint8
- SaveUnders bool
- RootDepth uint8
- AllowedDepths []Depth
+ MinInstalledMaps uint16
+ MaxInstalledMaps uint16
+ RootVisual uint32
+ BackingStores uint8
+ SaveUnders bool
+ RootDepth uint8
+ AllowedDepths []Depth
}
type ConnectionBlock struct {
- Major, Minor uint16
- Release uint32
- ResourceIDBase uint32
- ResourceIDMask uint32
- MotionBufferSize uint32
- MaximumRequestLength uint16
- ImageByteOrder uint8
- BitmapBitOrder uint8
- BitmapScanlineUnit uint8
- BitmapScanlinePad uint8
+ Major, Minor uint16
+ Release uint32
+ ResourceIDBase uint32
+ ResourceIDMask uint32
+ MotionBufferSize uint32
+ MaximumRequestLength uint16
+ ImageByteOrder uint8
+ BitmapBitOrder uint8
+ BitmapScanlineUnit uint8
+ BitmapScanlinePad uint8
MinKeycode, MaxKeycode uint8
- Vendor string
- PixmapFormats []Format
- Roots []Screen
+ Vendor string
+ PixmapFormats []Format
+ Roots []Screen
}
type Event struct {
- EventType uint8
- Sent bool
- Remainder [31]byte
+ EventType uint8
+ Sent bool
+ Remainder [31]byte
}
type Error struct {
- Sequence uint64
- BadValue uint32
- Minor uint16
- Major uint8
- Error uint8
+ Sequence uint64
+ BadValue uint32
+ Minor uint16
+ Major uint8
+ Error uint8
}
type Reply struct {
- Sequence uint64
- Length uint32
- Remainder []byte
- Aux byte
+ Sequence uint64
+ Length uint32
+ Remainder []byte
+ Aux byte
}
type Connection struct {
- Setup ConnectionBlock
- Event chan Event
- Error chan Error
- conn io.ReadWriteCloser
- out *bufio.Writer
- reply map[uint64]chan interface {}
- callback map[uint64]func(interface {})
- replyMutex sync.Mutex
- writeMutex sync.Mutex
- lastRequestWritten uint64
- lastSequenceRead uint64
- lastReplierSent uint64
+ Setup ConnectionBlock
+ Event chan Event
+ Error chan Error
+ conn io.ReadWriteCloser
+ out *bufio.Writer
+ reply map[uint64]chan interface{}
+ callback map[uint64]func(interface{})
+ replyMutex sync.Mutex
+ writeMutex sync.Mutex
+ lastRequestWritten uint64
+ lastSequenceRead uint64
+ lastReplierSent uint64
}
const events_before_readblock = 10000
const errors_before_readblock = 10000
-func parse_display (name string) (host string, protocol string, display int, screen int) {
- if len(name) == 0 {
+func parse_display(name string) (host string, protocol string, display int, screen int) {
+ if len(name) == 0 {
name = os.Getenv("DISPLAY")
}
- if len(name) == 0 {
- return
+ if len(name) == 0 {
+ return
}
- if !strings.HasPrefix(name, "/tmp/launch") {
+ if !strings.HasPrefix(name, "/tmp/launch") {
slash := strings.LastIndex(name, "/")
if slash >= 0 {
protocol = name[:slash]
@@ -129,16 +129,16 @@ func parse_display (name string) (host string, protocol string, display int, scr
}
var err os.Error
-
- dot := strings.LastIndex(name, ".");
+
+ dot := strings.LastIndex(name, ".")
if dot >= 0 {
- screen,err = strconv.Atoi(name[dot+1:])
+ screen, err = strconv.Atoi(name[dot+1:])
if err == nil {
name = name[:dot]
}
}
- colon := strings.LastIndex(name, ":");
- if colon < 0 {
+ colon := strings.LastIndex(name, ":")
+ if colon < 0 {
return
}
display, err = strconv.Atoi(name[colon+1:])
@@ -150,7 +150,7 @@ func parse_display (name string) (host string, protocol string, display int, scr
}
func open(host string, protocol string, display int) io.ReadWriteCloser {
- unix_base := "/tmp/.X11-unix/X";
+ unix_base := "/tmp/.X11-unix/X"
base := unix_base
if strings.HasPrefix(host, "/tmp/launch") {
@@ -159,11 +159,11 @@ func open(host string, protocol string, display int) io.ReadWriteCloser {
protocol = ""
}
- if(len(host) > 0 || len(protocol) > 0) {
+ if len(host) > 0 || len(protocol) > 0 {
if len(protocol) > 0 || "unix" != host { /* follow the old unix: rule */
/* display specifies TCP */
- port := X_TCP_PORT + display;
- return open_tcp(host, protocol, port);
+ port := X_TCP_PORT + display
+ return open_tcp(host, protocol, port)
}
}
@@ -175,12 +175,12 @@ func open(host string, protocol string, display int) io.ReadWriteCloser {
file = base + strconv.Itoa(display)
}
- return open_unix(protocol, file)
+ return open_unix(protocol, file)
}
func open_tcp(host string, protocol string, port int) io.ReadWriteCloser {
if len(protocol) > 0 && "tcp" != protocol && "inet" != protocol && "inet6" != protocol {
- return nil;
+ return nil
}
proto := "tcp"
if protocol == "inet6" {
@@ -191,7 +191,7 @@ func open_tcp(host string, protocol string, port int) io.ReadWriteCloser {
host = "localhost"
}
- conn, err := net.Dial(proto, "", host + ":" + strconv.Itoa(port))
+ conn, err := net.Dial(proto, "", host+":"+strconv.Itoa(port))
// TODO - remove
if err != nil {
println("TCP error ", err.String())
@@ -212,20 +212,20 @@ func open_unix(protocol string, file string) io.ReadWriteCloser {
return conn
}
-func Pad (i int) int {
+func Pad(i int) int {
return (-i) & 3
}
-func (c *Connection) write_setup (name string, data string) {
+func (c *Connection) write_setup(name string, data string) {
buf := make([]byte, 0, 100)
- buf = append(buf, 'B') // Big endian.
+ buf = append(buf, 'B') // Big endian.
buf = append(buf, 'l')
- buf = append(buf, 0, 11) // X11
- buf = append(buf, 0, 0) // .0
- buf = append(buf, byte((len(name) & 0xFF00) >> 8), byte(len(name) & 0xFF))
- buf = append(buf, byte((len(data) & 0xFF00) >> 8), byte(len(data) & 0xFF))
- buf = append(buf, 0, 0) // pad
+ buf = append(buf, 0, 11) // X11
+ buf = append(buf, 0, 0) // .0
+ buf = append(buf, byte((len(name)&0xFF00)>>8), byte(len(name)&0xFF))
+ buf = append(buf, byte((len(data)&0xFF00)>>8), byte(len(data)&0xFF))
+ buf = append(buf, 0, 0) // pad
if len(name) > 0 && len(data) > 0 {
n := bytes.NewBufferString(name)
@@ -265,7 +265,7 @@ func readUint32(in *bufio.Reader) uint32 {
return rv
}
-func skipBytes (in *bufio.Reader, skip uint) {
+func skipBytes(in *bufio.Reader, skip uint) {
for i := uint(0); i < skip; i++ {
_, _ = in.ReadByte()
}
@@ -306,7 +306,7 @@ func (c *Connection) read_setup(in *bufio.Reader) bool {
c.Setup.Minor = readUint16(in)
length := readUint16(in)
- todo := make([]byte, length * 4)
+ todo := make([]byte, length*4)
readAll(in, todo)
switch status {
@@ -329,7 +329,7 @@ func (c *Connection) read_setup(in *bufio.Reader) bool {
c.Setup.BitmapScanlinePad = todo[5]
c.Setup.MinKeycode = todo[6]
c.Setup.MaxKeycode = todo[7]
- todo = todo[12:] // 8 above, plus 4 pad
+ todo = todo[12:] // 8 above, plus 4 pad
c.Setup.Vendor = string(todo[:vendorLen])
vendorLen += -vendorLen & 3
@@ -373,7 +373,7 @@ func (c *Connection) read_setup(in *bufio.Reader) bool {
todo = todo[2:]
var visualsLen uint16
visualsLen, todo = getUint16(todo)
- todo = todo[4:] // Pad
+ todo = todo[4:] // Pad
d.Visuals = make([]VisualType, visualsLen)
for k := uint16(0); k < visualsLen; k++ {
v := &d.Visuals[k]
@@ -385,7 +385,7 @@ func (c *Connection) read_setup(in *bufio.Reader) bool {
v.RedMask, todo = getUint32(todo)
v.GreenMask, todo = getUint32(todo)
v.BlueMask, todo = getUint32(todo)
- todo = todo[4:] // Pad
+ todo = todo[4:] // Pad
}
}
}
@@ -409,7 +409,7 @@ func (c *Connection) fullSeq(seq uint16) uint64 {
return fs
}
-func (c *Connection) registerReply (reply chan interface{}) {
+func (c *Connection) registerReply(reply chan interface{}) {
c.replyMutex.Lock()
c.lastRequestWritten++
@@ -419,7 +419,7 @@ func (c *Connection) registerReply (reply chan interface{}) {
c.replyMutex.Unlock()
}
-func (c *Connection) registerCallback (reply func(interface{})) {
+func (c *Connection) registerCallback(reply func(interface{})) {
c.replyMutex.Lock()
c.lastRequestWritten++
@@ -429,7 +429,7 @@ func (c *Connection) registerCallback (reply func(interface{})) {
c.replyMutex.Unlock()
}
-func (c *Connection) postReply (seq uint64, reply interface{}) {
+func (c *Connection) postReply(seq uint64, reply interface{}) {
c.replyMutex.Lock()
if seq != c.lastSequenceRead {
@@ -463,7 +463,7 @@ func (c *Connection) postReply (seq uint64, reply interface{}) {
c.replyMutex.Unlock()
}
-func (c *Connection) read (in *bufio.Reader) {
+func (c *Connection) read(in *bufio.Reader) {
for {
t, err := in.ReadByte()
if err != nil {
@@ -486,24 +486,24 @@ func (c *Connection) read (in *bufio.Reader) {
r.Aux, _ = in.ReadByte()
r.Sequence = c.fullSeq(readUint16(in))
r.Length = readUint32(in)
- r.Remainder = make([]byte, r.Length * 4 + 24)
+ r.Remainder = make([]byte, r.Length*4+24)
readAll(in, r.Remainder)
c.postReply(r.Sequence, r)
default:
var e Event
e.EventType = t
- if t & 0x80 != 0 {
+ if t&0x80 != 0 {
e.EventType = t & 0x7F
e.Sent = true
}
readAll(in, e.Remainder[:])
c.Event <- e
- // TODO GenericEvent
+ // TODO GenericEvent
}
}
}
-func (c *Connection)connect_auth(name string, data string) {
+func (c *Connection) connect_auth(name string, data string) {
c.write_setup(name, data)
in := bufio.NewReader(c.conn)
if !c.read_setup(in) {
@@ -511,36 +511,36 @@ func (c *Connection)connect_auth(name string, data string) {
return
}
c.out = bufio.NewWriter(c.conn)
- c.Event = make (chan Event, events_before_readblock)
- c.Error = make (chan Error, errors_before_readblock)
- c.reply = make (map [uint64]chan interface{})
- c.callback = make (map [uint64]func(interface{}))
+ c.Event = make(chan Event, events_before_readblock)
+ c.Error = make(chan Error, errors_before_readblock)
+ c.reply = make(map[uint64]chan interface{})
+ c.callback = make(map[uint64]func(interface{}))
go c.read(in)
}
-func Connect (dpy string) (conn *Connection, screen int) {
+func Connect(dpy string) (conn *Connection, screen int) {
host, proto, display, screen := parse_display(dpy)
var c Connection
- c.conn = open(host, proto, display);
+ c.conn = open(host, proto, display)
- if c.conn == nil {
+ if c.conn == nil {
return
}
// TODO: name, data := c.get_auth_info()
name, data := "", ""
- c.connect_auth(name, data);
+ c.connect_auth(name, data)
conn = &c
return
}
-func (c *Connection) Disconnect () {
+func (c *Connection) Disconnect() {
c.conn.Close()
c.conn = nil
}
-func (c *Connection) writeRequest (req []byte, replier bool, rv chan interface{}) {
+func (c *Connection) writeRequest(req []byte, replier bool, rv chan interface{}) {
c.writeMutex.Lock()
c.registerReply(rv)
@@ -549,16 +549,16 @@ func (c *Connection) writeRequest (req []byte, replier bool, rv chan interface{}
if replier {
c.lastReplierSent = c.lastRequestWritten
} else {
- if c.lastRequestWritten - c.lastReplierSent >= 65534 {
+ if c.lastRequestWritten-c.lastReplierSent >= 65534 {
c.registerReply(make(chan interface{}, 1))
- c.out.Write([]byte{43,0,0,1})
+ c.out.Write([]byte{43, 0, 0, 1})
c.lastReplierSent = c.lastRequestWritten
}
}
c.writeMutex.Unlock()
}
-func (c *Connection) WriteReplyRequestCallback (req []byte, closure func (interface{})) {
+func (c *Connection) WriteReplyRequestCallback(req []byte, closure func(interface{})) {
c.writeMutex.Lock()
c.registerCallback(closure)
@@ -569,25 +569,25 @@ func (c *Connection) WriteReplyRequestCallback (req []byte, closure func (interf
c.writeMutex.Unlock()
}
-func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface{} {
+func (c *Connection) WriteMultiRequest(req []byte, expected int) chan interface{} {
if c == nil || c.conn == nil {
return nil
}
replier := true
- if (expected < 1) {
+ if expected < 1 {
expected = 1
replier = false
}
- rv := make(chan interface {}, expected)
+ rv := make(chan interface{}, expected)
c.writeRequest(req, replier, rv)
return rv
}
-func (c *Connection) WriteNoreplyRequest (req []byte, rv chan interface{}) {
+func (c *Connection) WriteNoreplyRequest(req []byte, rv chan interface{}) {
if c == nil || c.conn == nil {
return
}
@@ -595,11 +595,11 @@ func (c *Connection) WriteNoreplyRequest (req []byte, rv chan interface{}) {
c.writeRequest(req, false, rv)
}
-func (c *Connection) WriteReplyRequest (req []byte) chan interface{} {
+func (c *Connection) WriteReplyRequest(req []byte) chan interface{} {
return c.WriteMultiRequest(req, 1)
}
-func (c *Connection) Flush () {
+func (c *Connection) Flush() {
if c == nil || c.conn == nil {
return
}
@@ -609,7 +609,7 @@ func (c *Connection) Flush () {
c.writeMutex.Unlock()
}
-func (c *Connection) HasError () bool {
+func (c *Connection) HasError() bool {
if c == nil || c.conn == nil {
return true
}
diff --git a/xgob/util/atom.go b/xgob/util/atom.go
index c9bb8b0..88d2ce0 100644
--- a/xgob/util/atom.go
+++ b/xgob/util/atom.go
@@ -19,7 +19,7 @@ type state struct {
var lock sync.RWMutex
var db = make(map[*xgob.Connection]state)
-func newState (c *xgob.Connection) state {
+func newState(c *xgob.Connection) state {
var rv state
rv.c = c
rv.name = make(map[xproto.Atom]string)
@@ -30,7 +30,7 @@ func newState (c *xgob.Connection) state {
}
/* internAtom must be called under a write lock */
-func (s *state) internAtom (name string) xproto.Atom {
+func (s *state) internAtom(name string) xproto.Atom {
c, ok := s.pendingAtom[name]
if ok {
s.pendingAtom[name] = nil, false
@@ -39,17 +39,17 @@ func (s *state) internAtom (name string) xproto.Atom {
}
var reply xproto.InternAtomReply
select {
- case reply = <- c:
+ case reply = <-c:
// done
default:
s.c.Flush()
- reply = <- c
+ reply = <-c
}
if reply.Error == nil {
s.name[reply.Atom] = name
s.atom[name] = reply.Atom
} else {
- println("Atom Error",reply.Error.Error)
+ println("Atom Error", reply.Error.Error)
}
return reply.Atom
}
@@ -77,7 +77,7 @@ func getState(c *xgob.Connection, writelocked bool) *state {
func PreloadAtom(c *xgob.Connection, name string) {
lock.Lock()
-
+
s := getState(c, true)
_, ok := s.atom[name]
@@ -90,7 +90,7 @@ func PreloadAtom(c *xgob.Connection, name string) {
lock.Unlock()
}
-func Atom (c *xgob.Connection, name string) xproto.Atom {
+func Atom(c *xgob.Connection, name string) xproto.Atom {
lock.RLock()
s := getState(c, false)
@@ -110,6 +110,6 @@ func Atom (c *xgob.Connection, name string) xproto.Atom {
return atom
}
-func AtomName (c *xgob.Connection, atom xproto.Atom) string {
+func AtomName(c *xgob.Connection, atom xproto.Atom) string {
return fmt.Sprintf("0x%X", atom) // TODO
}
diff --git a/xgob/xproto.go b/xgob/xproto.go
index 895ba3b..3791ae2 100644
--- a/xgob/xproto.go
+++ b/xgob/xproto.go
@@ -8,35 +8,35 @@ type Atom uint32
type Window uint32
type QueryTreeReply struct {
- Error *xgob.Error
+ Error *xgob.Error
Root, Parent Window
- Children []Window
+ Children []Window
}
type InternAtomReply struct {
Error *xgob.Error
- Atom Atom
+ Atom Atom
}
type GetPropertyReply struct {
- Error *xgob.Error
- Format uint8
- Type Atom
+ Error *xgob.Error
+ Format uint8
+ Type Atom
BytesAfter uint32
- Value []byte
+ Value []byte
}
func appendUint16(buf []byte, val uint16) []byte {
- buf = append(buf, uint8(val >> 8))
- buf = append(buf, uint8(val & 0xFF))
+ buf = append(buf, uint8(val>>8))
+ buf = append(buf, uint8(val&0xFF))
return buf
}
func appendUint32(buf []byte, val uint32) []byte {
- buf = append(buf, uint8(val >> 24))
- buf = append(buf, uint8(val >> 16))
- buf = append(buf, uint8(val >> 8))
- buf = append(buf, uint8(val & 0xFF))
+ buf = append(buf, uint8(val>>24))
+ buf = append(buf, uint8(val>>16))
+ buf = append(buf, uint8(val>>8))
+ buf = append(buf, uint8(val&0xFF))
return buf
}
@@ -71,8 +71,8 @@ func queryTreeReply(data interface{}, out chan QueryTreeReply) {
children_len := getUint16(rep)
rep = rep[2:]
rv.Children = make([]Window, 0, children_len)
- rep = rep[14:] // Pad
-
+ rep = rep[14:] // Pad
+
for i := uint16(0); i < children_len; i++ {
rv.Children = append(rv.Children, Window(getUint32(rep)))
rep = rep[4:]
@@ -84,13 +84,13 @@ func queryTreeReply(data interface{}, out chan QueryTreeReply) {
func QueryTree(c *xgob.Connection, window Window) chan QueryTreeReply {
req := make([]byte, 0, 8)
- req = append(req, 15) // Opcode
- req = append(req, 0) // Pad
- req = appendUint16(req, 2) // Length
+ req = append(req, 15) // Opcode
+ req = append(req, 0) // Pad
+ req = appendUint16(req, 2) // Length
req = appendUint32(req, uint32(window))
rv := make(chan QueryTreeReply, 1)
- c.WriteReplyRequestCallback(req, func (in interface{}) { queryTreeReply(in, rv) })
+ c.WriteReplyRequestCallback(req, func(in interface{}) { queryTreeReply(in, rv) })
return rv
}
@@ -113,7 +113,7 @@ func InternAtom(c *xgob.Connection, only_if_exists bool, name string) chan Inter
req := make([]byte, 0, length)
- req = append(req, 16) // Opcode
+ req = append(req, 16) // Opcode
if only_if_exists {
req = append(req, 1)
} else {
@@ -121,13 +121,13 @@ func InternAtom(c *xgob.Connection, only_if_exists bool, name string) chan Inter
}
req = appendUint16(req, uint16(length/4))
req = appendUint16(req, uint16(len(name)))
- req = appendUint16(req, 0) // Pad
+ req = appendUint16(req, 0) // Pad
- req = req[0:length] // Expand for name
+ req = req[0:length] // Expand for name
copy(req[8:], name)
rv := make(chan InternAtomReply, 1)
- c.WriteReplyRequestCallback(req, func (in interface{}) { internAtomReply(in, rv) })
+ c.WriteReplyRequestCallback(req, func(in interface{}) { internAtomReply(in, rv) })
return rv
}
@@ -147,7 +147,7 @@ func getPropertyReply(data interface{}, out chan GetPropertyReply) {
rep = rep[4:]
value_len := getUint32(rep)
rep = rep[4:]
- rep = rep[12:] // Pad
+ rep = rep[12:] // Pad
rv.Value = rep[:value_len]
rep = rep[value_len:]
}
@@ -155,9 +155,9 @@ func getPropertyReply(data interface{}, out chan GetPropertyReply) {
}
func GetProperty(c *xgob.Connection, delete bool, window Window, property Atom, _type Atom, long_offset uint32, long_length uint32) chan GetPropertyReply {
- req := make([]byte, 0, 6 * 4)
+ req := make([]byte, 0, 6*4)
- req = append(req, 20) // Opcode
+ req = append(req, 20) // Opcode
if delete {
req = append(req, 1)
} else {
@@ -171,7 +171,7 @@ func GetProperty(c *xgob.Connection, delete bool, window Window, property Atom,
req = appendUint32(req, long_length)
rv := make(chan GetPropertyReply, 1)
- c.WriteReplyRequestCallback(req, func (in interface{}) { getPropertyReply(in, rv) })
+ c.WriteReplyRequestCallback(req, func(in interface{}) { getPropertyReply(in, rv) })
return rv
}
diff --git a/xlsclients.go b/xlsclients.go
index a3af291..b13dd48 100644
--- a/xlsclients.go
+++ b/xlsclients.go
@@ -31,26 +31,28 @@ func initAtoms(c *xgob.Connection) {
}
func formatTextField(c *xgob.Connection, s string, t *xproto.GetPropertyReply) string {
- if t.Error != nil || t.Type == xproto.Atom(0) || t.Format == 0 {
- return "''";
- }
+ if t.Error != nil || t.Type == xproto.Atom(0) || t.Format == 0 {
+ return "''"
+ }
rv := s
- if t.Type == atom.Atom(c, "STRING") && t.Format == 8 {
+ if t.Type == atom.Atom(c, "STRING") && t.Format == 8 {
rv += string(t.Value)
- } else {
+ } else {
rv += "<unknown type "
if t.Type == xproto.Atom(0) {
- rv += "None";
+ rv += "None"
} else {
/* This should happen so rarely as to make no odds. Eat a round-trip: */
rv += atom.AtomName(c, t.Type)
}
- rv += fmt.Sprintf(" (%d) or format %d>", t.Type, t.Format);
- }
+ rv += fmt.Sprintf(" (%d) or format %d>", t.Type, t.Format)
+ }
- if s != "" { rv += "\n" }
+ if s != "" {
+ rv += "\n"
+ }
return rv
}
@@ -96,7 +98,9 @@ func quotedWord(buf *bytes.Buffer, word []byte, maxlen uint) uint {
}
buf.WriteRune(int(c))
printed++
- if printed >= maxlen { break }
+ if printed >= maxlen {
+ break
+ }
}
/* close the quote if we opened one and if we printed the whole string */
@@ -151,8 +155,8 @@ func clientProperties(c *xgob.Connection, win xproto.Window, result chan string)
var name, iconName, class xproto.GetPropertyReply
if *verbose {
name = <-nameCookie
- iconName = <- iconNameCookie
- class = <- classCookie
+ iconName = <-iconNameCookie
+ class = <-classCookie
}
list := make([]string, 0)
@@ -211,17 +215,17 @@ func lookat(c *xgob.Connection, root xproto.Window, result chan string) {
var count uint
prop := make(chan string)
- /*
- * clients are not allowed to stomp on the root and ICCCM doesn't yet
- * say anything about window managers putting stuff there; but, try
- * anyway.
- */
+ /*
+ * clients are not allowed to stomp on the root and ICCCM doesn't yet
+ * say anything about window managers putting stuff there; but, try
+ * anyway.
+ */
go clientProperties(c, root, prop)
count++
treeCookie := xproto.QueryTree(c, root)
c.Flush()
- tree := <- treeCookie
+ tree := <-treeCookie
for _, child := range tree.Children {
go findClientProperties(c, child, prop)
count++
@@ -234,7 +238,7 @@ func lookat(c *xgob.Connection, root xproto.Window, result chan string) {
result <- strings.Join(list, "")
}
-func main () {
+func main() {
flag.Parse()
c, screen := xgob.Connect(*display)
diff --git a/xmu.go b/xmu.go
index 4535c7c..db62241 100644
--- a/xmu.go
+++ b/xmu.go
@@ -11,7 +11,7 @@ import (
C/libXmu searches the topmost windows first.
This change allows us to avoid as many round-trips as possible.
- */
+*/
func tryChildren(c *xgob.Connection, children []xproto.Window) xproto.Window {
queryCookies := make([]chan xproto.QueryTreeReply, 0)
@@ -53,12 +53,12 @@ func ClientWindow(c *xgob.Connection, win xproto.Window) xproto.Window {
stateCookie := xproto.GetProperty(c, false, win, atom.Atom(c, "WM_STATE"), xproto.Atom(0), 0, 0)
treeCookie := xproto.QueryTree(c, win)
c.Flush()
- state := <- stateCookie
+ state := <-stateCookie
if state.Error != nil && state.Type != xproto.Atom(0) {
return win
}
- tree := <- treeCookie
+ tree := <-treeCookie
if rv := tryChildren(c, tree.Children); rv != 0 {
win = rv
}