本文整理匯總了Golang中github.com/BurntSushi/xgb.NewConn函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConn函數的具體用法?Golang NewConn怎麽用?Golang NewConn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: xConnect
// Open the connection to the X server
func xConnect() *xgb.Conn {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
return X
}
示例2: main
func main(f func(screen.Screen)) (retErr error) {
xc, err := xgb.NewConn()
if err != nil {
return fmt.Errorf("x11driver: xgb.NewConn failed: %v", err)
}
defer func() {
if retErr != nil {
xc.Close()
}
}()
if err := render.Init(xc); err != nil {
return fmt.Errorf("x11driver: render.Init failed: %v", err)
}
if err := shm.Init(xc); err != nil {
return fmt.Errorf("x11driver: shm.Init failed: %v", err)
}
s, err := newScreenImpl(xc)
if err != nil {
return err
}
f(s)
// TODO: tear down the s.run goroutine? It's probably not worth the
// complexity of doing it cleanly, if the app is about to exit anyway.
return nil
}
示例3: main
func main() {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
// Initialize the Xinerama extension.
// The appropriate 'Init' function must be run for *every*
// extension before any of its requests can be used.
err = xinerama.Init(X)
if err != nil {
log.Fatal(err)
}
// Issue a request to get the screen information.
reply, err := xinerama.QueryScreens(X).Reply()
if err != nil {
log.Fatal(err)
}
// reply.Number is the number of active heads, while reply.ScreenInfo
// is a slice of XineramaScreenInfo containing the rectangle geometry
// of each head.
fmt.Printf("Number of heads: %d\n", reply.Number)
for i, screen := range reply.ScreenInfo {
fmt.Printf("%d :: X: %d, Y: %d, Width: %d, Height: %d\n",
i, screen.XOrg, screen.YOrg, screen.Width, screen.Height)
}
}
示例4: initPlan
func (p *Power) initPlan() {
p.screensaver.ConnectIdleOn(p.handleIdleOn)
p.screensaver.ConnectIdleOff(p.handleIdleOff)
p.updateIdletimer()
con, _ := xgb.NewConn()
dpms.Init(con)
dpmsOn = func() { dpms.ForceLevel(con, dpms.DPMSModeOn) }
dpmsOff = func() { dpms.ForceLevel(con, dpms.DPMSModeOff) }
}
示例5: NewWindowLogger
func NewWindowLogger(conf map[string]string) (LogGenerator, error) {
x, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
return &WindowLogger{
X11Connection: x,
}, nil
}
示例6: init
// init initializes the X connection, seeds the RNG and starts waiting
// for events.
func init() {
var err error
X, err = xgb.NewConn()
if err != nil {
log.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
go grabEvents()
}
示例7: ScreenRect
func ScreenRect() (image.Rectangle, error) {
c, err := xgb.NewConn()
if err != nil {
return image.Rectangle{}, err
}
defer c.Close()
screen := xproto.Setup(c).DefaultScreen(c)
x := screen.WidthInPixels
y := screen.HeightInPixels
return image.Rect(0, 0, int(x), int(y)), nil
}
示例8: NewMouse
func NewMouse() *Mouse {
mouse := &Mouse{}
x11, err := xgb.NewConn()
if err != nil {
panic("err")
}
xtest.Init(x11)
mouse.x11 = x11
return mouse
}
示例9: main
func main() {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
// Get the window id of the root window.
setup := xproto.Setup(X)
root := setup.DefaultScreen(X).Root
// Get the atom id (i.e., intern an atom) of "_NET_ACTIVE_WINDOW".
aname := "_NET_ACTIVE_WINDOW"
activeAtom, err := xproto.InternAtom(X, true, uint16(len(aname)),
aname).Reply()
if err != nil {
log.Fatal(err)
}
// Get the atom id (i.e., intern an atom) of "_NET_WM_NAME".
aname = "_NET_WM_NAME"
nameAtom, err := xproto.InternAtom(X, true, uint16(len(aname)),
aname).Reply()
if err != nil {
log.Fatal(err)
}
// Get the actual value of _NET_ACTIVE_WINDOW.
// Note that 'reply.Value' is just a slice of bytes, so we use an
// XGB helper function, 'Get32', to pull an unsigned 32-bit integer out
// of the byte slice. We then convert it to an X resource id so it can
// be used to get the name of the window in the next GetProperty request.
reply, err := xproto.GetProperty(X, false, root, activeAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
log.Fatal(err)
}
windowId := xproto.Window(xgb.Get32(reply.Value))
fmt.Printf("Active window id: %X\n", windowId)
// Now get the value of _NET_WM_NAME for the active window.
// Note that this time, we simply convert the resulting byte slice,
// reply.Value, to a string.
reply, err = xproto.GetProperty(X, false, windowId, nameAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Active window name: %s\n", string(reply.Value))
}
示例10: Run
// Start the process of updating the status bar. genTitle will be called
// repeatedly in the given interval.
func Run(interval time.Duration, genTitle GenTitleFunc) {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
var status bytes.Buffer
c := time.Tick(interval)
for now := range c {
genTitle(now, &status)
setStatus(status.Bytes(), X)
status.Reset()
}
}
示例11: TestMain
func TestMain(m *testing.M) {
if os.Getenv("DISPLAY") == "" {
log.Printf("No X; Skipping tests")
os.Exit(0)
}
var err error
X, err = xgb.NewConn()
if err != nil {
log.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
go grabEvents()
os.Exit(m.Run())
}
示例12: main
func main() {
// os.Setenv("DISPLAY", "localhost:6080")
c, err := xgb.NewConn()
if err != nil {
fmt.Println(err)
return
}
screen := xproto.Setup(c).DefaultScreen(c)
rect := image.Rect(0, 0, int(screen.WidthInPixels), int(screen.HeightInPixels))
x, y := rect.Dx(), rect.Dy()
xImg, err := xproto.GetImage(c,
xproto.ImageFormatZPixmap,
xproto.Drawable(screen.Root),
int16(rect.Min.X),
int16(rect.Min.Y),
uint16(x),
uint16(y),
0xffffffff).Reply()
if err != nil {
fmt.Println("Error: %s\r\n", err)
}
data := xImg.Data
for i := 0; i < len(data); i += 4 {
data[i], data[i+2], data[i+3] = data[i+2], data[i], 255
}
img := &image.RGBA{
data, 4 * x, image.Rect(0, 0, x, y)}
z.FcheckParents("screen")
f := z.FileW("screen")
defer f.Close()
png := jpeg.Encode(f, img, &jpeg.Options{90})
fmt.Printf("End with png: %v", png)
}
示例13: main
func main() {
var serve *bool = flag.Bool("serve", false, "Listen for connections")
flag.Usage = usage
flag.Parse()
if remote := os.Getenv("SSH_CONNECTION"); remote == "" && len(flag.Args()) != 0 {
invoked_as := os.Args[0]
actual_binary, err := os.Readlink("/proc/self/exe")
if err != nil {
log.Panic("/proc/self/exe doesn't exist!")
}
log.Print("Invoked as: '", invoked_as, "' (actual=", actual_binary, ")")
log.Panic("Not yet implemented: Would have run locally")
return
}
c, err := xgb.NewConn()
if err != nil {
log.Panic("cannot connect: %v\n", err)
}
s := xproto.Setup(c).DefaultScreen(c)
rl_execute_reply, err := xproto.InternAtom(c, false, uint16(len(atomname)), atomname).Reply()
if err != nil {
panic(err)
}
rl_execute_atom := rl_execute_reply.Atom
if *serve {
//log.Printf("c = %v, s = %v, a = %v", c, s, rl_execute_atom)
start_server(c, s, rl_execute_atom)
} else {
if len(flag.Args()) == 0 {
usage()
}
connect(c, s, rl_execute_atom, fixup_args(flag.Args()))
}
}
示例14: subscribeXEvents
func subscribeXEvents(ch chan<- Event, done <-chan struct{}) {
X, err := xgb.NewConn()
if err != nil {
ch <- Event{Error: err}
return
}
defer X.Close()
if err = randr.Init(X); err != nil {
ch <- Event{Error: err}
return
}
root := xproto.Setup(X).DefaultScreen(X).Root
eventMask := randr.NotifyMaskScreenChange |
randr.NotifyMaskCrtcChange |
randr.NotifyMaskOutputChange |
randr.NotifyMaskOutputProperty
err = randr.SelectInputChecked(X, root, uint16(eventMask)).Check()
if err != nil {
ch <- Event{Error: err}
return
}
for {
ev, err := X.WaitForEvent()
select {
case ch <- Event{Event: ev, Error: err}:
case <-time.After(eventSendTimeout):
continue
case <-done:
return
}
if err != nil {
log.Fatal(err)
}
}
}
示例15: main
func main() {
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
err = randr.Init(X)
if err != nil {
log.Fatal(err)
}
conf := newConfig()
hds := newHeads(X)
if cmdInfo, ok := commands[command]; ok {
cmdInfo.f(conf, hds)
} else {
fmt.Fprintf(os.Stderr, "Unknown command '%s'.\n", command)
flag.Usage()
}
os.Exit(0)
}