diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/saverwidget.cpp | 111 | ||||
-rw-r--r-- | src/saverwidget.h | 7 | ||||
-rw-r--r-- | src/screensaver.cpp | 12 |
3 files changed, 92 insertions, 38 deletions
diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp index 88cf5a3..13340a0 100644 --- a/src/saverwidget.cpp +++ b/src/saverwidget.cpp @@ -10,9 +10,10 @@ #include <QSettings> #include <QFile> #include <QDebug> -#include <X11/Xlib.h> +#include <QLocalSocket> +#include <QHash> -static const QChar C_ZERO('0'); +#define C_ZERO QLatin1Char('0') static QString formatTime(qlonglong span) { @@ -29,14 +30,19 @@ SaverWidget::SaverWidget(WId parentWinId, QWidget *parent) : QWidget(parent), ui(new Ui::Saver), _parentWinId(parentWinId), - _lastMouseFake(0), _logoutDeadline(0), _shutdownDeadline(0), _counter(0), _deadlineType(DeadlineType::Unknown), _standbyDisabled(false), - _isLocked(false) + _isLocked(false), + _unixSocket(nullptr), + _display(QString::fromLocal8Bit(qgetenv("DISPLAY"))) { + int i = _display.indexOf('.'); + if (i != -1) { + _display = _display.left(i); + } QString qss = Config::getMainQss(); qDebug() << "Applying QSS: " << qss; this->setStyleSheet(qss); @@ -47,7 +53,7 @@ SaverWidget::SaverWidget(WId parentWinId, QWidget *parent) : if (_counter % 60 == 0) { this->reloadValues(); } - if (_counter % 4 == 0) { + if (!_isLocked && _counter % 4 == 0) { _isLocked = ScreenSaver::isLocked(); } _counter++; @@ -99,36 +105,75 @@ SaverWidget::~SaverWidget() void SaverWidget::reloadValues() { - QString display = QString::fromLocal8Bit(qgetenv("DISPLAY")); - int i = display.indexOf('.'); - if (i != -1) { - display = display.left(i); + if (_unixSocket != nullptr) { + _unixSocket->blockSignals(true); + _unixSocket->deleteLater(); } - QSettings s(QString("/run/openslx/idleaction-") + display, QSettings::IniFormat); - _logoutDeadline = s.value("lockDeadline", 0).toLongLong(); - _shutdownDeadline = s.value("shutdownDeadline", 0).toLongLong(); - // TODO: Load text strings for everything - _deadlineType = DeadlineType::Unknown; + _unixSocket = new QLocalSocket(); + connect(_unixSocket, &QLocalSocket::connected, [=]() { + qDebug() << "Connected to daewmweon"; + _unixSocket->write((QLatin1String("get ") + _display).toLocal8Bit()); + QTimer::singleShot(1000, [this]() { + _unixSocket->disconnectFromServer(); + }); + }); + connect(_unixSocket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error), [=](QLocalSocket::LocalSocketError err) { + qDebug() << "Local socket error:" << err; + }); + connect(_unixSocket, &QLocalSocket::disconnected, this, &SaverWidget::parseDaemonData); + _unixSocket->connectToServer("/run/idle-daemon"); } -void SaverWidget::mouseMoveEvent(QMouseEvent *) +void SaverWidget::parseDaemonData() { - /* - // Doesn't work, method is never called :-( - qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (now - _lastMouseFake < 1000) - return; - ui->lblText->setText(QString::number(int(now / 1000))); - _lastMouseFake = now; - XEvent ev; - memset(&ev, 0, sizeof(ev)); - ev.type = ButtonPress; - ev.xbutton.button = 1; - ev.xbutton.same_screen = True; - ev.xbutton.root = ev.xbutton.window = ev.xbutton.subwindow = _parentWinId; - XSendEvent(QX11Info::display(), _parentWinId, True, 0xfff, &ev); - ev.type = ButtonRelease; - ev.xbutton.state = 0x100; - XSendEvent(QX11Info::display(), _parentWinId, True, 0xfff, &ev); - */ + QTextStream ts(_unixSocket); + QString line; +#define SEC_NONE 0 +#define SEC_GENERAL 1 +#define SEC_ME 2 +#define STORE(x) else if (key == QLatin1String( #x )) x = value.toString() + int sec = SEC_NONE; + QString nextAction, nextActionTime, logoutTime, locked; + while (!ts.atEnd()) { + line = ts.readLine(); + if (line.isEmpty()) + continue; + if (line.at(0) == QLatin1Char('[')) { + // Section + if (line == QLatin1String("[General]")) { + sec = SEC_GENERAL; + } else if ( line == "[" + _display + "]") { + sec = SEC_ME; + } else { + sec = SEC_NONE; + } + } else { + // Value + int i = line.indexOf(QLatin1Char('=')); + if (i == -1) + continue; + const QStringRef key(&line, 0, i); + const QStringRef value(&line, i+ 1, line.size() - (i + 1)); + if (sec == SEC_GENERAL) { + if (false); + STORE(nextAction); + STORE(nextActionTime); + } else if (sec == SEC_ME) { + if (false); + STORE(logoutTime); + STORE(locked); + } + } + } + if (nextAction.isEmpty() || nextAction == QLatin1String("none") || nextActionTime.isEmpty()) { + _shutdownDeadline = 0; + } else { + _shutdownDeadline = nextActionTime.toLongLong(); + } + _logoutDeadline = logoutTime.toLongLong(); + if (!_isLocked && locked.toInt() != 0) { + _isLocked = true; + } + // TODO: Load text strings for everything + _deadlineType = DeadlineType::Unknown; } diff --git a/src/saverwidget.h b/src/saverwidget.h index bb76bbf..f2112e0 100644 --- a/src/saverwidget.h +++ b/src/saverwidget.h @@ -9,6 +9,8 @@ class Saver; class DeadlineType; +class QLocalSocket; + class SaverWidget : public QWidget { Q_OBJECT @@ -18,15 +20,14 @@ public: ~SaverWidget(); protected: - void mouseMoveEvent(QMouseEvent *e) override; protected slots: void reloadValues(); + void parseDaemonData(); private: Ui::Saver *ui; WId _parentWinId; - qint64 _lastMouseFake; // qlonglong _logoutDeadline; qlonglong _shutdownDeadline; // Actually used for reboot, standby too... Same result for user (session = dead) @@ -34,6 +35,8 @@ private: const DeadlineType *_deadlineType; bool _standbyDisabled; bool _isLocked; + QLocalSocket *_unixSocket; + QString _display; }; #endif // SAVERWIDGET_H diff --git a/src/screensaver.cpp b/src/screensaver.cpp index 75e6ba5..053dd99 100644 --- a/src/screensaver.cpp +++ b/src/screensaver.cpp @@ -175,16 +175,22 @@ bool isLocked() if (!init()) return false; char *v = nullptr; - Window window = find_screensaver_window( display, &v ); + static Window window = 0; + if ( !window ) + find_screensaver_window( display, &v ); if( !window ) return false; - if( !v || !*v ) + if( !v || !*v ) { + window = 0; return false; + } XClassHint hint; memset( &hint, 0, sizeof( hint ) ); XGetClassHint( display, window, &hint ); - if( !hint.res_class ) + if( !hint.res_class ) { + window = 0; return false; + } Atom type; int format; |