diff options
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/loginform.cpp | 11 | ||||
-rw-r--r-- | src/loginform.h | 2 | ||||
-rw-r--r-- | src/settings.h | 1 | ||||
-rw-r--r-- | src/x11util.cpp | 27 | ||||
-rw-r--r-- | src/x11util.h | 1 |
6 files changed, 45 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 47eb417..914c32d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,10 @@ file(GLOB UIS src/*.ui) FIND_PACKAGE(Qt5 COMPONENTS Widgets X11Extras Svg REQUIRED) FIND_PACKAGE(X11 REQUIRED) +IF(X11_Xscreensaver_FOUND) + ADD_DEFINITIONS(-DX11_Xscreensaver_FOUND) +ENDIF() + QT5_ADD_RESOURCES(RSCS qt-lightdm-greeter.qrc) QT5_WRAP_UI(UI_HEADERS ${UIS}) @@ -53,6 +57,7 @@ target_link_libraries ( qt-lightdm-greeter Qt5::Svg ${LIGHTDM_QT_LIBRARIES} ${X11_LIBRARIES} + ${X11_Xscreensaver_LIB} ) diff --git a/src/loginform.cpp b/src/loginform.cpp index 9016d41..f41d99e 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -28,7 +28,6 @@ #include <QListView> #include <QSvgRenderer> #include <QX11Info> - #include <iostream> LoginForm::LoginForm(QWidget *parent) : @@ -92,6 +91,16 @@ void LoginForm::initialize() this->checkCaps(); }); + resetFormTimer.setInterval(Settings::sessionChooserResetTimer() != 0 ? + Settings::sessionChooserResetTimer() * 1000 : 30000); // default to 30s + connect(&resetFormTimer, &QTimer::timeout, this, [this]() { + long idleTime = static_cast<long>(getIdleTime(QX11Info::display())); + std::cerr << "User idle time: " << idleTime << std::endl; + if (idleTime > Settings::sessionChooserResetTimer() * 1000l) + resetLoginChooser(); + }); + resetFormTimer.start(); + if (!Global::testMode()) { ui->hostnameLabel->setText(Global::greeter()->hostname()); if(!Settings::usernamePlaceholder().isEmpty()) { diff --git a/src/loginform.h b/src/loginform.h index 11cee99..64edacc 100644 --- a/src/loginform.h +++ b/src/loginform.h @@ -15,7 +15,6 @@ #include <QGraphicsOpacityEffect> #include <QMap> #include <QTimer> - #include <QLightDM/Greeter> namespace QLightDM { @@ -63,6 +62,7 @@ private: QTimer cancelLoginTimer; QTimer hideMessageTimer; + QTimer resetFormTimer; bool clearMsg; int capsOn; diff --git a/src/settings.h b/src/settings.h index 97c8c28..e61a8a1 100644 --- a/src/settings.h +++ b/src/settings.h @@ -48,6 +48,7 @@ public: static QString guestSessionButtonText() { return s_settings->value("guest-session-button-text").toString(); } static QString guestSessionStartText() { return s_settings->value("guest-session-start-text").toString(); } static QString guestSessionStartButtonText() { return s_settings->value("guest-session-start-button-text").toString(); } + static int sessionChooserResetTimer() { return s_settings->value("session-chooser-reset-timer").toInt(); } }; #endif // SETTINGS_H diff --git a/src/x11util.cpp b/src/x11util.cpp index d2c1229..ce9192c 100644 --- a/src/x11util.cpp +++ b/src/x11util.cpp @@ -3,6 +3,7 @@ extern "C" { #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/XKBlib.h> + #include <X11/extensions/scrnsaver.h> } #include <cstring> #include <cstdlib> @@ -71,3 +72,29 @@ unsigned int getKeyMask(Display *dpy) XkbGetIndicatorState(dpy, XkbUseCoreKbd, &n); return n; } + +extern "C" +unsigned long getIdleTime(Display *dpy) +{ + if (dpy == nullptr) + return 0; + int event_basep, error_basep; + XScreenSaverInfo *ssi = nullptr; + if (!XScreenSaverQueryExtension(dpy, &event_basep, &error_basep)) { + fprintf(stderr, "Screen saver extension not supported\n"); + return 0; + } + ssi = XScreenSaverAllocInfo(); + if (ssi == nullptr) { + fprintf(stderr, "Couldn't allocate screen saver info\n"); + } + + if (!XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), ssi)) { + fprintf(stderr, "Couldn't query screen saver info\n"); + return 0; + } + unsigned long idleTime = ssi->idle; + if (ssi != nullptr) + XFree(ssi); + return idleTime; +} diff --git a/src/x11util.h b/src/x11util.h index f62de8f..6699074 100644 --- a/src/x11util.h +++ b/src/x11util.h @@ -8,6 +8,7 @@ extern "C" { void AddPixmapToBackground(unsigned const char* imgData, const unsigned int width, const unsigned int height, const unsigned int depth, const int bytesPerLine, const size_t byteCount); unsigned int getKeyMask(Display *dpy); + unsigned long getIdleTime(Display *dpy); } #endif /* X11UTIL_H_ */ |