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.
This commit is contained in:
Vlad Zahorodnii
2023-10-15 16:41:46 +03:00
parent e2f7ff14dc
commit ea4a5a463d
4 changed files with 17 additions and 0 deletions

View File

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

View File

@@ -167,6 +167,7 @@ private Q_SLOTS:
void profileListChanged(const QList<QAction *> &sessionActions);
void configureNotifications();
void setBlur(bool blur);
void setTranslucentBackgroundEnabled(bool enabled);
void updateWindowIcon();
void updateWindowCaption();
@@ -223,6 +224,7 @@ private:
std::vector<IKonsolePlugin *> _plugins;
QList<QAction *> _pluginsActions;
bool _blurEnabled = false;
bool _translucentBackgroundEnabled = false;
bool _firstShowEvent = true;
struct {

View File

@@ -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)

View File

@@ -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();