Commit fd3e067e authored by Nigel Tao's avatar Nigel Tao

Delete xgb from the main repository. It has moved to

http://code.google.com/p/x-go-binding/

R=rsc
CC=golang-dev
https://golang.org/cl/846043
parent 5d230418
...@@ -123,7 +123,6 @@ DIRS=\ ...@@ -123,7 +123,6 @@ DIRS=\
utf16\ utf16\
utf8\ utf8\
websocket\ websocket\
xgb\
xml\ xml\
NOTEST=\ NOTEST=\
...@@ -140,7 +139,6 @@ NOTEST=\ ...@@ -140,7 +139,6 @@ NOTEST=\
runtime/pprof\ runtime/pprof\
syscall\ syscall\
testing/iotest\ testing/iotest\
xgb\
NOBENCH=\ NOBENCH=\
container/vector\ container/vector\
......
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../Make.$(GOARCH)
TARG=xgb
GOFILES=\
auth.go\
xgb.go\
xproto.go\
include ../../Make.pkg
xproto: proto/src/xproto.xml
python go_client.py -p proto/ proto/src/xproto.xml
gofmt -w xproto.go
proto/src/xproto.xml:
git clone git://anongit.freedesktop.org/git/xcb/proto
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xgb
import (
"bufio"
"io"
"os"
)
func getU16BE(r io.Reader, b []byte) (uint16, os.Error) {
_, err := io.ReadFull(r, b[0:2])
if err != nil {
return 0, err
}
return uint16(b[0])<<8 + uint16(b[1]), nil
}
func getBytes(r io.Reader, b []byte) ([]byte, os.Error) {
n, err := getU16BE(r, b)
if err != nil {
return nil, err
}
if int(n) > len(b) {
return nil, os.NewError("bytes too long for buffer")
}
_, err = io.ReadFull(r, b[0:n])
if err != nil {
return nil, err
}
return b[0:n], nil
}
func getString(r io.Reader, b []byte) (string, os.Error) {
b, err := getBytes(r, b)
if err != nil {
return "", err
}
return string(b), nil
}
// readAuthority reads the X authority file for the DISPLAY.
// If hostname == "" or hostname == "localhost",
// readAuthority uses the system's hostname (as returned by os.Hostname) instead.
func readAuthority(hostname, display string) (name string, data []byte, err os.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).
var b [256]byte
// As per /usr/include/X11/Xauth.h.
const familyLocal = 256
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 = os.NewError("Xauthority not found: $XAUTHORITY, $HOME not set")
return "", nil, err
}
fname = home + "/.Xauthority"
}
r, err := os.Open(fname, os.O_RDONLY, 0444)
if err != nil {
return "", nil, err
}
defer r.Close()
br := bufio.NewReader(r)
for {
family, err := getU16BE(br, b[0:2])
if err != nil {
return "", nil, err
}
addr, err := getString(br, b[0:])
if err != nil {
return "", nil, err
}
disp, err := getString(br, b[0:])
if err != nil {
return "", nil, err
}
name0, err := getString(br, b[0:])
if err != nil {
return "", nil, err
}
data0, err := getBytes(br, b[0:])
if err != nil {
return "", nil, err
}
if family == familyLocal && addr == hostname && disp == display {
return name0, data0, nil
}
}
panic("unreachable")
}
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"xgb"
)
func main() {
c, err := xgb.Dial(os.Getenv("DISPLAY"))
if err != nil {
fmt.Printf("cannot connect: %v\n", err)
os.Exit(1)
}
fmt.Printf("vendor = '%s'\n", string(c.Setup.Vendor))
win := c.NewId()
gc := c.NewId()
c.CreateWindow(0, win, c.DefaultScreen().Root, 150, 150, 200, 200, 0, 0, 0, 0, nil)
c.ChangeWindowAttributes(win, xgb.CWEventMask,
[]uint32{xgb.EventMaskExposure | xgb.EventMaskKeyRelease})
c.CreateGC(gc, win, 0, nil)
c.MapWindow(win)
atom, _ := c.InternAtom(0, "HELLO")
fmt.Printf("atom = %d\n", atom.Atom)
points := make([]xgb.Point, 2)
points[0] = xgb.Point{5, 5}
points[1] = xgb.Point{100, 120}
hosts, _ := c.ListHosts()
fmt.Printf("hosts = %+v\n", hosts)
ecookie := c.ListExtensionsRequest()
exts, _ := c.ListExtensionsReply(ecookie)
for _, name := range exts.Names {
fmt.Printf("exts = '%s'\n", name.Name)
}
for {
reply, err := c.WaitForEvent()
if err != nil {
fmt.Printf("error: %v\n", err)
os.Exit(1)
}
fmt.Printf("event %T\n", reply)
switch event := reply.(type) {
case xgb.ExposeEvent:
c.PolyLine(xgb.CoordModeOrigin, win, gc, points)
case xgb.KeyReleaseEvent:
fmt.Printf("key release!\n")
points[0].X = event.EventX
points[0].Y = event.EventY
c.PolyLine(xgb.CoordModeOrigin, win, gc, points)
c.Bell(75)
}
}
c.Close()
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment