- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.3k
Background transparency #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
26dd7b3
              b4cc2bd
              821aee9
              6b21c14
              63b5c18
              c36180c
              4b536ec
              e64105e
              fe38c26
              700e01e
              5f1a31c
              1dea36b
              951bcce
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -22,3 +22,5 @@ Intermediates/ | |
| NMSSH.framework.dSYM/ | ||
| NMSSH/ | ||
| iTerm2.xcodeproj/xcuserdata/ | ||
|  | ||
| .idea/* | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -155,6 +155,7 @@ - (id)initWithSession:(PTYSession*)session | |
| activeSession_ = session; | ||
| [session setActivityCounter:@(_activityCounter++)]; | ||
| [[session view] setDimmed:NO]; | ||
| [[session tab] recheckBlur]; | ||
| [self setRoot:[[[PTYSplitView alloc] init] autorelease]]; | ||
| PTYTab *oldTab = [session tab]; | ||
| if (oldTab && [oldTab tmuxWindow] >= 0) { | ||
|  | @@ -360,7 +361,7 @@ - (void)setActiveSession:(PTYSession*)session updateActivityCounter:(BOOL)update | |
| // a invisible textview the first responder. | ||
| [[realParentWindow_ window] makeFirstResponder:[session textview]]; | ||
| } | ||
| [realParentWindow_ setDimmingForSessions]; | ||
| [realParentWindow_ updateDimAndBlurForSessions]; | ||
| } | ||
| for (PTYSession* aSession in [self sessions]) { | ||
| [[aSession textview] refresh]; | ||
|  | @@ -1855,51 +1856,86 @@ - (NSSize)_minSizeOfView:(NSView*)view | |
| } | ||
|  | ||
| // Blur the window if any session is blurred. | ||
| - (bool)blur | ||
| { | ||
| int n = 0; | ||
| int y = 0; | ||
| - (BOOL)blur { | ||
| NSArray* sessions = [self sessions]; | ||
| for (PTYSession* session in sessions) { | ||
| if ([session transparency] > 0 && | ||
| [[session textview] useTransparency] && | ||
| [[[session profile] objectForKey:KEY_BLUR] boolValue]) { | ||
| ++y; | ||
| } else { | ||
| ++n; | ||
| return YES; | ||
| } | ||
| } | ||
| return y > 0; | ||
| return NO; | ||
| } | ||
|  | ||
| - (double)blurRadius | ||
| { | ||
| - (double)averageBlurRadiusForInactive:(BOOL)inactive { | ||
| double sum = 0; | ||
| double count = 0; | ||
| NSArray* sessions = [self sessions]; | ||
|          | ||
| for (PTYSession* session in sessions) { | ||
| if ([[[session profile] objectForKey:KEY_BLUR] boolValue]) { | ||
| sum += [[session profile] objectForKey:KEY_BLUR_RADIUS] ? [[[session profile] objectForKey:KEY_BLUR_RADIUS] floatValue] : 2.0; | ||
| BOOL useBlur = inactive ? [session inactiveBlur] : [session blur]; | ||
| if (useBlur) { | ||
| double blurRadius = inactive ? [session inactiveBlurRadius] : [session blurRadius]; | ||
| sum += blurRadius; | ||
| ++count; | ||
| } | ||
| } | ||
| if (count > 0) { | ||
| return sum / count; | ||
| } else { | ||
| // This shouldn't actually happen, but better save than divide by zero. | ||
| // This shouldn't actually happen, but better safe than divide by zero. | ||
| return 2.0; | ||
| } | ||
| } | ||
|  | ||
| - (void)recheckBlur | ||
| { | ||
| - (double)blurRadius { | ||
| return [self averageBlurRadiusForInactive:NO]; | ||
| } | ||
|  | ||
| - (BOOL)useInactiveTransparency { | ||
| NSArray *sessions = [self sessions]; | ||
| for (PTYSession *session in sessions) { | ||
| if ([[session textview] useInactiveTransparency]) { | ||
| return YES; | ||
| } | ||
| } | ||
| return NO; | ||
| } | ||
|  | ||
| - (BOOL)inactiveBlur { | ||
| NSArray* sessions = [self sessions]; | ||
| for (PTYSession* session in sessions) { | ||
| if ([session inactiveTransparency] > 0 && | ||
| [session useInactiveTransparency] && | ||
| [session inactiveBlur]) { | ||
| return YES; | ||
| } | ||
| } | ||
| return NO; | ||
| } | ||
|  | ||
| - (double)inactiveBlurRadius { | ||
|          | ||
| return [self averageBlurRadiusForInactive:YES]; | ||
| } | ||
|  | ||
| - (void)recheckBlur { | ||
| PtyLog(@"PTYTab recheckBlur"); | ||
| if ([realParentWindow_ currentTab] == self && | ||
| ![[realParentWindow_ window] isMiniaturized]) { | ||
| if ([self blur]) { | ||
| [parentWindow_ enableBlur:[self blurRadius]]; | ||
| if ([[[self realParentWindow] window] isKeyWindow]) { | ||
| if ([self blur]) { | ||
| [parentWindow_ enableBlur:[self blurRadius]]; | ||
| } else { | ||
| [parentWindow_ disableBlur]; | ||
| } | ||
| } else { | ||
| [parentWindow_ disableBlur]; | ||
| if ([self inactiveBlur]) { | ||
| [parentWindow_ enableBlur:[self inactiveBlurRadius]]; | ||
| } else if (![self useInactiveTransparency] && [self blur]) { | ||
| [parentWindow_ enableBlur:[self blurRadius]]; | ||
| } else { | ||
| [parentWindow_ disableBlur]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|  | @@ -2271,7 +2307,7 @@ - (void)addToTerminal:(NSWindowController<iTermWindowController> *)term | |
| } | ||
|  | ||
| [self numberOfSessionsDidChange]; | ||
| [term setDimmingForSessions]; | ||
| [term updateDimAndBlurForSessions]; | ||
| [term updateTabColors]; | ||
| } | ||
|  | ||
|  | @@ -3006,7 +3042,7 @@ - (void)replaceViewHierarchyWithParseTree:(NSMutableDictionary *)parseTree | |
| [realParentWindow_ tmuxTabLayoutDidChange:YES]; | ||
| [realParentWindow_ endTmuxOriginatedResize]; | ||
| --tmuxOriginatedResizeInProgress_; | ||
| [realParentWindow_ setDimmingForSessions]; | ||
| [realParentWindow_ updateDimAndBlurForSessions]; | ||
| } | ||
|  | ||
| - (void)setTmuxLayout:(NSMutableDictionary *)parseTree | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -199,11 +199,16 @@ typedef enum { | |
| // Transparency level. 0 to 1. | ||
| @property(nonatomic, assign) double transparency; | ||
|  | ||
| // Inactive Window Transparency level. 0 to 1. | ||
| @property(nonatomic, assign) double inactiveTransparency; | ||
|  | ||
| // Blending level for background color over background image | ||
| @property(nonatomic, assign) double blend; | ||
|  | ||
| // Should transparency be used? | ||
| @property(nonatomic, readonly) BOOL useTransparency; | ||
| @property(nonatomic, readonly) BOOL useInactiveTransparency; | ||
| @property(nonatomic, readonly) BOOL windowInactive; | ||
|          | ||
|  | ||
| // Indicates if the last key pressed was a repeat. | ||
| @property(nonatomic, readonly) BOOL keyIsARepeat; | ||
|  | @@ -419,5 +424,11 @@ typedef enum { | |
| prefix:(NSString *)prefix | ||
| suffix:(NSString *)suffix; | ||
|  | ||
| // Get the transparency value for view based on if this window is key or not. | ||
| - (double)transparencyAlpha; | ||
|  | ||
| // Allow a special transparency for inactive windows. | ||
| - (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency; | ||
|  | ||
| @end | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!