示例#1
0
文件: get.go 项目: BurntSushi/wingo
func (cmd GetActive) Run() gribble.Value {
	reply, err := xproto.GetInputFocus(wm.X.Conn()).Reply()
	if err != nil {
		logger.Warning.Printf("Could not get input focus: %s", err)
		return 0
	}

	// If our dummy window has focus, then it's equivalent to having root
	// window focus.
	// XXX: This may not be right if we're in a DE with desktop windows...
	if reply.Focus == wm.X.Dummy() {
		return 0
	}
	if focused := wm.LastFocused(); focused != nil {
		client := focused.(*xclient.Client)
		return int(client.Id())
	}
	return 0
}
示例#2
0
func Focused(c *xgb.Conn) uint32 {
	incookie := xproto.GetInputFocus(c)
	rep, err := incookie.Reply()
	if err != nil {
		return 0
	}
	win := rep.Focus

	trcookie := xproto.TranslateCoordinates(c, win,
		xproto.Setup(c).DefaultScreen(c).Root,
		0, 0)
	att, err := trcookie.Reply()
	if err != nil {
		return 0
	}
	x, y := int32(att.DstX), int32(att.DstY)

	for i, size := range sizes {
		if size.X <= x && size.X+size.W >= x && size.Y <= y && size.Y+size.H >= y {
			return uint32(i)
		}
	}
	return 0
}
示例#3
0
// Sync forces XGB to catch up with all events/requests and synchronize.
// This is done by issuing a benign round trip request to X.
func (xu *XUtil) Sync() {
	xproto.GetInputFocus(xu.Conn()).Reply()
}