diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 29f9a5d78..8beda587c 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -1,99 +1,101 @@ configure_file(config-ktexteditor.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ktexteditor.h ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-plasma.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-plasma.h) add_definitions(-DPLASMA_DEPRECATED=) set(scripting_SRC scripting/appinterface.cpp scripting/applet.cpp scripting/containment.cpp scripting/configgroup.cpp scripting/i18n.cpp scripting/panel.cpp scripting/rect.cpp scripting/scriptengine.cpp scripting/scriptengine_v1.cpp scripting/widget.cpp ) set(plasmashell_dbusXML dbus/org.kde.PlasmaShell.xml) qt5_add_dbus_adaptor(scripting_SRC ${plasmashell_dbusXML} shellcorona.h ShellCorona plasmashelladaptor) ecm_qt_declare_logging_category(plasmashell HEADER debug.h IDENTIFIER PLASMASHELL CATEGORY_NAME kde.plasmashell DEFAULT_SEVERITY Info) set (plasma_shell_SRCS alternativeshelper.cpp main.cpp containmentconfigview.cpp currentcontainmentactionsmodel.cpp desktopview.cpp panelview.cpp panelconfigview.cpp panelshadows.cpp shellcorona.cpp shellmanager.cpp standaloneappcorona osd.cpp coronatesthelper.cpp debug.cpp screenpool.cpp + softwarerendernotifier.cpp ${scripting_SRC} ) set(krunner_xml ${plasma-workspace_SOURCE_DIR}/krunner/dbus/org.kde.krunner.App.xml) qt5_add_dbus_interface(plasma_shell_SRCS ${krunner_xml} krunner_interface) add_executable(plasmashell ${plasma_shell_SRCS} ) target_link_libraries(plasmashell Qt5::Quick Qt5::DBus KF5::KIOCore KF5::WindowSystem KF5::Crash KF5::Plasma KF5::PlasmaQuick Qt5::Script KF5::Solid KF5::Declarative KF5::I18n KF5::IconThemes KF5::Activities KF5::GlobalAccel KF5::CoreAddons KF5::DBusAddons KF5::Declarative KF5::QuickAddons KF5::XmlGui KF5::Package KF5::WaylandClient KF5::WindowSystem + KF5::Notifications PW::KWorkspace ) target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}") target_compile_definitions(plasmashell PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") if(HAVE_X11) target_link_libraries(plasmashell ${X11_LIBRARIES} ${XCB_LIBRARIES} ) target_link_libraries(plasmashell Qt5::X11Extras) endif() install(TARGETS plasmashell ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES org.kde.plasmashell.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES org.kde.plasmashell.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR}) install( FILES dbus/org.kde.PlasmaShell.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} ) install(FILES scripting/plasma-layouttemplate.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) add_subdirectory(packageplugins) if(BUILD_TESTING) add_subdirectory(autotests) endif() diff --git a/shell/main.cpp b/shell/main.cpp index d656ef4df..9c760d9a9 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -1,212 +1,213 @@ /* * Copyright 2012 Marco Martin * Copyright 2013 Sebastian Kügler * Copyright 2015 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "shellcorona.h" #include "standaloneappcorona.h" #include "shellmanager.h" #include "coronatesthelper.h" +#include "softwarerendernotifier.h" #include int main(int argc, char *argv[]) { //Plasma scales itself to font DPI //on X, where we don't have compositor scaling, this generally works fine. //also there are bugs on older Qt, especially when it comes to fractional scaling //there's advantages to disabling, and (other than small context menu icons) few advantages in enabling //On wayland, it's different. Everything is simpler as all co-ordinates are in the same co-ordinate system //we don't have fractional scaling on the client so don't hit most the remaining bugs and //even if we don't use Qt scaling the compositor will try to scale us anyway so we have no choice if (!qEnvironmentVariableIsSet("PLASMA_USE_QT_SCALING")) { qunsetenv("QT_DEVICE_PIXEL_RATIO"); QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } else { QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); } QQuickWindow::setDefaultAlphaBuffer(true); const bool qpaVariable = qEnvironmentVariableIsSet("QT_QPA_PLATFORM"); KWorkSpace::detectPlatform(argc, argv); QApplication app(argc, argv); if (!qpaVariable) { // don't leak the env variable to processes we start qunsetenv("QT_QPA_PLATFORM"); } KLocalizedString::setApplicationDomain("plasmashell"); // The executable's path is added to the library/plugin paths. // This does not make much sense for plasmashell. app.removeLibraryPath(QCoreApplication::applicationDirPath()); KQuickAddons::QtQuickSettings::init(); KAboutData aboutData(QStringLiteral("plasmashell"), i18n("Plasma"), QStringLiteral(PROJECT_VERSION), i18n("Plasma Shell"), KAboutLicense::GPL); KAboutData::setApplicationData(aboutData); app.setQuitOnLastWindowClosed(false); { QCommandLineParser cliOptions; QCommandLineOption dbgOption(QStringList() << QStringLiteral("d") << QStringLiteral("qmljsdebugger"), i18n("Enable QML Javascript debugger")); QCommandLineOption noRespawnOption(QStringList() << QStringLiteral("n") << QStringLiteral("no-respawn"), i18n("Do not restart plasma-shell automatically after a crash")); QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"), i18n("Force loading the given shell plugin"), QStringLiteral("plugin")); QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"), i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified")); QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance")); QCommandLineOption testOption(QStringList() << QStringLiteral("test"), i18n("Enables test mode and specifies the layout javascript file to set up the testing environment"), i18n("file"), QStringLiteral("layout.js")); cliOptions.addOption(dbgOption); cliOptions.addOption(noRespawnOption); cliOptions.addOption(shellPluginOption); cliOptions.addOption(standaloneOption); cliOptions.addOption(testOption); cliOptions.addOption(replaceOption); aboutData.setupCommandLine(&cliOptions); cliOptions.process(app); aboutData.processCommandLine(&cliOptions); QGuiApplication::setFallbackSessionManagementEnabled(false); auto disableSessionManagement = [](QSessionManager &sm) { sm.setRestartHint(QSessionManager::RestartNever); }; QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); ShellManager::s_fixedShell = cliOptions.value(shellPluginOption); if (!cliOptions.isSet(noRespawnOption) && !cliOptions.isSet(testOption)) { KCrash::setFlags(KCrash::AutoRestart); } if (cliOptions.isSet(testOption)) { const QUrl layoutUrl = QUrl::fromUserInput(cliOptions.value(testOption), {}, QUrl::AssumeLocalFile); if (!layoutUrl.isLocalFile()) { qWarning() << "ensure the layout file is local" << layoutUrl; cliOptions.showHelp(1); } QStandardPaths::setTestModeEnabled(true); QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).removeRecursively(); ShellManager::s_testModeLayout = layoutUrl.toLocalFile(); qApp->setProperty("org.kde.KActivities.core.disableAutostart", true); QObject::connect(ShellManager::instance(), &ShellManager::shellChanged, ShellManager::instance(), [layoutUrl]() { new CoronaTestHelper(ShellManager::instance()->corona()); } ); } if (cliOptions.isSet(standaloneOption)) { if (cliOptions.isSet(shellPluginOption)) { ShellManager::s_standaloneOption = true; app.setApplicationName("plasmashell_"+cliOptions.value(shellPluginOption)); app.setQuitOnLastWindowClosed(true); KDBusService service(KDBusService::Unique); //This will not leak, because corona deletes itself on window close new StandaloneAppCorona(cliOptions.value(shellPluginOption)); return app.exec(); } else { cliOptions.showHelp(1); } } if (cliOptions.isSet(replaceOption)) { auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/MainApplication"), QStringLiteral("org.qtproject.Qt.QCoreApplication"), QStringLiteral("quit")); QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits } } 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 static bool s_multipleInvokations = false; if (s_multipleInvokations) { return; } s_multipleInvokations = true; qCritical("Open GL context could not be created"); auto configGroup = KSharedConfig::openConfig()->group("QtQuickRendererSettings"); if (configGroup.readEntry("SceneGraphBackend") != QLatin1String("software")) { configGroup.writeEntry("SceneGraphBackend", "software", KConfigBase::Global | KConfigBase::Persistent); configGroup.sync(); QProcess::startDetached("plasmashell", app.arguments()); } else { QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets); QMessageBox::critical(nullptr, i18n("Plasma Failed To Start"), i18n("Plasma is unable to start as it could not correctly use OpenGL 2 or software fallback\nPlease check that your graphic drivers are set up correctly.")); } app.exit(-1); }); + SoftwareRendererNotifier::notifyIfRelevant(); QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater); return app.exec(); } diff --git a/shell/softwarerendernotifier.cpp b/shell/softwarerendernotifier.cpp new file mode 100644 index 000000000..933044b29 --- /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; + diff --git a/shell/softwarerendernotifier.h b/shell/softwarerendernotifier.h new file mode 100644 index 000000000..59ef76388 --- /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(); +};