* Source/NSScreen.m: Read -userSpaceScaleFactor from the GSScaleFactor

user default.
* Source/GSWindowDecorationView.m: Apply -[NSScreen userSpaceScaleFactor]
in +frameRectForContentRect and +contentRectForFrameRect, as well as
setting a scaled bounds size in -layout.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@32898 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-04-19 08:42:59 +00:00
parent 899b4e5139
commit 5d40709f7d
3 changed files with 67 additions and 11 deletions

View file

@ -1,3 +1,11 @@
2011-04-19 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSScreen.m: Read -userSpaceScaleFactor from the GSScaleFactor
user default.
* Source/GSWindowDecorationView.m: Apply -[NSScreen userSpaceScaleFactor]
in +frameRectForContentRect and +contentRectForFrameRect, as well as
setting a scaled bounds size in -layout.
2011-04-18 Eric Wasylishen <ewasylishen@gmail.com> 2011-04-18 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSWindow.m: Remove unnecessary FIXMEs related to * Source/NSWindow.m: Remove unnecessary FIXMEs related to

View file

@ -31,6 +31,7 @@
#import "AppKit/NSColor.h" #import "AppKit/NSColor.h"
#import "AppKit/NSGraphics.h" #import "AppKit/NSGraphics.h"
#import "AppKit/NSMenuView.h" #import "AppKit/NSMenuView.h"
#import "AppKit/NSScreen.h"
#import "AppKit/NSWindow.h" #import "AppKit/NSWindow.h"
#import "GNUstepGUI/GSDisplayServer.h" #import "GNUstepGUI/GSDisplayServer.h"
#import "GNUstepGUI/GSTheme.h" #import "GNUstepGUI/GSTheme.h"
@ -39,6 +40,14 @@
@implementation GSWindowDecorationView @implementation GSWindowDecorationView
static inline NSRect RectWithSizeScaledByFactor(NSRect aRect, CGFloat factor)
{
return NSMakeRect(aRect.origin.x,
aRect.origin.y,
aRect.size.width * factor,
aRect.size.height * factor);
}
+ (id<GSWindowDecorator>) windowDecorator + (id<GSWindowDecorator>) windowDecorator
{ {
if ([GSCurrentServer() handlesWindowDecorations]) if ([GSCurrentServer() handlesWindowDecorations])
@ -72,7 +81,16 @@
aRect.size.height -= t + b; aRect.size.height -= t + b;
aRect.origin.x += l; aRect.origin.x += l;
aRect.origin.y += b; aRect.origin.y += b;
return aRect;
if (0 == (aStyle & NSUnscaledWindowMask))
{
// FIXME: This method should probably take a screen parameter
// rather than assuming the mainScreen
CGFloat factor = [[NSScreen mainScreen] userSpaceScaleFactor];
aRect = RectWithSizeScaledByFactor(aRect, 1/factor);
}
return aRect;
} }
+ (NSRect) frameRectForContentRect: (NSRect)aRect + (NSRect) frameRectForContentRect: (NSRect)aRect
@ -81,10 +99,20 @@
float t = 0.0, b = 0.0, l = 0.0, r = 0.0; float t = 0.0, b = 0.0, l = 0.0, r = 0.0;
[self offsets: &l : &r : &t : &b forStyleMask: aStyle]; [self offsets: &l : &r : &t : &b forStyleMask: aStyle];
if (0 == (aStyle & NSUnscaledWindowMask))
{
// FIXME: This method should probably take a screen parameter
// rather than assuming the mainScreen
CGFloat factor = [[NSScreen mainScreen] userSpaceScaleFactor];
aRect = RectWithSizeScaledByFactor(aRect, factor);
}
aRect.size.width += l + r; aRect.size.width += l + r;
aRect.size.height += t + b; aRect.size.height += t + b;
aRect.origin.x -= l; aRect.origin.x -= l;
aRect.origin.y -= b; aRect.origin.y -= b;
return aRect; return aRect;
} }
@ -286,6 +314,13 @@
contentViewFrame.size.height -= newToolbarViewHeight; contentViewFrame.size.height -= newToolbarViewHeight;
} }
if (0 == ([window styleMask] & NSUnscaledWindowMask))
{
CGFloat factor = [window userSpaceScaleFactor];
NSRect aRect = RectWithSizeScaledByFactor([self frame], 1/factor);
[self setBoundsSize: aRect.size];
}
if ([windowContentView superview] == self) if ([windowContentView superview] == self)
{ {
[windowContentView setFrame:contentViewFrame]; [windowContentView setFrame:contentViewFrame];

View file

@ -35,6 +35,7 @@
#import <Foundation/NSGeometry.h> #import <Foundation/NSGeometry.h>
#import <Foundation/NSNotification.h> #import <Foundation/NSNotification.h>
#import <Foundation/NSValue.h> #import <Foundation/NSValue.h>
#import <Foundation/NSUserDefaults.h>
#import "AppKit/AppKitExceptions.h" #import "AppKit/AppKitExceptions.h"
#import "AppKit/NSApplication.h" #import "AppKit/NSApplication.h"
#import "AppKit/NSInterfaceStyle.h" #import "AppKit/NSInterfaceStyle.h"
@ -414,19 +415,31 @@ static NSMutableArray *screenArray = nil;
- (float) userSpaceScaleFactor - (float) userSpaceScaleFactor
{ {
GSDisplayServer *srv; NSNumber *factor = [[NSUserDefaults standardUserDefaults]
NSSize dpi; objectForKey: @"GSScaleFactor"];
srv = GSCurrentServer(); if (factor != nil)
//if (srv != nil)
// {
// dpi = [GSCurrentServer() resolutionForScreen: _screenNumber];
// // take average for 72dpi
// return (dpi.width + dpi.height) / 144;
// }
//else
{ {
return [factor floatValue];
}
else
{
return 1.0; return 1.0;
// FIXME: The following is commented out for now because
// it might cause the UI to be scaled unexpectedly.
//GSDisplayServer *srv = GSCurrentServer();
//if (srv != nil)
//{
// NSSize dpi = [GSCurrentServer() resolutionForScreen: _screenNumber];
// // take average for 72dpi
// return (dpi.width + dpi.height) / 144;
//}
//else
//{
// return 1.0;
//}
} }
} }