rentzsch.com: tales from the red shed

-[NSWindow frame] lies

Cocoa

You’d think Cocoa would get right something basic like “what’s the position of this window on the screen?” You’d be mistaken.

-[NSWindow frame] is supposed to return the window’s frame. And it mostly does. Unless you’re dragging a window around, and then it just returns the window’s saved-off drag starting frame, not its actual current frame. Until you stop moving the mouse. Then it’s swell and reports reality again.

Uck.

I wrote a category for NSWindow called -liveFrame. It wraps a Carbon API that reports the window’s current rectangle, like, all! the! time! Those Carbon APIs are so boring.

Here’s the compiled demo app if you want to bask in -frame’s duplicity for yourself. Drag the window around and watch -frame’s numbers not update until you stop moving the mouse. Then revel in -liveFrame’s consistent output sincerity.

Wednesday, October 03, 2007
02:41 PM