-
-
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 5 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
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1855,21 +1855,16 @@ - (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 | ||
|
|
@@ -1891,15 +1886,66 @@ - (double)blurRadius | |
| } | ||
| } | ||
|
|
||
| - (void)recheckBlur | ||
| { | ||
| - (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 textview] useInactiveTransparency] && | ||
| [[[session profile] objectForKey:KEY_INACTIVE_BLUR] boolValue]) { | ||
|
||
| return YES; | ||
| } | ||
| } | ||
| return NO; | ||
| } | ||
|
|
||
| - (double)inactiveBlurRadius { | ||
|
||
| double sum = 0; | ||
| double count = 0; | ||
| NSArray* sessions = [self sessions]; | ||
| for (PTYSession* session in sessions) { | ||
| if ([[[session profile] objectForKey:KEY_INACTIVE_BLUR] boolValue]) { | ||
| sum += [[session profile] objectForKey:KEY_INACTIVE_BLUR_RADIUS] | ||
| ? [[[session profile] objectForKey:KEY_INACTIVE_BLUR_RADIUS] floatValue] | ||
| : 2.0; | ||
| ++count; | ||
| } | ||
| } | ||
| if (count > 0) { | ||
| return sum / count; | ||
| } else { | ||
| // This shouldn't actually happen, but better save than divide by zero. | ||
| return 2.0; | ||
| } | ||
| } | ||
|
|
||
| - (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]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
|
|
||
| // 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 isBackground; | ||
|
|
||
| // Indicates if the last key pressed was a repeat. | ||
| @property(nonatomic, readonly) BOOL keyIsARepeat; | ||
|
|
@@ -317,6 +322,9 @@ typedef enum { | |
| // Updates the preferences for semantic history. | ||
| - (void)setSemanticHistoryPrefs:(NSDictionary *)prefs; | ||
|
|
||
| // Is the main window active? | ||
| - (void)setIsBackground:(BOOL)isBackground; | ||
|
||
|
|
||
| // Various accessors (TODO: convert as many as possible into properties) | ||
| - (void)setFont:(NSFont*)aFont | ||
| nonAsciiFont:(NSFont *)nonAsciiFont | ||
|
|
@@ -419,5 +427,11 @@ typedef enum { | |
| prefix:(NSString *)prefix | ||
| suffix:(NSString *)suffix; | ||
|
|
||
| // Get the transparency value for foreground or background windows. | ||
|
||
| - (double)transparencyAlpha; | ||
|
|
||
| // Allow a special transparency for inactive windows. | ||
| - (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency; | ||
|
|
||
| @end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5221,6 +5221,27 @@ - (void)setTransparency:(double)fVal | |
| [self setNeedsDisplay:YES]; | ||
| } | ||
|
|
||
| - (void)setInactiveTransparency:(double)inactiveTransparency | ||
| { | ||
|
||
| _inactiveTransparency = inactiveTransparency; | ||
| [_colorMap invalidateCache]; | ||
| [self setNeedsDisplay:YES]; | ||
| } | ||
|
|
||
| - (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency | ||
| { | ||
| _useInactiveTransparency = useInactiveTransparency; | ||
| [_colorMap invalidateCache]; | ||
| [self setNeedsDisplay:YES]; | ||
| } | ||
|
|
||
| - (void)setIsBackground:(BOOL)isBackground | ||
|
||
| { | ||
| _isBackground = isBackground; | ||
| [_colorMap invalidateCache]; | ||
| [self setNeedsDisplay:YES]; | ||
| } | ||
|
|
||
| - (void)setBlend:(double)fVal | ||
| { | ||
| _blend = MIN(MAX(0.3, fVal), 1); | ||
|
|
@@ -6376,7 +6397,11 @@ - (BOOL)_drawLine:(int)line | |
| int WIDTH = [_dataSource width]; | ||
| screen_char_t* theLine = [_dataSource getLineAtIndex:line]; | ||
| BOOL hasBGImage = [_delegate textViewHasBackgroundImage]; | ||
|
|
||
| double selectedAlpha = 1.0 - _transparency; | ||
| if(_isBackground){ | ||
|
||
| selectedAlpha = 1.0 - _inactiveTransparency; | ||
| } | ||
| double alphaIfTransparencyInUse = [self transparencyAlpha]; | ||
| BOOL reversed = [[_dataSource terminal] reverseVideo]; | ||
| NSColor *aColor = nil; | ||
|
|
@@ -7163,7 +7188,13 @@ - (NSColor *)smartCursorColorForChar:(screen_char_t)screenChar | |
| } | ||
|
|
||
| - (double)transparencyAlpha { | ||
| return [self useTransparency] ? 1.0 - _transparency : 1.0; | ||
| if([self useTransparency]){ | ||
|
||
| if([self isBackground] && [self useInactiveTransparency]){ | ||
| return 1.0 - _inactiveTransparency; | ||
| } | ||
| return 1.0 - _transparency; | ||
| } | ||
| return 1.0; | ||
| } | ||
|
|
||
| - (screen_char_t)charForCursorAtColumn:(int)column | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,7 +155,12 @@ - (void)awakeFromNib { | |
| static const CGFloat kMaxHeight = 438; | ||
| if (view.frame.size.height > kMaxHeight) { | ||
| // If the view is too tall, wrap it in a scroll view. | ||
| NSRect theFrame = NSMakeRect(0, 0, view.frame.size.width, kMaxHeight); | ||
|
|
||
| CGFloat widthWithScrollBar = view.frame.size.width + | ||
| [NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy]; | ||
|
||
|
|
||
| NSRect theFrame = NSMakeRect(0, 0, widthWithScrollBar, kMaxHeight); | ||
|
|
||
| iTermSizeRememberingView *sizeRememberingView = | ||
| [[[iTermSizeRememberingView alloc] initWithFrame:theFrame] autorelease]; | ||
| sizeRememberingView.autoresizingMask = (NSViewWidthSizable | NSViewHeightSizable); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ @implementation ProfilesWindowPreferencesViewController { | |
| IBOutlet NSSlider *_transparency; | ||
| IBOutlet NSButton *_useBlur; | ||
| IBOutlet NSSlider *_blurRadius; | ||
| IBOutlet NSButton *_useInactiveTransparency; | ||
| IBOutlet NSSlider *_inactiveTransparency; | ||
| IBOutlet NSButton *_useInactiveBlur; | ||
| IBOutlet NSSlider *_inactiveBlurRadius; | ||
| IBOutlet NSButton *_useBackgroundImage; | ||
| IBOutlet iTermImageWell *_backgroundImagePreview; | ||
| IBOutlet NSButton *_backgroundImageTiled; | ||
|
|
@@ -70,6 +74,31 @@ - (void)awakeFromNib { | |
| key:KEY_BLUR_RADIUS | ||
| type:kPreferenceInfoTypeSlider]; | ||
|
|
||
| info = [self defineControl:_useInactiveTransparency | ||
| key:KEY_USE_INACTIVE_TRANSPARENCY | ||
| type:kPreferenceInfoTypeCheckbox]; | ||
| info.observer = ^() { | ||
| _inactiveTransparency.enabled = (_useInactiveTransparency.state == NSOnState); | ||
| _useInactiveBlur.enabled = (_useInactiveTransparency.state == NSOnState); | ||
| }; | ||
|
|
||
| [self defineControl:_inactiveTransparency | ||
| key:KEY_INACTIVE_TRANSPARENCY | ||
| type:kPreferenceInfoTypeSlider]; | ||
|
|
||
| info = [self defineControl:_useInactiveBlur | ||
| key:KEY_INACTIVE_BLUR | ||
| type:kPreferenceInfoTypeCheckbox]; | ||
| info.observer = ^() { | ||
| _inactiveBlurRadius.enabled = | ||
| (_useInactiveTransparency.state == NSOnState | ||
| && _useInactiveBlur.state == NSOnState); | ||
|
||
| }; | ||
|
|
||
| [self defineControl:_inactiveBlurRadius | ||
| key:KEY_INACTIVE_BLUR_RADIUS | ||
| type:kPreferenceInfoTypeSlider]; | ||
|
|
||
| [self defineControl:_backgroundImageTiled | ||
| key:KEY_BACKGROUND_IMAGE_TILED | ||
| type:kPreferenceInfoTypeCheckbox]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2390,6 +2390,11 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification { | |
| [self hideMenuBar]; | ||
| } | ||
| } | ||
|
|
||
| for (PTYSession *aSession in [self allSessions]) { | ||
| [[aSession textview] setIsBackground:NO]; | ||
| } | ||
|
|
||
|
|
||
| // Note: there was a bug in the old iterm that setting fonts didn't work | ||
| // properly if the font panel was left open in focus-follows-mouse mode. | ||
|
|
@@ -2682,6 +2687,7 @@ - (void)windowDidResignKey:(NSNotification *)aNotification { | |
| [[aSession textview] endFindCursor]; | ||
| } | ||
| [[aSession textview] removeUnderline]; | ||
| [[aSession textview] setIsBackground:YES]; | ||
| } | ||
|
|
||
| PtyLog(@"PseudoTerminal windowDidResignKey"); | ||
|
|
@@ -2709,6 +2715,7 @@ - (void)windowDidResignKey:(NSNotification *)aNotification { | |
| tabBarControl.flashing = NO; | ||
| [self showMenuBar]; | ||
| } | ||
|
|
||
| // update the cursor | ||
| [[[self currentSession] textview] refresh]; | ||
| [[[self currentSession] textview] setNeedsDisplay:YES]; | ||
|
|
@@ -5596,6 +5603,7 @@ - (void)setDimmingForSession:(PTYSession *)aSession | |
| // broadcasting to the current session. | ||
| [[aSession view] setDimmed:YES]; | ||
| } | ||
| [[aSession tab] recheckBlur]; | ||
|
||
| [[aSession view] setNeedsDisplay:YES]; | ||
| } | ||
|
|
||
|
|
||
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.
New code should not look up values in _profile directly because it bypasses the relatively new mechanism for defaults. Older code generally had default values of 0 so it happens to work, and I'm slowly moving everything the new model. Instead, write:
[iTermProfilePreferences objectForKey:KEY_INACTIVE_TRANSPARENCY inProfile:_profile]