From 073dee6c0b93b531b9567ec44ecdc6209a841c22 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Nov 2017 12:39:18 +0100 Subject: Support autologin via guest session --- src/main.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index ece6b87..8eee16f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include "settings.h" #include "mainwindow.h" #include "x11util.h" +#include "global.h" static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) { @@ -35,34 +36,49 @@ static inline int size(const QRect& r) int main(int argc, char *argv[]) { - //dup2(2, 1) + if (argc > 1 && QString(argv[1]) == QString("--test")) { + Global::enableTestMode(); + } + + QApplication a(argc, argv); + // I have no idea why, but Qt's stock qWarning() output never makes it // to /var/log/lightdm/x-0-greeter.log, so we use std::cerr instead.. qInstallMessageHandler(messageHandler); - QApplication a(argc, argv); - if (! Settings().iconThemeName().isEmpty()) { QIcon::setThemeName(Settings().iconThemeName()); } - // Build background for X server, in case we start a session that - // doesn't set one on its own this will make sure it's not simply - // black - QImage entire; - QSize desktopSize = QApplication::desktop()->size(); - qWarning() << "Desktop full size is " << desktopSize; - entire = QImage(desktopSize, QImage::Format_RGB32); - QPainter painter(&entire); + if (!Global::testMode() && !Settings().autoLoginCheckCmd().isEmpty()) { + QProcess p; + int ret = QProcess::execute(Settings().autoLoginCheckCmd()); + if (ret == 0) { + if (Global::autoLoginGuest()) { + qWarning() << "Guest login ok"; + return a.exec(); + // TODO: Background? + } else { + qWarning() << "Guest login failed"; + // TODO: Set error message, display somewhere + } + } + } - const bool testMode = argc > 1 && QString(argv[1]) == QString("--test"); + // Build background for X server, in case we start a session that + // doesn't set one on its own this will make sure it's not simply + // black + QImage entire; // Get a list of non-overlapping screens, as this might lead to a broken // greeter with main windows covering other login forms QMap screens; - if (testMode) { + if (Global::testMode()) { screens.insert(0, QRect(0, 0, 1024, 768)); } else { + QSize desktopSize = QApplication::desktop()->size(); + qWarning() << "Desktop full size is " << desktopSize; + entire = QImage(desktopSize, QImage::Format_RGB32); for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) { QRect r = QApplication::desktop()->screenGeometry(i); QMutableMapIteratorit(screens); @@ -83,6 +99,7 @@ int main(int argc, char *argv[]) skip_rect: ; // Do nothing } } + // Determine primary screen int primary; if (screens.contains(QApplication::desktop()->primaryScreen())) { @@ -94,11 +111,12 @@ int main(int argc, char *argv[]) } // Now set up all the screens + QPainter painter(&entire); MainWindow *focusWindow = 0; QMapIterator it(screens); while (it.hasNext()) { it.next(); - MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value(), testMode); + MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value()); w->show(); if (w->showLoginForm()) { focusWindow = w; -- cgit v1.2.3-55-g7522