Beispiel #1
0
func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Create window for receiving compressed MotionNotify events.
	cwin := newWindow(X, 0x00ff00)

	// Attach event handler for MotionNotify that compresses events.
	xevent.MotionNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
			ev = compressMotionNotify(X, ev)
			fmt.Printf("COMPRESSED: (EventX %d, EventY %d)\n",
				ev.EventX, ev.EventY)
			time.Sleep(workTime)
		}).Connect(X, cwin.Id)

	// Create window for receiving uncompressed MotionNotify events.
	uwin := newWindow(X, 0xff0000)

	// Attach event handler for MotionNotify that does not compress events.
	xevent.MotionNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
			fmt.Printf("UNCOMPRESSED: (EventX %d, EventY %d)\n",
				ev.EventX, ev.EventY)
			time.Sleep(workTime)
		}).Connect(X, uwin.Id)

	xevent.Main(X)
}
Beispiel #2
0
// Drag is the public interface that will make the appropriate connections
// to register a drag event for three functions: the begin function, the
// step function and the end function.
// The 'grabwin' is the window that the grab is placed on (and therefore the
// window where all button events are redirected to after the drag has started),
// and the 'win' is the window that the initial 'begin' callback is set on.
// In typical use cases, these windows should be the same.
// If 'grab' is false, then no pointer grab is issued.
func Drag(xu *xgbutil.XUtil, grabwin xproto.Window, win xproto.Window,
	buttonStr string, grab bool,
	begin xgbutil.MouseDragBeginFun, step xgbutil.MouseDragFun,
	end xgbutil.MouseDragFun) {

	ButtonPressFun(
		func(xu *xgbutil.XUtil, ev xevent.ButtonPressEvent) {
			dragBegin(xu, ev, grabwin, win, begin, step, end)
		}).Connect(xu, win, buttonStr, false, grab)

	// If the grab win isn't the dummy, then setup event handlers for the
	// grab window.
	if grabwin != xu.Dummy() {
		xevent.MotionNotifyFun(dragStep).Connect(xu, grabwin)
		xevent.ButtonReleaseFun(dragEnd).Connect(xu, grabwin)
	}
}
Beispiel #3
0
// Initialize attaches the appropriate callbacks to make mouse bindings easier.
// i.e., prep the dummy window to handle mouse dragging events
func Initialize(xu *xgbutil.XUtil) {
	xevent.MotionNotifyFun(dragStep).Connect(xu, xu.Dummy())
	xevent.ButtonReleaseFun(dragEnd).Connect(xu, xu.Dummy())
}