diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -41,6 +41,7 @@ coronatesthelper.cpp debug.cpp screenpool.cpp + softwarerendernotifier.cpp ${scripting_SRC} ) @@ -74,6 +75,7 @@ KF5::Package KF5::WaylandClient KF5::WindowSystem + KF5::Notifications PW::KWorkspace ) target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}") diff --git a/shell/main.cpp b/shell/main.cpp --- a/shell/main.cpp +++ b/shell/main.cpp @@ -40,6 +40,7 @@ #include "standaloneappcorona.h" #include "shellmanager.h" #include "coronatesthelper.h" +#include "softwarerendernotifier.h" #include @@ -183,7 +184,6 @@ KDBusService service(KDBusService::Unique); - QObject::connect(ShellManager::instance(), &ShellManager::glInitialisationFailed, &app, [&app]() { //scene graphs errors come from a thread //even though we process them in the main thread, app.exit could still process these events @@ -206,6 +206,7 @@ } app.exit(-1); }); + SoftwareRendererNotifier::notifyIfRelevant(); QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater); return app.exec(); diff --git a/shell/softwarerendernotifier.h b/shell/softwarerendernotifier.h new file mode 100644 --- /dev/null +++ b/shell/softwarerendernotifier.h @@ -0,0 +1,35 @@ +/* + * Copyright 2018 David Edmundson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +/** + * Responsible for showing an SNI if the software renderer is used + * to allow the a user to open the KCM + */ + +class SoftwareRendererNotifier: public KStatusNotifierItem +{ + Q_OBJECT +public: + //only exposed as void static constructor as internally it is self memory managing + static void notifyIfRelevant(); +private: + SoftwareRendererNotifier(QObject *parent=nullptr); + ~SoftwareRendererNotifier(); +}; diff --git a/shell/softwarerendernotifier.cpp b/shell/softwarerendernotifier.cpp new file mode 100644 --- /dev/null +++ b/shell/softwarerendernotifier.cpp @@ -0,0 +1,50 @@ +#include "softwarerendernotifier.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +void SoftwareRendererNotifier::notifyIfRelevant() +{ + if (QQuickWindow::sceneGraphBackend() == QLatin1String("software")) { + auto group = KSharedConfig::openConfig()->group(QStringLiteral("softwarerenderer")); + bool neverShow = group.readEntry("neverShow", false); + if (neverShow) { + return; + } + new SoftwareRendererNotifier(qApp); + } +} + +SoftwareRendererNotifier::SoftwareRendererNotifier(QObject *parent) + : KStatusNotifierItem(parent) +{ + setTitle(i18n("Software Renderer In Use")); + setToolTipTitle(i18nc("Tooltip telling user their GL drivers are broken", "Software Renderer In Use")); + setToolTipSubTitle(i18nc("Tooltip telling user their GL drivers are broken", "Rendering may be degraded")); + setIconByName(QStringLiteral("video-card-inactive")); + setStatus(KStatusNotifierItem::Active); + setStandardActionsEnabled(false); + + connect(this, &KStatusNotifierItem::activateRequested, this, []() { + QProcess::startDetached("kcmshell5 qtquicksettings"); + }); + + auto menu = new QMenu; //ownership is transferred in setContextMenu + auto action = new QAction(i18n("Never show again")); + connect(action, &QAction::triggered, this, [this]() { + auto group = KSharedConfig::openConfig()->group(QStringLiteral("softwarerenderer")); + group.writeEntry("neverShow", true); + deleteLater(); + }); + menu->addAction(action); + setContextMenu(menu); +} + +SoftwareRendererNotifier::~SoftwareRendererNotifier() = default; +