From 9aa4059a31d57d31338b45aba1251468975807f4 Mon Sep 17 00:00:00 2001 From: "saki.shen" Date: Tue, 19 Mar 2024 17:01:07 +0800 Subject: [PATCH] [EDIT] By Saki, replace _AXUIElementGetWindow with AXUIElementCopyAttributeValue --- window/pub.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/window/pub.h b/window/pub.h index af1158b..b8a941a 100644 --- a/window/pub.h +++ b/window/pub.h @@ -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; @@ -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; + } } }