Skip to content

Commit

Permalink
Use colored fgColor on hover in gtk buttons (Issue #50)
Browse files Browse the repository at this point in the history
The minimize and maximize colors are from SierraBreezeEnhanced.

The bg fill doesn't reach the headerbar edges since the Breeze GTK
theme has huge margins around the buttons.
  • Loading branch information
Zren committed Jun 8, 2021
1 parent 33258cc commit c71e9a4
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/Button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ QColor Button::backgroundColor() const
return {};
}

if (m_isGtkButton) {
// Breeze GTK has huge margins around the button. It looks better
// when we just change the fgColor on hover instead of the bgColor.
return Qt::transparent;
}

//--- CloseButton
if (type() == KDecoration2::DecorationButtonType::Close) {
auto *decoratedClient = deco->client().toStrongRef().data();
Expand Down Expand Up @@ -395,7 +401,7 @@ QColor Button::foregroundColor() const

//--- Checked
if (isChecked() && type() != KDecoration2::DecorationButtonType::Maximize) {
QColor activeColor = KColorUtils::mix(
const QColor activeColor = KColorUtils::mix(
deco->titleBarBackgroundColor(),
deco->titleBarForegroundColor(),
0.2);
Expand All @@ -410,15 +416,42 @@ QColor Button::foregroundColor() const
}

//--- Normal
QColor normalColor = KColorUtils::mix(
const QColor normalColor = KColorUtils::mix(
deco->titleBarBackgroundColor(),
deco->titleBarForegroundColor(),
0.8);

if (isPressed() || isHovered()) {
// Breeze GTK has huge margins around the button. It looks better
// when we just change the fgColor on hover instead of the bgColor.
QColor hoveredColor;
if (m_isGtkButton && type() == KDecoration2::DecorationButtonType::Close) {
auto *decoratedClient = deco->client().toStrongRef().data();
hoveredColor = decoratedClient->color(
KDecoration2::ColorGroup::Warning,
KDecoration2::ColorRole::Foreground
);
} else if (m_isGtkButton && type() == KDecoration2::DecorationButtonType::Maximize) {
const grayValue = qGray(deco->titleBarBackgroundColor().rgb());
if (grayValue < 128) { // Dark Bg
hoveredColor = QColor(100, 196, 86); // from SierraBreeze
} else { // Light Bg
hoveredColor = QColor(40, 200, 64); // from SierraBreeze
}
} else if (m_isGtkButton && type() == KDecoration2::DecorationButtonType::Minimize) {
const grayValue = qGray(deco->titleBarBackgroundColor().rgb());
if (grayValue < 128) {
hoveredColor = QColor(223, 192, 76); // from SierraBreeze
} else { // Light Bg
hoveredColor = QColor(255, 188, 48); // from SierraBreeze
}
} else {
hoveredColor = deco->titleBarForegroundColor();
}

return KColorUtils::mix(
normalColor,
deco->titleBarForegroundColor(),
hoveredColor,
m_transitionValue);
}

Expand Down

0 comments on commit c71e9a4

Please sign in to comment.