本文整理汇总了Golang中github.com/BurntSushi/xgb/xproto.Setup函数的典型用法代码示例。如果您正苦于以下问题:Golang Setup函数的具体用法?Golang Setup怎么用?Golang Setup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Setup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewXHandle
func NewXHandle(display string) (*xhandle, error) {
c, err := xgb.NewConnDisplay(display)
if err != nil {
return nil, err
}
s := xproto.Setup(c)
screen := s.DefaultScreen(c)
kb, err := NewKeyboard(s, c)
if err != nil {
return nil, err
}
h := &xhandle{
conn: c,
root: screen.Root,
Events: make([]Event, 0, 1000),
EvtsLck: &sync.RWMutex{},
keyboard: kb,
Keys: make(map[int]map[xproto.Window]map[Input][]Key),
KeysLck: &sync.RWMutex{},
}
return h, nil
}
示例2: newHeads
func newHeads(X *xgb.Conn) heads {
var primaryHead *head
var primaryOutput randr.Output
root := xproto.Setup(X).DefaultScreen(X).Root
resources, err := randr.GetScreenResourcesCurrent(X, root).Reply()
if err != nil {
log.Fatalf("Could not get screen resources: %s.", err)
}
primaryOutputReply, _ := randr.GetOutputPrimary(X, root).Reply()
if primaryOutputReply != nil {
primaryOutput = primaryOutputReply.Output
}
hds := make([]head, 0, len(resources.Outputs))
off := make([]string, 0)
disconnected := make([]string, 0)
for i, output := range resources.Outputs {
oinfo, err := randr.GetOutputInfo(X, output, 0).Reply()
if err != nil {
log.Fatalf("Could not get output info for screen %d: %s.", i, err)
}
outputName := string(oinfo.Name)
if oinfo.Connection != randr.ConnectionConnected {
disconnected = append(disconnected, outputName)
continue
}
if oinfo.Crtc == 0 {
off = append(off, outputName)
continue
}
crtcinfo, err := randr.GetCrtcInfo(X, oinfo.Crtc, 0).Reply()
if err != nil {
log.Fatalf("Could not get crtc info for screen (%d, %s): %s.",
i, outputName, err)
}
head := newHead(output, outputName, crtcinfo)
if output == primaryOutput {
primaryHead = &head
}
hds = append(hds, head)
}
if primaryHead == nil && len(hds) > 0 {
tmp := hds[0]
primaryHead = &tmp
}
hdsPrim := heads{
primary: primaryHead,
heads: hds,
off: off,
disconnected: disconnected,
}
sort.Sort(hdsPrim)
return hdsPrim
}
示例3: Lock
// Lock grabs the keyboard and pointer locking the X11 display
func Lock(X *xgb.Conn) error {
screen := xproto.Setup(X).DefaultScreen(X)
passEventsToOwner := false
kbCookie := xproto.GrabKeyboard(X, passEventsToOwner, screen.Root, xproto.TimeCurrentTime, xproto.GrabModeAsync, xproto.GrabModeAsync)
kbReply, err := kbCookie.Reply()
if err != nil {
return err
}
if kbReply.Status != xproto.GrabStatusSuccess {
return fmt.Errorf("GrabKeyboard status %v", grabStatus(kbReply.Status))
}
ptrCookie := xproto.GrabPointer(X, passEventsToOwner, screen.Root, 0, xproto.GrabModeAsync, xproto.GrabModeAsync, xproto.AtomNone, xproto.AtomNone, xproto.TimeCurrentTime)
ptrReply, err := ptrCookie.Reply()
if err != nil {
xproto.UngrabKeyboard(X, xproto.TimeCurrentTime)
return err
}
if ptrReply.Status != xproto.GrabStatusSuccess {
return fmt.Errorf("GrabPointer status %v", grabStatus(kbReply.Status))
}
return nil
}
示例4: getPrimaryScreenBestResolution
func getPrimaryScreenBestResolution() (w uint16, h uint16) {
// if connect to x failed, just return 1024x768
w, h = 1024, 768
XU, err := xgbutil.NewConn()
if err != nil {
return
}
err = randr.Init(XU.Conn())
if err != nil {
return
}
_, err = randr.QueryVersion(XU.Conn(), 1, 4).Reply()
if err != nil {
return
}
Root := xproto.Setup(XU.Conn()).DefaultScreen(XU.Conn()).Root
resources, err := randr.GetScreenResources(XU.Conn(), Root).Reply()
if err != nil {
return
}
bestModes := make([]uint32, 0)
for _, output := range resources.Outputs {
reply, err := randr.GetOutputInfo(XU.Conn(), output, 0).Reply()
if err == nil && reply.NumModes > 1 {
bestModes = append(bestModes, uint32(reply.Modes[0]))
}
}
w, h = 0, 0
for _, m := range resources.Modes {
for _, id := range bestModes {
if id == m.Id {
bw, bh := m.Width, m.Height
if w == 0 || h == 0 {
w, h = bw, bh
} else if uint32(bw)*uint32(bh) < uint32(w)*uint32(h) {
w, h = bw, bh
}
}
}
}
if w == 0 || h == 0 {
// get resource failed, use root window's geometry
rootRect := xwindow.RootGeometry(XU)
w, h = uint16(rootRect.Width()), uint16(rootRect.Height())
}
if w == 0 || h == 0 {
w, h = 1024, 768 // default value
}
logger.Debugf("primary screen's best resolution is %dx%d", w, h)
return
}
示例5: Load
func Load(c *xgb.Conn) error {
ctxs = make(map[string]*gcontext)
scr := xproto.Setup(c).DefaultScreen(c)
err := loadGCS(c, scr)
if err != nil {
return err
}
return nil
}
示例6: Move
func (m *Mouse) Move(args *MoveArgs, reply *int) error {
//fmt.Printf("%#v\n", args)
screen := xproto.Setup(m.x11).DefaultScreen(m.x11)
cookie := xtest.FakeInputChecked(m.x11, xproto.MotionNotify, 0, 0, screen.Root, int16(args.X), int16(args.Y), 0)
if cookie.Check() != nil {
fmt.Println("FakeInput failed")
}
return nil
}
示例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: 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))
}
示例9: adjust
func (b *brightness) adjust(Xu *xgbutil.XUtil, increase bool) error {
X := Xu.Conn()
root := xproto.Setup(X).DefaultScreen(X).Root
screens, err := randr.GetScreenResources(X, root).Reply()
if err != nil {
return fmt.Errorf("getting screen: %v", err)
}
for _, output := range screens.Outputs {
query, err := randr.QueryOutputProperty(X, output, b.prop).Reply()
if err != nil {
if _, ok := err.(xproto.NameError); ok {
// this output has no backlight
continue
}
return fmt.Errorf("query backlight: %v", err)
}
if !query.Range {
return errors.New("backlight brightness range not specified")
}
if len(query.ValidValues) != 2 {
return fmt.Errorf("expected min and max, got: %v", query.ValidValues)
}
min, max := query.ValidValues[0], query.ValidValues[1]
// log.Printf("backlight range: %d .. %d", min, max)
get, err := randr.GetOutputProperty(X, output, b.prop, xproto.AtomNone, 0, 4, false, false).Reply()
if err != nil {
return fmt.Errorf("get backlight property: %v", err)
}
if get.Type != xproto.AtomInteger ||
get.NumItems != 1 ||
get.Format != 32 {
return fmt.Errorf("backlight property value looks wrong")
}
old := *(*int32)(unsafe.Pointer(&get.Data[0]))
// log.Printf("backlight data: %d", old)
bri := delta5(old, min, max, increase)
data := (*[4]byte)(unsafe.Pointer(&bri))[:]
if err := randr.ChangeOutputPropertyChecked(X, output, b.prop, xproto.AtomInteger, 32, xproto.PropModeReplace, 1, data).Check(); err != nil {
return err
}
}
return nil
}
示例10: 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)
}
示例11: getCurWindowTitle
func (logger *WindowLogger) getCurWindowTitle() (name string, err error) {
// Get the window id of the root window.
setup := xproto.Setup(logger.X11Connection)
root := setup.DefaultScreen(logger.X11Connection).Root
// Get the atom id (i.e., intern an atom) of "_NET_ACTIVE_WINDOW".
aname := "_NET_ACTIVE_WINDOW"
activeAtom, err := xproto.InternAtom(logger.X11Connection, true, uint16(len(aname)),
aname).Reply()
if err != nil {
return "", err
}
// Get the atom id (i.e., intern an atom) of "_NET_WM_NAME".
aname = "_NET_WM_NAME"
nameAtom, err := xproto.InternAtom(logger.X11Connection, true, uint16(len(aname)),
aname).Reply()
if err != nil {
return "", 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(logger.X11Connection, false, root, activeAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return "", err
}
windowId := xproto.Window(xgb.Get32(reply.Value))
// 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(logger.X11Connection, false, windowId, nameAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return "", err
}
return string(reply.Value), nil
}
示例12: newScreenImpl
func newScreenImpl(xc *xgb.Conn) (*screenImpl, error) {
s := &screenImpl{
xc: xc,
xsi: xproto.Setup(xc).DefaultScreen(xc),
buffers: map[shm.Seg]*bufferImpl{},
uploads: map[uint16]completion{},
windows: map[xproto.Window]*windowImpl{},
}
if err := s.initAtoms(); err != nil {
return nil, err
}
if err := s.initPictformats(); err != nil {
return nil, err
}
if err := s.initWindow32(); err != nil {
return nil, err
}
go s.run()
return s, nil
}
示例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: CaptureRect
func CaptureRect(rect image.Rectangle) (*image.RGBA, error) {
c, err := xgb.NewConn()
if err != nil {
return nil, err
}
defer c.Close()
screen := xproto.Setup(c).DefaultScreen(c)
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 {
return nil, 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)}
return img, nil
}