Parcourir la source

Allow suppression of screensaver via dbus

Change-Id: Ibcf1117d328bc8c5f61685b8cc26e9ff509c1652
Donald Carr il y a 8 ans
Parent
commit
19a5d8b548
2 fichiers modifiés avec 14 ajouts et 3 suppressions
  1. 1 1
      artriculate.pro
  2. 13 2
      src/main.cpp

+ 1 - 1
artriculate.pro

@@ -1,6 +1,6 @@
 TEMPLATE = app
 
-QT += qml quick
+QT += qml quick dbus
 CONFIG += c++11
 
 SOURCES += src/main.cpp \

+ 13 - 2
src/main.cpp

@@ -25,14 +25,14 @@
 #include <QSurfaceFormat>
 #include <QTimer>
 #include <QQuickWindow>
-
 #include <QDir>
 #include <QFile>
 #include <QFileInfo>
 #include <QTextStream>
-
 #include <QDebug>
 #include <QScreen>
+#include <QDBusInterface>
+#include <QDBusConnection>
 
 class FileReader : public QObject {
     Q_OBJECT
@@ -90,6 +90,17 @@ int main(int argc, char *argv[])
         }
     }
 
+    // qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver Inhibit "artriculate" "media playback"
+
+    if (settings.value("suppressScreensaver", false).toBool()) {
+        QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
+        uint id = screenSaver.call("Inhibit", app.applicationName(), "Media playback").arguments().at(0).toInt();
+        QObject::connect(&app, &QCoreApplication::aboutToQuit, [id]() {
+            QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
+            screenSaver.call("UnInhibit", id);
+        });
+    }
+
     QQmlApplicationEngine engine;
     qmlRegisterType<PictureModel>("PictureModel", 1, 0, "PictureModel");