summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wayland/qwaylandsessionmanager.cpp
blob: 9539bb15221f0855232b7f31c550987ecda24acf (plain)
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
// Copyright (C) 2024 David Edmundson <davidedmundson@kde.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwaylandsessionmanager_p.h"

#ifndef QT_NO_SESSIONMANAGER

#include "qwaylanddisplay_p.h"
#include "qwaylandwindow_p.h"

#include <private/qsessionmanager_p.h>
#include <private/qguiapplication_p.h>

#include <QtCore/QDebug>

QT_BEGIN_NAMESPACE

namespace QtWaylandClient {

QWaylandSessionManager::QWaylandSessionManager(QWaylandDisplay *display, const QString &id)
    : QObject(nullptr)
    , QPlatformSessionManager(id, QString())
    , mDisplay(display)
{
    if (!display->xxSessionManager())
        return;

    // The protocol also exposes a way of supporting crash handling to expose later
    startSession();
}

QWaylandSession *QWaylandSessionManager::session() const
{
    return mSession.data();
}

QWaylandSessionManager *QWaylandSessionManager::instance()
{
    auto *qGuiAppPriv = QGuiApplicationPrivate::instance();
    auto *managerPrivate = static_cast<QSessionManagerPrivate*>(QObjectPrivate::get(qGuiAppPriv->session_manager));
    return static_cast<QWaylandSessionManager *>(managerPrivate->platformSessionManager);
}

void QWaylandSessionManager::setSessionId(const QString &id)
{
    m_sessionId = id;
}

void QWaylandSessionManager::startSession()
{
    QtWayland::xx_session_manager_v1::reason restoreReason = QtWayland::xx_session_manager_v1::reason_launch;
    if (!sessionId().isEmpty()) {
        restoreReason = QtWayland::xx_session_manager_v1::reason_session_restore;
    }
    mSession.reset(new QWaylandSession(this));
    mSession->init(mDisplay->xxSessionManager()->get_session(restoreReason, sessionId()));
    mDisplay->forceRoundTrip();
}

QWaylandSession::QWaylandSession(QWaylandSessionManager *sessionManager)
    : mSessionManager(sessionManager)
{
}

QWaylandSession::~QWaylandSession() {
    // There's also remove which is another dtor
    // depending on whether we're meant to clean up server side or not
    // we might need to expose that later
    destroy();
}

void QWaylandSession::xx_session_v1_created(const QString &id) {
    qCDebug(lcQpaWayland) << "Session created" << id;
    mSessionManager->setSessionId(id);
}

void QWaylandSession::xx_session_v1_restored() {
    qCDebug(lcQpaWayland) << "Session restored";
    // session Id won't have change, do nothing
}

void QWaylandSession::xx_session_v1_replaced() {
    qCDebug(lcQpaWayland) << "Session replaced";
    mSessionManager->setSessionId(QString());
}

}

QT_END_NAMESPACE

#endif