Merge pull request #612 from yms2772/master

Fix: panic occurs when current window is minimized on macOS
This commit is contained in:
Evans 2023-09-15 07:21:43 -07:00 committed by GitHub
commit a780825c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -367,11 +367,11 @@ MData get_active(void) {
if (focused == NULL) { return result; } // Verify if (focused == NULL) { return result; } // Verify
AXUIElementRef element; AXUIElementRef element;
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) {
CGWindowID win = 0;
// 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
@ -380,6 +380,9 @@ MData get_active(void) {
} else { } else {
CFRelease(element); CFRelease(element);
} }
} else {
result.CgID = win;
result.AxID = element;
} }
CFRelease(focused); CFRelease(focused);