Ejemplo n.º 1
0
func (r *Region) mouseInRegion() bool {
	region := r.GetDockRegion()
	cookie := xproto.QueryPointer(XU.Conn(), XU.RootWin())
	reply, err := cookie.Reply()
	if err != nil {
		return false
	}

	mouseX := int32(reply.RootX - displayRect.X)
	mouseY := int32(reply.RootY - displayRect.Y)

	logger.Debugf("mouse position: (%d, %d)", mouseX, mouseY)

	startX := int32(region.X)
	startY := int32(region.Y)

	endX := startX + int32(region.Width)
	endY := startY + int32(region.Height)

	inHorizontal := startX <= mouseX && mouseX <= endX
	inVertical := startY <= mouseY && mouseY <= endY
	inRegion := inHorizontal && inVertical

	return inRegion
}
Ejemplo n.º 2
0
func (cmd Focus) Run() gribble.Value {
	return syncRun(func() gribble.Value {
		return withClient(cmd.Client, func(c *xclient.Client) {
			if c == nil {
				focus.Root()

				// Use the mouse coordinates to find which workspace it was
				// clicked in. If a workspace can be found (i.e., no clicks in
				// dead areas), then activate it.
				xc, rw := wm.X.Conn(), wm.X.RootWin()
				qp, err := xproto.QueryPointer(xc, rw).Reply()
				if err != nil {
					logger.Warning.Printf("Could not query pointer: %s", err)
					return
				}

				geom := xrect.New(int(qp.RootX), int(qp.RootY), 1, 1)
				if wrk := wm.Heads.FindMostOverlap(geom); wrk != nil {
					wm.SetWorkspace(wrk, false)
				}
			} else {
				c.Focus()
				xevent.ReplayPointer(wm.X)
			}
		})
	})
}
Ejemplo n.º 3
0
Archivo: mouse.go Proyecto: justjake/j3
// 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
}
Ejemplo n.º 4
0
Archivo: root.go Proyecto: mkrull/wingo
func handleMotionNotify(X *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
	qp, err := xproto.QueryPointer(X.Conn(), X.RootWin()).Reply()
	if err != nil {
		logger.Warning.Printf("Could not query pointer: %s", err)
		return
	}

	geom := xrect.New(int(qp.RootX), int(qp.RootY), 1, 1)
	if wrk := wm.Heads.FindMostOverlap(geom); wrk != nil {
		if wrk != wm.Workspace() {
			wm.SetWorkspace(wrk, false)
			wm.FocusFallback()
		}
	}
}
Ejemplo n.º 5
0
func (k *workspace) makeList() {
	switch k.listing {
	case listWindows:
		k.list = k.makeWindowList()
	case listWorkspaces:
		k.list = k.makeWorkspaceList()
	default:
		k.list = nil
	}
	k.index = -1
	if len(k.list) != 0 {
		if p, err := xp.QueryPointer(xConn, rootXWin).Reply(); err != nil {
			log.Println(err)
		} else if p != nil {
			k.index = k.indexForPoint(p.RootX, p.RootY)
		}
	}
	k.configure()
	k.screen.repaint()
}
Ejemplo n.º 6
0
func unmanage(xWin xp.Window) {
	w := findWindow(func(w *window) bool { return w.xWin == xWin })
	if w == nil {
		return
	}
	if quitting && findWindow(func(w *window) bool { return true }) == nil {
		os.Exit(0)
	}
	if w.hasTransientFor {
		for {
			w1 := findWindow(func(w2 *window) bool { return w2.transientFor == w })
			if w1 == nil {
				break
			}
			w1.transientFor = nil
		}
	}
	if f := w.frame; f != nil {
		k := f.workspace
		replacement := (*window)(nil)
		if w.transientFor != nil && w.transientFor.frame == nil {
			replacement = w.transientFor
		} else {
			bestOffscreenSeqNum := uint32(0)
			for w1 := w.link[next]; w1 != w; w1 = w1.link[next] {
				if w1.offscreenSeqNum <= bestOffscreenSeqNum {
					continue
				}
				if k.fullscreen {
					if w1.frame == k.focusedFrame {
						continue
					}
				} else if w1.frame != nil {
					continue
				}
				replacement, bestOffscreenSeqNum = w1, w1.offscreenSeqNum
			}
		}
		if replacement != nil {
			if f0 := replacement.frame; f0 != nil {
				f0.window, replacement.frame = nil, nil
			}
			f.window, replacement.frame = replacement, f
			replacement.configure()
			if p, err := xp.QueryPointer(xConn, rootXWin).Reply(); err != nil {
				log.Println(err)
			} else if p != nil && contains(f.rect, p.RootX, p.RootY) {
				focus(replacement)
			}
		} else {
			f.window = nil
			if k.fullscreen && f == k.focusedFrame {
				doFullscreen(k, nil)
			}
		}
	}
	w.link[next].link[prev] = w.link[prev]
	w.link[prev].link[next] = w.link[next]
	*w = window{}
	makeLists()
	pulseChan <- time.Now()
}
Ejemplo n.º 7
0
func manage(xWin xp.Window, mapRequest bool) {
	callFocus := false
	w := findWindow(func(w *window) bool { return w.xWin == xWin })
	if w == nil {
		wmDeleteWindow, wmTakeFocus := false, false
		if prop, err := xp.GetProperty(xConn, false, xWin, atomWMProtocols,
			xp.GetPropertyTypeAny, 0, 64).Reply(); err != nil {
			log.Println(err)
		} else if prop != nil {
			for v := prop.Value; len(v) >= 4; v = v[4:] {
				switch xp.Atom(u32(v)) {
				case atomWMDeleteWindow:
					wmDeleteWindow = true
				case atomWMTakeFocus:
					wmTakeFocus = true
				}
			}
		}

		transientFor := (*window)(nil)
		if prop, err := xp.GetProperty(xConn, false, xWin, atomWMTransientFor,
			xp.GetPropertyTypeAny, 0, 64).Reply(); err != nil {
			log.Println(err)
		} else if prop != nil {
			if v := prop.Value; len(v) == 4 {
				transientForXWin := xp.Window(u32(v))
				transientFor = findWindow(func(w *window) bool {
					return w.xWin == transientForXWin
				})
			}
		}

		k := screens[0].workspace
		if p, err := xp.QueryPointer(xConn, rootXWin).Reply(); err != nil {
			log.Println(err)
		} else if p != nil {
			k = screenContaining(p.RootX, p.RootY).workspace
		}
		w = &window{
			transientFor: transientFor,
			xWin:         xWin,
			rect: xp.Rectangle{
				X:      offscreenXY,
				Y:      offscreenXY,
				Width:  1,
				Height: 1,
			},
			wmDeleteWindow: wmDeleteWindow,
			wmTakeFocus:    wmTakeFocus,
		}
		f := k.focusedFrame
		previous := k.dummyWindow.link[prev]
		if transientFor != nil {
			previous = transientFor
		} else if f.window != nil {
			previous = f.window
		}
		w.link[next] = previous.link[next]
		w.link[prev] = previous
		w.link[next].link[prev] = w
		w.link[prev].link[next] = w

		if transientFor != nil && transientFor.frame != nil {
			f = transientFor.frame
			f.window, transientFor.frame = nil, nil
		} else if f.window != nil {
			f = k.mainFrame.firstEmptyFrame()
		}
		if f != nil {
			f.window, w.frame = w, f
			callFocus = f == k.focusedFrame
		} else {
			pulseChan <- time.Now()
		}

		check(xp.ChangeWindowAttributesChecked(xConn, xWin, xp.CwEventMask,
			[]uint32{xp.EventMaskEnterWindow | xp.EventMaskStructureNotify},
		))
		w.configure()
		if transientFor != nil {
			transientFor.hasTransientFor = true
			transientFor.configure()
		}
	}
	if mapRequest {
		check(xp.MapWindowChecked(xConn, xWin))
	}
	if callFocus {
		focus(w)
	}
	makeLists()
	pulseChan <- time.Now()
}