Permalink
Browse files

Add the update timer to the runloop's common modes only during live r…

…esize as it breaks updates while a key is repeating to do so ordinarily.
  • Loading branch information...
1 parent d8a3e82 commit 6c41394fde62f2fc48619b7e09ba4a09b1bde813 @gnachman committed Jan 6, 2017
Showing with 42 additions and 3 deletions.
  1. +41 −1 sources/PTYSession.m
  2. +1 −2 sources/PseudoTerminal.m
View
@@ -428,6 +428,13 @@ @implementation PTYSession {
// is posted and all sessions with that bogus GUID can hide their profile and reload their
// profile.
NSString *_missingSavedArrangementProfileGUID;
+
+ // The containing window is in the midst of a live resize. The update timer
+ // runs in the common modes runlooup in this case. That's not acceptable
+ // for normal use for reasons that Apple leaves up to your imagination (it
+ // doesn't fire while you hold down a key, for example), but it does fire
+ // during live resize (unlike the default runloops).
+ BOOL _inLiveResize;
}
+ (void)registerSessionInArrangement:(NSDictionary *)arrangement {
@@ -530,6 +537,14 @@ - (instancetype)init {
selector:@selector(savedArrangementWasRepaired:)
name:PTYSessionDidRepairSavedArrangement
object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(windowWillStartLiveResize:)
+ name:NSWindowWillStartLiveResizeNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(windowDidEndLiveResize:)
+ name:NSWindowDidEndLiveResizeNotification
+ object:nil];
[self updateVariables];
}
return self;
@@ -3854,7 +3869,7 @@ - (void)setUpdateCadence:(NSTimeInterval)cadence {
DLog(@"Set cadence of %@ to %f", self, cadence);
[_updateTimer invalidate];
- if ([iTermAdvancedSettingsModel trackingRunloopForLiveResize]) {
+ if (_inLiveResize) {
// This solves the bug where we don't redraw properly during live resize.
// I'm worried about the possible side effects it might have since there's no way to
// know all the tracking event loops.
@@ -4008,6 +4023,31 @@ - (void)savedArrangementWasRepaired:(NSNotification *)notification {
}
}
+- (void)windowWillStartLiveResize:(NSNotification *)notification {
+ if ([iTermAdvancedSettingsModel trackingRunloopForLiveResize]) {
+ if (notification.object == self.textview.window) {
+ _inLiveResize = YES;
+ if (_updateTimer) {
+ [[NSRunLoop currentRunLoop] addTimer:_updateTimer forMode:NSRunLoopCommonModes];
+ }
+ }
+ }
+}
+
+- (void)windowDidEndLiveResize:(NSNotification *)notification {
+ if ([iTermAdvancedSettingsModel trackingRunloopForLiveResize]) {
+ if (notification.object == self.textview.window) {
+ _inLiveResize = NO;
+ if (_updateTimer) {
+ NSTimeInterval cadence = _updateTimer.timeInterval;
+ [_updateTimer invalidate];
+ _updateTimer = nil;
+ [self setUpdateCadence:cadence];
+ }
+ }
+ }
+}
+
- (void)synchronizeTmuxFonts:(NSNotification *)notification
{
if (!_exited && [self isTmuxClient]) {
@@ -3537,8 +3537,7 @@ - (BOOL)scrollbarShouldBeVisible {
return _contentView.scrollbarShouldBeVisible;
}
-- (void)windowWillStartLiveResize:(NSNotification *)notification
-{
+- (void)windowWillStartLiveResize:(NSNotification *)notification {
liveResize_ = YES;
}

0 comments on commit 6c41394

Please sign in to comment.