From 9b23c98f59a9a5f05d2733dc5ffc51bf95436ec5 Mon Sep 17 00:00:00 2001 From: janbar Date: Wed, 18 Oct 2023 01:06:57 +0200 Subject: [PATCH] try to fix issue #60 --- CMakeLists.txt | 14 ++++++++++-- src/platformextras.cpp | 51 ++++++++++++++++++++++++++++++++++-------- src/platformextras.h | 4 ++++ 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9f36d16..c153b1b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ option(INSTALL_TESTS "Install the tests on make install" OFF) option(BUILD_DEVICE_MOBILE "Enable behaviors for mobile devices" OFF) set(APP_VERSION "1.10.4") -set(APP_VERSION_CODE 59) +set(APP_VERSION_CODE 60) set(APP_ID "io.github.janbar.osmin") set(APP_NAME "osmin") @@ -110,7 +110,11 @@ find_package(Qt5QuickControls2 ${QT_MIN_VERSION} REQUIRED) if(ANDROID) find_package(Qt5AndroidExtras REQUIRED) +elseif(UNIX AND NOT APPLE) + find_library(DBUS_LIBRARIES dbus-1 REQUIRED) + find_package(Qt5DBus REQUIRED) endif() + find_package(Qt5Widgets REQUIRED) find_package(Qt5Xml REQUIRED) find_package(Qt5Svg REQUIRED) @@ -199,12 +203,18 @@ if(ANDROID) add_definitions(-frtti) # dynamic_cast: https://github.com/android/ndk/issues/519 target_link_libraries(osmin Qt5::QuickControls2 Qt5::AndroidExtras android log Qt5::RemoteObjects Qt5::Positioning Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) -else() +elseif(APPLE) if(BUILD_DEVICE_MOBILE) add_definitions(-DDEVICE_MOBILE) endif() target_link_libraries(osmin Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) +elseif(UNIX) + if(BUILD_DEVICE_MOBILE) + add_definitions(-DDEVICE_MOBILE) + endif() + target_link_libraries(osmin Qt5::QuickControls2 Qt5::DBus Qt5::RemoteObjects Qt5::Positioning + Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) endif() if(ANDROID) diff --git a/src/platformextras.cpp b/src/platformextras.cpp index 98171361..b2acf6fa 100644 --- a/src/platformextras.cpp +++ b/src/platformextras.cpp @@ -20,24 +20,29 @@ #include #include #include -#ifdef Q_OS_ANDROID -#include -#include -#endif -#ifdef SAILFISHOS +#if defined(SAILFISHOS) #define AUTO_MOUNT "/run/media/" -#else -#ifdef Q_OS_ANDROID + +#elif defined(Q_OS_ANDROID) +#include +#include #define AUTO_MOUNT "/storage/" + +#elif defined(Q_OS_LINUX) +#include +#define AUTO_MOUNT "/media/" + #else #define AUTO_MOUNT "/media/" #endif -#endif PlatformExtras::PlatformExtras(QObject* parent) : QObject(parent) , m_preventBlanking(false) +#ifdef Q_OS_LINUX +, m_cookie(0) +#endif { } @@ -96,9 +101,11 @@ QStringList PlatformExtras::getStorageDirs() void PlatformExtras::setPreventBlanking(bool on) { + if (m_preventBlanking == on) + return; m_preventBlanking = on; -#ifdef Q_OS_ANDROID +#if defined(Q_OS_ANDROID) { QtAndroid::runOnAndroidThread([on] { @@ -110,5 +117,31 @@ void PlatformExtras::setPreventBlanking(bool on) window.callMethod("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON); }); } + +#elif defined(Q_OS_LINUX) + QDBusConnection bus = QDBusConnection::sessionBus(); + if(bus.isConnected()) + { + QDBusInterface interface("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", + "org.freedesktop.ScreenSaver", bus); + if (interface.isValid()) + { + if(on) + { + QDBusReply reply = interface.call("Inhibit", "osmin", "navigation enabled"); + if (reply.isValid()) + m_cookie = reply.value(); + else + { + QDBusError error = reply.error(); + qWarning("%s: %s", error.name().toUtf8().constData(), error.message().toUtf8().constData()); + } + } + else + { + interface.call("UnInhibit", m_cookie); + } + } + } #endif } diff --git a/src/platformextras.h b/src/platformextras.h index a6bd16dc..22554fb8 100644 --- a/src/platformextras.h +++ b/src/platformextras.h @@ -52,6 +52,10 @@ class PlatformExtras : public QObject void setPreventBlanking(bool on); bool m_preventBlanking; + +#ifdef Q_OS_LINUX + uint m_cookie; +#endif }; #endif // PLATFORM_EXTRAS_H