summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-09-06 17:27:38 +0200
committerSimon Rettberg2018-09-06 17:27:38 +0200
commit346228af2bf851d6c6e850810d0e2c80ca7e7997 (patch)
tree2ae8ac991f743c5c32663e8a888688d426381386
parentFix reverting resolution (diff)
downloadbeamergui-346228af2bf851d6c6e850810d0e2c80ca7e7997.tar.gz
beamergui-346228af2bf851d6c6e850810d0e2c80ca7e7997.tar.xz
beamergui-346228af2bf851d6c6e850810d0e2c80ca7e7997.zip
Support waking GUI up via user session bus
-rw-r--r--src/bus.cpp48
-rw-r--r--src/bus.h8
-rw-r--r--src/widget.cpp22
3 files changed, 48 insertions, 30 deletions
diff --git a/src/bus.cpp b/src/bus.cpp
index 1dadedb..1a722c1 100644
--- a/src/bus.cpp
+++ b/src/bus.cpp
@@ -13,28 +13,42 @@ Bus::Bus(QObject *parent) : QObject(parent), _hasListener(false)
bool Bus::registerListener()
{
- if (!QDBusConnection::systemBus().isConnected()) {
- qDebug() << "Cannot connect to system bus";
- return false;
+ QList<QDBusConnection> cons = {QDBusConnection::systemBus(), QDBusConnection::sessionBus()};
+ int index = 0; // 0 == system, 1 == session
+ for (auto con : cons) {
+ if (!con.isConnected()) {
+ qDebug() << "Cannot connect to" << con.name();
+ } else {
+ QDBusServiceWatcher *w = new QDBusServiceWatcher(SERVICE_NAME, con);
+ w->setParent(this);
+ connect(w, &QDBusServiceWatcher::serviceRegistered, [=](const QString & /* service */) {
+ emit serviceConnected(index == 1);
+ });
+ }
+ ++index;
}
- QDBusServiceWatcher *w = new QDBusServiceWatcher("de.bwlehrpool.beamergui", QDBusConnection::systemBus());
- w->setParent(this);
- connect(w, &QDBusServiceWatcher::serviceRegistered, [=](const QString &service) {
- qDebug() << "Registered Service" << service;
- emit serviceConnected();
- });
return true;
}
+/**
+ * Try to grab the service name on either the system or the session
+ * bus. This signals the listening beamergui (if any) that it should show
+ * up again.
+ */
bool Bus::registerService()
{
- if (!QDBusConnection::systemBus().isConnected()) {
- qDebug() << "Cannot connect to system bus";
- return false;
+ bool ok = false;
+ QList<QDBusConnection> cons = {QDBusConnection::systemBus(), QDBusConnection::sessionBus()};
+ for (auto con : cons) {
+ if (!con.isConnected()) {
+ qDebug() << "Cannot connect to" << con.name();
+ } else {
+ if (con.registerService(SERVICE_NAME)) {
+ ok = true;
+ } else {
+ qDebug() << con.lastError().message();
+ }
+ }
}
- if (!QDBusConnection::systemBus().registerService(SERVICE_NAME)) {
- qDebug() << QDBusConnection::systemBus().lastError().message();
- return false;
- }
- return true;
+ return ok;
}
diff --git a/src/bus.h b/src/bus.h
index f98ee65..34da9ac 100644
--- a/src/bus.h
+++ b/src/bus.h
@@ -3,22 +3,24 @@
#include <QObject>
+class QDBusConnection;
+
class Bus : public QObject
{
Q_OBJECT
public:
bool registerListener();
- bool registerService();
+ bool registerService();
inline static Bus* inst() {
if (_instance == nullptr) _instance = new Bus();
return _instance;
}
signals:
- void serviceConnected();
+ void serviceConnected(bool sessionBus);
private:
- explicit Bus(QObject *parent = nullptr);
+ explicit Bus(QObject *parent = nullptr);
bool _hasListener;
static Bus *_instance;
};
diff --git a/src/widget.cpp b/src/widget.cpp
index 49e5285..85aacea 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -176,9 +176,13 @@ Widget::Widget(QWidget *parent) :
// TODO: GUI feedback
} else {
// GUI popup logic
- connect(Bus::inst(), &Bus::serviceConnected, [=]() {
+ connect(Bus::inst(), &Bus::serviceConnected, [=](bool isSession) {
qDebug() << "\\o/ Received DBus connect notification \\o/";
- popupGui();
+ if (isSession) { // Session bus means user triggered, show immediately
+ this->show();
+ } else { // Otherwise, systembus means udev event -- take normal route
+ popupGui();
+ }
});
}
// Xlib
@@ -506,17 +510,13 @@ bool Widget::keepResolution()
continue;
// Show a dialog asking if the res should be kept
TimeOutDialog *keepDialog = new TimeOutDialog(15, this);
- //keepDialog->setWindowModality(Qt::WindowModal);
- keepDialog->setWindowTitle(" ");
- keepDialog->setLabelText(trUtf8("Do you want to keep this resolution?"));
- keepDialog->setCancelButtonText(trUtf8("Keep"));
- keepDialog->setWindowFlag(Qt::WindowStaysOnTopHint, true);
QSize s = (geo.size() - keepDialog->size()) / 2;
QPoint tl = geo.topLeft();
tl.rx() += s.width();
tl.ry() += s.height();
keepDialog->move(tl);
keepDialog->show();
+ keepDialog->move(tl);
list.append(keepDialog);
}
@@ -526,10 +526,12 @@ bool Widget::keepResolution()
active = true;
QCoreApplication::processEvents();
for (auto win : list) {
- active = active && win->isActive();
- wasCanceled = wasCanceled || win->wasCanceled();
+ if (!win->isActive()) {
+ active = false;
+ wasCanceled = win->wasCanceled();
+ }
}
- } while (active && !wasCanceled);
+ } while (active);
for (auto win : list) {
win->deleteLater();