On Apr 4, 2013, at 10:56 AM, Patrick Cusack < email@hidden> wrote: When you observe a different process, I would certainly expect that you'd get the kAXMenuOpenedNotification immediately when the other process opens a contextual menu. Is that not the case for you?
No, its not. I add an observer notication (kAXMenuOpenedNotification) for another application's axuielementref. When the other application's menu opens, its only when the menu closes that I receive the callback, at which point, it is has been destroyed.
if I call:
if (AXUIElementPerformAction((AXUIElementRef)child, kAXShowMenuAction) != kAXErrorSuccess) { LOGSELECTORERROR; } I only see the notification callback when the menu disappears.
I think I'm beginning to understand…
So we have two processes here, A and B. A is your app. B is the process you're observing.
Is the AXUIElementPerformAction(kAXShowMenuAction) your code in process A to trigger process B to display its contextual menu?
If so, what happens if you just use a right-click with the mouse to display the contextual menu in process B? Do you get the MenuOpened notification callback in process A immediately in that case, as soon as the menu opens?
If so, then I think what's happening is just that the AXUIElementPerformAction in process A is blocking while it waits for process B to perform the action - that is, display the menu. No notifications will be delivered until that blocking routine returns, which doesn't happen until process B closes the menu.
However, if perform the kAXShowMenuAction using another queue, I get the call back immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0UL), ^{ if (AXUIElementPerformAction((AXUIElementRef)child, kAXShowMenuAction) != kAXErrorSuccess) { LOGSELECTORERROR; } });
That seems reasonable, assuming that AXUIElementPerformAction is sufficiently thread-safe or that you're not making any other Accessibility API calls at the same time.
Greg - do you think the AX framework implementation is thread-safe enough to handle usage from a secondary thread?
-eric
|