Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Slate/AccessibilityWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
static AXUIElementRef systemWideElement = NULL;
static NSDictionary *unselectableApps = nil;

// private Apple API; via:
// https://github.com/sdegutis/hydra/blob/fb4ef150f827a5a78fa0b9ba7f75ac4e43d54860/Hydra/API/application.m#L154-L170
typedef int CGSConnectionID;
CG_EXTERN CGSConnectionID CGSMainConnectionID(void);
bool CGSEventIsAppUnresponsive(CGSConnectionID cid, const ProcessSerialNumber *psn);

@implementation AccessibilityWrapper

@synthesize app;
Expand Down Expand Up @@ -211,8 +217,26 @@ + (pid_t)processIdentifierOfUIElement:(AXUIElementRef)element {
}
}

+ (BOOL)appIsUnresponsive:(AXUIElementRef)app {
pid_t pid = [AccessibilityWrapper processIdentifierOfUIElement:app];
if (!pid) {
return true;
}

ProcessSerialNumber psn;
GetProcessForPID(pid, &psn);

CGSConnectionID conn = CGSMainConnectionID();
return CGSEventIsAppUnresponsive(conn, &psn);
}

+ (CFArrayRef)windowsInApp:(AXUIElementRef)app {
[AccessibilityWrapper createSystemWideElement];

if ([AccessibilityWrapper appIsUnresponsive:app]) {
return nil;
}

CFArrayRef _windows;
if (AXUIElementCopyAttributeValues(app, kAXWindowsAttribute, 0, 100, &_windows) == kAXErrorSuccess) {
return _windows;
Expand Down