From 610bcae568ca19a468c9ceaf4b8913bc8d4d112c Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Tue, 12 Dec 2023 10:08:17 +0100 Subject: [PATCH] Add GNOME-like client-side decoration plugin Adds a client-side decoration plugin implementing GNOME's Adwaita style. This is trying to follow GTK4 Adwaita style, using xdg-desktop-portal to get user's configuration in order to get whether a light or dark colors should be used and to get the titlebar button layout. This plugin is now used on GNOME by default, while defaulting to the original behavior for non-GNOME DEs. It depends on QtSvg used to draw titlebar buttons so in case QtSvg is not found, this plugin will not be build. [ChangeLog][QtWaylandClient][Added GNOME-like client-side decoration plugin] Fixes: QTBUG-120070 Change-Id: I0f1777c4e0aa3467dafbbae8004b594cc82f9aa0 Reviewed-by: David Edmundson --- src/platformsupport/wayland/configure.cmake | 8 ++++++++ .../plugins/decorations/CMakeLists.txt | 3 +++ .../platforms/wayland/qwaylandwindow.cpp | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/platformsupport/wayland/configure.cmake b/src/platformsupport/wayland/configure.cmake index eda1f085019..45f94533348 100644 --- a/src/platformsupport/wayland/configure.cmake +++ b/src/platformsupport/wayland/configure.cmake @@ -245,6 +245,11 @@ qt_feature("wayland-vulkan-server-buffer" PRIVATE qt_feature("wayland-datadevice" PRIVATE CONDITION QT_FEATURE_draganddrop OR QT_FEATURE_clipboard ) +qt_feature("wayland-decoration-adwaita" PRIVATE + LABEL "GNOME-like client-side decorations" + CONDITION NOT WIN32 AND QT_FEATURE_wayland_client AND TARGET Qt::DBus AND TARGET Qt::Svg +) + qt_configure_add_summary_entry(ARGS "wayland-client") qt_configure_add_summary_entry(ARGS "wayland-server") @@ -257,6 +262,9 @@ qt_configure_add_summary_entry(ARGS "wayland-dmabuf-server-buffer") qt_configure_add_summary_entry(ARGS "wayland-shm-emulation-server-buffer") qt_configure_add_summary_entry(ARGS "wayland-vulkan-server-buffer") qt_configure_end_summary_section() # end of "Qt Wayland Drivers" section +qt_configure_add_summary_section(NAME "Qt Wayland Decoration Plugins") +qt_configure_add_summary_entry(ARGS "wayland-decoration-adwaita") +qt_configure_end_summary_section() # end of "Qt Wayland Decoration Plugins" section qt_configure_add_report_entry( TYPE ERROR diff --git a/src/plugins/platforms/wayland/plugins/decorations/CMakeLists.txt b/src/plugins/platforms/wayland/plugins/decorations/CMakeLists.txt index 73c59e4a547..abe3c375b88 100644 --- a/src/plugins/platforms/wayland/plugins/decorations/CMakeLists.txt +++ b/src/plugins/platforms/wayland/plugins/decorations/CMakeLists.txt @@ -2,5 +2,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Generated from decorations.pro. +if (QT_FEATURE_wayland_decoration_adwaita) + add_subdirectory(adwaita) +endif() add_subdirectory(bradient) diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 215193a7bf8..c0a415725e4 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -36,6 +37,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace QtWaylandClient { Q_LOGGING_CATEGORY(lcWaylandBackingstore, "qt.qpa.wayland.backingstore") @@ -1092,6 +1095,22 @@ bool QWaylandWindow::createDecoration() } } + if (targetKey.isEmpty()) { + auto unixServices = dynamic_cast( + QGuiApplicationPrivate::platformIntegration()->services()); + const QByteArray currentDesktop = unixServices->desktopEnvironment(); + if (currentDesktop == "GNOME") { + if (decorations.contains("adwaita"_L1)) + targetKey = "adwaita"_L1; + else if (decorations.contains("gnome"_L1)) + targetKey = "gnome"_L1; + } else { + // Do not use Adwaita/GNOME decorations on other DEs + decorations.removeAll("adwaita"_L1); + decorations.removeAll("gnome"_L1); + } + } + if (targetKey.isEmpty()) targetKey = decorations.first(); // first come, first served.