mirror of
https://github.com/go-vgo/robotgo
synced 2026-05-24 02:08:33 +00:00
optimize robot unix getxid func
This commit is contained in:
parent
5984aad7bc
commit
b4fffb3d06
2 changed files with 22 additions and 25 deletions
|
|
@ -32,16 +32,7 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
|||
return internalGetBounds(pid, hwnd)
|
||||
}
|
||||
|
||||
if xu == nil {
|
||||
var err error
|
||||
xu, err = xgbutil.NewConn()
|
||||
if err != nil {
|
||||
log.Println("xgbutil.NewConn errors is: ", err)
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
|
||||
xid, err := GetXidFromPid(xu, pid)
|
||||
xid, err := GetXId(xu, pid)
|
||||
if err != nil {
|
||||
log.Println("GetXidFromPid errors is: ", err)
|
||||
return 0, 0, 0, 0
|
||||
|
|
@ -61,16 +52,7 @@ func ActivePIDC(pid int32, args ...int) {
|
|||
return
|
||||
}
|
||||
|
||||
if xu == nil {
|
||||
var err error
|
||||
xu, err = xgbutil.NewConn()
|
||||
if err != nil {
|
||||
log.Println("xgbutil.NewConn errors is: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
xid, err := GetXidFromPid(xu, pid)
|
||||
xid, err := GetXId(xu, pid)
|
||||
if err != nil {
|
||||
log.Println("GetXidFromPid errors is: ", err)
|
||||
return
|
||||
|
|
@ -114,6 +96,21 @@ func ActivePID(pid int32, args ...int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetXId get the xid
|
||||
func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||
if xu == nil {
|
||||
var err error
|
||||
xu, err = xgbutil.NewConn()
|
||||
if err != nil {
|
||||
// log.Println("xgbutil.NewConn errors is: ", err)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
xid, err := GetXidFromPid(xu, pid)
|
||||
return xid, err
|
||||
}
|
||||
|
||||
// GetXidFromPid get the xide from pid
|
||||
func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||
windows, err := ewmh.ClientListGet(xu)
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||
|
||||
// Determine the current point of the window
|
||||
if (AXUIElementCopyAttributeValue(AxID,
|
||||
kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
!= kAXErrorSuccess || axp == NULL){
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Determine the current size of the window
|
||||
if (AXUIElementCopyAttributeValue(AxID,
|
||||
kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
!= kAXErrorSuccess || axs == NULL){
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -36,9 +36,9 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||
bounds.W = s.width;
|
||||
bounds.H = s.height;
|
||||
}
|
||||
|
||||
exit:
|
||||
if (axp != NULL) { CFRelease(axp); }
|
||||
|
||||
exit:
|
||||
if (axp != NULL) { CFRelease(axp); }
|
||||
if (axs != NULL) { CFRelease(axs); }
|
||||
|
||||
return bounds;
|
||||
|
|
|
|||
Loading…
Reference in a new issue