Changeset View
Changeset View
Standalone View
Standalone View
logout-greeter/greeter.cpp
- This file was copied from logout-greeter/main.cpp.
1 | /***************************************************************** | 1 | /***************************************************************** | ||
---|---|---|---|---|---|
2 | ksmserver - the KDE session management server | 2 | ksmserver - the KDE session management server | ||
3 | 3 | | |||
4 | Copyright 2016 Martin Graesslin <mgraesslin@kde.org> | 4 | Copyright 2016 Martin Graesslin <mgraesslin@kde.org> | ||
5 | Copyright 2018 David Edmundson <davidedmundson@kde.org> | ||||
5 | 6 | | |||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | of this software and associated documentation files (the "Software"), to deal | 8 | of this software and associated documentation files (the "Software"), to deal | ||
8 | in the Software without restriction, including without limitation the rights | 9 | in the Software without restriction, including without limitation the rights | ||
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | copies of the Software, and to permit persons to whom the Software is | 11 | copies of the Software, and to permit persons to whom the Software is | ||
11 | furnished to do so, subject to the following conditions: | 12 | furnished to do so, subject to the following conditions: | ||
12 | 13 | | |||
13 | The above copyright notice and this permission notice shall be included in | 14 | The above copyright notice and this permission notice shall be included in | ||
14 | all copies or substantial portions of the Software. | 15 | all copies or substantial portions of the Software. | ||
15 | 16 | | |||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | 20 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
20 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
22 | 23 | | |||
23 | ******************************************************************/ | 24 | ******************************************************************/ | ||
24 | #include <QApplication> | 25 | | ||
25 | #include <QCommandLineParser> | 26 | #include "greeter.h" | ||
27 | | ||||
26 | #include <QDebug> | 28 | #include <QDebug> | ||
27 | #include <QScreen> | 29 | #include <QScreen> | ||
30 | #include <QApplication> | ||||
31 | | ||||
28 | #include "shutdowndlg.h" | 32 | #include "shutdowndlg.h" | ||
29 | 33 | | |||
30 | #include <KQuickAddons/QtQuickSettings> | 34 | #include <KQuickAddons/QtQuickSettings> | ||
31 | | ||||
32 | #include <KWindowSystem> | 35 | #include <KWindowSystem> | ||
33 | 36 | | |||
34 | #include <KWayland/Client/connection_thread.h> | 37 | #include <KWayland/Client/connection_thread.h> | ||
35 | #include <KWayland/Client/registry.h> | 38 | #include <KWayland/Client/registry.h> | ||
36 | #include <KWayland/Client/plasmashell.h> | 39 | #include <KWayland/Client/plasmashell.h> | ||
37 | 40 | | |||
38 | #include <unistd.h> | 41 | #include <unistd.h> | ||
39 | 42 | | |||
40 | class Greeter : public QObject | | |||
41 | { | | |||
42 | Q_OBJECT | | |||
43 | public: | | |||
44 | Greeter(int fd, bool shutdownAllowed, bool choose, KWorkSpace::ShutdownType type); | | |||
45 | ~Greeter() override; | | |||
46 | | ||||
47 | void init(); | | |||
48 | | ||||
49 | bool eventFilter(QObject *watched, QEvent *event) override; | | |||
50 | | ||||
51 | private: | | |||
52 | void adoptScreen(QScreen *screen); | | |||
53 | void rejected(); | | |||
54 | void setupWaylandIntegration(); | | |||
55 | | ||||
56 | int m_fd; | | |||
57 | bool m_shutdownAllowed; | | |||
58 | bool m_choose; | | |||
59 | KWorkSpace::ShutdownType m_shutdownType; | | |||
60 | QVector<KSMShutdownDlg *> m_dialogs; | | |||
61 | KWayland::Client::PlasmaShell *m_waylandPlasmaShell; | | |||
62 | }; | | |||
63 | | ||||
64 | Greeter::Greeter(int fd, bool shutdownAllowed, bool choose, KWorkSpace::ShutdownType type) | 43 | Greeter::Greeter(int fd, bool shutdownAllowed, bool choose, KWorkSpace::ShutdownType type) | ||
65 | : QObject() | 44 | : QObject() | ||
66 | , m_fd(fd) | 45 | , m_fd(fd) | ||
67 | , m_shutdownAllowed(shutdownAllowed) | 46 | , m_shutdownAllowed(shutdownAllowed) | ||
68 | , m_choose(choose) | 47 | , m_choose(choose) | ||
69 | , m_shutdownType(type) | 48 | , m_shutdownType(type) | ||
70 | , m_waylandPlasmaShell(nullptr) | 49 | , m_waylandPlasmaShell(nullptr) | ||
71 | { | 50 | { | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 131 | for (auto it = m_dialogs.constBegin(); it != m_dialogs.constEnd(); ++it) { | |||
155 | } | 134 | } | ||
156 | } | 135 | } | ||
157 | // click outside, close | 136 | // click outside, close | ||
158 | rejected(); | 137 | rejected(); | ||
159 | } | 138 | } | ||
160 | } | 139 | } | ||
161 | return false; | 140 | return false; | ||
162 | } | 141 | } | ||
163 | | ||||
164 | int main(int argc, char *argv[]) | | |||
165 | { | | |||
166 | // Qt does not currently (5.9.4) support fullscreen on xdg_shell v6. | | |||
167 | qputenv("QT_WAYLAND_SHELL_INTEGRATION", "wl-shell"); | | |||
168 | | ||||
169 | KWorkSpace::detectPlatform(argc, argv); | | |||
170 | QQuickWindow::setDefaultAlphaBuffer(true); | | |||
171 | QApplication app(argc, argv); | | |||
172 | | ||||
173 | KQuickAddons::QtQuickSettings::init(); | | |||
174 | | ||||
175 | QCommandLineParser parser; | | |||
176 | parser.addHelpOption(); | | |||
177 | | ||||
178 | // TODO: should these things be translated? It's internal after all... | | |||
179 | QCommandLineOption shutdownAllowedOption(QStringLiteral("shutdown-allowed"), | | |||
180 | QStringLiteral("Whether the user is allowed to shut down the system.")); | | |||
181 | parser.addOption(shutdownAllowedOption); | | |||
182 | | ||||
183 | QCommandLineOption chooseOption(QStringLiteral("choose"), | | |||
184 | QStringLiteral("Whether the user is offered the choices between logout, shutdown, etc.")); | | |||
185 | parser.addOption(chooseOption); | | |||
186 | | ||||
187 | QCommandLineOption modeOption(QStringLiteral("mode"), | | |||
188 | QStringLiteral("The initial exit mode to offer to the user."), | | |||
189 | QStringLiteral("logout|shutdown|reboot"), | | |||
190 | QStringLiteral("logout")); | | |||
191 | parser.addOption(modeOption); | | |||
192 | | ||||
193 | QCommandLineOption fdOption(QStringLiteral("mode-fd"), | | |||
194 | QStringLiteral("An optional file descriptor the selected mode is written to on accepted"), | | |||
195 | QStringLiteral("fd"), QString::number(-1)); | | |||
196 | parser.addOption(fdOption); | | |||
197 | | ||||
198 | parser.process(app); | | |||
199 | | ||||
200 | KWorkSpace::ShutdownType type = KWorkSpace::ShutdownTypeDefault; | | |||
201 | if (parser.isSet(modeOption)) { | | |||
202 | const QString modeValue = parser.value(modeOption); | | |||
203 | if (QString::compare(QLatin1String("logout"), modeValue, Qt::CaseInsensitive) == 0) { | | |||
204 | type = KWorkSpace::ShutdownTypeNone; | | |||
205 | } else if (QString::compare(QLatin1String("shutdown"), modeValue, Qt::CaseInsensitive) == 0) { | | |||
206 | type = KWorkSpace::ShutdownTypeHalt; | | |||
207 | } else if (QString::compare(QLatin1String("reboot"), modeValue, Qt::CaseInsensitive) == 0) { | | |||
208 | type = KWorkSpace::ShutdownTypeReboot; | | |||
209 | } else { | | |||
210 | return 1; | | |||
211 | } | | |||
212 | } | | |||
213 | | ||||
214 | int fd = -1; | | |||
215 | if (parser.isSet(fdOption)) { | | |||
216 | bool ok = false; | | |||
217 | const int passedFd = parser.value(fdOption).toInt(&ok); | | |||
218 | if (ok) { | | |||
219 | fd = dup(passedFd); | | |||
220 | } | | |||
221 | } | | |||
222 | Greeter greeter(fd, parser.isSet(shutdownAllowedOption), parser.isSet(chooseOption), type); | | |||
223 | greeter.init(); | | |||
224 | | ||||
225 | return app.exec(); | | |||
226 | } | | |||
227 | | ||||
228 | #include "main.moc" | |