mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
Merge pull request #447 from go-vgo/bitmap-pr
add GetClient bounds support
This commit is contained in:
commit
ce43fa6621
@ -1401,6 +1401,12 @@ func internalGetBounds(pid int32, hwnd int) (int, int, int, int) {
|
||||
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
|
||||
}
|
||||
|
||||
// internalGetClient get the window client bounds
|
||||
func internalGetClient(pid int32, hwnd int) (int, int, int, int) {
|
||||
bounds := C.get_client(C.uintptr(pid), C.uintptr(hwnd))
|
||||
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
|
||||
}
|
||||
|
||||
// Is64Bit determine whether the sys is 64bit
|
||||
func Is64Bit() bool {
|
||||
b := C.Is64Bit()
|
||||
|
@ -23,6 +23,16 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
return internalGetBounds(pid, hwnd)
|
||||
}
|
||||
|
||||
// GetClient get the window client bounds
|
||||
func GetClient(pid int32, args ...int) (int, int, int, int) {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
}
|
||||
|
||||
return internalGetClient(pid, hwnd)
|
||||
}
|
||||
|
||||
// internalGetTitle get the window title
|
||||
func internalGetTitle(pid int32, args ...int32) string {
|
||||
var isHwnd int32
|
||||
|
@ -44,6 +44,23 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
return internalGetBounds(int32(xid), hwnd)
|
||||
}
|
||||
|
||||
// GetClient get the window client bounds
|
||||
func GetClient(pid int32, args ...int) (int, int, int, int) {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
return internalGetClient(pid, hwnd)
|
||||
}
|
||||
|
||||
xid, err := GetXId(xu, pid)
|
||||
if err != nil {
|
||||
log.Println("Get Xid from Pid errors is: ", err)
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
||||
return internalGetClient(int32(xid), hwnd)
|
||||
}
|
||||
|
||||
// internalGetTitle get the window title
|
||||
func internalGetTitle(pid int32, args ...int32) string {
|
||||
var hwnd int32
|
||||
|
@ -88,22 +88,20 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
||||
AXUIElementRef AxID = AXUIElementCreateApplication(pid);
|
||||
|
||||
// Determine the current point of the window
|
||||
if (AXUIElementCopyAttributeValue(
|
||||
AxID, kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXPositionAttribute, (CFTypeRef*) &axp)
|
||||
!= kAXErrorSuccess || axp == NULL){
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Determine the current size of the window
|
||||
if (AXUIElementCopyAttributeValue(
|
||||
AxID, kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
if (AXUIElementCopyAttributeValue(AxID, kAXSizeAttribute, (CFTypeRef*) &axs)
|
||||
!= kAXErrorSuccess || axs == NULL){
|
||||
goto exit;
|
||||
}
|
||||
|
||||
CGPoint p; CGSize s;
|
||||
// Attempt to convert both values into atomic types
|
||||
if (AXValueGetValue(axp, kAXValueCGPointType, &p) &&
|
||||
if (AXValueGetValue(axp, kAXValueCGPointType, &p) &&
|
||||
AXValueGetValue(axs, kAXValueCGSizeType, &s)){
|
||||
bounds.X = p.x;
|
||||
bounds.Y = p.y;
|
||||
@ -174,8 +172,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
||||
int32_t x = 0, y = 0;
|
||||
|
||||
// Check if the window is the root
|
||||
XQueryTree(rDisplay, win.XWin,
|
||||
&root, &parent, &children, &count);
|
||||
XQueryTree(rDisplay, win.XWin, &root, &parent, &children, &count);
|
||||
if (children) { XFree(children); }
|
||||
|
||||
// Retrieve window attributes
|
||||
@ -183,9 +180,8 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
||||
XGetWindowAttributes(rDisplay, win.XWin, &attr);
|
||||
|
||||
// Coordinates must be translated
|
||||
if (parent != attr.root){
|
||||
XTranslateCoordinates(rDisplay, win.XWin, attr.root, attr.x,
|
||||
attr.y, &x, &y, &parent);
|
||||
if (parent != attr.root) {
|
||||
XTranslateCoordinates(rDisplay, win.XWin, attr.root, attr.x, attr.y, &x, &y, &parent);
|
||||
}
|
||||
// Coordinates can be left alone
|
||||
else {
|
||||
@ -209,7 +205,6 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
||||
hwnd = (HWND)pid;
|
||||
}
|
||||
|
||||
|
||||
RECT rect = { 0 };
|
||||
GetClientRect(hwnd, &rect);
|
||||
|
||||
|
@ -532,13 +532,12 @@ char* named(void *result) {
|
||||
|
||||
char* get_title_by_hand(MData m_data){
|
||||
// Check if the window is valid
|
||||
if (!IsValid()) {return "IsValid failed.";}
|
||||
if (!IsValid()) { return "IsValid failed."; }
|
||||
#if defined(IS_MACOSX)
|
||||
CFStringRef data = NULL;
|
||||
|
||||
// Determine the current title of the window
|
||||
if (AXUIElementCopyAttributeValue(m_data.AxID,
|
||||
kAXTitleAttribute, (CFTypeRef*) &data) == kAXErrorSuccess && data != NULL) {
|
||||
if (AXUIElementCopyAttributeValue(m_data.AxID, kAXTitleAttribute, (CFTypeRef*) &data) ==
|
||||
kAXErrorSuccess && data != NULL) {
|
||||
char conv[512];
|
||||
// Convert result to a C-String
|
||||
CFStringGetCString(data, conv, 512, kCFStringEncodingUTF8);
|
||||
|
Loading…
Reference in New Issue
Block a user