File indexing completed on 2024-05-05 05:38:56

0001 /*
0002     SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "debug.h"
0008 #include "startplasma.h"
0009 #include <KConfig>
0010 #include <KConfigGroup>
0011 #include <QDBusConnection>
0012 #include <QDBusInterface>
0013 #include <signal.h>
0014 
0015 int main(int argc, char **argv)
0016 {
0017     QCoreApplication app(argc, argv);
0018 
0019     createConfigDirectory();
0020     setupCursor(true);
0021     signal(SIGTERM, sigtermHandler);
0022 
0023     // Let clients try to reconnect to kwin after a restart
0024     qputenv("QT_WAYLAND_RECONNECT", "1");
0025 
0026     // Query whether org.freedesktop.locale1 is available. If it is, try to
0027     // set XKB_DEFAULT_{MODEL,LAYOUT,VARIANT,OPTIONS} accordingly.
0028     {
0029         const QString locale1Service = QStringLiteral("org.freedesktop.locale1");
0030         const QString locale1Path = QStringLiteral("/org/freedesktop/locale1");
0031         QDBusMessage message =
0032             QDBusMessage::createMethodCall(locale1Service, locale1Path, QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("GetAll"));
0033         message << locale1Service;
0034         QDBusMessage resultMessage = QDBusConnection::systemBus().call(message);
0035         if (resultMessage.type() == QDBusMessage::ReplyMessage) {
0036             QVariantMap result;
0037             QDBusArgument dbusArgument = resultMessage.arguments().at(0).value<QDBusArgument>();
0038             while (!dbusArgument.atEnd()) {
0039                 dbusArgument >> result;
0040             }
0041 
0042             auto queryAndSet = [&](const QByteArray &var, const QString &value) {
0043                 const auto r = result.value(value).toString();
0044                 if (!r.isEmpty())
0045                     qputenv(var, r.toUtf8());
0046             };
0047 
0048             queryAndSet("XKB_DEFAULT_MODEL", QStringLiteral("X11Model"));
0049             queryAndSet("XKB_DEFAULT_LAYOUT", QStringLiteral("X11Layout"));
0050             queryAndSet("XKB_DEFAULT_VARIANT", QStringLiteral("X11Variant"));
0051             queryAndSet("XKB_DEFAULT_OPTIONS", QStringLiteral("X11Options"));
0052         } else {
0053             qCWarning(PLASMA_STARTUP) << "not a reply org.freedesktop.locale1" << resultMessage;
0054         }
0055     }
0056     runEnvironmentScripts();
0057 
0058     if (!qEnvironmentVariableIsSet("DBUS_SESSION_BUS_ADDRESS")) {
0059         out << "startplasmacompositor: Could not start D-Bus. Can you call qdbus?\n";
0060         return 1;
0061     }
0062     setupPlasmaEnvironment();
0063     runStartupConfig();
0064     qputenv("XDG_SESSION_TYPE", "wayland");
0065 
0066     auto oldSystemdEnvironment = getSystemdEnvironment();
0067     if (!syncDBusEnvironment()) {
0068         out << "Could not sync environment to dbus.\n";
0069         return 1;
0070     }
0071 
0072     // We import systemd environment after we sync the dbus environment here.
0073     // Otherwise it may leads to some unwanted order of applying environment
0074     // variables (e.g. LANG and LC_*)
0075     importSystemdEnvrionment();
0076 
0077     if (!startPlasmaSession(true))
0078         return 4;
0079 
0080     // Anything after here is logout
0081     // It is not called after shutdown/restart
0082     waitForKonqi();
0083     out << "startplasma-wayland: Shutting down...\n";
0084 
0085     // Keep for KF5; remove in KF6 (KInit will be gone then)
0086     runSync(QStringLiteral("kdeinit5_shutdown"), {});
0087 
0088     out << "startplasmacompositor: Shutting down...\n";
0089     cleanupPlasmaEnvironment(oldSystemdEnvironment);
0090     out << "startplasmacompositor: Done.\n";
0091 
0092     return 0;
0093 }