summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 21:36:03 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 21:36:03 (GMT)
commitc4287096a3226f63851be5be03f38acfb52ec32b (patch)
treeb162b1bb0e2a60fabd5798ff4fc1b933a3bebd43
parent6875dc88cfcabf1092730d46b63afd6244a04a98 (diff)
Fix inhibiting of sleep on modern linux systems, port away from deprecated Solid methods
-rw-r--r--ui/presentationwidget.cpp67
-rw-r--r--ui/presentationwidget.h2
2 files changed, 60 insertions, 9 deletions
diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp
index a7cfb0a..16f4c3f 100644
--- a/ui/presentationwidget.cpp
+++ b/ui/presentationwidget.cpp
@@ -41,7 +41,10 @@
#include <kselectaction.h>
#include <QDialog>
-#include <Solid/PowerManagement>
+#ifdef Q_OS_LINUX
+#include <QDBusUnixFileDescriptor>
+#include <unistd.h> // For ::close() for sleep inhibition
+#endif
// system includes
#include <stdlib.h>
@@ -135,6 +138,7 @@ class PresentationToolBar : public QToolBar
PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc, DrawingToolActions * drawingToolActions, KActionCollection * collection )
: QWidget( 0 /* must be null, to have an independent widget */, Qt::FramelessWindowHint ),
m_pressedLink( 0 ), m_handCursor( false ), m_drawingEngine( 0 ),
+ m_screenInhibitCookie(0), m_sleepInhibitCookie(0),
m_parentWidget( parent ),
m_document( doc ), m_frameIndex( -1 ), m_topBar( 0 ), m_pagesEdit( 0 ), m_searchBar( 0 ),
m_ac( collection ), m_screenSelect( 0 ), m_isSetup( false ), m_blockNotifications( false ), m_inBlackScreenMode( false ),
@@ -1642,19 +1646,66 @@ void PresentationWidget::applyNewScreenSize( const QSize & oldSize )
void PresentationWidget::inhibitPowerManagement()
{
+#ifdef Q_OS_LINUX
QString reason = i18nc( "Reason for inhibiting the screensaver activation, when the presentation mode is active", "Giving a presentation" );
- // Inhibit screen and sleep
- // Note: beginSuppressingScreenPowerManagement inhibits DPMS, automatic brightness change and screensaver
- m_screenInhibitCookie = Solid::PowerManagement::beginSuppressingScreenPowerManagement(reason);
- m_sleepInhibitCookie = Solid::PowerManagement::beginSuppressingSleep(reason);
+ if (!m_screenInhibitCookie) {
+ QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.ScreenSaver", "/ScreenSaver",
+ "org.freedesktop.ScreenSaver", "Inhibit");
+ message << QCoreApplication::applicationName();
+ message << reason;
+
+ QDBusPendingReply<uint> reply = QDBusConnection::sessionBus().asyncCall(message);
+ reply.waitForFinished();
+ if (reply.isValid()) {
+ m_screenInhibitCookie = reply.value();
+ qDebug() << "Screen inhibition cookie" << m_screenInhibitCookie;
+ } else {
+ qWarning() << "Unable to inhibit screensaver" << reply.error();
+ }
+ }
+
+ if (!m_sleepInhibitCookie) {
+ QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.login1"),
+ QStringLiteral("/org/freedesktop/login1"),
+ QStringLiteral("org.freedesktop.login1.Manager"),
+ QStringLiteral("Inhibit")
+ );
+ message << QStringLiteral("sleep");
+ message << QCoreApplication::applicationName();
+ message << reason;
+ message << QStringLiteral("block");
+
+ QDBusPendingReply<QDBusUnixFileDescriptor> reply = QDBusConnection::systemBus().asyncCall(message);
+ reply.waitForFinished();
+ if (reply.isValid()) {
+ m_sleepInhibitCookie = reply.value().fileDescriptor();
+ } else {
+ qWarning() << "Unable to inhibit sleep" << reply.error();
+ }
+ }
+#endif
}
void PresentationWidget::allowPowerManagement()
{
- // Remove cookies
- Solid::PowerManagement::stopSuppressingScreenPowerManagement(m_screenInhibitCookie);
- Solid::PowerManagement::stopSuppressingSleep(m_sleepInhibitCookie);
+#ifdef Q_OS_LINUX
+ if (m_sleepInhibitCookie) {
+ ::close(m_sleepInhibitCookie);
+ m_sleepInhibitCookie = 0;
+ }
+
+ if (m_screenInhibitCookie) {
+ QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.ScreenSaver", "/ScreenSaver",
+ "org.freedesktop.ScreenSaver", "UnInhibit");
+ message << m_screenInhibitCookie;
+
+ QDBusPendingReply<uint> reply = QDBusConnection::sessionBus().asyncCall(message);
+ reply.waitForFinished();
+
+ m_screenInhibitCookie = 0;
+ }
+#endif
}
void PresentationWidget::showTopBar( bool show )
diff --git a/ui/presentationwidget.h b/ui/presentationwidget.h
index 76a5bd0..69574d2 100644
--- a/ui/presentationwidget.h
+++ b/ui/presentationwidget.h
@@ -111,7 +111,7 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
SmoothPathEngine * m_drawingEngine;
QRect m_drawingRect;
int m_screen;
- int m_screenInhibitCookie;
+ uint m_screenInhibitCookie;
int m_sleepInhibitCookie;
// transition related