Example #1
0
ax_application *AXLibGetFocusedApplication()
{
    local_persist AXUIElementRef SystemWideElement = AXUIElementCreateSystemWide();
    AXUIElementRef Ref = (AXUIElementRef) AXLibGetWindowProperty(SystemWideElement, kAXFocusedApplicationAttribute);

    if(Ref)
    {
        pid_t PID;
        AXUIElementGetPid(Ref, &PID);
        CFRelease(Ref);

        if(AXLibIsApplicationCached(PID))
            return &(*AXApplications)[PID];
    }

    return NULL;
}
Example #2
0
AXError AXUIElementCopyWindowAtPosition(CGPoint position, AXUIElementRef *window) {

    *window = NULL;

    AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
    AXUIElementRef element = NULL;
    CFStringRef role = NULL;

    // First, retrieve the element at the given position.
    AXError error = AXUIElementCopyElementAtPosition(systemWideElement,
                                                     position.x,
                                                     position.y,
                                                     &element);

    if (error != kAXErrorSuccess)
        goto end;

    // If this element is a window, return it.
    error = AXUIElementCopyAttributeValue(element,
                                          kAXRoleAttribute,
                                          (CFTypeRef *) &role);
    if (error != kAXErrorSuccess)
        goto end;

    if (CFStringCompare(role, kAXWindowRole, 0) == kCFCompareEqualTo) {
        *window = element;
        CFRetain(*window);
        goto end;
    }

    // Otherwise, return the window attribute.
    error = AXUIElementCopyAttributeValue(element,
                                          kAXWindowAttribute,
                                          (CFTypeRef *)window);

end:
    CFRelease(systemWideElement);
    if (element != NULL)
        CFRelease(element);
    if (role != NULL)
        CFRelease(role);
    return error;
}
Example #3
0
/* TODO(koekeishiya): Required for compatibility with current Kwm code */
bool AXLibGetFocusedWindow(AXUIElementRef *WindowRef)
{
    local_persist AXUIElementRef SystemWideElement = AXUIElementCreateSystemWide();
    AXUIElementRef Application = (AXUIElementRef) AXLibGetWindowProperty(SystemWideElement, kAXFocusedApplicationAttribute);

    if(Application)
    {
        AXUIElementRef AppWindowRef = (AXUIElementRef) AXLibGetWindowProperty(Application, kAXFocusedWindowAttribute);
        CFRelease(Application);

        if(AppWindowRef)
        {
            *WindowRef = AppWindowRef;
            return true;
        }
    }

    return false;
}