當前位置: 首頁>>代碼示例>>Golang>>正文


Golang XUtil.Conn方法代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil.XUtil.Conn方法的典型用法代碼示例。如果您正苦於以下問題:Golang XUtil.Conn方法的具體用法?Golang XUtil.Conn怎麽用?Golang XUtil.Conn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/BurntSushi/xgbutil.XUtil的用法示例。


在下文中一共展示了XUtil.Conn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Ungrab

// Ungrab undoes Grab. It will handle all combinations of modifiers found
// in xevent.IgnoreMods.
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16,
	button xproto.Button) {

	for _, m := range xevent.IgnoreMods {
		xproto.UngrabButtonChecked(xu.Conn(), byte(button), win, mods|m).Check()
	}
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:9,代碼來源:mousebind.go

示例2: ComposeShape

// compose a number of rectabgles into a window shape
func ComposeShape(X *xgbutil.XUtil, dst xproto.Window, rects []xrect.Rect) (err error) {

	combine_bounds := make([]shape.CombineCookie, len(rects))
	combine_clip := make([]shape.CombineCookie, len(rects))

	var operation shape.Op

	for i, rect := range rects {
		// make rectangular window of correct goemetry
		win, err := xwindow.Generate(X)
		if err != nil {
			log.Fatalf("ComposeShape: Error creating rectange %v window.", rect)
			return err
		}
		win.Create(X.RootWin(), rect.X(), rect.Y(), rect.Width(), rect.Height(), xproto.CwBackPixel, 0xffffff)

		// choose operation. on the first one, we want to set the shape.
		if i == 0 {
			operation = shape.SoSet
		} else {
			operation = shape.SoUnion
		}

		// combine window request
		x, y := int16(rect.X()), int16(rect.Y())

		combine_kind := shape.Kind(shape.SkBounding)
		combine_bounds[i] = shape.CombineChecked(X.Conn(), operation, combine_kind, combine_kind, dst, x, y, win.Id)
		combine_kind = shape.Kind(shape.SkClip)
		combine_clip[i] = shape.CombineChecked(X.Conn(), operation, combine_kind, combine_kind, dst, x, y, win.Id)
	}
	return nil
}
開發者ID:justjake,項目名稱:j3,代碼行數:34,代碼來源:shape.go

示例3: Ungrab

// Ungrab undoes Grab. It will handle all combinations od modifiers found
// in xevent.IgnoreMods.
func Ungrab(xu *xgbutil.XUtil, win xproto.Window,
	mods uint16, key xproto.Keycode) {

	for _, m := range xevent.IgnoreMods {
		xproto.UngrabKeyChecked(xu.Conn(), key, win, mods|m).Check()
	}
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:9,代碼來源:keybind.go

示例4: newParent

func newParent(X *xgbutil.XUtil, cid xproto.Window) (*Parent, error) {
	parent, err := xwindow.Generate(X)
	if err != nil {
		logger.Error.Printf("Could not create a parent window for client "+
			"with id '%d' because: %s", cid, err)
		logger.Error.Fatalf("In a state where no new windows can be created. " +
			"Unfortunately, we must exit.")
	}

	err = parent.CreateChecked(X.RootWin(), 0, 0, 1, 1,
		xproto.CwEventMask,
		xproto.EventMaskSubstructureRedirect|
			xproto.EventMaskButtonPress|xproto.EventMaskButtonRelease)
	if err != nil {
		return nil, err
	}

	err = xproto.ReparentWindowChecked(X.Conn(),
		cid, parent.Id, 0, 0).Check()
	if err != nil {
		return nil, err
	}

	return &Parent{parent}, nil
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:25,代碼來源:parent.go

示例5: GrabKeyboard

// GrabKeyboard grabs the entire keyboard.
// Returns whether GrabStatus is successful and an error if one is reported by
// XGB. It is possible to not get an error and the grab to be unsuccessful.
// The purpose of 'win' is that after a grab is successful, ALL Key*Events will
// be sent to that window. Make sure you have a callback attached :-)
func GrabKeyboard(xu *xgbutil.XUtil, win xproto.Window) error {
	reply, err := xproto.GrabKeyboard(xu.Conn(), false, win, 0,
		xproto.GrabModeAsync, xproto.GrabModeAsync).Reply()
	if err != nil {
		return fmt.Errorf("GrabKeyboard: Error grabbing keyboard on "+
			"window '%x': %s", win, err)
	}

	switch reply.Status {
	case xproto.GrabStatusSuccess:
		// all is well
	case xproto.GrabStatusAlreadyGrabbed:
		return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
			"Status: AlreadyGrabbed.")
	case xproto.GrabStatusInvalidTime:
		return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
			"Status: InvalidTime.")
	case xproto.GrabStatusNotViewable:
		return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
			"Status: NotViewable.")
	case xproto.GrabStatusFrozen:
		return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
			"Status: Frozen.")
	}
	return nil
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:31,代碼來源:keybind.go

示例6: NewDrawable

// NewDrawable converts an X drawable into a xgraphics.Image.
// This is used in NewIcccmIcon.
func NewDrawable(X *xgbutil.XUtil, did xproto.Drawable) (*Image, error) {
	// Get the geometry of the pixmap for use in the GetImage request.
	pgeom, err := xwindow.RawGeometry(X, xproto.Drawable(did))
	if err != nil {
		return nil, err
	}

	// Get the image data for each pixmap.
	pixmapData, err := xproto.GetImage(X.Conn(), xproto.ImageFormatZPixmap,
		did,
		0, 0, uint16(pgeom.Width()), uint16(pgeom.Height()),
		(1<<32)-1).Reply()
	if err != nil {
		return nil, err
	}

	// Now create the xgraphics.Image and populate it with data from
	// pixmapData and maskData.
	ximg := New(X, image.Rect(0, 0, pgeom.Width(), pgeom.Height()))

	// We'll try to be a little flexible with the image format returned,
	// but not completely flexible.
	err = readDrawableData(X, ximg, did, pixmapData,
		pgeom.Width(), pgeom.Height())
	if err != nil {
		return nil, err
	}

	return ximg, nil
}
開發者ID:JessonChan,項目名稱:xgbutil,代碼行數:32,代碼來源:new.go

示例7: CreateCursorExtra

// CreateCursorExtra features all available parameters to creating a cursor.
// It will return an error if there is a problem with any of the requests
// made to create the cursor.
// (This implies each request is a checked request. The performance loss is
// probably acceptable since cursors should be created once and reused.)
func CreateCursorExtra(xu *xgbutil.XUtil, cursor, foreRed, foreGreen,
	foreBlue, backRed, backGreen, backBlue uint16) (xproto.Cursor, error) {

	fontId, err := xproto.NewFontId(xu.Conn())
	if err != nil {
		return 0, err
	}

	cursorId, err := xproto.NewCursorId(xu.Conn())
	if err != nil {
		return 0, err
	}

	err = xproto.OpenFontChecked(xu.Conn(), fontId,
		uint16(len("cursor")), "cursor").Check()
	if err != nil {
		return 0, err
	}

	err = xproto.CreateGlyphCursorChecked(xu.Conn(), cursorId, fontId, fontId,
		cursor, cursor+1,
		foreRed, foreGreen, foreBlue,
		backRed, backGreen, backBlue).Check()
	if err != nil {
		return 0, err
	}

	err = xproto.CloseFontChecked(xu.Conn(), fontId).Check()
	if err != nil {
		return 0, err
	}

	return cursorId, nil
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:39,代碼來源:xcursor.go

示例8: Generate

// Generate is just like New, but generates a new X resource id for you.
// Geom is initialized to (0, 0) 1x1.
// It is possible for id generation to return an error, in which case, an
// error is returned here.
func Generate(xu *xgbutil.XUtil) (*Window, error) {
	wid, err := xproto.NewWindowId(xu.Conn())
	if err != nil {
		return nil, err
	}
	return New(xu, wid), nil
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:11,代碼來源:xwindow.go

示例9: PhysicalHeads

// PhyiscalHeads returns the list of heads in a physical ordering.
// Namely, left to right then top to bottom. (Defined by (X, Y).)
// Xinerama must have been initialized, otherwise the xinerama.QueryScreens
// request will panic.
// PhysicalHeads also checks to make sure each rectangle has a unique (x, y)
// tuple, so as not to return the geometry of cloned displays.
// (At present moment, xgbutil initializes Xinerama automatically during
// initial connection.)
func PhysicalHeads(xu *xgbutil.XUtil) (Heads, error) {
	xinfo, err := xinerama.QueryScreens(xu.Conn()).Reply()
	if err != nil {
		return nil, err
	}

	hds := make(Heads, 0)
	for _, info := range xinfo.ScreenInfo {
		head := xrect.New(int(info.XOrg), int(info.YOrg),
			int(info.Width), int(info.Height))

		// Maybe Xinerama is enabled, but we have cloned displays...
		unique := true
		for _, h := range hds {
			if h.X() == head.X() && h.Y() == head.Y() {
				unique = false
				break
			}
		}

		if unique {
			hds = append(hds, head)
		}
	}

	sort.Sort(hds)
	return hds, nil
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:36,代碼來源:xinerama.go

示例10: Grab

// Grab grabs a key with mods on a particular window.
// This will also grab all combinations of modifiers found in xevent.IgnoreMods.
func Grab(xu *xgbutil.XUtil, win xproto.Window,
	mods uint16, key xproto.Keycode) {

	for _, m := range xevent.IgnoreMods {
		xproto.GrabKey(xu.Conn(), true, win, mods|m, key,
			xproto.GrabModeAsync, xproto.GrabModeAsync)
	}
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:10,代碼來源:keybind.go

示例11: RawGeometry

// RawGeometry isn't smart. It just queries the window given for geometry.
func RawGeometry(xu *xgbutil.XUtil, win xproto.Drawable) (xrect.Rect, error) {
	xgeom, err := xproto.GetGeometry(xu.Conn(), win).Reply()
	if err != nil {
		return nil, err
	}
	return xrect.New(int(xgeom.X), int(xgeom.Y),
		int(xgeom.Width), int(xgeom.Height)), nil
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:9,代碼來源:xwindow.go

示例12: clientMessage

func clientMessage(X *xgbutil.XUtil, event xgb.Event) {
	ev := event.(xproto.ClientMessageEvent)
	cookie := xproto.GetAtomName(X.Conn(), ev.Type)
	reply, _ := cookie.Reply()
	log.WithFields(log.Fields{
		"name": reply.Name,
		"data": ev.Data,
	}).Info("client Message:", ev)
}
開發者ID:fangyuanziti,項目名稱:wayland-html,代碼行數:9,代碼來源:xwm.go

示例13: TranslateCoordinatesSync

// translate an X, Y value from one window to the euclidean space of another. Useful for translating
// the arbitrary position of some window's (0,0) point into root window space
func TranslateCoordinatesSync(X *xgbutil.XUtil, src, dest xproto.Window, x, y int) (dest_x, dest_y int, err error) {
	Xx, Xy := int16(x), int16(y)
	cookie := xproto.TranslateCoordinates(X.Conn(), src, dest, Xx, Xy)
	reply, err := cookie.Reply()
	if err != nil {
		return 0, 0, err
	}
	dest_x, dest_y = int(reply.DstX), int(reply.DstY)
	return
}
開發者ID:justjake,項目名稱:j3,代碼行數:12,代碼來源:mouse.go

示例14: FindNextUnderMouse

// wrapper around xproto.QueryPointer that performs a simple synchronous query
func FindNextUnderMouse(X *xgbutil.XUtil, parent xproto.Window) (xproto.Window, *xproto.QueryPointerReply, error) {
	// start query pointer request
	cookie := xproto.QueryPointer(X.Conn(), parent)

	// block and get reply for client
	reply, err := cookie.Reply()
	if err != nil {
		return 0, nil, err
	}
	return reply.Child, reply, nil
}
開發者ID:justjake,項目名稱:j3,代碼行數:12,代碼來源:mouse.go

示例15: currentTime

// currentTime forcefully causes a PropertyNotify event to fire on the root
// window, then scans the event queue and picks up the time.
//
// It is NOT SAFE to call this function in a place other than Wingo's
// initialization. Namely, this function subverts xevent's queue and reads
// events directly from X.
func currentTime(X *xgbutil.XUtil) (xproto.Timestamp, error) {
	wmClassAtom, err := xprop.Atm(X, "WM_CLASS")
	if err != nil {
		return 0, err
	}

	stringAtom, err := xprop.Atm(X, "STRING")
	if err != nil {
		return 0, err
	}

	// Make sure we're listening to PropertyChange events on the root window.
	err = xwindow.New(X, X.RootWin()).Listen(xproto.EventMaskPropertyChange)
	if err != nil {
		return 0, fmt.Errorf(
			"Could not listen to Root window events (PropertyChange): %s", err)
	}

	// Do a zero-length append on a property as suggested by ICCCM 2.1.
	err = xproto.ChangePropertyChecked(
		X.Conn(), xproto.PropModeAppend, X.RootWin(),
		wmClassAtom, stringAtom, 8, 0, nil).Check()
	if err != nil {
		return 0, err
	}

	// Now look for the PropertyNotify generated by that zero-length append
	// and return the timestamp attached to that event.
	// Note that we do this outside of xgbutil/xevent, since ownership
	// is literally the first thing we do after connecting to X.
	// (i.e., we don't have our event handling system initialized yet.)
	timeout := time.After(3 * time.Second)
	for {
		select {
		case <-timeout:
			return 0, fmt.Errorf(
				"Expected a PropertyNotify event to get a valid timestamp, " +
					"but never received one.")
		default:
			ev, err := X.Conn().PollForEvent()
			if err != nil {
				continue
			}
			if propNotify, ok := ev.(xproto.PropertyNotifyEvent); ok {
				X.TimeSet(propNotify.Time) // why not?
				return propNotify.Time, nil
			}
			time.Sleep(100 * time.Millisecond)
		}
	}
	panic("unreachable")
}
開發者ID:mkrull,項目名稱:wingo,代碼行數:58,代碼來源:ownership.go


注:本文中的github.com/BurntSushi/xgbutil.XUtil.Conn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。