diff --git a/ksmserver/logout-greeter/CMakeLists.txt b/ksmserver/logout-greeter/CMakeLists.txt index ad329e5ea..723f77bfb 100644 --- a/ksmserver/logout-greeter/CMakeLists.txt +++ b/ksmserver/logout-greeter/CMakeLists.txt @@ -1,21 +1,21 @@ -set(KSMSERVER_LOGOUT_GREETER_SRCS main.cpp ../shutdowndlg.cpp ../ksmserver_debug.cpp) +set(KSMSERVER_LOGOUT_GREETER_SRCS main.cpp shutdowndlg.cpp ../ksmserver_debug.cpp) add_executable(ksmserver-logout-greeter ${KSMSERVER_LOGOUT_GREETER_SRCS}) target_link_libraries(ksmserver-logout-greeter PW::KWorkspace Qt5::Widgets Qt5::Quick Qt5::X11Extras KF5::Declarative KF5::IconThemes KF5::I18n KF5::Package KF5::QuickAddons KF5::KDELibs4Support # Solid/PowerManagement KF5::WaylandClient ${X11_LIBRARIES} ) install(TARGETS ksmserver-logout-greeter DESTINATION ${KDE_INSTALL_LIBEXECDIR}) if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/ksmserver/logout-greeter/main.cpp b/ksmserver/logout-greeter/main.cpp index 79d420845..4b0b53bab 100644 --- a/ksmserver/logout-greeter/main.cpp +++ b/ksmserver/logout-greeter/main.cpp @@ -1,228 +1,228 @@ /***************************************************************** ksmserver - the KDE session management server Copyright 2016 Martin Graesslin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #include #include #include #include -#include "../shutdowndlg.h" +#include "shutdowndlg.h" #include #include #include #include #include #include class Greeter : public QObject { Q_OBJECT public: Greeter(int fd, bool shutdownAllowed, bool choose, KWorkSpace::ShutdownType type); ~Greeter() override; void init(); bool eventFilter(QObject *watched, QEvent *event) override; private: void adoptScreen(QScreen *screen); void rejected(); void setupWaylandIntegration(); int m_fd; bool m_shutdownAllowed; bool m_choose; KWorkSpace::ShutdownType m_shutdownType; QVector m_dialogs; KWayland::Client::PlasmaShell *m_waylandPlasmaShell; }; Greeter::Greeter(int fd, bool shutdownAllowed, bool choose, KWorkSpace::ShutdownType type) : QObject() , m_fd(fd) , m_shutdownAllowed(shutdownAllowed) , m_choose(choose) , m_shutdownType(type) , m_waylandPlasmaShell(nullptr) { } Greeter::~Greeter() { qDeleteAll(m_dialogs); } void Greeter::setupWaylandIntegration() { if (!KWindowSystem::isPlatformWayland()) { return; } using namespace KWayland::Client; ConnectionThread *connection = ConnectionThread::fromApplication(this); if (!connection) { return; } Registry *registry = new Registry(this); registry->create(connection); connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_waylandPlasmaShell = registry->createPlasmaShell(name, version, this); } ); registry->setup(); connection->roundtrip(); } void Greeter::init() { setupWaylandIntegration(); foreach (QScreen *screen, qApp->screens()) { adoptScreen(screen); } connect(qApp, &QGuiApplication::screenAdded, this, &Greeter::adoptScreen); } void Greeter::adoptScreen(QScreen* screen) { // TODO: last argument is the theme, maybe add command line option for it? KSMShutdownDlg *w = new KSMShutdownDlg(nullptr, m_shutdownAllowed, m_choose, m_shutdownType, m_waylandPlasmaShell); w->installEventFilter(this); m_dialogs << w; QObject::connect(screen, &QObject::destroyed, w, [w, this] { m_dialogs.removeOne(w); w->deleteLater(); }); connect(w, &KSMShutdownDlg::rejected, this, &Greeter::rejected); connect(w, &KSMShutdownDlg::accepted, this, [w, this] { if (m_fd != -1) { QFile f; if (f.open(m_fd, QFile::WriteOnly, QFile::AutoCloseHandle)) { f.write(QByteArray::number(int(w->shutdownType()))); f.close(); } } QApplication::quit(); } ); w->setScreen(screen); w->setGeometry(screen->geometry()); w->init(); } void Greeter::rejected() { if (m_fd != -1) { close(m_fd); } QApplication::exit(1); } bool Greeter::eventFilter(QObject *watched, QEvent *event) { if (qobject_cast(watched)) { if (event->type() == QEvent::MouseButtonPress) { // check that the position is on no window QMouseEvent *me = static_cast(event); for (auto it = m_dialogs.constBegin(); it != m_dialogs.constEnd(); ++it) { if ((*it)->geometry().contains(me->globalPos())) { return false; } } // click outside, close rejected(); } } return false; } int main(int argc, char *argv[]) { // Qt does not currently (5.9.4) support fullscreen on xdg_shell v6. qputenv("QT_WAYLAND_SHELL_INTEGRATION", "wl-shell"); KWorkSpace::detectPlatform(argc, argv); QQuickWindow::setDefaultAlphaBuffer(true); QApplication app(argc, argv); KQuickAddons::QtQuickSettings::init(); QCommandLineParser parser; parser.addHelpOption(); // TODO: should these things be translated? It's internal after all... QCommandLineOption shutdownAllowedOption(QStringLiteral("shutdown-allowed"), QStringLiteral("Whether the user is allowed to shut down the system.")); parser.addOption(shutdownAllowedOption); QCommandLineOption chooseOption(QStringLiteral("choose"), QStringLiteral("Whether the user is offered the choices between logout, shutdown, etc.")); parser.addOption(chooseOption); QCommandLineOption modeOption(QStringLiteral("mode"), QStringLiteral("The initial exit mode to offer to the user."), QStringLiteral("logout|shutdown|reboot"), QStringLiteral("logout")); parser.addOption(modeOption); QCommandLineOption fdOption(QStringLiteral("mode-fd"), QStringLiteral("An optional file descriptor the selected mode is written to on accepted"), QStringLiteral("fd"), QString::number(-1)); parser.addOption(fdOption); parser.process(app); KWorkSpace::ShutdownType type = KWorkSpace::ShutdownTypeDefault; if (parser.isSet(modeOption)) { const QString modeValue = parser.value(modeOption); if (QString::compare(QLatin1String("logout"), modeValue, Qt::CaseInsensitive) == 0) { type = KWorkSpace::ShutdownTypeNone; } else if (QString::compare(QLatin1String("shutdown"), modeValue, Qt::CaseInsensitive) == 0) { type = KWorkSpace::ShutdownTypeHalt; } else if (QString::compare(QLatin1String("reboot"), modeValue, Qt::CaseInsensitive) == 0) { type = KWorkSpace::ShutdownTypeReboot; } else { return 1; } } int fd = -1; if (parser.isSet(fdOption)) { bool ok = false; const int passedFd = parser.value(fdOption).toInt(&ok); if (ok) { fd = dup(passedFd); } } Greeter greeter(fd, parser.isSet(shutdownAllowedOption), parser.isSet(chooseOption), type); greeter.init(); return app.exec(); } #include "main.moc" diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/logout-greeter/shutdowndlg.cpp similarity index 97% rename from ksmserver/shutdowndlg.cpp rename to ksmserver/logout-greeter/shutdowndlg.cpp index 7fcaf861e..3bc3f11b8 100644 --- a/ksmserver/shutdowndlg.cpp +++ b/ksmserver/logout-greeter/shutdowndlg.cpp @@ -1,320 +1,319 @@ /***************************************************************** ksmserver - the KDE session management server Copyright 2000 Matthias Ettrich Copyright 2007 Urs Wolfer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #include "shutdowndlg.h" #include "ksmserver_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include Q_DECLARE_METATYPE(Solid::PowerManagement::SleepState) KSMShutdownDlg::KSMShutdownDlg( QWindow* parent, bool maysd, bool choose, KWorkSpace::ShutdownType sdtype, KWayland::Client::PlasmaShell *plasmaShell) - : QQuickView(parent), + : QuickViewSharedEngine(parent), m_result(false), m_waylandPlasmaShell(plasmaShell) // this is a WType_Popup on purpose. Do not change that! Not // having a popup here has severe side effects. { // window stuff setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); - setResizeMode(QQuickView::SizeRootObjectToView); + setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView); // Qt doesn't set this on unmanaged windows //FIXME: or does it? if (KWindowSystem::isPlatformX11()) { XChangeProperty( QX11Info::display(), winId(), XInternAtom( QX11Info::display(), "WM_WINDOW_ROLE", False ), XA_STRING, 8, PropModeReplace, (unsigned char *)"logoutdialog", strlen( "logoutdialog" )); XClassHint classHint; classHint.res_name = const_cast("ksmserver"); classHint.res_class = const_cast("ksmserver"); XSetClassHint(QX11Info::display(), winId(), &classHint); } //QQuickView *windowContainer = QQuickView::createWindowContainer(m_view, this); //windowContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QQmlContext *context = rootContext(); context->setContextProperty(QStringLiteral("maysd"), maysd); context->setContextProperty(QStringLiteral("choose"), choose); context->setContextProperty(QStringLiteral("sdtype"), sdtype); QQmlPropertyMap *mapShutdownType = new QQmlPropertyMap(this); mapShutdownType->insert(QStringLiteral("ShutdownTypeDefault"), QVariant::fromValue(KWorkSpace::ShutdownTypeDefault)); mapShutdownType->insert(QStringLiteral("ShutdownTypeNone"), QVariant::fromValue(KWorkSpace::ShutdownTypeNone)); mapShutdownType->insert(QStringLiteral("ShutdownTypeReboot"), QVariant::fromValue(KWorkSpace::ShutdownTypeReboot)); mapShutdownType->insert(QStringLiteral("ShutdownTypeHalt"), QVariant::fromValue(KWorkSpace::ShutdownTypeHalt)); mapShutdownType->insert(QStringLiteral("ShutdownTypeLogout"), QVariant::fromValue(KWorkSpace::ShutdownTypeLogout)); context->setContextProperty(QStringLiteral("ShutdownType"), mapShutdownType); QQmlPropertyMap *mapSpdMethods = new QQmlPropertyMap(this); QSet spdMethods = Solid::PowerManagement::supportedSleepStates(); mapSpdMethods->insert(QStringLiteral("StandbyState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::StandbyState))); mapSpdMethods->insert(QStringLiteral("SuspendState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::SuspendState))); mapSpdMethods->insert(QStringLiteral("HibernateState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::HibernateState))); context->setContextProperty(QStringLiteral("spdMethods"), mapSpdMethods); context->setContextProperty(QStringLiteral("canLogout"), KAuthorized::authorize(QStringLiteral("logout"))); QString bootManager = KConfig(QStringLiteral(KDE_CONFDIR "/kdm/kdmrc"), KConfig::SimpleConfig) .group("Shutdown") .readEntry("BootManager", "None"); context->setContextProperty(QStringLiteral("bootManager"), bootManager); QStringList options; int def, cur; if ( KDisplayManager().bootOptions( rebootOptions, def, cur ) ) { if ( cur > -1 ) { def = cur; } } QQmlPropertyMap *rebootOptionsMap = new QQmlPropertyMap(this); rebootOptionsMap->insert(QStringLiteral("options"), QVariant::fromValue(rebootOptions)); rebootOptionsMap->insert(QStringLiteral("default"), QVariant::fromValue(def)); context->setContextProperty(QStringLiteral("rebootOptions"), rebootOptionsMap); // engine stuff KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.setupBindings(); // windowContainer->installEventFilter(this); } void KSMShutdownDlg::init() { rootContext()->setContextProperty(QStringLiteral("screenGeometry"), screen()->geometry()); QString fileName; QString fileUrl; KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); if (!packageName.isEmpty()) { package.setPath(packageName); } fileName = package.filePath("logoutmainscript"); if (QFile::exists(fileName)) { //qCDebug(KSMSERVER) << "Using QML theme" << fileName; setSource(package.fileUrl("logoutmainscript")); } else { qCWarning(KSMSERVER) << "Couldn't find a theme for the Shutdown dialog" << fileName; return; } if(!errors().isEmpty()) { qCWarning(KSMSERVER) << errors(); } connect(rootObject(), SIGNAL(logoutRequested()), SLOT(slotLogout())); connect(rootObject(), SIGNAL(haltRequested()), SLOT(slotHalt())); connect(rootObject(), SIGNAL(suspendRequested(int)), SLOT(slotSuspend(int)) ); connect(rootObject(), SIGNAL(rebootRequested()), SLOT(slotReboot())); connect(rootObject(), SIGNAL(rebootRequested2(int)), SLOT(slotReboot(int)) ); connect(rootObject(), SIGNAL(cancelRequested()), SLOT(reject())); connect(rootObject(), SIGNAL(lockScreenRequested()), SLOT(slotLockScreen())); connect(screen(), &QScreen::geometryChanged, this, [this] { setGeometry(screen()->geometry()); }); //decide in backgroundcontrast wether doing things darker or lighter //set backgroundcontrast here, because in QEvent::PlatformSurface //is too early and we don't have the root object yet const QColor backgroundColor = rootObject() ? rootObject()->property("backgroundColor").value() : QColor(); KWindowEffects::enableBackgroundContrast(winId(), true, 0.4, (backgroundColor.value() > 128 ? 1.6 : 0.3), 1.7); - QQuickView::showFullScreen(); + KQuickAddons::QuickViewSharedEngine::showFullScreen(); requestActivate(); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager); setKeyboardGrabEnabled(true); } void KSMShutdownDlg::resizeEvent(QResizeEvent *e) { - QQuickView::resizeEvent( e ); + KQuickAddons::QuickViewSharedEngine::resizeEvent( e ); if( KWindowSystem::compositingActive()) { //TODO: reenable window mask when we are without composite? // clearMask(); } else { // setMask(m_view->mask()); } } bool KSMShutdownDlg::event(QEvent *e) { if (e->type() == QEvent::PlatformSurface) { switch (static_cast(e)->surfaceEventType()) { case QPlatformSurfaceEvent::SurfaceCreated: setupWaylandIntegration(); KWindowEffects::enableBlurBehind(winId(), true); break; case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: delete m_shellSurface; m_shellSurface = nullptr; break; } } - return QQuickView::event(e); + return KQuickAddons::QuickViewSharedEngine::event(e); } void KSMShutdownDlg::setupWaylandIntegration() { if (m_shellSurface) { // already setup return; } using namespace KWayland::Client; if (!m_waylandPlasmaShell) { return; } Surface *s = Surface::fromWindow(this); if (!s) { return; } m_shellSurface = m_waylandPlasmaShell->createSurface(s, this); // TODO: set a proper window type to indicate to KWin that this is the logout dialog // maybe we need a dedicated type for it? m_shellSurface->setPosition(geometry().topLeft()); } void KSMShutdownDlg::slotLogout() { m_shutdownType = KWorkSpace::ShutdownTypeNone; accept(); } void KSMShutdownDlg::slotReboot() { // no boot option selected -> current m_bootOption.clear(); m_shutdownType = KWorkSpace::ShutdownTypeReboot; accept(); } void KSMShutdownDlg::slotReboot(int opt) { if (int(rebootOptions.size()) > opt) m_bootOption = rebootOptions[opt]; m_shutdownType = KWorkSpace::ShutdownTypeReboot; accept(); } void KSMShutdownDlg::slotLockScreen() { m_bootOption.clear(); QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral("org.kde.screensaver"), QStringLiteral("/ScreenSaver"), QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("Lock")); QDBusConnection::sessionBus().asyncCall(call); reject(); } void KSMShutdownDlg::slotHalt() { m_bootOption.clear(); m_shutdownType = KWorkSpace::ShutdownTypeHalt; accept(); } void KSMShutdownDlg::slotSuspend(int spdMethod) { m_bootOption.clear(); switch (spdMethod) { case Solid::PowerManagement::StandbyState: case Solid::PowerManagement::SuspendState: Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, nullptr, nullptr); break; case Solid::PowerManagement::HibernateState: Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, nullptr, nullptr); break; } reject(); } void KSMShutdownDlg::accept() { emit accepted(); } void KSMShutdownDlg::reject() { emit rejected(); } diff --git a/ksmserver/shutdowndlg.h b/ksmserver/logout-greeter/shutdowndlg.h similarity index 90% rename from ksmserver/shutdowndlg.h rename to ksmserver/logout-greeter/shutdowndlg.h index d9414a505..3a7d7c28b 100644 --- a/ksmserver/shutdowndlg.h +++ b/ksmserver/logout-greeter/shutdowndlg.h @@ -1,98 +1,83 @@ /***************************************************************** ksmserver - the KDE session management server Copyright 2000 Matthias Ettrich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #ifndef SHUTDOWNDLG_H #define SHUTDOWNDLG_H -#include -#include +#include #include -class QMenu; -class QTimer; -class QTimeLine; -class QLabel; -class LogoutEffect; - -namespace Plasma -{ - class Svg; - class FrameSvg; -} - namespace KWayland { namespace Client { class PlasmaShell; class PlasmaShellSurface; } } -class QQuickView; - // The confirmation dialog -class KSMShutdownDlg : public QQuickView +class KSMShutdownDlg : public KQuickAddons::QuickViewSharedEngine { Q_OBJECT public: KSMShutdownDlg( QWindow* parent, bool maysd, bool choose, KWorkSpace::ShutdownType sdtype, KWayland::Client::PlasmaShell *plasmaShell = nullptr ); void init(); bool result() const; KWorkSpace::ShutdownType shutdownType() const { return m_shutdownType; } public Q_SLOTS: void accept(); void reject(); void slotLogout(); void slotHalt(); void slotReboot(); void slotReboot(int); void slotSuspend(int); void slotLockScreen(); Q_SIGNALS: void accepted(); void rejected(); protected: void resizeEvent(QResizeEvent *e) override; bool event(QEvent *e) override; private: void setupWaylandIntegration(); KWorkSpace::ShutdownType m_shutdownType; QString m_bootOption; QStringList rebootOptions; bool m_result : 1; KWayland::Client::PlasmaShell *m_waylandPlasmaShell; KWayland::Client::PlasmaShellSurface *m_shellSurface = nullptr; }; #endif