Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDIT] By Saki, 去除 robotgo.go 的 window/goWindow.h #647

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions window/pub.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct _Bounds Bounds;
static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
static CFStringRef* gkAXTrustedCheckOptionPrompt;

AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
//AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
static AXUIElementRef GetUIElement(CGWindowID win){
intptr pid = 0;
// double_t pid = 0;
Expand Down Expand Up @@ -90,13 +90,25 @@ typedef struct _Bounds Bounds;
AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i);
CGWindowID temp = 0;
// Use undocumented API to get WindowID
_AXUIElementGetWindow(element, &temp);
/*_AXUIElementGetWindow(element, &temp);

if (temp == win) {
// Retain element
CFRetain(element);
result = element;
break;
}*/
CFTypeRef cfWindow = NULL;
if (AXUIElementCopyAttributeValue(element, kAXWindowAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
temp = *(CGWindowID*)CFDataGetBytePtr(cfWindow);
CFRelease(cfWindow);

if (temp == win) {
// Retain element
CFRetain(element);
result = element;
break;
}
}
}

Expand Down
28 changes: 26 additions & 2 deletions window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ MData get_active(void) {
AXUIElementRef focused = AXUIElementCreateApplication(pid);
if (focused == NULL) { return result; } // Verify

AXUIElementRef element;
/*AXUIElementRef element;
CGWindowID win = 0;
// Retrieve the currently focused window
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element)
== kAXErrorSuccess && element) {

// Use undocumented API to get WID
if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) {
// Manually set internals
Expand All @@ -383,7 +383,31 @@ MData get_active(void) {
} else {
result.CgID = win;
result.AxID = element;
}*/

AXUIElementRef windowElement = NULL;
CGWindowID win = 0;

// Retrieve the currently focused window
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &windowElement) == kAXErrorSuccess && windowElement) {
// Use AXUIElementCopyAttributeValue to get parent window
CFTypeRef cfWindow = NULL;
if (AXUIElementCopyAttributeValue(windowElement, kAXParentAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
AXUIElementRef parentWindow = (AXUIElementRef)cfWindow;
if (AXUIElementCopyAttributeValue(parentWindow, kAXWindowAttribute, (CFTypeRef*)&win) == kAXErrorSuccess && win) {
// Manually set internals
result.CgID = win;
result.AxID = windowElement;
} else {
CFRelease(parentWindow);
}
}
CFRelease(windowElement);
} else {
result.CgID = 0;
result.AxID = NULL;
}

CFRelease(focused);

return result;
Expand Down