// Lock grabs the keyboard and pointer locking the X11 display func Lock(X *xgb.Conn) error { screen := xproto.Setup(X).DefaultScreen(X) passEventsToOwner := false kbCookie := xproto.GrabKeyboard(X, passEventsToOwner, screen.Root, xproto.TimeCurrentTime, xproto.GrabModeAsync, xproto.GrabModeAsync) kbReply, err := kbCookie.Reply() if err != nil { return err } if kbReply.Status != xproto.GrabStatusSuccess { return fmt.Errorf("GrabKeyboard status %v", grabStatus(kbReply.Status)) } ptrCookie := xproto.GrabPointer(X, passEventsToOwner, screen.Root, 0, xproto.GrabModeAsync, xproto.GrabModeAsync, xproto.AtomNone, xproto.AtomNone, xproto.TimeCurrentTime) ptrReply, err := ptrCookie.Reply() if err != nil { xproto.UngrabKeyboard(X, xproto.TimeCurrentTime) return err } if ptrReply.Status != xproto.GrabStatusSuccess { return fmt.Errorf("GrabPointer status %v", grabStatus(kbReply.Status)) } return nil }
// UngrabKeyboard undoes GrabKeyboard. func UngrabKeyboard(xu *xgbutil.XUtil) { xproto.UngrabKeyboard(xu.Conn(), 0) }
// Unlock restores user control of keyboard and pointer func Unlock(X *xgb.Conn) { xproto.UngrabKeyboard(X, xproto.TimeCurrentTime) xproto.UngrabPointer(X, xproto.TimeCurrentTime) }