Skip to content

Commit 560fae4

Browse files
committed
Fix switching to fullscreen loses keyboard focus if titlebar is hidden
For some reason, when the titlebar is hidden, if we use `set fullscreen` in native full screen mode, the focus will be lost and the user needs to manually click on the screen to be able to type in MacVim. Current theory is that because fullscreen window always has a title bar, sometime that resulted in the window being defocused when the OS is fixing it up. For an easy fix, simply assert the focus by using `makeFirstResponder` on the text view. This may not work well if the program is more complicated but for MacVim the text view should always be where the focus goes. Fix #1078
1 parent 8b25779 commit 560fae4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/MacVim/MMWindowController.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,11 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification
14191419
// full-screen using :fullscreen option (including Ctrl-Cmd-f).
14201420
[vimController sendMessage:BackingPropertiesChangedMsgID data:nil];
14211421
}
1422+
1423+
// Sometimes full screen will de-focus the text view. This seems to happen
1424+
// when titlebar is configured as hidden. Simply re-assert it to make sure
1425+
// text is still focused.
1426+
[decoratedWindow makeFirstResponder:[vimView textView]];
14221427
}
14231428

14241429
- (void)windowDidFailToEnterFullScreen:(NSWindow *)window
@@ -1436,6 +1441,11 @@ - (void)windowDidFailToEnterFullScreen:(NSWindow *)window
14361441
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
14371442
[self updateTablineSeparator];
14381443
[window setFrame:preFullScreenFrame display:YES];
1444+
1445+
// Sometimes full screen will de-focus the text view. This seems to happen
1446+
// when titlebar is configured as hidden. Simply re-assert it to make sure
1447+
// text is still focused.
1448+
[decoratedWindow makeFirstResponder:[vimView textView]];
14391449
}
14401450

14411451
- (NSArray *)customWindowsToExitFullScreenForWindow:(NSWindow *)window
@@ -1500,6 +1510,11 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification
15001510
}
15011511

15021512
[self updateTablineSeparator];
1513+
1514+
// Sometimes full screen will de-focus the text view. This seems to happen
1515+
// when titlebar is configured as hidden. Simply re-assert it to make sure
1516+
// text is still focused.
1517+
[decoratedWindow makeFirstResponder:[vimView textView]];
15031518
}
15041519

15051520
- (void)windowDidFailToExitFullScreen:(NSWindow *)window
@@ -1515,6 +1530,11 @@ - (void)windowDidFailToExitFullScreen:(NSWindow *)window
15151530
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
15161531
[self updateTablineSeparator];
15171532
[self maximizeWindow:fullScreenOptions];
1533+
1534+
// Sometimes full screen will de-focus the text view. This seems to happen
1535+
// when titlebar is configured as hidden. Simply re-assert it to make sure
1536+
// text is still focused.
1537+
[decoratedWindow makeFirstResponder:[vimView textView]];
15181538
}
15191539

15201540
#endif // (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)

0 commit comments

Comments
 (0)