Exemple #1
0
extern "C" Q_DECL_EXPORT int kdemain( int argc, char* argv[] )
{
    sanity_check(argc, argv);

    putenv((char*)"SESSION_MANAGER=");
    checkComposite();

    QApplication *a = new QApplication(argc, argv);

    QApplication::setApplicationName( QStringLiteral( "ksmserver") );
    QApplication::setApplicationVersion( QString::fromLatin1( version ) );
    QApplication::setOrganizationDomain( QStringLiteral( "kde.org") );

    fcntl(ConnectionNumber(QX11Info::display()), F_SETFD, 1);

    a->setQuitOnLastWindowClosed(false); // #169486

    QCommandLineParser parser;
    parser.setApplicationDescription(QString::fromLatin1(description));
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption restoreOption(QStringList() << QStringLiteral("r") << QStringLiteral("restore"),
                                     i18n("Restores the saved user session if available"));
    parser.addOption(restoreOption);

    QCommandLineOption wmOption(QStringList() << QStringLiteral("w") << QStringLiteral("windowmanager"),
                                i18n("Starts <wm> in case no other window manager is \nparticipating in the session. Default is 'kwin'"),
                                i18n("wm"));
    parser.addOption(wmOption);

    QCommandLineOption nolocalOption(QStringLiteral("nolocal"),
                                     i18n("Also allow remote connections"));
    parser.addOption(nolocalOption);

#if COMPILE_SCREEN_LOCKER
    QCommandLineOption lockscreenOption(QStringLiteral("lockscreen"),
                                        i18n("Starts the session in locked mode"));
    parser.addOption(lockscreenOption);
#endif

    parser.process(*a);

//TODO: should we still use this?
//    if( !QDBusConnection::sessionBus().interface()->
//            registerService( QStringLiteral( "org.kde.ksmserver" ),
//                             QDBusConnectionInterface::DontQueueService ) )
//    {
//        qWarning("Could not register with D-BUS. Aborting.");
//        return 1;
//    }

    QString wm = parser.value(wmOption);

    bool only_local = !parser.isSet(nolocalOption);
#ifndef HAVE__ICETRANSNOLISTEN
    /* this seems strange, but the default is only_local, so if !only_local
     * the option --nolocal was given, and we warn (the option --nolocal
     * does nothing on this platform, as here the default is reversed)
     */
    if (!only_local) {
        qWarning("--nolocal is not supported on your platform. Sorry.");
    }
    only_local = false;
#endif

#if COMPILE_SCREEN_LOCKER
    KSMServer *server = new KSMServer( wm, only_local, parser.isSet(lockscreenOption ) );
#else
    KSMServer *server = new KSMServer( wm, only_local );
#endif
    
    // for the KDE-already-running check in startkde
    KSelectionOwner kde_running( "_KDE_RUNNING", 0 );
    kde_running.claim( false );

    IceSetIOErrorHandler( IoErrorHandler );

    KConfigGroup config(KSharedConfig::openConfig(), "General");

    int realScreenCount = ScreenCount( QX11Info::display() );
    bool screenCountChanged =
         ( config.readEntry( "screenCount", realScreenCount ) != realScreenCount );

    QString loginMode = config.readEntry( "loginMode", "restorePreviousLogout" );

    if ( parser.isSet( restoreOption ) && ! screenCountChanged )
        server->restoreSession( QStringLiteral( SESSION_BY_USER ) );
    else if ( loginMode == QStringLiteral( "default" ) || screenCountChanged )
        server->startDefaultSession();
    else if ( loginMode == QStringLiteral( "restorePreviousLogout" ) )
        server->restoreSession( QStringLiteral( SESSION_PREVIOUS_LOGOUT ) );
    else if ( loginMode == QStringLiteral( "restoreSavedSession" ) )
        server->restoreSession( QStringLiteral( SESSION_BY_USER ) );
    else
        server->startDefaultSession();

    KDBusService service(KDBusService::Unique);

    int ret = a->exec();
    kde_running.release(); // needs to be done before QApplication destruction
    delete a;
    return ret;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    LXQt::Application a(argc, argv);
    LXQt::Translator::translateApplication();

    LXQt::PowerManager powermanager(&a);
    LXQt::ScreenSaver screensaver(&a);

    QCommandLineParser parser;
    parser.setApplicationDescription(QStringLiteral("lxqt-leave"));
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption logoutOption(QStringLiteral("logout"), QCoreApplication::translate("main", "Logout."));
    parser.addOption(logoutOption);

    QCommandLineOption lockscreenOption(QStringLiteral("lockscreen"), QCoreApplication::translate("main", "Lockscreen."));
    parser.addOption(lockscreenOption);

    QCommandLineOption suspendOption(QStringLiteral("suspend"), QCoreApplication::translate("main", "Suspend."));
    parser.addOption(suspendOption);

    QCommandLineOption hibernateOption(QStringLiteral("hibernate"), QCoreApplication::translate("main", "Hibernate."));
    parser.addOption(hibernateOption);

    QCommandLineOption shutdownOption(QStringLiteral("shutdown"), QCoreApplication::translate("main", "Shutdown."));
    parser.addOption(shutdownOption);

    QCommandLineOption rebootOption(QStringLiteral("reboot"), QCoreApplication::translate("main", "Reboot."));
    parser.addOption(rebootOption);

    parser.process(a);

    if (parser.isSet(logoutOption)) {
        powermanager.logout();
        return 0;
    }

    if (parser.isSet(lockscreenOption)) {
        a.connect(&screensaver, &LXQt::ScreenSaver::done, &a, &LXQt::Application::quit);
        screensaver.lockScreen();
        a.exec();
        return 0;
    }

    if (parser.isSet(suspendOption)) {
        powermanager.suspend();
        return 0;
    }

    if (parser.isSet(hibernateOption)) {
        powermanager.hibernate();
        return 0;
    }

    if (parser.isSet(shutdownOption)) {
        powermanager.shutdown();
        return 0;
    }

    if (parser.isSet(rebootOption)) {
        powermanager.reboot();
        return 0;
    }

    LeaveDialog dialog;
    dialog.setGeometry(QStyle::alignedRect(Qt::LeftToRight,
                Qt::AlignCenter,
                dialog.size(),
                qApp->desktop()->screenGeometry(QCursor::pos())));
    dialog.setMaximumSize(dialog.minimumSize());
    return dialog.exec();
}
Exemple #3
0
extern "C" Q_DECL_EXPORT int kdemain( int argc, char* argv[] )
{
    sanity_check(argc, argv);

    putenv((char*)"SESSION_MANAGER=");
    checkComposite();

    // force xcb QPA plugin as ksmserver is very X11 specific
    const QByteArray origQpaPlatform = qgetenv("QT_QPA_PLATFORM");
    qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("xcb"));

    QQuickWindow::setDefaultAlphaBuffer(true);
    QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
    QApplication *a = new QApplication(argc, argv);

    // now the QPA platform is set, unset variable again to not launch apps with incorrect environment
    if (origQpaPlatform.isEmpty()) {
        qunsetenv("QT_QPA_PLATFORM");
    } else {
        qputenv("QT_QPA_PLATFORM", origQpaPlatform);
    }

    QApplication::setApplicationName( QStringLiteral( "ksmserver") );
    QApplication::setApplicationVersion( QString::fromLatin1( version ) );
    QApplication::setOrganizationDomain( QStringLiteral( "kde.org") );

    fcntl(ConnectionNumber(QX11Info::display()), F_SETFD, 1);

    a->setQuitOnLastWindowClosed(false); // #169486

    QCommandLineParser parser;
    parser.setApplicationDescription(i18n(description));
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption restoreOption(QStringList() << QStringLiteral("r") << QStringLiteral("restore"),
                                     i18n("Restores the saved user session if available"));
    parser.addOption(restoreOption);

    QCommandLineOption wmOption(QStringList() << QStringLiteral("w") << QStringLiteral("windowmanager"),
                                i18n("Starts <wm> in case no other window manager is \nparticipating in the session. Default is 'kwin'"),
                                i18n("wm"));
    parser.addOption(wmOption);

    QCommandLineOption nolocalOption(QStringLiteral("nolocal"),
                                     i18n("Also allow remote connections"));
    parser.addOption(nolocalOption);

    QCommandLineOption lockscreenOption(QStringLiteral("lockscreen"),
                                        i18n("Starts the session in locked mode"));
    parser.addOption(lockscreenOption);

    QCommandLineOption noLockscreenOption(QStringLiteral("no-lockscreen"),
                                         i18n("Starts without lock screen support. Only needed if other component provides the lock screen."));
    parser.addOption(noLockscreenOption);

    parser.process(*a);

//TODO: should we still use this?
//    if( !QDBusConnection::sessionBus().interface()->
//            registerService( QStringLiteral( "org.kde.ksmserver" ),
//                             QDBusConnectionInterface::DontQueueService ) )
//    {
//        qCWarning(KSMSERVER, "Could not register with D-BUS. Aborting.");
//        return 1;
//    }

    QString wm = parser.value(wmOption);

    bool only_local = !parser.isSet(nolocalOption);
#ifndef HAVE__ICETRANSNOLISTEN
    /* this seems strange, but the default is only_local, so if !only_local
     * the option --nolocal was given, and we warn (the option --nolocal
     * does nothing on this platform, as here the default is reversed)
     */
    if (!only_local) {
        qCWarning(KSMSERVER, "--nolocal is not supported on your platform. Sorry.");
    }
    only_local = false;
#endif

    KSMServer::InitFlags flags = KSMServer::InitFlag::None;
    if (only_local) {
        flags |= KSMServer::InitFlag::OnlyLocal;
    }
    if (parser.isSet(lockscreenOption)) {
        flags |= KSMServer::InitFlag::ImmediateLockScreen;
    }
    if (parser.isSet(noLockscreenOption)) {
        flags |= KSMServer::InitFlag::NoLockScreen;
    }

    KSMServer *server = new KSMServer( wm, flags);

    // for the KDE-already-running check in startkde
    KSelectionOwner kde_running( "_KDE_RUNNING", 0 );
    kde_running.claim( false );

    IceSetIOErrorHandler( IoErrorHandler );

    KConfigGroup config(KSharedConfig::openConfig(), "General");

    int realScreenCount = ScreenCount( QX11Info::display() );
    bool screenCountChanged =
         ( config.readEntry( "screenCount", realScreenCount ) != realScreenCount );

    QString loginMode = config.readEntry( "loginMode", "restorePreviousLogout" );

    if ( parser.isSet( restoreOption ) && ! screenCountChanged )
        server->restoreSession( QStringLiteral( SESSION_BY_USER ) );
    else if ( loginMode == QStringLiteral( "default" ) || screenCountChanged )
        server->startDefaultSession();
    else if ( loginMode == QStringLiteral( "restorePreviousLogout" ) )
        server->restoreSession( QStringLiteral( SESSION_PREVIOUS_LOGOUT ) );
    else if ( loginMode == QStringLiteral( "restoreSavedSession" ) )
        server->restoreSession( QStringLiteral( SESSION_BY_USER ) );
    else
        server->startDefaultSession();

    KDBusService service(KDBusService::Unique);

    int ret = a->exec();
    kde_running.release(); // needs to be done before QApplication destruction
    delete a;
    return ret;
}