From ea4a5a463ded8dd499cede31660e8f5d079df2fe Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 15 Oct 2023 16:41:46 +0300 Subject: [PATCH] Provide compositor opaque hint Konsole requests alpha channel even when background is opaque. Since the opaque region is not set, the compositor (kwin) will render windows beneath konsole because it has no idea what part of konsole is actually opaque. This change makes Konsole set the Qt::WA_TranslucentBackground attribute based on whether opacity is set in the color scheme profile. If the opacity is 1, the translucent background attribute will be unset and QtWayland will set an opaque region, which would allow kwin to avoid repainting windows behind konsole. If the opacity changes to a value other than 1, the translucent background flag will be set and QtWayland will unset the opaque region. --- src/MainWindow.cpp | 13 +++++++++++++ src/MainWindow.h | 2 ++ src/ViewManager.cpp | 1 + src/ViewManager.h | 1 + 4 files changed, 17 insertions(+) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f684d6a12..b9fe17165 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -92,6 +92,7 @@ MainWindow::MainWindow() connect(_viewManager, &Konsole::ViewManager::unplugController, this, &Konsole::MainWindow::disconnectController); connect(_viewManager, &Konsole::ViewManager::viewPropertiesChanged, bookmarkHandler(), &Konsole::BookmarkHandler::setViews); connect(_viewManager, &Konsole::ViewManager::blurSettingChanged, this, &Konsole::MainWindow::setBlur); + connect(_viewManager, &Konsole::ViewManager::translucentBackgroundSettingChanged, this, &Konsole::MainWindow::setTranslucentBackgroundEnabled); connect(_viewManager, &Konsole::ViewManager::updateWindowIcon, this, &Konsole::MainWindow::updateWindowIcon); connect(_viewManager, &Konsole::ViewManager::newViewWithProfileRequest, this, &Konsole::MainWindow::newFromProfile); @@ -155,6 +156,10 @@ void MainWindow::updateUseTransparency() setAttribute(Qt::WA_TranslucentBackground, useTranslucency); setAttribute(Qt::WA_NoSystemBackground, false); WindowSystemInfo::HAVE_TRANSPARENCY = useTranslucency; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) + windowHandle()->setOpaque(!_translucentBackgroundEnabled); +#endif } void MainWindow::activationRequest(const QString &xdgActivationToken) @@ -995,6 +1000,14 @@ void MainWindow::setBlur(bool blur) } } +void MainWindow::setTranslucentBackgroundEnabled(bool enabled) +{ + if (enabled != _translucentBackgroundEnabled) { + _translucentBackgroundEnabled = enabled; + updateUseTransparency(); + } +} + void MainWindow::setMenuBarInitialVisibility(bool showMenuBar) { _windowArgsMenuBarVisible.enabled = true; diff --git a/src/MainWindow.h b/src/MainWindow.h index 990904d65..b968321b6 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -167,6 +167,7 @@ private Q_SLOTS: void profileListChanged(const QList &sessionActions); void configureNotifications(); void setBlur(bool blur); + void setTranslucentBackgroundEnabled(bool enabled); void updateWindowIcon(); void updateWindowCaption(); @@ -223,6 +224,7 @@ private: std::vector _plugins; QList _pluginsActions; bool _blurEnabled = false; + bool _translucentBackgroundEnabled = false; bool _firstShowEvent = true; struct { diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 617e8cb1e..b4e621f74 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -1091,6 +1091,7 @@ void ViewManager::applyProfileToView(TerminalDisplay *view, const Profile::Ptr & view->applyProfile(profile); Q_EMIT updateWindowIcon(); Q_EMIT blurSettingChanged(view->colorScheme()->blur()); + Q_EMIT translucentBackgroundSettingChanged(view->colorScheme()->opacity() != 1.0); } void ViewManager::updateViewsForSession(Session *session) diff --git a/src/ViewManager.h b/src/ViewManager.h index 544ad1d57..82b8388ea 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -228,6 +228,7 @@ Q_SIGNALS: void updateWindowIcon(); void blurSettingChanged(bool); + void translucentBackgroundSettingChanged(bool); /** Requests creation of a new view with the default profile. */ void newViewRequest();