Helium Foot Software

Making your Mac more agile, more powerful and more fun

August 2008
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
About
Helium Foot Software develops MercuryMover: Don't let the mouse slow you down! Move and resize windows on your Mac with the keyboard.
Recent Entries
MercuryMover v2.0 Beta(08/21 22:05)
Off of the Bus(08/15 10:45)
Short(cut) time(08/14 12:11)
Shortcuts and Setbacks(08/13 09:47)
Short(cut) update(08/12 09:59)
Week[0](08/11 09:44)
Episode Two: Attack of the Podcast(08/03 21:02)
Big Day(07/29 23:14)
Going Global(07/17 20:58)
I (NS)Screen, You (NS)Screen(07/07 01:26)
Recent Comments
Re: Off of the Bus(Chad : 08/22 23:14)
Re: Off of the Bus(kalperin : 08/18 13:51)
Re: Off of the Bus(Chad : 08/15 20:16)
Re: Episode Two: Attack of the Podcast(Evan : 08/04 11:40)
Re: Going Global(keith alperin : 07/25 14:36)
Re: Going Global(Mark Schulman : 07/22 18:52)
Re: I (NS)Screen, You (NS)Screen(Howard Lovatt : 07/11 00:57)
Re: I (NS)Screen, You (NS)Screen(E : 07/07 09:43)
Re: MercuryMover v1.1.3 is Out(kalperin : 06/25 01:21)
Re: MercuryMover v1.1.3 is Out(Elgorf : 06/25 00:11)
Recent Trackbacks
There are no trackbacks.
Categories
Helium Foot (14 items)
Software (4 items)
MercuryMover (33 items)
Blog (3 items)
MacSanta (3 items)
Marketing (10 items)
Philanthropy (0 items)
Podcasts (2 items)
Archives
Blogroll

Syndicate this site (XML)

RSS/RDF 0.91

07 July
2008

I (NS)Screen, You (NS)Screen

Where Keith fixes a longstanding bug

A problem that has dogged me with MercuryMover since the beginning is getting MercuryMover to recognize where the edges of the screen are when using two displays in a top-to-bottom configuration. (If using your mouse to move and resize windows is dogging you then try MercuryMover!) Having promised a user that this would be fixed in the upcoming v2.0 release, i finally had to sit down and figure it out. The crux of the problem is that while the NSScreen API dutifully returns the dimensions of any screen as an NSRect, and the Accessibility API lets us determine the position and size of any window (by copying the values to an NSRect), these two operations return NSRects in different coordinate systems. The NSScreen API returns a coordinate system where the bottom left corner of the main screen is 0,0 with the y axis going up. Accessibility however treats the top left corner of the main screen as 0,0 with the y axis going down. While the latter seems more sensible to me, i don't claim to be smarter than the engineers at apple (quite the contrary!) so it's not for me to question, but to convert. Fortunately, those same Apple engineers (the royal Apple Engineers, the editorial Apple Engineers) provide us with a mechanism to transform one coordinate system to another. Using NSAffineTransform, we can specify a transformation like so:

	NSAffineTransform* coordinateFlipper = [NSAffineTransform transform];
	[coordinateFlipper translateXBy:0.0 yBy:frameOfMainScreen.size.height];
	[coordinateFlipper scaleXBy:1.0 yBy:-1.0];
	[coordinateFlipper concat];	
There's more than meets the eye here. This transformer will take a point and let us work with it as if its origin were push up the y axis by the an amount equal to the height of the main screen:
 
	[coordinateFlipper translateXBy:0.0 yBy:frameOfMainScreen.size.height];
This accounts for the fact that the two coordinate systems have origins on opposite left hand corners. Secondly, this guy will change the direction that the y axis counts (numbers getting bigger as you move down the screen, instead of up):
 
	[coordinateFlipper scaleXBy:1.0 yBy:-1.0];
Now, i can transform the origin of my key window (the one that MercuryMover is controlling):
	NSRect flippedRectOfKeyWindow = rectOfKeyWindow;
	flippedRectOfKeyWindow.origin = 
		[coordinateFlipper transformPoint:flippedRectOfKeyWindow.origin];
and my coordinate systems line up.

Posted by kalperin at 01:26 | Comments (2)
<< Strong-ish finish | Main | Going Global >>
Comments
Re: I (NS)Screen, You (NS)Screen

Yasher koach : )

Posted by: E at July 07,2008 09:43
Re: I (NS)Screen, You (NS)Screen

On a related issue. I use a Mac Book Pro (MBP) and when at my desk connect an external screen. With coming and going to meetings I am continually putting the MBP to sleep and waking it with a different screen size. OS X doesn't do a great job of coping with this and often puts stuff off screen. So I thought a nice feature for MM would be a screen sanity command which gets all of all of the windows on screen.

Posted by: Howard Lovatt at July 11,2008 00:57
Post a comment