Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 147 additions & 35 deletions Interfaces/PreferencePanel.xib

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion iTerm2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4658,7 +4658,7 @@
0464AB0C006CD2EC7F000001 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 0620;
};
buildConfigurationList = BB024D39096EE4080021E793 /* Build configuration list for PBXProject "iTerm2" */;
compatibilityVersion = "Xcode 3.2";
Expand Down
4 changes: 4 additions & 0 deletions sources/ITAddressBookMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
#define KEY_BLEND @"Blend"
#define KEY_BLUR @"Blur"
#define KEY_BLUR_RADIUS @"Blur Radius"
#define KEY_USE_INACTIVE_TRANSPARENCY @"Use Inactive Transparency Values"
#define KEY_INACTIVE_TRANSPARENCY @"Inactive Transparency"
#define KEY_INACTIVE_BLUR @"Use Inactive Blur"
#define KEY_INACTIVE_BLUR_RADIUS @"Inactive Blur Radius"
#define KEY_ANTI_ALIASING @"Anti Aliasing" // DEPRECATED
#define KEY_ASCII_ANTI_ALIASED @"ASCII Anti Aliased"
#define KEY_USE_NONASCII_FONT @"Use Non-ASCII Font"
Expand Down
4 changes: 4 additions & 0 deletions sources/KeysPreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ - (void)generateHotkeyWindowProfile {
[dict setObject:[NSNumber numberWithFloat:0.3] forKey:KEY_TRANSPARENCY];
[dict setObject:[NSNumber numberWithFloat:0.5] forKey:KEY_BLEND];
[dict setObject:[NSNumber numberWithFloat:2.0] forKey:KEY_BLUR_RADIUS];
[dict setObject:[NSNumber numberWithFloat:0.3] forKey:KEY_INACTIVE_TRANSPARENCY];
[dict setObject:[NSNumber numberWithFloat:2.0] forKey:KEY_INACTIVE_BLUR_RADIUS];
[dict setObject:[NSNumber numberWithBool:YES] forKey:KEY_BLUR];
[dict setObject:[NSNumber numberWithBool:YES] forKey:KEY_INACTIVE_BLUR];
[dict setObject:[NSNumber numberWithBool:YES] forKey:KEY_USE_INACTIVE_TRANSPARENCY];
[dict setObject:[NSNumber numberWithInt:-1] forKey:KEY_SCREEN];
[dict setObject:[NSNumber numberWithInt:-1] forKey:KEY_SPACE];
[dict setObject:@"" forKey:KEY_SHORTCUT];
Expand Down
2 changes: 2 additions & 0 deletions sources/PTYSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ typedef enum {

@property(nonatomic, retain) iTermColorMap *colorMap;
@property(nonatomic, assign) float transparency;
@property(nonatomic, assign) BOOL useInactiveTransparency;
@property(nonatomic, assign) float inactiveTransparency;
@property(nonatomic, assign) float blend;
@property(nonatomic, assign) BOOL useBoldFont;
@property(nonatomic, assign) BOOL useItalicFont;
Expand Down
26 changes: 25 additions & 1 deletion sources/PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ - (BOOL)setScreenSize:(NSRect)aRect parent:(id<WindowControllerInterface>)parent
horizontalSpacing:[[_profile objectForKey:KEY_HORIZONTAL_SPACING] floatValue]
verticalSpacing:[[_profile objectForKey:KEY_VERTICAL_SPACING] floatValue]];
[self setTransparency:[[_profile objectForKey:KEY_TRANSPARENCY] floatValue]];
[self setInactiveTransparency:[[_profile objectForKey:KEY_INACTIVE_TRANSPARENCY] floatValue]];
Copy link
Owner

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]

[self setUseInactiveTransparency:[[_profile objectForKey:KEY_USE_INACTIVE_TRANSPARENCY] boolValue]];
const float theBlend =
[_profile objectForKey:KEY_BLEND] ? [[_profile objectForKey:KEY_BLEND] floatValue] : 0.5;
[self setBlend:theBlend];
Expand Down Expand Up @@ -2281,6 +2283,8 @@ - (void)setPreferencesFromAddressBookEntry:(NSDictionary *)aePrefs

// transparency
[self setTransparency:[iTermProfilePreferences floatForKey:KEY_TRANSPARENCY inProfile:aDict]];
[self setUseInactiveTransparency:[iTermProfilePreferences boolForKey:KEY_USE_INACTIVE_TRANSPARENCY inProfile:aDict]];
[self setInactiveTransparency:[iTermProfilePreferences floatForKey:KEY_INACTIVE_TRANSPARENCY inProfile:aDict]];
[self setBlend:[iTermProfilePreferences floatForKey:KEY_BLEND inProfile:aDict]];

// bold
Expand Down Expand Up @@ -2669,6 +2673,26 @@ - (void)setTransparency:(float)transparency
[_textview setTransparency:transparency];
}

- (float)inactiveTransparency {
return [_textview inactiveTransparency];
}

- (void)setInactiveTransparency:(float)inactiveTransparency {
// Limit transparency because fully transparent windows can't be clicked on.
if (inactiveTransparency > 0.9) {
inactiveTransparency = 0.9;
}
[_textview setInactiveTransparency:inactiveTransparency];
}

- (BOOL)useInactiveTransparency {
return [_textview useInactiveTransparency];
}

- (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency {
[_textview setUseInactiveTransparency:useInactiveTransparency];
}

- (float)blend
{
return [_textview blend];
Expand Down Expand Up @@ -4648,7 +4672,7 @@ - (NSImage *)patternedImage {
- (void)textViewDrawBackgroundImageInView:(NSView *)view
viewRect:(NSRect)rect
blendDefaultBackground:(BOOL)blendDefaultBackground {
const float alpha = _textview.useTransparency ? (1.0 - _textview.transparency) : 1.0;
float alpha = [_textview transparencyAlpha];
if (_backgroundImage) {
NSRect localRect = [_view convertRect:rect fromView:view];
NSImage *image;
Expand Down
2 changes: 1 addition & 1 deletion sources/PTYTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
- (PTYSession*)sessionBelow:(PTYSession*)session;
- (BOOL)canSplitVertically:(BOOL)isVertical withSize:(NSSize)newSessionSize;
- (NSImage*)image:(BOOL)withSpaceForFrame;
- (bool)blur;
- (BOOL)blur;
- (double)blurRadius;
- (void)recheckBlur;

Expand Down
72 changes: 59 additions & 13 deletions sources/PTYTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}
}
return y > 0;
return NO;
}

- (double)blurRadius
Expand All @@ -1891,15 +1886,66 @@ - (double)blurRadius
}
}

- (void)recheckBlur
{
- (BOOL)useInactiveTransparency {
NSArray* sessions = [self sessions];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New code should look like NSArray *sessions with the space before the *.

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]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to define and use session.inactiveBlur than to peek into the profile.

return YES;
}
}
return NO;
}

- (double)inactiveBlurRadius {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplicated code with -blurRadius. Please refactor into a common method like
- (double)averageBlurRadiusForInactive:(BOOL)inactive

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]){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a space between ) and {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Xcode have a setting to make spacing consistent? I'm used to having reshaper do that for me in visual studio.

On Mar 18, 2015, at 17:24, gnachman [email protected] wrote:

In sources/PTYTab.m:

 PtyLog(@"PTYTab recheckBlur");
 if ([realParentWindow_ currentTab] == self &&
     ![[realParentWindow_ window] isMiniaturized]) {
  •    if ([self blur]) {
    
  •        [parentWindow_ enableBlur:[self blurRadius]];
    
  •    if ([[[self realParentWindow] window] isKeyWindow]){
    
    Needs a space between ) and {


Reply to this email directly or view it on GitHub.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of. XCode is bad in surprising ways.

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];
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions sources/PTYTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,16 @@ typedef enum {
// Transparency level. 0 to 1.
@property(nonatomic, assign) double transparency;

// Transparency level. 0 to 1.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 isBackground;

// Indicates if the last key pressed was a repeat.
@property(nonatomic, readonly) BOOL keyIsARepeat;
Expand Down Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to break direct dependencies between PseudoTerminal and PTYTextView. Rather than have PseudoTerminal call setIsBackground: directly from windowDidBecomeKey: and windowDidResignKey:, we can use notifications to keep this decoupled.

You can register for notifications like this, in -[PTYTextView initWithFrame:colorMap:]:

  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(windowDidBecomeKey:)
                                               name:NSWindowDidBecomeKeyNotification
                                             object:nil];

  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(windowDidResignKey:)
                                               name:NSWindowDidResignKeyNotification
                                             object:nil];

And add methods like these:

  - (void)windowDidBecomeKey:(NSNotification *)notification {
      if ([notification object] == [self window]) {
          [self setIsBackground:NO];
      }
  }

  - (void)windowDidResignKey:(NSNotification *)notification {
      if ([notification object] == [self window]) {
          [self setIsBackground:YES];
      }
  }

And then -setIsBackground can be a private method.


// Various accessors (TODO: convert as many as possible into properties)
- (void)setFont:(NSFont*)aFont
nonAsciiFont:(NSFont *)nonAsciiFont
Expand Down Expand Up @@ -419,5 +427,11 @@ typedef enum {
prefix:(NSString *)prefix
suffix:(NSString *)suffix;

// Get the transparency value for foreground or background windows.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment means it gets the transparency value for this view, which may vary depending on whether the window is active or not. Can you clarify?

- (double)transparencyAlpha;

// Allow a special transparency for inactive windows.
- (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency;

@end

33 changes: 32 additions & 1 deletion sources/PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -5221,6 +5221,27 @@ - (void)setTransparency:(double)fVal
[self setNeedsDisplay:YES];
}

- (void)setInactiveTransparency:(double)inactiveTransparency
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New code should put the { starting a method on the preceding line.

_inactiveTransparency = inactiveTransparency;
[_colorMap invalidateCache];
[self setNeedsDisplay:YES];
}

- (void)setUseInactiveTransparency:(BOOL)useInactiveTransparency
{
_useInactiveTransparency = useInactiveTransparency;
[_colorMap invalidateCache];
[self setNeedsDisplay:YES];
}

- (void)setIsBackground:(BOOL)isBackground
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For style and consistency, this should be setWindowInactive: and the backing variable should be _windowInactive.

{
_isBackground = isBackground;
[_colorMap invalidateCache];
[self setNeedsDisplay:YES];
}

- (void)setBlend:(double)fVal
{
_blend = MIN(MAX(0.3, fVal), 1);
Expand Down Expand Up @@ -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){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always put a space after if.

selectedAlpha = 1.0 - _inactiveTransparency;
}
double alphaIfTransparencyInUse = [self transparencyAlpha];
BOOL reversed = [[_dataSource terminal] reverseVideo];
NSColor *aColor = nil;
Expand Down Expand Up @@ -7163,7 +7188,13 @@ - (NSColor *)smartCursorColorForChar:(screen_char_t)screenChar
}

- (double)transparencyAlpha {
return [self useTransparency] ? 1.0 - _transparency : 1.0;
if([self useTransparency]){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a space after if.

if([self isBackground] && [self useInactiveTransparency]){
return 1.0 - _inactiveTransparency;
}
return 1.0 - _transparency;
}
return 1.0;
}

- (screen_char_t)charForCursorAtColumn:(int)column
Expand Down
7 changes: 6 additions & 1 deletion sources/ProfilePreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break this into two lines, aligning the colons (when readability isn't hurt, lines are kept under 100 characters)


NSRect theFrame = NSMakeRect(0, 0, widthWithScrollBar, kMaxHeight);

iTermSizeRememberingView *sizeRememberingView =
[[[iTermSizeRememberingView alloc] initWithFrame:theFrame] autorelease];
sizeRememberingView.autoresizingMask = (NSViewWidthSizable | NSViewHeightSizable);
Expand Down
29 changes: 29 additions & 0 deletions sources/ProfilesWindowPreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the && to the end of the preceding line.

};

[self defineControl:_inactiveBlurRadius
key:KEY_INACTIVE_BLUR_RADIUS
type:kPreferenceInfoTypeSlider];

[self defineControl:_backgroundImageTiled
key:KEY_BACKGROUND_IMAGE_TILED
type:kPreferenceInfoTypeCheckbox];
Expand Down
8 changes: 8 additions & 0 deletions sources/PseudoTerminal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2682,6 +2687,7 @@ - (void)windowDidResignKey:(NSNotification *)aNotification {
[[aSession textview] endFindCursor];
}
[[aSession textview] removeUnderline];
[[aSession textview] setIsBackground:YES];
}

PtyLog(@"PseudoTerminal windowDidResignKey");
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -5596,6 +5603,7 @@ - (void)setDimmingForSession:(PTYSession *)aSession
// broadcasting to the current session.
[[aSession view] setDimmed:YES];
}
[[aSession tab] recheckBlur];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is only meant to adjust dimming. I see that it gets called from several places, so to avoid having recheckBlur calls littered all over the place, the simplest thing might be to rename it from setDimmingForSession: to updateDimAndBlurForSession:, and rename callers as needed (e.g., setDimmingForSessions). XCode's "refactoring" feature makes this pretty easy to do.

[[aSession view] setNeedsDisplay:YES];
}

Expand Down
Loading