Commit 598f3e28 authored by Tor Andersson's avatar Tor Andersson Committed by Russ Cox

A first stab at porting the XCB X11 protocol bindings to go.

The python script needs a checkout of xcb/proto to generate
an xproto.go file, which together with xgb.go provide functions
to access all of the core X11 protocol requests. I have included the
generated file.

Extensions and authentication methods are not implemented.

R=r, rsc, nigeltao_golang
https://golang.org/cl/162053
parent 9d50b468
......@@ -99,6 +99,7 @@ DIRS=\
unicode\
utf8\
websocket\
xgb\
xml\
NOTEST=\
......@@ -113,6 +114,7 @@ NOTEST=\
runtime\
syscall\
testing/iotest\
xgb\
TEST=\
$(filter-out $(NOTEST),$(DIRS))
......
# 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=\
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 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[1] = 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