1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package mousebind
import (
x "github.com/linuxdeepin/go-x11-client"
)
func GrabPointer(conn *x.Conn, win x.Window, eventMask uint16, confineTo x.Window, cursor x.Cursor) error {
reply, err := x.GrabPointer(conn, true, win, eventMask,
x.GrabModeAsync, x.GrabModeAsync,
confineTo, cursor, x.CurrentTime).Reply(conn)
if err != nil {
return err
}
if reply.Status == x.GrabStatusSuccess {
return nil
}
return GrabPointerError{reply.Status}
}
type GrabPointerError struct {
Status byte
}
func (err GrabPointerError) Error() string {
const errMsgPrefix = "GrabPointer Failed status: "
switch err.Status {
case x.GrabStatusAlreadyGrabbed:
return errMsgPrefix + "AlreadyGrabbed"
case x.GrabStatusInvalidTime:
return errMsgPrefix + "InvalidTime"
case x.GrabStatusNotViewable:
return errMsgPrefix + "NotViewable"
case x.GrabStatusFrozen:
return errMsgPrefix + "Frozen"
default:
return errMsgPrefix + "Unknown"
}
}
func UngrabPointer(conn *x.Conn) error {
return x.UngrabPointerChecked(conn, x.CurrentTime).Check(conn)
}
|