mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
add internalGetBounds and x11 getXidFromPid to GetBounds
This commit is contained in:
parent
5c7cc1fb1d
commit
8f8937daad
@ -1398,13 +1398,8 @@ func GetPID() int32 {
|
||||
return int32(pid)
|
||||
}
|
||||
|
||||
// GetBounds get the window bounds
|
||||
func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
}
|
||||
|
||||
// internalGetBounds get the window bounds
|
||||
func internalGetBounds(pid int32, hwnd int) (int, int, int, int) {
|
||||
bounds := C.get_bounds(C.uintptr(pid), C.uintptr(hwnd))
|
||||
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
|
||||
}
|
||||
|
@ -12,6 +12,16 @@
|
||||
|
||||
package robotgo
|
||||
|
||||
// GetBounds get the window bounds
|
||||
func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
}
|
||||
|
||||
return internalGetBounds(pid, hwnd)
|
||||
}
|
||||
|
||||
// ActivePID active the window by PID,
|
||||
// If args[0] > 0 on the Windows platform via a window handle to active
|
||||
func ActivePID(pid int32, args ...int) error {
|
||||
|
@ -23,6 +23,33 @@ import (
|
||||
|
||||
var xu *xgbutil.XUtil
|
||||
|
||||
// GetBounds get the window bounds
|
||||
func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
log.Println("GetXidFromPid errors is: ", err)
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
||||
internalGetBounds(int32(xid), hwnd)
|
||||
}
|
||||
|
||||
// ActivePIDC active the window by PID,
|
||||
// If args[0] > 0 on the unix platform via a xid to active
|
||||
func ActivePIDC(pid int32, args ...int) {
|
||||
@ -73,6 +100,7 @@ func ActivePID(pid int32, args ...int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// get xid from pid
|
||||
xid, err := GetXidFromPid(xu, pid)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -103,5 +131,5 @@ func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return 0, errors.New("failed to find a window with a matching pid")
|
||||
return 0, errors.New("failed to find a window with a matching pid.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user