mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
optimize robot unix getxid func
This commit is contained in:
parent
5984aad7bc
commit
b4fffb3d06
@ -32,16 +32,7 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
|||||||
return internalGetBounds(pid, hwnd)
|
return internalGetBounds(pid, hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if xu == nil {
|
xid, err := GetXId(xu, pid)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("GetXidFromPid errors is: ", err)
|
log.Println("GetXidFromPid errors is: ", err)
|
||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
@ -61,16 +52,7 @@ func ActivePIDC(pid int32, args ...int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if xu == nil {
|
xid, err := GetXId(xu, pid)
|
||||||
var err error
|
|
||||||
xu, err = xgbutil.NewConn()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("xgbutil.NewConn errors is: ", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xid, err := GetXidFromPid(xu, pid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("GetXidFromPid errors is: ", err)
|
log.Println("GetXidFromPid errors is: ", err)
|
||||||
return
|
return
|
||||||
@ -114,6 +96,21 @@ func ActivePID(pid int32, args ...int) error {
|
|||||||
return nil
|
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
|
// GetXidFromPid get the xide from pid
|
||||||
func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||||
windows, err := ewmh.ClientListGet(xu)
|
windows, err := ewmh.ClientListGet(xu)
|
||||||
|
@ -15,14 +15,14 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||||||
|
|
||||||
// Determine the current point of the window
|
// Determine the current point of the window
|
||||||
if (AXUIElementCopyAttributeValue(AxID,
|
if (AXUIElementCopyAttributeValue(AxID,
|
||||||
kAXPositionAttribute, (CFTypeRef*) &axp)
|
kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||||
!= kAXErrorSuccess || axp == NULL){
|
!= kAXErrorSuccess || axp == NULL){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the current size of the window
|
// Determine the current size of the window
|
||||||
if (AXUIElementCopyAttributeValue(AxID,
|
if (AXUIElementCopyAttributeValue(AxID,
|
||||||
kAXSizeAttribute, (CFTypeRef*) &axs)
|
kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||||
!= kAXErrorSuccess || axs == NULL){
|
!= kAXErrorSuccess || axs == NULL){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -36,9 +36,9 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||||||
bounds.W = s.width;
|
bounds.W = s.width;
|
||||||
bounds.H = s.height;
|
bounds.H = s.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (axp != NULL) { CFRelease(axp); }
|
if (axp != NULL) { CFRelease(axp); }
|
||||||
if (axs != NULL) { CFRelease(axs); }
|
if (axs != NULL) { CFRelease(axs); }
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
|
Loading…
Reference in New Issue
Block a user