File: startplasma-x11.cpp

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (98 lines) | stat: -rw-r--r-- 2,803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
    SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "startplasma.h"

#include <KConfig>
#include <KConfigGroup>
#include <signal.h>
#include <unistd.h>

void sighupHandler(int)
{
    out << "GOT SIGHUP\n";
}

int main(int argc, char **argv)
{
    // When the X server dies we get a HUP signal from xinit. We must ignore it
    // because we still need to do some cleanup.
    signal(SIGHUP, sighupHandler);
    qputenv("QT_NO_XDG_DESKTOP_PORTAL", QByteArrayLiteral("1"));

    QCoreApplication app(argc, argv);

    // Check if a Plasma session already is running and whether it's possible to connect to X
    switch (kCheckRunning()) {
    case NoX11:
        out << "$DISPLAY is not set or cannot connect to the X server.\n";
        return 1;
    case PlasmaRunning:
        messageBox(QStringLiteral("Plasma seems to be already running on this display.\n"));
        return 1;
    case NoPlasmaRunning:
        break;
    }

    createConfigDirectory();
    runStartupConfig();

    // Do not sync any of this section with the wayland versions as there scale factors are
    // sent properly over wl_output

    {
        KConfig cfg(QStringLiteral("kdeglobals"));

        KConfigGroup kscreenGroup = cfg.group("KScreen");
        const auto screenScaleFactors = kscreenGroup.readEntry("ScreenScaleFactors", QByteArray());
        if (!screenScaleFactors.isEmpty()) {
            qputenv("QT_SCREEN_SCALE_FACTORS", screenScaleFactors);
        }
    }

    // NOTE: Be very mindful of what you start this early in the process. The environment is not yet complete.
    setupCursor(false);
    std::unique_ptr<QProcess, KillBeforeDeleter> ksplash(setupKSplash());
    Q_UNUSED(ksplash)

    runEnvironmentScripts();

    out << "startkde: Starting up...\n";

    setupPlasmaEnvironment();
    setupX11();

    qunsetenv("QT_NO_XDG_DESKTOP_PORTAL");
    auto oldSystemdEnvironment = getSystemdEnvironment();
    if (!syncDBusEnvironment()) {
        // Startup error
        messageBox(QStringLiteral("Could not sync environment to dbus.\n"));
        return 1;
    }

    // We import systemd environment after we sync the dbus environment here.
    // Otherwise it may leads to some unwanted order of applying environment
    // variables (e.g. LANG and LC_*)
    importSystemdEnvrionment();

    if (!startPlasmaSession(false))
        return 1;

    // Anything after here is logout
    // It is not called after shutdown/restart
    waitForKonqi();

    out << "startkde: Shutting down...\n";

    // Keep for KF5; remove in KF6 (KInit will be gone then)
    runSync(QStringLiteral("kdeinit5_shutdown"), {});

    cleanupPlasmaEnvironment(oldSystemdEnvironment);

    out << "startkde: Done.\n";

    return 0;
}