Compare commits

...

7 Commits

Author SHA1 Message Date
Sakishum
e4a4700e52
Merge 9aa4059a31 into c07f3f0171 2025-01-27 19:30:45 +08:00
Evans
c07f3f0171
Merge pull request #701 from ronaldpetty/patch-1
Some checks failed
Go / test (macOS-latest) (push) Has been cancelled
Go / test (windows-latest) (push) Has been cancelled
Update README.md
2024-12-10 11:32:09 -08:00
Ronald Petty
0b18fa5058
Update README.md
Added missing import
2024-12-09 19:51:43 -08:00
saki.shen
9aa4059a31 [EDIT] By Saki, replace _AXUIElementGetWindow with AXUIElementCopyAttributeValue 2024-03-19 17:01:07 +08:00
saki.shen
31ddf1a959 [EDIT] By Saki, fixed bug of previous definition 2024-03-19 16:46:34 +08:00
saki.shen
de95edb1a8 [EDIT] By Saki, 去除 _AXUIElementGetWindow 的调用 2024-03-19 16:41:19 +08:00
saki.shen
df394a94b8 [EDIT] By Saki, 去除 robotgo.go 的 window/goWindow.h 2024-03-19 16:16:39 +08:00
3 changed files with 41 additions and 4 deletions

View File

@ -244,6 +244,7 @@ package main
import ( import (
"fmt" "fmt"
"strconv"
"github.com/go-vgo/robotgo" "github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo" "github.com/vcaesar/imgo"

View File

@ -42,7 +42,7 @@ typedef struct _Bounds Bounds;
static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef); static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
static CFStringRef* gkAXTrustedCheckOptionPrompt; static CFStringRef* gkAXTrustedCheckOptionPrompt;
AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out); //AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
static AXUIElementRef GetUIElement(CGWindowID win){ static AXUIElementRef GetUIElement(CGWindowID win){
intptr pid = 0; intptr pid = 0;
// double_t pid = 0; // double_t pid = 0;
@ -90,13 +90,25 @@ typedef struct _Bounds Bounds;
AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i); AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i);
CGWindowID temp = 0; CGWindowID temp = 0;
// Use undocumented API to get WindowID // Use undocumented API to get WindowID
_AXUIElementGetWindow(element, &temp); /*_AXUIElementGetWindow(element, &temp);
if (temp == win) { if (temp == win) {
// Retain element // Retain element
CFRetain(element); CFRetain(element);
result = element; result = element;
break; 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;
}
} }
} }

View File

@ -366,12 +366,12 @@ MData get_active(void) {
AXUIElementRef focused = AXUIElementCreateApplication(pid); AXUIElementRef focused = AXUIElementCreateApplication(pid);
if (focused == NULL) { return result; } // Verify if (focused == NULL) { return result; } // Verify
AXUIElementRef element; /*AXUIElementRef element;
CGWindowID win = 0; CGWindowID win = 0;
// Retrieve the currently focused window // Retrieve the currently focused window
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element) if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element)
== kAXErrorSuccess && element) { == kAXErrorSuccess && element) {
// Use undocumented API to get WID // Use undocumented API to get WID
if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) { if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) {
// Manually set internals // Manually set internals
@ -383,7 +383,31 @@ MData get_active(void) {
} else { } else {
result.CgID = win; result.CgID = win;
result.AxID = element; 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); CFRelease(focused);
return result; return result;