diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h
--- a/src/EditProfileDialog.h
+++ b/src/EditProfileDialog.h
@@ -120,6 +120,7 @@
void terminalColumnsEntryChanged(int);
void terminalRowsEntryChanged(int);
void showTerminalSizeHint(bool);
+ void setDimWhenInactive(bool);
void showEnvironmentEditor();
void silenceSecondsChanged(int);
diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp
--- a/src/EditProfileDialog.cpp
+++ b/src/EditProfileDialog.cpp
@@ -359,6 +359,7 @@
// window options
_ui->showTerminalSizeHintButton->setChecked(profile->showTerminalSizeHint());
+ _ui->dimWhenInactiveCheckbox->setChecked(profile->dimWhenInactive());
// signals and slots
connect(_ui->dirSelectButton, &QToolButton::clicked, this,
@@ -384,6 +385,9 @@
connect(_ui->showTerminalSizeHintButton, &QCheckBox::toggled, this,
&Konsole::EditProfileDialog::showTerminalSizeHint);
+
+ connect(_ui->dimWhenInactiveCheckbox, &QCheckBox::toggled, this,
+ &Konsole::EditProfileDialog::setDimWhenInactive);
}
void EditProfileDialog::showEnvironmentEditor()
@@ -457,6 +461,11 @@
updateTempProfileProperty(Profile::ShowTerminalSizeHint, value);
}
+void EditProfileDialog::setDimWhenInactive(bool value)
+{
+ updateTempProfileProperty(Profile::DimWhenInactive, value);
+}
+
void EditProfileDialog::tabTitleFormatChanged(const QString &format)
{
updateTempProfileProperty(Profile::LocalTabTitleFormat, format);
diff --git a/src/EditProfileDialog.ui b/src/EditProfileDialog.ui
--- a/src/EditProfileDialog.ui
+++ b/src/EditProfileDialog.ui
@@ -343,6 +343,16 @@
+ -
+
+
+ Indicate whether the window is active by dimming the colors
+
+
+ Dim the colors when the window loses focus
+
+
+
diff --git a/src/Profile.h b/src/Profile.h
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -114,6 +114,9 @@
* resizing the application window.
*/
ShowTerminalSizeHint,
+ /** (bool) If the background color should change to indicate if the window is active
+ */
+ DimWhenInactive,
/** (QFont) The font to use in terminal displays using this profile. */
Font,
/** (QString) The name of the color scheme to use in terminal
@@ -439,6 +442,12 @@
return property(Profile::ShowTerminalSizeHint);
}
+ /** Convenience method for property(Profile::DimWhenInactive) */
+ bool dimWhenInactive() const
+ {
+ return property(Profile::DimWhenInactive);
+ }
+
/** Convenience method for property(Profile::Font) */
QFont font() const
{
diff --git a/src/Profile.cpp b/src/Profile.cpp
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -67,6 +67,7 @@
, { LocalTabTitleFormat , "tabtitle" , nullptr , QVariant::String }
, { RemoteTabTitleFormat , "RemoteTabTitleFormat" , GENERAL_GROUP , QVariant::String }
, { ShowTerminalSizeHint , "ShowTerminalSizeHint" , GENERAL_GROUP , QVariant::Bool }
+ , { DimWhenInactive , "DimWhenInactive" , GENERAL_GROUP , QVariant::Bool }
, { StartInCurrentSessionDir , "StartInCurrentSessionDir" , GENERAL_GROUP , QVariant::Bool }
, { SilenceSeconds, "SilenceSeconds" , GENERAL_GROUP , QVariant::Int }
, { TerminalColumns, "TerminalColumns" , GENERAL_GROUP , QVariant::Int }
@@ -166,6 +167,7 @@
setProperty(LocalTabTitleFormat, QStringLiteral("%d : %n"));
setProperty(RemoteTabTitleFormat, QStringLiteral("(%u) %H"));
setProperty(ShowTerminalSizeHint, true);
+ setProperty(DimWhenInactive, false);
setProperty(StartInCurrentSessionDir, true);
setProperty(MenuIndex, QStringLiteral("0"));
setProperty(SilenceSeconds, 10);
diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h
--- a/src/TerminalDisplay.h
+++ b/src/TerminalDisplay.h
@@ -696,6 +696,13 @@
*/
void setCenterContents(bool enable);
+ /**
+ * Sets whether the background should change when the window loses focus
+ */
+ void setDimWhenInactive(bool shouldDim) {
+ _dimWhenInactive = shouldDim;
+ }
+
// Used to show/hide the message widget
void updateReadOnlyState(bool readonly);
IncrementalSearchBar *searchBar() const;
@@ -798,7 +805,8 @@
void inputMethodEvent(QInputMethodEvent *event) Q_DECL_OVERRIDE;
QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
- void updateScrollBarPalette();
+ void onColorsChanged();
+
protected Q_SLOTS:
void scrollBarPositionChanged(int value);
@@ -955,6 +963,7 @@
QVector _lineProperties;
ColorEntry _colorTable[TABLE_COLORS];
+
uint _randomSeed;
bool _resizing;
@@ -1065,6 +1074,8 @@
qreal _opacity;
+ bool _dimWhenInactive;
+
ScrollState _scrollWheelState;
IncrementalSearchBar *_searchBar;
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -137,55 +137,64 @@
return _colorTable;
}
-void TerminalDisplay::updateScrollBarPalette()
+void TerminalDisplay::onColorsChanged()
{
+ // Mostly just fix the scrollbar
+ // this is a workaround to add some readability to old themes like Fusion
+ // changing the light value for button a bit makes themes like fusion, windows and oxygen way more readable and pleasing
+
+ QPalette p = QApplication::palette();
+
+ QColor buttonTextColor = _colorTable[DEFAULT_FORE_COLOR];
QColor backgroundColor = _colorTable[DEFAULT_BACK_COLOR];
backgroundColor.setAlphaF(_opacity);
- QPalette p = palette();
- p.setColor(QPalette::Window, backgroundColor);
- //this is a workaround to add some readability to old themes like Fusion
- //changing the light value for button a bit makes themes like fusion, windows and oxygen way more readable and pleasing
- QColor buttonColor;
- buttonColor.setHsvF(backgroundColor.hueF(), backgroundColor.saturationF(), backgroundColor.valueF() + (backgroundColor.valueF() < 0.5 ? 0.2 : -0.2));
+ QColor buttonColor = backgroundColor.toHsv();
+ if (buttonColor.valueF() < 0.5) {
+ buttonColor = buttonColor.lighter();
+ } else {
+ buttonColor = buttonColor.darker();
+ }
p.setColor(QPalette::Button, buttonColor);
+ p.setColor(QPalette::Window, backgroundColor);
+ p.setColor(QPalette::WindowText, buttonTextColor);
+ p.setColor(QPalette::ButtonText, buttonTextColor);
+
+ setPalette(p);
- p.setColor(QPalette::WindowText, _colorTable[DEFAULT_FORE_COLOR]);
- p.setColor(QPalette::ButtonText, _colorTable[DEFAULT_FORE_COLOR]);
_scrollBar->setPalette(p);
+ update();
}
void TerminalDisplay::setBackgroundColor(const QColor& color)
{
_colorTable[DEFAULT_BACK_COLOR] = color;
- QPalette p = palette();
- p.setColor(backgroundRole(), color);
- setPalette(p);
-
- updateScrollBarPalette();
- update();
+ onColorsChanged();
}
+
QColor TerminalDisplay::getBackgroundColor() const
{
- QPalette p = palette();
- return p.color(backgroundRole());
+ return _colorTable[DEFAULT_BACK_COLOR];
}
+
void TerminalDisplay::setForegroundColor(const QColor& color)
{
_colorTable[DEFAULT_FORE_COLOR] = color;
- updateScrollBarPalette();
- update();
+ onColorsChanged();
}
+
void TerminalDisplay::setColorTable(const ColorEntry table[])
{
for (int i = 0; i < TABLE_COLORS; i++) {
_colorTable[i] = table[i];
}
setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR]);
+
+ onColorsChanged();
}
/* ------------------------------------------------------------------------- */
@@ -467,6 +476,7 @@
, _readOnlyMessageWidget(nullptr)
, _readOnly(false)
, _opacity(1.0)
+ , _dimWhenInactive(false)
, _scrollWheelState(ScrollState())
, _searchBar(new IncrementalSearchBar(this))
{
@@ -869,7 +879,7 @@
}*/
_blendColor = color.rgba();
- updateScrollBarPalette();
+ onColorsChanged();
}
void TerminalDisplay::setWallpaper(ColorSchemeWallpaper::Ptr p)
@@ -1037,7 +1047,7 @@
const QColor backgroundColor = style->backgroundColor.color(_colorTable);
// draw background if different from the display's background color
- if (backgroundColor != palette().background().color()) {
+ if (backgroundColor != getBackgroundColor()) {
drawBackground(painter, rect, backgroundColor,
false /* do not use transparency */);
}
@@ -1476,14 +1486,23 @@
QRegion dirtyImageRegion;
foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) {
dirtyImageRegion += widgetToImage(rect);
- drawBackground(paint, rect, palette().background().color(), true /* use opacity setting */);
+ drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */);
}
+
foreach(const QRect & rect, dirtyImageRegion.rects()) {
drawContents(paint, rect);
}
drawCurrentResultRect(paint);
drawInputMethodPreeditString(paint, preeditRect());
paintFilters(paint);
+
+ const bool drawDimmed = _dimWhenInactive && !hasFocus();
+ const QColor dimColor(0, 0, 0, 128);
+ foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) {
+ if (drawDimmed) {
+ paint.fillRect(rect, dimColor);
+ }
+ }
}
void TerminalDisplay::printContent(QPainter& painter, bool friendly)
@@ -1542,7 +1561,7 @@
getCharacterPosition(cursorPos, cursorLine, cursorColumn, false);
Character cursorCharacter = _image[loc(qMin(cursorColumn, _columns - 1), cursorLine)];
- painter.setPen(QPen(cursorCharacter.foregroundColor.color(colorTable())));
+ painter.setPen(QPen(cursorCharacter.foregroundColor.color(_colorTable)));
// iterate over hotspots identified by the display's currently active filters
// and draw appropriate visuals to indicate the presence of the hotspot
@@ -3653,7 +3672,11 @@
break;
case QEvent::PaletteChange:
case QEvent::ApplicationPaletteChange:
- _scrollBar->setPalette(QApplication::palette());
+ onColorsChanged();
+ break;
+ case QEvent::FocusOut:
+ case QEvent::FocusIn:
+ update();
break;
default:
break;
@@ -3732,7 +3755,7 @@
_colorTable[DEFAULT_BACK_COLOR] = _colorTable[DEFAULT_FORE_COLOR];
_colorTable[DEFAULT_FORE_COLOR] = color;
- update();
+ onColorsChanged();
}
/* --------------------------------------------------------------------- */
diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp
--- a/src/ViewManager.cpp
+++ b/src/ViewManager.cpp
@@ -811,6 +811,7 @@
// show hint about terminal size after resizing
view->setShowTerminalSizeHint(profile->showTerminalSizeHint());
+ view->setDimWhenInactive(profile->dimWhenInactive());
// terminal features
view->setBlinkingCursorEnabled(profile->blinkingCursorEnabled());