From 3677a60cb4c974110218457d012af0c6ca63c0ff Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Thu, 21 Jun 2018 15:25:43 -0700 Subject: [PATCH 01/10] Linux depends on QtDBus --- gui.pro | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gui.pro b/gui.pro index 6884920e..57c1b7c9 100644 --- a/gui.pro +++ b/gui.pro @@ -12,6 +12,9 @@ mac { win32 { LIBS += -luser32 } +linux { + QT += dbus +} include(src/QtAwesome/QtAwesome/QtAwesome.pri) include (src/QSimpleUpdater/QSimpleUpdater.pri) From 45ce78f85e18df9466967db2184cb0414c8bb61d Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Thu, 21 Jun 2018 15:30:59 -0700 Subject: [PATCH 02/10] Catch screen lock event in Ubuntu --- src/SystemEventHandler.cpp | 18 ++++++++++++++++++ src/SystemEventHandler.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index a4ab83aa..a62cccb0 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -5,6 +5,8 @@ #elif defined(Q_OS_WIN) #include #include +#elif defined(Q_OS_LINUX) +#include #endif #include @@ -29,6 +31,10 @@ SystemEventHandler::SystemEventHandler() regFunc((HWND) widget.winId(), 0); } } +#elif defined(Q_OS_LINUX) + // Catch Ubuntu events. + QDBusConnection::sessionBus().connect("", "/com/ubuntu/Upstart", "", + "EventEmitted", "sas", this, SLOT(upstartEventEmitted(QString,QStringList))); #endif } @@ -48,6 +54,9 @@ SystemEventHandler::~SystemEventHandler() unRegFunc((HWND) widget.winId()); } } +#elif defined(Q_OS_LINUX) + QDBusConnection::sessionBus().disconnect("", "/com/ubuntu/Upstart", "", + "EventEmitted", "sas", this, SLOT(upstartEventEmitted(QString,QStringList))); #endif } @@ -128,3 +137,12 @@ void SystemEventHandler::readyToTerminate() ::readyToTerminate(); } #endif + +void SystemEventHandler::upstartEventEmitted(const QString &name, const QStringList &env) +{ + Q_UNUSED(env); + if (name == "desktop-lock") + { + emit screenLocked(); + } +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index 7ddcca7b..8f3ec85d 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -32,6 +32,9 @@ public slots: void readyToTerminate(); #endif +private slots: + void upstartEventEmitted(const QString &name, const QStringList &env); + private: #ifdef Q_OS_MAC void *eventHandler = nullptr; From 0eceb78ba4b502758f3e74c2d8a20291b8ca9335 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Thu, 21 Jun 2018 15:35:33 -0700 Subject: [PATCH 03/10] Enable lock device check box on Linux --- src/MainWindow.cpp | 7 ------- src/MainWindow.h | 5 ----- 2 files changed, 12 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index baaa7f9f..751b01da 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -538,12 +538,7 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent connect(ui->checkBoxBoot, SIGNAL(toggled(bool)), this, SLOT(checkSettingsChanged())); connect(ui->checkBoxTuto, SIGNAL(toggled(bool)), this, SLOT(checkSettingsChanged())); -#ifdef Q_OS_LINUX - ui->checkBoxLockDevice->setChecked(false); - ui->checkBoxLockDevice->setVisible(false); -#else ui->checkBoxLockDevice->setChecked(s.value("settings/LockDeviceOnSystemEvents", true).toBool()); -#endif connect(ui->checkBoxLockDevice, &QCheckBox::toggled, this, &MainWindow::onLockDeviceSystemEventsChanged); connect(ui->comboBoxScreenBrightness, SIGNAL(currentIndexChanged(int)), this, SLOT(checkSettingsChanged())); @@ -562,12 +557,10 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent //Setup the confirm view ui->widgetSpin->setPixmap(AppGui::qtAwesome()->icon(fa::circleonotch).pixmap(QSize(80, 80))); -#if defined(Q_OS_MAC) || defined(Q_OS_WIN) connect(&eventHandler, &SystemEventHandler::screenLocked, this, &MainWindow::onSystemEvents); connect(&eventHandler, &SystemEventHandler::loggingOff, this, &MainWindow::onSystemEvents); connect(&eventHandler, &SystemEventHandler::goingToSleep, this, &MainWindow::onSystemEvents); connect(&eventHandler, &SystemEventHandler::shuttingDown, this, &MainWindow::onSystemEvents); -#endif checkAutoStart(); diff --git a/src/MainWindow.h b/src/MainWindow.h index f47860a2..2dd2b4d3 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -24,10 +24,7 @@ #include #include "DbMasterController.h" #include "WindowLog.h" - -#if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SystemEventHandler.h" -#endif #include @@ -161,9 +158,7 @@ private slots: DbMasterController *dbMasterController; void initHelpLabels(); -#if defined(Q_OS_MAC) || defined(Q_OS_WIN) SystemEventHandler eventHandler; -#endif }; #endif // MAINWINDOW_H From 4ca32d677a78f615d5c81c928e9dbcdd92602d6c Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 11:11:37 -0700 Subject: [PATCH 04/10] Catch GNOME shutdown event --- src/SystemEventHandler.cpp | 22 ++++++++++++++++++---- src/SystemEventHandler.h | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index a62cccb0..a91e19a0 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -32,9 +32,15 @@ SystemEventHandler::SystemEventHandler() } } #elif defined(Q_OS_LINUX) + auto bus = QDBusConnection::sessionBus(); + // Catch Ubuntu events. - QDBusConnection::sessionBus().connect("", "/com/ubuntu/Upstart", "", - "EventEmitted", "sas", this, SLOT(upstartEventEmitted(QString,QStringList))); + bus.connect("", "/com/ubuntu/Upstart", "", "EventEmitted", "sas", this, + SLOT(upstartEventEmitted(QString,QStringList))); + + // Catch Gnome shutdown events. + bus.connect("", "", "org.gnome.SessionManager.ClientPrivate", "EndSession", "u", this, + SLOT(clientPrivateEndSession(quint32))); #endif } @@ -55,8 +61,11 @@ SystemEventHandler::~SystemEventHandler() } } #elif defined(Q_OS_LINUX) - QDBusConnection::sessionBus().disconnect("", "/com/ubuntu/Upstart", "", - "EventEmitted", "sas", this, SLOT(upstartEventEmitted(QString,QStringList))); + auto bus = QDBusConnection::sessionBus(); + bus.disconnect("", "/com/ubuntu/Upstart", "", "EventEmitted", "sas", this, + SLOT(upstartEventEmitted(QString,QStringList))); + bus.disconnect("", "", "org.gnome.SessionManager.ClientPrivate", "EndSession", "u", this, + SLOT(clientPrivateEndSession(quint32))); #endif } @@ -146,3 +155,8 @@ void SystemEventHandler::upstartEventEmitted(const QString &name, const QStringL emit screenLocked(); } } + +void SystemEventHandler::clientPrivateEndSession(quint32 id) +{ + emit loggingOff(); +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index 8f3ec85d..d76d9c21 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -34,6 +34,7 @@ public slots: private slots: void upstartEventEmitted(const QString &name, const QStringList &env); + void clientPrivateEndSession(quint32 id); private: #ifdef Q_OS_MAC From dc95911b8634d69e5c61b7a94eb92be1dc2be521 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 11:14:28 -0700 Subject: [PATCH 05/10] Catch org.freedesktop.ScreenSaver lock screen event This is at least used by KDE at the time of writing. --- src/SystemEventHandler.cpp | 14 ++++++++++++++ src/SystemEventHandler.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index a91e19a0..638d15fd 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -41,6 +41,10 @@ SystemEventHandler::SystemEventHandler() // Catch Gnome shutdown events. bus.connect("", "", "org.gnome.SessionManager.ClientPrivate", "EndSession", "u", this, SLOT(clientPrivateEndSession(quint32))); + + // Catch org.freedesktop.ScreenSaver event (Used with KDE at least). + bus.connect("", "/org/freedesktop/ScreenSaver", "", "ActiveChanged", "b", this, + SLOT(screenSaverActiveChanged(bool))); #endif } @@ -66,6 +70,8 @@ SystemEventHandler::~SystemEventHandler() SLOT(upstartEventEmitted(QString,QStringList))); bus.disconnect("", "", "org.gnome.SessionManager.ClientPrivate", "EndSession", "u", this, SLOT(clientPrivateEndSession(quint32))); + bus.disconnect("", "/org/freedesktop/ScreenSaver", "", "ActiveChanged", "b", this, + SLOT(screenSaverActiveChanged(bool))); #endif } @@ -160,3 +166,11 @@ void SystemEventHandler::clientPrivateEndSession(quint32 id) { emit loggingOff(); } + +void SystemEventHandler::screenSaverActiveChanged(bool on) +{ + if (on) + { + emit screenLocked(); + } +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index d76d9c21..f666db26 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -35,6 +35,7 @@ public slots: private slots: void upstartEventEmitted(const QString &name, const QStringList &env); void clientPrivateEndSession(quint32 id); + void screenSaverActiveChanged(bool on); private: #ifdef Q_OS_MAC From 92c7635d73a72622cdd87da0fd8cda4c945323a1 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 11:20:01 -0700 Subject: [PATCH 06/10] Catch Ubuntu shutdown event --- src/SystemEventHandler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index 638d15fd..1836f47f 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -155,11 +155,14 @@ void SystemEventHandler::readyToTerminate() void SystemEventHandler::upstartEventEmitted(const QString &name, const QStringList &env) { - Q_UNUSED(env); if (name == "desktop-lock") { emit screenLocked(); } + else if (name == "session-end" && env.size() == 1 && env.first().toLower() == "type=shutdown") + { + emit shuttingDown(); + } } void SystemEventHandler::clientPrivateEndSession(quint32 id) From 8c8b6cba9effaf70dfc09ada12094d04f553f483 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 11:23:12 -0700 Subject: [PATCH 07/10] Ignore unused argument --- src/SystemEventHandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index 1836f47f..da8eb41b 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -167,7 +167,8 @@ void SystemEventHandler::upstartEventEmitted(const QString &name, const QStringL void SystemEventHandler::clientPrivateEndSession(quint32 id) { - emit loggingOff(); + Q_UNUSED(id); + emit loggingOff(); } void SystemEventHandler::screenSaverActiveChanged(bool on) From 7bde6c4d8ec7bddd22efdf5cb1713b2a6c55f3bd Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 11:43:00 -0700 Subject: [PATCH 08/10] Catch KDE about-to-suspend event --- src/SystemEventHandler.cpp | 11 +++++++++++ src/SystemEventHandler.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index da8eb41b..86fed940 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -45,6 +45,10 @@ SystemEventHandler::SystemEventHandler() // Catch org.freedesktop.ScreenSaver event (Used with KDE at least). bus.connect("", "/org/freedesktop/ScreenSaver", "", "ActiveChanged", "b", this, SLOT(screenSaverActiveChanged(bool))); + + // Catch KDE about-to-suspend event. + bus.connect("", "/org/kde/Solid/PowerManagement/Actions/SuspendSession", "", "aboutToSuspend", + this, SLOT(kdeAboutToSuspend())); #endif } @@ -72,6 +76,8 @@ SystemEventHandler::~SystemEventHandler() SLOT(clientPrivateEndSession(quint32))); bus.disconnect("", "/org/freedesktop/ScreenSaver", "", "ActiveChanged", "b", this, SLOT(screenSaverActiveChanged(bool))); + bus.disconnect("", "/org/kde/Solid/PowerManagement/Actions/SuspendSession", "", "aboutToSuspend", + this, SLOT(kdeAboutToSuspend())); #endif } @@ -178,3 +184,8 @@ void SystemEventHandler::screenSaverActiveChanged(bool on) emit screenLocked(); } } + +void SystemEventHandler::kdeAboutToSuspend() +{ + emit goingToSleep(); +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index f666db26..da9cddf4 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -36,6 +36,7 @@ private slots: void upstartEventEmitted(const QString &name, const QStringList &env); void clientPrivateEndSession(quint32 id); void screenSaverActiveChanged(bool on); + void kdeAboutToSuspend(); private: #ifdef Q_OS_MAC From c5b1fc691465f7a7afbeba6753e32593c5d22735 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 12:09:45 -0700 Subject: [PATCH 09/10] Catch suspend event from org.freedesktop.login1 --- src/SystemEventHandler.cpp | 20 ++++++++++++++++++++ src/SystemEventHandler.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index 86fed940..defdb098 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -32,6 +32,7 @@ SystemEventHandler::SystemEventHandler() } } #elif defined(Q_OS_LINUX) + /* Session events */ auto bus = QDBusConnection::sessionBus(); // Catch Ubuntu events. @@ -49,6 +50,13 @@ SystemEventHandler::SystemEventHandler() // Catch KDE about-to-suspend event. bus.connect("", "/org/kde/Solid/PowerManagement/Actions/SuspendSession", "", "aboutToSuspend", this, SLOT(kdeAboutToSuspend())); + + /* System events */ + auto sysBus = QDBusConnection::systemBus(); + + // Catch suspend event from org.freedesktop.login1. + sysBus.connect("", "/org/freedesktop/login1", "", "PrepareForSleep", "b", this, + SLOT(login1PrepareForSleep(bool))); #endif } @@ -78,6 +86,10 @@ SystemEventHandler::~SystemEventHandler() SLOT(screenSaverActiveChanged(bool))); bus.disconnect("", "/org/kde/Solid/PowerManagement/Actions/SuspendSession", "", "aboutToSuspend", this, SLOT(kdeAboutToSuspend())); + + auto sysBus = QDBusConnection::systemBus(); + sysBus.disconnect("", "/org/freedesktop/login1", "", "PrepareForSleep", "b", this, + SLOT(login1PrepareForSleep(bool))); #endif } @@ -189,3 +201,11 @@ void SystemEventHandler::kdeAboutToSuspend() { emit goingToSleep(); } + +void SystemEventHandler::login1PrepareForSleep(bool active) +{ + if (active) + { + emit goingToSleep(); + } +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index da9cddf4..d99cb452 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -37,6 +37,7 @@ private slots: void clientPrivateEndSession(quint32 id); void screenSaverActiveChanged(bool on); void kdeAboutToSuspend(); + void login1PrepareForSleep(bool active); private: #ifdef Q_OS_MAC From a2dab4345e4b4cd1d6590593828fd1d7d25f243e Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Fri, 22 Jun 2018 12:36:59 -0700 Subject: [PATCH 10/10] Catch shutdown event from org.freedesktop.login1 --- src/SystemEventHandler.cpp | 14 ++++++++++++++ src/SystemEventHandler.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/SystemEventHandler.cpp b/src/SystemEventHandler.cpp index defdb098..90a7408b 100644 --- a/src/SystemEventHandler.cpp +++ b/src/SystemEventHandler.cpp @@ -57,6 +57,10 @@ SystemEventHandler::SystemEventHandler() // Catch suspend event from org.freedesktop.login1. sysBus.connect("", "/org/freedesktop/login1", "", "PrepareForSleep", "b", this, SLOT(login1PrepareForSleep(bool))); + + // Catch shutdown event from org.freedesktop.login1. + sysBus.connect("", "/org/freedesktop/login1", "", "PrepareForShutdown", "b", this, + SLOT(login1PrepareForShutdown(bool))); #endif } @@ -90,6 +94,8 @@ SystemEventHandler::~SystemEventHandler() auto sysBus = QDBusConnection::systemBus(); sysBus.disconnect("", "/org/freedesktop/login1", "", "PrepareForSleep", "b", this, SLOT(login1PrepareForSleep(bool))); + sysBus.connect("", "/org/freedesktop/login1", "", "PrepareForShutdown", "b", this, + SLOT(login1PrepareForShutdown(bool))); #endif } @@ -209,3 +215,11 @@ void SystemEventHandler::login1PrepareForSleep(bool active) emit goingToSleep(); } } + +void SystemEventHandler::login1PrepareForShutdown(bool active) +{ + if (active) + { + emit shuttingDown(); + } +} diff --git a/src/SystemEventHandler.h b/src/SystemEventHandler.h index d99cb452..addd2f70 100644 --- a/src/SystemEventHandler.h +++ b/src/SystemEventHandler.h @@ -38,6 +38,7 @@ private slots: void screenSaverActiveChanged(bool on); void kdeAboutToSuspend(); void login1PrepareForSleep(bool active); + void login1PrepareForShutdown(bool active); private: #ifdef Q_OS_MAC