• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang xgb.NewConn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/BurntSushi/xgb.NewConn函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConn函数的具体用法?Golang NewConn怎么用?Golang NewConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewConn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:akesling,项目名称:Gonads,代码行数:8,代码来源:util.go


示例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
}
开发者ID:kleopatra999,项目名称:exp,代码行数:27,代码来源:x11driver.go


示例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)
	}
}
开发者ID:tejohnso,项目名称:xgb,代码行数:29,代码来源:main.go


示例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) }
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:9,代码来源:handle_plan.go


示例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
}
开发者ID:erasche,项目名称:gologme,代码行数:10,代码来源:windowlogger.go


示例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()
}
开发者ID:JessonChan,项目名称:xgb,代码行数:14,代码来源:xproto_test.go


示例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
}
开发者ID:joshgordon,项目名称:screenshot,代码行数:13,代码来源:screenshot_freebsd.go


示例8: NewMouse

func NewMouse() *Mouse {
	mouse := &Mouse{}

	x11, err := xgb.NewConn()
	if err != nil {
		panic("err")
	}

	xtest.Init(x11)

	mouse.x11 = x11
	return mouse
}
开发者ID:jordansissel,项目名称:fingerpoken,代码行数:13,代码来源:foo.go


示例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))
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:49,代码来源:main.go


示例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()
	}
}
开发者ID:thomas11,项目名称:dwmstatus,代码行数:17,代码来源:dwmstatus.go


示例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())
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:16,代码来源:xproto_test.go


示例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)
}
开发者ID:MasteringGolang,项目名称:BasicKnowledge,代码行数:44,代码来源:prtSc.go


示例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()))
	}
}
开发者ID:pwaller,项目名称:runlocal,代码行数:40,代码来源:main.go


示例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)
		}
	}
}
开发者ID:fd0,项目名称:grobi,代码行数:40,代码来源:cmd_watch.go


示例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)
}
开发者ID:BurntSushi,项目名称:gohead,代码行数:22,代码来源:main.go


示例16: 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
}
开发者ID:joshgordon,项目名称:screenshot,代码行数:22,代码来源:screenshot_freebsd.go


示例17: default1

func default1() {

	X, err := xgb.NewConn()
	if err != nil {
		fmt.Println(err)
		return
	}

	wid, _ := xproto.NewWindowId(X)
	screen := xproto.Setup(X).DefaultScreen(X)
	xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root,
		0, 0, 500, 500, 0,
		xproto.WindowClassInputOutput, screen.RootVisual,
		xproto.CwBackPixel|xproto.CwEventMask,
		[]uint32{
			0xffffffff,
			xproto.EventMaskStructureNotify |
				xproto.EventMaskKeyPress |
				xproto.EventMaskKeyRelease})

	xproto.MapWindow(X, wid)
	for {
		ev, xerr := X.WaitForEvent()
		if ev == nil && xerr == nil {
			fmt.Println("Both event and error are nil. Exiting...")
			return
		}

		if ev != nil {
			fmt.Println("Event: %s\r\n", ev)
		}
		if xerr != nil {
			fmt.Println("Error: %s\r\n", xerr)
		}

	}

}
开发者ID:MasteringGolang,项目名称:BasicKnowledge,代码行数:38,代码来源:prtSc.go


示例18: main

func main() {
	X, err := xgb.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	defer X.Close()

	for {
		err = trlock.Lock(X)
		if err != nil {
			log.Fatal(err)
		}

		log.Println("Locked")
		time.Sleep(5 * time.Second)

		log.Println("Unlocking")
		trlock.Unlock(X)

		log.Println("Unlocked; ctrl-c now")
		time.Sleep(3 * time.Second)
	}
}
开发者ID:chlunde,项目名称:trlock,代码行数:23,代码来源:main.go


示例19: main

func main() {
	X, _ := xgb.NewConn()

	// Every extension must be initialized before it can be used.
	err := randr.Init(X)
	if err != nil {
		log.Fatal(err)
	}

	// Get the root window on the default screen.
	root := xproto.Setup(X).DefaultScreen(X).Root

	// Gets the current screen resources. Screen resources contains a list
	// of names, crtcs, outputs and modes, among other things.
	resources, err := randr.GetScreenResources(X, root).Reply()
	if err != nil {
		log.Fatal(err)
	}

	// Iterate through all of the outputs and show some of their info.
	for _, output := range resources.Outputs {
		info, err := randr.GetOutputInfo(X, output, 0).Reply()
		if err != nil {
			log.Fatal(err)
		}

		bestMode := info.Modes[0]
		for _, mode := range resources.Modes {
			if mode.Id == uint32(bestMode) {
				fmt.Printf("Width: %d, Height: %d\n", mode.Width, mode.Height)
			}
		}
	}

	fmt.Println("\n")

	// Iterate through all of the crtcs and show some of their info.
	for _, crtc := range resources.Crtcs {
		info, err := randr.GetCrtcInfo(X, crtc, 0).Reply()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("X: %d, Y: %d, Width: %d, Height: %d\n",
			info.X, info.Y, info.Width, info.Height)
	}

	// Tell RandR to send us events. (I think these are all of them, as of 1.3.)
	err = randr.SelectInputChecked(X, root,
		randr.NotifyMaskScreenChange|
			randr.NotifyMaskCrtcChange|
			randr.NotifyMaskOutputChange|
			randr.NotifyMaskOutputProperty).Check()
	if err != nil {
		log.Fatal(err)
	}

	// Listen to events and just dump them to standard out.
	// A more involved approach will have to read the 'U' field of
	// RandrNotifyEvent, which is a union (really a struct) of type
	// RanrNotifyDataUnion.
	for {
		ev, err := X.WaitForEvent()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(ev)
	}
}
开发者ID:rjmcguire,项目名称:xgb,代码行数:68,代码来源:main.go


示例20: main

func main() {
	// Open the connection to the X server
	X, err := xgb.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	defer X.Close()

	// geometric objects
	points := []xproto.Point{
		{10, 10},
		{10, 20},
		{20, 10},
		{20, 20}}

	polyline := []xproto.Point{
		{50, 10},
		{5, 20}, // rest of points are relative
		{25, -20},
		{10, 10}}

	segments := []xproto.Segment{
		{100, 10, 140, 30},
		{110, 25, 130, 60}}

	rectangles := []xproto.Rectangle{
		{10, 50, 40, 20},
		{80, 50, 10, 40}}

	arcs := []xproto.Arc{
		{10, 100, 60, 40, 0, 90 << 6},
		{90, 100, 55, 40, 0, 270 << 6}}

	setup := xproto.Setup(X)
	// Get the first screen
	screen := setup.DefaultScreen(X)

	// Create black (foreground) graphic context
	foreground, _ := xproto.NewGcontextId(X)
	mask := uint32(xproto.GcForeground | xproto.GcGraphicsExposures)
	values := []uint32{screen.BlackPixel, 0}
	xproto.CreateGC(X, foreground, xproto.Drawable(screen.Root), mask, values)

	// Ask for our window's Id
	win, _ := xproto.NewWindowId(X)
	winDrawable := xproto.Drawable(win)

	// Create the window
	mask = uint32(xproto.CwBackPixel | xproto.CwEventMask)
	values = []uint32{screen.WhitePixel, xproto.EventMaskExposure}
	xproto.CreateWindow(X, // Connection
		screen.RootDepth, // Depth
		win,              // Window Id
		screen.Root,      // Parent Window
		0, 0,             // x, y
		150, 150, // width, height
		10, // border_width
		xproto.WindowClassInputOutput, // class
		screen.RootVisual,             // visual
		mask, values)                  // masks

	// Map the window on the screen
	xproto.MapWindow(X, win)

	// Obey the window-delete protocol
	tp := "WM_PROTOCOLS"
	prp := "WM_DELETE_WINDOW"
	typeAtom, _ := xproto.InternAtom(X, true, uint16(len(tp)), tp).Reply()
	propertyAtom, _ := xproto.InternAtom(X, true, uint16(len(prp)), prp).Reply()

	// It turns out that we need the window ID as a byte-stream... WTF!!
	// xprop.ChangeProp(xu, win, 8, "WM_NAME", "STRING", ([]byte)(name))
	// ChangeProp(xu *xgbutil.XUtil, win xproto.Window, format byte, prop string, typ string, data []byte)
	data := make([]byte, 4)
	xgb.Put32(data, uint32(propertyAtom.Atom))
	xproto.ChangeProperty(X, xproto.PropModeReplace, win, typeAtom.Atom, xproto.AtomAtom, 32, 1, data)

	for {
		evt, err := X.WaitForEvent()
		fmt.Printf("An event of type %T occured.\n", evt)

		if evt == nil && err == nil {
			fmt.Println("Exiting....")
			return
		} else if err != nil {
			log.Fatal(err)
		}

		switch event := evt.(type) {
		case xproto.ExposeEvent:
			/* We draw the points */
			xproto.PolyPoint(X, xproto.CoordModeOrigin, winDrawable, foreground, points)

			/* We draw the polygonal line */
			xproto.PolyLine(X, xproto.CoordModePrevious, winDrawable, foreground, polyline)

			/* We draw the segments */
			xproto.PolySegment(X, winDrawable, foreground, segments)

			/* We draw the rectangles */
//.........这里部分代码省略.........
开发者ID:akesling,项目名称:Gonads,代码行数:101,代码来源:xgb_test_close.go



注:本文中的github.com/BurntSushi/xgb.NewConn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang xgb.Pad函数代码示例发布时间:2022-05-24
下一篇:
Golang xgb.Get32函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap