Skip to content

Commit fa0fad6

Browse files
committed
Fixed double-clicking on border resulting in bad resize
Fix issue where if the user double-clicks on the window border or corner to resize MacVim (the macOS behavior is to resize the window all the way to the screen's border), it results in an incomplete resize and also takes a long time. The code was spamming the Vim instance with live resize messages, leading to slowdown and dropped messages. Fix it by rate limiting the messages to one at a time, which speeds things up, and clean up when live resize finishes to make sure things look right.
1 parent ad821e4 commit fa0fad6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/MacVim/MMVimView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
NSMutableArray *scrollbars;
2828
}
2929

30+
@property BOOL pendingLiveResize;
31+
3032
- (MMVimView *)initWithFrame:(NSRect)frame vimController:(MMVimController *)c;
3133

3234
- (MMTextView *)textView;

src/MacVim/MMVimView.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,19 @@ - (void)frameSizeMayHaveChanged:(BOOL)keepGUISize
920920
"%dx%d (%s)", cols, rows, constrained[1], constrained[0],
921921
MessageStrings[msgid]);
922922

923-
[vimController sendMessageNow:msgid data:data timeout:1];
923+
if (msgid != LiveResizeMsgID || !self.pendingLiveResize) {
924+
// Live resize messages can be sent really rapidly, especailly if
925+
// it's from double clicking the window border (to indicate filling
926+
// all the way to that side to the window manager). We want to rate
927+
// limit sending live resize one at a time, or the IPC will get
928+
// swamped which causes slowdowns and some messages will also be dropped.
929+
// As a result we basically discard all live resize messages if one
930+
// is already going on. liveResizeDidEnd: will perform a final clean
931+
// up resizing.
932+
self.pendingLiveResize = (msgid == LiveResizeMsgID);
933+
934+
[vimController sendMessageNow:msgid data:data timeout:1];
935+
}
924936

925937
// We only want to set the window title if this resize came from
926938
// a live-resize, not (for example) setting 'columns' or 'lines'.

src/MacVim/MMWindowController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ - (void)setTextDimensionsWithRows:(int)rows columns:(int)cols isLive:(BOOL)live
398398
// user drags to resize the window.
399399

400400
[vimView setDesiredRows:rows columns:cols];
401+
vimView.pendingLiveResize = NO;
401402

402403
if (setupDone && !live && !keepGUISize) {
403404
shouldResizeVimView = YES;
@@ -712,6 +713,13 @@ - (void)liveResizeDidEnd
712713
[lastSetTitle release];
713714
lastSetTitle = nil;
714715
}
716+
717+
// If we are in the middle of rapid resize (e.g. double-clicking on the border/corner
718+
// of window), we would fire off a lot of LiveResizeMsgID messages where some will be
719+
// intentionally omitted to avoid swamping IPC. If that happens this will perform a
720+
// final clean up that makes sure the Vim view is sized correctly within the window.
721+
// See frameSizeMayHaveChanged: for where the omission/rate limiting happens.
722+
[self resizeView];
715723
}
716724

717725
- (void)setBlurRadius:(int)radius

0 commit comments

Comments
 (0)