Skip to content
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

Read shadowColor from KDecoration2::DecorationShadow #217

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/debian12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: |
apt update
apt -y install --no-install-recommends aptitude
aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev
aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev libkdecorations2-dev
aptitude -y install --without-recommends dpkg-dev file

- name: Configure CMake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fedora40.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Install Dependencies
run: |
dnf -y install cmake gcc-c++ extra-cmake-modules kwin-devel kf6-kconfigwidgets-devel libepoxy-devel kf6-kcmutils-devel qt6-qtbase-private-devel wayland-devel
dnf -y install cmake gcc-c++ extra-cmake-modules kwin-devel kf6-kconfigwidgets-devel libepoxy-devel kf6-kcmutils-devel qt6-qtbase-private-devel wayland-devel kdecoration-devel
dnf -y install rpm-build

- name: Configure CMake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kubuntu2204-backports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: sudo add-apt-repository -y ppa:kubuntu-ppa/backports-extra

- name: Install Dependencies
run: sudo aptitude install -y --without-recommends gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev
run: sudo aptitude install -y --without-recommends gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev libkdecorations2-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kubuntu2404.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install Dependencies
run: |
apt -y install --no-install-recommends aptitude
aptitude install -y --without-recommends cmake g++ gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev
aptitude install -y --without-recommends cmake g++ gettext extra-cmake-modules qttools5-dev libkf5configwidgets-dev kwin-dev libkdecorations2-dev
aptitude -y install --without-recommends dpkg-dev file

- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/neon-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Install Dependencies
run: |
sudo aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qt6-base-dev-tools libkf6configwidgets-dev libkf6kcmutils-dev kwin-dev
sudo aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qt6-base-dev-tools libkf6configwidgets-dev libkf6kcmutils-dev kwin-dev libkdecorations2-dev
sudo aptitude -y install --without-recommends dpkg-dev file

- name: Configure CMake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/neon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Install Dependencies
run: |
sudo aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qt6-base-dev-tools libkf6configwidgets-dev libkf6kcmutils-dev kwin-dev
sudo aptitude -y install --without-recommends cmake g++ gettext extra-cmake-modules qt6-base-dev-tools libkf6configwidgets-dev libkf6kcmutils-dev kwin-dev libkdecorations2-dev
sudo aptitude -y install --without-recommends dpkg-dev file

- name: Initialize CodeQL
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(${QT_MAJOR_VERSION} EQUAL 6)
else()
find_package(KWinEffects REQUIRED COMPONENTS kwineffects kwinglutils)
endif ()
find_package(KDecoration2 REQUIRED COMPONENTS KDecoration)
find_package(epoxy REQUIRED)
find_package(XCB REQUIRED COMPONENTS XCB)
find_package(KWinDBusInterface CONFIG REQUIRED)
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ set(effect_SRCS
kconfig_add_kcfg_files(effect_SRCS Config.kcfgc)
kcoreaddons_add_plugin(kwin4_effect_shapecorners SOURCES ${effect_SRCS} INSTALL_NAMESPACE "kwin/effects/plugins/")

target_include_directories(kwin4_effect_shapecorners PUBLIC
"/usr/include/KDecoration2"
)
target_link_libraries(kwin4_effect_shapecorners
Qt${QT_MAJOR_VERSION}::DBus
KF${QT_MAJOR_VERSION}::ConfigGui
KDecoration2::KDecoration
)
if(${QT_MAJOR_VERSION} EQUAL 6)
target_link_libraries(kwin4_effect_shapecorners
Expand Down
25 changes: 16 additions & 9 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#else
#include <kwineffects.h>
#endif
#include <KDecoration2/Decoration>
#include <KDecoration2/DecorationShadow>

QWidget ShapeCorners::Window::m_widget {};

Expand Down Expand Up @@ -59,7 +61,7 @@ void ShapeCorners::Window::animateProperties(const std::chrono::milliseconds& ti
float configShadowSize;
float configOutlineSize;
float configSecondOutlineSize;
Color configShadowColor;
Color configShadowColor = Color(getDecorationShadowColor());
Color configOutlineColor;
Color configSecondOutlineColor;
const QPalette& m_palette = m_widget.palette();
Expand All @@ -68,10 +70,6 @@ void ShapeCorners::Window::animateProperties(const std::chrono::milliseconds& ti
configShadowSize = static_cast<float>(Config::shadowSize());
configOutlineSize = static_cast<float>(Config::outlineThickness());
configSecondOutlineSize = static_cast<float>(Config::secondOutlineThickness());

configShadowColor = Color(Config::activeShadowUsePalette() ?
m_palette.color(QPalette::Active, static_cast<QPalette::ColorRole>(Config::activeShadowPalette())):
Config::shadowColor());
configShadowColor.setAlpha(Config::activeShadowAlpha());

configOutlineColor = Color(Config::activeOutlineUsePalette() ?
Expand All @@ -88,10 +86,6 @@ void ShapeCorners::Window::animateProperties(const std::chrono::milliseconds& ti
configShadowSize = static_cast<float>(Config::inactiveShadowSize());
configOutlineSize = static_cast<float>(Config::inactiveOutlineThickness());
configSecondOutlineSize = static_cast<float>(Config::inactiveSecondOutlineThickness());

configShadowColor = Color(Config::inactiveShadowUsePalette() ?
m_palette.color(QPalette::Inactive, static_cast<QPalette::ColorRole>(Config::inactiveShadowPalette())):
Config::inactiveShadowColor());
configShadowColor.setAlpha(Config::inactiveShadowAlpha());

configOutlineColor = Color(Config::inactiveOutlineUsePalette() ?
Expand Down Expand Up @@ -186,3 +180,16 @@ void ShapeCorners::Window::animateProperties(const std::chrono::milliseconds& ti
#endif
w->addRepaintFull();
}

QColor ShapeCorners::Window::getDecorationShadowColor() const {
QColor result = Qt::transparent;
auto decoration = w->decoration();
if (decoration) {
auto shadow = decoration->shadow().get();
if (shadow) {
auto shadowImage = shadow->shadow();
result = shadowImage.pixelColor(135, 54);
}
}
return result;
}
2 changes: 2 additions & 0 deletions src/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace ShapeCorners {
* \brief Used only for its `palette()` function which holds the currently active highlight colors.
*/
static QWidget m_widget;

[[nodiscard]] QColor getDecorationShadowColor() const;
};
}

Expand Down
19 changes: 0 additions & 19 deletions src/kcm/KCM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ ShapeCorners::KCM::KCM(QWidget* parent, const QVariantList& args)
QIcon icon (pix);
ui->kcfg_ActiveOutlinePalette->setItemIcon(index, icon);
ui->kcfg_ActiveSecondOutlinePalette->setItemIcon(index, icon);
ui->kcfg_ActiveShadowPalette->setItemIcon(index, icon);

c = palette().color(QPalette::Inactive, static_cast<QPalette::ColorRole>(index));
pix.fill(c);
QIcon icon2 (pix);
ui->kcfg_InactiveOutlinePalette->setItemIcon(index, icon2);
ui->kcfg_InactiveSecondOutlinePalette->setItemIcon(index, icon2);
ui->kcfg_InactiveShadowPalette->setItemIcon(index, icon2);
}

connect(ui->kcfg_ActiveOutlinePalette, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KCM::update_colors);
Expand All @@ -52,13 +50,6 @@ ShapeCorners::KCM::KCM(QWidget* parent, const QVariantList& args)
connect(ui->kcfg_ActiveSecondOutlineUsePalette, &QRadioButton::toggled, this, &KCM::update_colors);
connect(ui->kcfg_InactiveSecondOutlineUsePalette, &QRadioButton::toggled, this, &KCM::update_colors);

connect(ui->kcfg_ActiveShadowPalette, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KCM::update_colors);
connect(ui->kcfg_ActiveShadowPalette, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KCM::update_colors);
connect(ui->kcfg_ShadowColor, &KColorButton::changed, this, &KCM::update_colors);
connect(ui->kcfg_InactiveShadowColor, &KColorButton::changed, this, &KCM::update_colors);
connect(ui->kcfg_ActiveShadowUsePalette, &QRadioButton::toggled, this, &KCM::update_colors);
connect(ui->kcfg_InactiveShadowUsePalette, &QRadioButton::toggled, this, &KCM::update_colors);

// It was expected that the Apply button would get enabled automatically as the gradient sliders move, but it doesn't.
// Maybe it is a bug on the KCM side. Need to check and delete these lines later.
connect(ui->kcfg_ActiveShadowAlpha, &KGradientSelector::sliderMoved, this, &KCM::markAsChanged);
Expand Down Expand Up @@ -150,16 +141,6 @@ void ShapeCorners::KCM::update_colors() {
index = ui->kcfg_InactiveSecondOutlinePalette->currentIndex();
color = checked ? palette().color(QPalette::Inactive, static_cast<QPalette::ColorRole>(index)): ui->kcfg_InactiveSecondOutlineColor->color();
ui->kcfg_InactiveSecondOutlineAlpha->setSecondColor(color);

checked = ui->kcfg_ActiveShadowUsePalette->isChecked();
index = ui->kcfg_ActiveShadowPalette->currentIndex();
color = checked ? palette().color(QPalette::Active, static_cast<QPalette::ColorRole>(index)): ui->kcfg_ShadowColor->color();
ui->kcfg_ActiveShadowAlpha->setSecondColor(color);

checked = ui->kcfg_InactiveShadowUsePalette->isChecked();
index = ui->kcfg_InactiveShadowPalette->currentIndex();
color = checked ? palette().color(QPalette::Inactive, static_cast<QPalette::ColorRole>(index)): ui->kcfg_InactiveShadowColor->color();
ui->kcfg_InactiveShadowAlpha->setSecondColor(color);
}

void ShapeCorners::KCM::update_windows() const {
Expand Down
Loading