Re: AXPosition and AXSize during window drags CORRECTED
Re: AXPosition and AXSize during window drags CORRECTED
- Subject: Re: AXPosition and AXSize during window drags CORRECTED
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 27 Nov 2007 07:50:33 -0500
- Thread-topic: AXPosition and AXSize during window drags CORRECTED
on 2007-11-26 12:13 PM, Bill Cheeseman at email@hidden wrote:
> When my event tap's delegate method fires repeatedly while the target window
> is being dragged or resized, I reset the frame of the overlay window by
> getting the new bounds of the target window, using the saved CGWindowID.
>
> - (void)eventTap:(PFEventTap *)tap didPostEvent:(PFEvent *)event {
> // Delegate method per PFEventTap to monitor left mouse dragged, mouse
> down and mouse up events, in order to move and resize the highlighting
> overlay window synchronously with the underlying highlighted UI element.
> NSRect highlightRect = NSZeroRect;
> NSArray *windowNumbers = [NSArray arrayWithObject:(void *)[self
> highlightedWindowNumber]]; // windowNumber is pointer
> NSArray *windowList = (NSArray
> *)CGWindowListCreateDescriptionFromArray((CFArrayRef)windowNumbers);
The above excerpt from the code I posted yesterday isn't quite right. This
line...
NSArray *targetWindowNumberArray = [NSArray arrayWithObject:(void
*)[self highlightedWindowNumber]]; // CGWindowID is address
...should be replaced by these lines:
CGWindowID windowID = [self highlightedWindowNumber];
CGWindowID *windowIDs = calloc(1, sizeof(CGWindowID));
windowIDs[0] = windowID;
NSArray *targetWindowNumberArray = (NSArray
*)CFArrayCreate(kCFAllocatorDefault, (const void**)windowIDs, 1, NULL);
free(windowIDs);
The original line worked sometimes but failed sometimes.
I derived the replacement lines from the new Leopard "Son of Grab" sample
code on the Apple Developer site, where this technique is used and explained
with the CGWindow function CGWindowListCreateImageFromArray(), which is
analogous to the CGWindowListCreateDescriptionFromArray() function I use.
The issue is that the CGWindow API expects an array of CGWindowID, which is
a uint32_t number, not a CFNumberRef or NSNumber object. Cocoa array
creation methods don't let me force the number into an array without
occasional retain/release problems, but the CFArrayCreate() function does
allow this by passing NULL in the last parameter.
This technique is also explained at
<http://shiftedbits.org/category/leopard/>.
I wonder why these CGWindow functions were written to require a CFArrayRef
containing uint32_t numbers instead of CFNumberRef objects. Is it just a
mistake, or is there some benefit to it? I never would have figured out how
to code this without the sample code or the shiftedbits blog.
The CGWindow.h header defines a CFNumberRef encoding constant for CGWindowID
numbers, but, oddly, it seems to refer to a signed integer whereas
CGWindowID is declared as an unsigned integer. At this point I haven't
actually attempted to create a CFNumberRef object for the CGWindowID using
this constant, then putting the CFNumberRef object into the array passed to
CGWindowListCreateDescriptionFromArray(). The fact that the sample code and
blog don't do that suggests I would be wasting my time, but who knows?
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden