Skip to content

Commit

Permalink
Moves main window creation from xib to code. This fixes a bug introdu…
Browse files Browse the repository at this point in the history
…ced with OS X 10.9 support where setting the style flag NSFullSizeContentViewWindowMask after the window has been created and displayed (and thus after frameAutosave had happened), the window frame would be slightly modified, causing the window to shrink in size over time
  • Loading branch information
rsms committed Apr 10, 2015
1 parent f0d3dad commit a80cddf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
40 changes: 25 additions & 15 deletions Messenger/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ static void __attribute__((constructor))_init() {
}

@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (nonatomic, readonly) BOOL canMakeTextLarger;
- (IBAction)makeTextLarger:(id)sender;
@property (nonatomic, readonly) BOOL canMakeTextSmaller;
Expand All @@ -22,27 +21,36 @@ - (IBAction)makeTextStandardSize:(id)sender;
@end

@implementation AppDelegate {
WebView* _webView;
NSView* _titlebarView; // NSTitlebarView
NSWindow* _window;
WebView* _webView;
NSView* _titlebarView; // NSTitlebarView
NSString* _lastNotificationCount;
}

- (void)applicationDidFinishLaunching:(NSNotification*)notification {
// Register ourselves as the default-user-notification center delegate
[NSUserNotificationCenter defaultUserNotificationCenter].delegate = self;

// Configure main window
// Create main window
NSUInteger windowStyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
if (kCFIsOSX_10_10_orNewer) {
self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
self.window.titleVisibility = NSWindowTitleHidden;
self.window.titlebarAppearsTransparent = YES;
self.window.styleMask |= NSFullSizeContentViewWindowMask;
windowStyle |= NSFullSizeContentViewWindowMask;
}
self.window.delegate = self;
_window = [[NSWindow alloc] initWithContentRect:{{0,0},{800,600}} styleMask:windowStyle backing:NSBackingStoreBuffered defer:YES];
if (kCFIsOSX_10_10_orNewer) {
_window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
_window.titleVisibility = NSWindowTitleHidden;
_window.titlebarAppearsTransparent = YES;
}
_window.minSize = {640,400};
_window.releasedWhenClosed = NO;
_window.delegate = self;
[_window center];
_window.frameAutosaveName = @"main";

if (kCFIsOSX_10_10_orNewer) {
// Hack to hide "traffic lights" but still allowing window manipulation (which isn't the case if we use proper window flags)
_titlebarView = [self.window standardWindowButton:NSWindowCloseButton].superview;
_titlebarView = [_window standardWindowButton:NSWindowCloseButton].superview;
_titlebarView.wantsLayer = YES;
_titlebarView.layer.opacity = 0.0;
auto titlebarTrackingArea = [[NSTrackingArea alloc] initWithRect:_titlebarView.bounds options:NSTrackingMouseEnteredAndExited|NSTrackingActiveInActiveApp owner:self userInfo:nil];
Expand Down Expand Up @@ -103,14 +111,17 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {

// Web view in main window
auto webView = [[WebView alloc] initWithFrame:{{0,0},{100,100}} frameName:@"main" groupName:@"main"];
self.window.contentView = webView;
_window.contentView = webView;
webView.policyDelegate = self;
webView.frameLoadDelegate = self;
webView.UIDelegate = self;
webView.preferences = wp;
auto req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.messenger.com/t/"]];
[webView.mainFrame loadRequest:req];
_webView = webView;

// Present main window
[_window makeKeyAndOrderFront:self];

//- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;

Expand Down Expand Up @@ -153,12 +164,12 @@ - (IBAction)checkForUpdates:(id)sender {


- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
[self.window makeKeyAndOrderFront:self];
[_window makeKeyAndOrderFront:self];
return YES;
}

- (void)applicationDidBecomeActive:(NSNotification *)notification {
[self.window makeKeyAndOrderFront:self];
[_window makeKeyAndOrderFront:self];
}


Expand Down Expand Up @@ -246,8 +257,7 @@ - (void)webView:(WebView*)webView runOpenPanelForFileButtonWithResultListener:(i
[resultListener cancel];
}
};
[openPanel beginSheetModalForWindow:self.window completionHandler:onComplete];
// [openPanel beginWithCompletionHandler:onComplete];
[openPanel beginSheetModalForWindow:_window completionHandler:onComplete];
}


Expand Down
19 changes: 1 addition & 18 deletions Messenger/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
Expand Down Expand Up @@ -373,19 +369,6 @@
</menuItem>
</items>
</menu>
<window title="Messenger" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="main" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="335" y="390" width="850" height="663"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
<value key="minSize" type="size" width="640" height="380"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="850" height="663"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<point key="canvasLocation" x="377" y="251.5"/>
</window>
<menuItem title="Format" id="GpI-Y1-MZs">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Format" id="GKh-OC-Bid">
Expand Down
2 changes: 1 addition & 1 deletion admin/dist/addchangelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ul>
]]></description>
<pubDate>{pubdate}</pubDate>
<sparkle:minimumSystemVersion>10.10</sparkle:minimumSystemVersion>
<sparkle:minimumSystemVersion>10.9</sparkle:minimumSystemVersion>
<enclosure
gitrev="{gitrev}"
url="http://fbmacmessenger.rsms.me/dist/{filename}"
Expand Down

0 comments on commit a80cddf

Please sign in to comment.