Skip to content

Commit ca03594

Browse files
Merge pull request #6 from jpetrie/multimonitor-window-sizing
Fix 'flicker' during window presentation caused by early-out criteria.
2 parents 2476bac + 8564f74 commit ca03594

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/MacVim/MMAppController.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
769769
if (!screen)
770770
screen = [win screen];
771771

772+
BOOL willSwitchScreens = screen != [win screen];
772773
if (cascadeFrom) {
773774
// Do manual cascading instead of using
774775
// -[MMWindow cascadeTopLeftFromPoint:] since it is rather
@@ -795,7 +796,14 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
795796
ASLogNotice(@"Window not on screen, don't constrain position");
796797
}
797798

798-
[win setFrameTopLeftPoint:topLeft];
799+
// setFrameTopLeftPoint will trigger a resize event if the window is
800+
// moved across monitors; at this point such a resize would incorrectly
801+
// constrain the window to the default vim dimensions, so a specialized
802+
// method is used that will avoid that behavior.
803+
if (willSwitchScreens)
804+
[windowController moveWindowAcrossScreens:topLeft];
805+
else
806+
[win setFrameTopLeftPoint:topLeft];
799807
}
800808

801809
if (1 == [vimControllers count]) {

src/MacVim/MMWindowController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
NSPoint userTopLeft;
4646
NSPoint defaultTopLeft;
4747
NSToolbar *toolbar;
48+
BOOL resizingDueToMove;
4849
}
4950

5051
- (id)initWithVimController:(MMVimController *)controller;
@@ -55,6 +56,7 @@
5556
- (void)cleanup;
5657
- (void)openWindow;
5758
- (BOOL)presentWindow:(id)unused;
59+
- (void)moveWindowAcrossScreens:(NSPoint)origin;
5860
- (void)updateTabsWithData:(NSData *)data;
5961
- (void)selectTabWithIndex:(int)idx;
6062
- (void)setTextDimensionsWithRows:(int)rows columns:(int)cols isLive:(BOOL)live

src/MacVim/MMWindowController.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ - (id)initWithVimController:(MMVimController *)controller
150150
self = [super initWithWindow:win];
151151
if (!self) return nil;
152152

153+
resizingDueToMove = NO;
154+
153155
vimController = controller;
154156
decoratedWindow = [win retain];
155157

@@ -347,6 +349,18 @@ - (BOOL)presentWindow:(id)unused
347349
return YES;
348350
}
349351

352+
- (void)moveWindowAcrossScreens:(NSPoint)topLeft
353+
{
354+
// HACK! This method moves a window to a new origin and to a different
355+
// screen. This is primarily useful to avoid a scenario where such a move
356+
// will trigger a resize, even though the frame didn't actually change size.
357+
// This method should not be called unless the new origin is definitely on
358+
// a different screen, otherwise the next legitimate resize message will
359+
// be skipped.
360+
resizingDueToMove = YES;
361+
[[self window] setFrameTopLeftPoint:topLeft];
362+
}
363+
350364
- (void)updateTabsWithData:(NSData *)data
351365
{
352366
[vimView updateTabsWithData:data];
@@ -993,7 +1007,13 @@ - (void)windowDidMove:(NSNotification *)notification
9931007

9941008
- (void)windowDidResize:(id)sender
9951009
{
996-
if (!setupDone || fullScreenEnabled || !windowPresented) return;
1010+
if (resizingDueToMove)
1011+
{
1012+
resizingDueToMove = NO;
1013+
return;
1014+
}
1015+
1016+
if (!setupDone || fullScreenEnabled) return;
9971017

9981018
// NOTE: Since we have no control over when the window may resize (Cocoa
9991019
// may resize automatically) we simply set the view to fill the entire

0 commit comments

Comments
 (0)