Commit dbb591d8 authored by Nigel Tao's avatar Nigel Tao

exp/gui: delete exp/gui and exp/gui/x11. They are moving to

x-go-binding.googlecode.com.

R=rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/5406041
parent e2467f04
......@@ -80,8 +80,6 @@ DIRS=\
exp/ebnf\
exp/ebnflint\
exp/gotype\
exp/gui\
exp/gui/x11\
exp/norm\
exp/ssh\
exp/spdy\
......@@ -204,8 +202,6 @@ NOTEST+=\
crypto/openpgp/error\
crypto/x509/pkix\
exp/ebnflint\
exp/gui\
exp/gui/x11\
go/doc\
hash\
image/bmp\
......
# 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.inc
TARG=exp/gui
GOFILES=\
gui.go\
include ../../../Make.pkg
// 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 gui defines a basic graphical user interface programming model.
package gui
import (
"image"
"image/draw"
)
// A Window represents a single graphics window.
type Window interface {
// Screen returns an editable Image for the window.
Screen() draw.Image
// FlushImage flushes changes made to Screen() back to screen.
FlushImage()
// EventChan returns a channel carrying UI events such as key presses,
// mouse movements and window resizes.
EventChan() <-chan interface{}
// Close closes the window.
Close() error
}
// A KeyEvent is sent for a key press or release.
type KeyEvent struct {
// The value k represents key k being pressed.
// The value -k represents key k being released.
// The specific set of key values is not specified,
// but ordinary characters represent themselves.
Key int
}
// A MouseEvent is sent for a button press or release or for a mouse movement.
type MouseEvent struct {
// Buttons is a bit mask of buttons: 1<<0 is left, 1<<1 middle, 1<<2 right.
// It represents button state and not necessarily the state delta: bit 0
// being on means that the left mouse button is down, but does not imply
// that the same button was up in the previous MouseEvent.
Buttons int
// Loc is the location of the cursor.
Loc image.Point
// Nsec is the event's timestamp.
Nsec int64
}
// A ConfigEvent is sent each time the window's color model or size changes.
// The client should respond by calling Window.Screen to obtain a new image.
type ConfigEvent struct {
Config image.Config
}
// An ErrEvent is sent when an error occurs.
type ErrEvent struct {
Err error
}
# 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.inc
TARG=exp/gui/x11
GOFILES=\
auth.go\
conn.go\
include ../../../../Make.pkg
// 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 x11
import (
"bufio"
"errors"
"io"
"os"
)
// readU16BE reads a big-endian uint16 from r, using b as a scratch buffer.
func readU16BE(r io.Reader, b []byte) (uint16, error) {
_, err := io.ReadFull(r, b[0:2])
if err != nil {
return 0, err
}
return uint16(b[0])<<8 + uint16(b[1]), nil
}
// readStr reads a length-prefixed string from r, using b as a scratch buffer.
func readStr(r io.Reader, b []byte) (string, error) {
n, err := readU16BE(r, b)
if err != nil {
return "", err
}
if int(n) > len(b) {
return "", errors.New("Xauthority entry too long for buffer")
}
_, err = io.ReadFull(r, b[0:n])
if err != nil {
return "", err
}
return string(b[0:n]), nil
}
// readAuth reads the X authority file and returns the name/data pair for the display.
// displayStr is the "12" out of a $DISPLAY like ":12.0".
func readAuth(displayStr string) (name, data string, err 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
fn := os.Getenv("XAUTHORITY")
if fn == "" {
home := os.Getenv("HOME")
if home == "" {
err = errors.New("Xauthority not found: $XAUTHORITY, $HOME not set")
return
}
fn = home + "/.Xauthority"
}
r, err := os.Open(fn)
if err != nil {
return
}
defer r.Close()
br := bufio.NewReader(r)
hostname, err := os.Hostname()
if err != nil {
return
}
for {
var family uint16
var addr, disp, name0, data0 string
family, err = readU16BE(br, b[0:2])
if err != nil {
return
}
addr, err = readStr(br, b[0:])
if err != nil {
return
}
disp, err = readStr(br, b[0:])
if err != nil {
return
}
name0, err = readStr(br, b[0:])
if err != nil {
return
}
data0, err = readStr(br, b[0:])
if err != nil {
return
}
if family == familyLocal && addr == hostname && disp == displayStr {
return name0, data0, nil
}
}
panic("unreachable")
}
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