diff --git a/CMakeLists.txt b/CMakeLists.txt index a247515..5b5839a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,65 +1,65 @@ cmake_minimum_required(VERSION 3.0) project(PlasmaIntegration) set(PROJECT_VERSION "5.15.80") set(PROJECT_VERSION_MAJOR 5) -set(QT_MIN_VERSION "5.11.0") +set(QT_MIN_VERSION "5.12.0") set(KF5_MIN_VERSION "5.54.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) include(GenerateExportHeader) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Widgets DBus X11Extras QuickControls2) find_package(Qt5Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config ConfigWidgets I18n IconThemes KIO Notifications Wayland WidgetsAddons WindowSystem ConfigWidgets ) find_package(XCB COMPONENTS XCB) set_package_properties(XCB PROPERTIES DESCRIPTION "X protocol C-language Binding" URL "http://xcb.freedesktop.org" TYPE REQUIRED PURPOSE "Required to pass style properties to native Windows on X11 Platform" ) find_package(Breeze 5 CONFIG) set_package_properties(Breeze PROPERTIES TYPE REQUIRED PURPOSE "For setting the default QStyle name") # dependencies for QPA plugin find_package(Qt5ThemeSupport REQUIRED) set(QT5PLATFORMSUPPORT_LIBS Qt5ThemeSupport::Qt5ThemeSupport) add_definitions(-DTRANSLATION_DOMAIN=\"plasmaintegration5\") if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ki18n_install(po) endif() add_subdirectory(src) add_subdirectory(autotests) add_subdirectory(tests) find_package(FontNotoSans) set_package_properties(FontNotoSans PROPERTIES PURPOSE "Default sans-serif font -- this is not detected automatically, pass -DCMAKE_DISABLE_FIND_PACKAGE_FontNotoSans=true to mark it ignored." URL "https://www.google.com/get/noto/" TYPE RUNTIME ) find_package(FontHack) set_package_properties(FontHack PROPERTIES PURPOSE "Default monospace font -- this is not detected automatically, pass -DCMAKE_DISABLE_FIND_PACKAGE_FontHack=true to mark it ignored." URL "http://sourcefoundry.org/hack/" TYPE RUNTIME ) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/platformtheme/kwaylandintegration.cpp b/src/platformtheme/kwaylandintegration.cpp index 2288f73..1c6b415 100644 --- a/src/platformtheme/kwaylandintegration.cpp +++ b/src/platformtheme/kwaylandintegration.cpp @@ -1,205 +1,173 @@ /* This file is part of the KDE libraries * Copyright 2015 Martin Gräßlin * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kwaylandintegration.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace KWayland::Client; static const QByteArray s_schemePropertyName = QByteArrayLiteral("KDE_COLOR_SCHEME_PATH"); static const QByteArray s_blurBehindPropertyName = QByteArrayLiteral("ENABLE_BLUR_BEHIND_HINT"); KWaylandIntegration::KWaylandIntegration() : QObject() - , m_decoration(nullptr) { } KWaylandIntegration::~KWaylandIntegration() = default; void KWaylandIntegration::init() { auto connection = ConnectionThread::fromApplication(this); if (!connection) { return; } m_registry = new Registry(this); m_registry->create(connection); QObject::connect(m_registry, &Registry::interfacesAnnounced, this, [this] { - const auto interface = m_registry->interface(Registry::Interface::ServerSideDecorationManager); - if (interface.name != 0) { - m_decoration = m_registry->createServerSideDecorationManager(interface.name, interface.version, this); - qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); - QCoreApplication::instance()->installEventFilter(this); - - } + QCoreApplication::instance()->installEventFilter(this); const auto menuInterface = m_registry->interface(Registry::Interface::AppMenu); if (menuInterface.name != 0) { m_appMenuManager = m_registry->createAppMenuManager(menuInterface.name, menuInterface.version, this); } } ); m_registry->setup(); connection->roundtrip(); } bool KWaylandIntegration::eventFilter(QObject *watched, QEvent *event) { - if (!m_decoration) { - return false; - } else if (event->type() == QEvent::Expose) { + if (event->type() == QEvent::Expose) { auto ee = static_cast(event); if (ee->region().isNull()) { return false; } QWindow *w = qobject_cast(watched); if (!w || w->parent() || !w->isVisible()) { return false; } if (w->property("org.kde.plasma.integration.shellSurfaceCreated").isNull()) { shellSurfaceCreated(w); } } else if (event->type() == QEvent::Hide) { QWindow *w = qobject_cast(watched); if (!w || w->parent()) { return false; } shellSurfaceDestroyed(w); } else if (event->type() == QEvent::ApplicationPaletteChange) { const auto topLevelWindows = QGuiApplication::topLevelWindows(); for (QWindow *w : topLevelWindows) { installColorScheme(w); } } return false; } void KWaylandIntegration::shellSurfaceCreated(QWindow *w) { // set colorscheme hint if (qApp->property(s_schemePropertyName.constData()).isValid()) { installColorScheme(w); } const auto blurBehindProperty = w->property(s_blurBehindPropertyName.constData()); if (blurBehindProperty.isValid()) { KWindowEffects::enableBlurBehind(w->winId(), blurBehindProperty.toBool()); } // create deco Surface *s = Surface::fromWindow(w); if (!s) { return; } w->setProperty("org.kde.plasma.integration.shellSurfaceCreated", true); - if (QLibraryInfo::version() < QVersionNumber(5, 12, 0)) - { - auto deco = m_decoration->create(s, w); - connect(deco, &ServerSideDecoration::modeChanged, w, - [deco, w] { - const auto flags = w->flags(); - const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; - if (deco->mode() != ourMode) { - deco->requestMode(ourMode); - } - } - ); - const auto flags = w->flags(); - const auto ourMode = (flags.testFlag(Qt::FramelessWindowHint) || flags.testFlag(Qt::Popup) || flags.testFlag(Qt::ToolTip)) ? ServerSideDecoration::Mode::None : ServerSideDecoration::Mode::Server; - if (deco->defaultMode() != ourMode) { - deco->requestMode(ourMode); - } - w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant::fromValue(deco)); - } - if (m_appMenuManager) { auto menu = m_appMenuManager->create(s, w); w->setProperty("org.kde.plasma.integration.appmenu", QVariant::fromValue(menu)); menu->setAddress(m_windowInfo[w].appMenuServiceName, m_windowInfo[w].appMenuObjectPath); } } void KWaylandIntegration::shellSurfaceDestroyed(QWindow *w) { w->setProperty("org.kde.plasma.integration.shellSurfaceCreated", QVariant()); - delete w->property("org.kde.plasma.integration.waylandserverdecoration").value(); - w->setProperty("org.kde.plasma.integration.waylandserverdecoration", QVariant()); - delete w->property("org.kde.plasma.integration.appmenu").value(); w->setProperty("org.kde.plasma.integration.appmenu", QVariant()); delete w->property("org.kde.plasma.integration.palette").value(); w->setProperty("org.kde.plasma.integration.palette", QVariant()); } void KWaylandIntegration::installColorScheme(QWindow *w) { if (!m_paletteManager) { const auto paletteManagerInterface = m_registry->interface(Registry::Interface::ServerSideDecorationPalette); if (paletteManagerInterface.name == 0) { return; } else { m_paletteManager = m_registry->createServerSideDecorationPaletteManager(paletteManagerInterface.name, paletteManagerInterface.version, this); } } auto palette = w->property("org.kde.plasma.integration.palette").value(); if (!palette) { Surface *s = Surface::fromWindow(w); if (!s) { return; } palette = m_paletteManager->create(s, w); w->setProperty("org.kde.plasma.integration.palette", QVariant::fromValue(palette)); } if (palette) { palette->setPalette(qApp->property(s_schemePropertyName.constData()).toString()); } } void KWaylandIntegration::setAppMenu(QWindow *window, const QString &serviceName, const QString &objectPath) { if (!m_windowInfo.contains(window)) { //effectively makes this connect unique connect(window, &QObject::destroyed, this, [=]() { m_windowInfo.remove(window); }); } m_windowInfo[window].appMenuServiceName = serviceName; m_windowInfo[window].appMenuObjectPath = objectPath; auto menu = window->property("org.kde.plasma.integration.appmenu").value(); if (menu) { menu->setAddress(serviceName, objectPath); } } diff --git a/src/platformtheme/kwaylandintegration.h b/src/platformtheme/kwaylandintegration.h index e8df873..7c4653d 100644 --- a/src/platformtheme/kwaylandintegration.h +++ b/src/platformtheme/kwaylandintegration.h @@ -1,69 +1,68 @@ /* This file is part of the KDE libraries * Copyright 2015 Martin Gräßlin * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KWAYLANDINTEGRATION_H #define KWAYLANDINTEGRATION_H #include #include class QWindow; namespace KWayland { namespace Client { class ServerSideDecorationManager; class ServerSideDecorationPaletteManager; class AppMenuManager; class Registry; } } class KWaylandIntegration : public QObject { Q_OBJECT public: explicit KWaylandIntegration(); ~KWaylandIntegration() override; void init(); void setAppMenu(QWindow *window, const QString &serviceName, const QString &objectPath); void setPalette(QWindow *window, const QString &paletteName); bool eventFilter(QObject *watched, QEvent *event) override; private: void shellSurfaceCreated(QWindow *w); void shellSurfaceDestroyed(QWindow *w); void installColorScheme(QWindow *w); - KWayland::Client::ServerSideDecorationManager *m_decoration = nullptr; KWayland::Client::AppMenuManager *m_appMenuManager = nullptr; KWayland::Client::ServerSideDecorationPaletteManager *m_paletteManager = nullptr; KWayland::Client::Registry* m_registry = nullptr; struct WindowInfo { QString appMenuServiceName; QString appMenuObjectPath; }; QHash m_windowInfo; }; #endif