mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 03:37:47 +00:00
Inhibit sleep on Linux when playing the game
This fixes a "deficiency" in KWin, where controller input does not wake up the screen. You have to manually block the screen locking or else you need to move the mouse every so often. The system could also sleep while patching, which is really bad. This is a really simple implementation that can be expanded upon later.
This commit is contained in:
parent
32c73a6126
commit
f136f6475c
4 changed files with 65 additions and 0 deletions
|
@ -50,6 +50,10 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
if (BUILD_WEBVIEW)
|
if (BUILD_WEBVIEW)
|
||||||
find_package(Qt6WebView ${QT_MIN_VERSION} REQUIRED)
|
find_package(Qt6WebView ${QT_MIN_VERSION} REQUIRED)
|
||||||
endif ()
|
endif ()
|
||||||
|
if (LINUX)
|
||||||
|
find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS DBus)
|
||||||
|
endif ()
|
||||||
|
|
||||||
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami I18n Config CoreAddons Archive)
|
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami I18n Config CoreAddons Archive)
|
||||||
find_package(KF6KirigamiAddons 1.2.1 REQUIRED)
|
find_package(KF6KirigamiAddons 1.2.1 REQUIRED)
|
||||||
find_package(QCoro6 REQUIRED COMPONENTS Core Network Qml)
|
find_package(QCoro6 REQUIRED COMPONENTS Core Network Qml)
|
||||||
|
|
|
@ -120,6 +120,11 @@ if (BUILD_SYNC)
|
||||||
target_link_libraries(astra_static PRIVATE QuotientQt6)
|
target_link_libraries(astra_static PRIVATE QuotientQt6)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (TARGET Qt6::DBus)
|
||||||
|
target_link_libraries(astra_static PRIVATE Qt6::DBus)
|
||||||
|
target_compile_definitions(astra_static PRIVATE -DHAS_DBUS)
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_executable(astra)
|
add_executable(astra)
|
||||||
|
|
||||||
target_sources(astra PRIVATE
|
target_sources(astra PRIVATE
|
||||||
|
|
|
@ -167,6 +167,12 @@ private:
|
||||||
/// Updates FFXIV.cfg with some recommended options like turning the opening cutscene movie off
|
/// Updates FFXIV.cfg with some recommended options like turning the opening cutscene movie off
|
||||||
void updateConfig(const Account *account);
|
void updateConfig(const Account *account);
|
||||||
|
|
||||||
|
/// Tell the system to keep the screen on and don't go to sleep
|
||||||
|
void inhibitSleep();
|
||||||
|
|
||||||
|
/// Tell the system we can allow the screen to turn off
|
||||||
|
void uninhibitSleep();
|
||||||
|
|
||||||
SteamAPI *m_steamApi = nullptr;
|
SteamAPI *m_steamApi = nullptr;
|
||||||
|
|
||||||
bool m_loadingFinished = false;
|
bool m_loadingFinished = false;
|
||||||
|
@ -188,4 +194,6 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int m_currentProfileIndex = 0;
|
int m_currentProfileIndex = 0;
|
||||||
|
|
||||||
|
unsigned int screenSaverDbusCookie = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
#include "syncmanager.h"
|
#include "syncmanager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_DBUS
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusReply>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
LauncherCore::LauncherCore()
|
LauncherCore::LauncherCore()
|
||||||
|
@ -78,6 +84,8 @@ void LauncherCore::login(Profile *profile, const QString &username, const QStrin
|
||||||
{
|
{
|
||||||
Q_ASSERT(profile != nullptr);
|
Q_ASSERT(profile != nullptr);
|
||||||
|
|
||||||
|
inhibitSleep();
|
||||||
|
|
||||||
const auto loginInformation = new LoginInformation(this);
|
const auto loginInformation = new LoginInformation(this);
|
||||||
loginInformation->profile = profile;
|
loginInformation->profile = profile;
|
||||||
|
|
||||||
|
@ -572,6 +580,10 @@ QCoro::Task<> LauncherCore::fetchNews()
|
||||||
|
|
||||||
QCoro::Task<> LauncherCore::handleGameExit(const Profile *profile)
|
QCoro::Task<> LauncherCore::handleGameExit(const Profile *profile)
|
||||||
{
|
{
|
||||||
|
qCDebug(ASTRA_LOG) << "Game has closed.";
|
||||||
|
|
||||||
|
uninhibitSleep();
|
||||||
|
|
||||||
#ifdef BUILD_SYNC
|
#ifdef BUILD_SYNC
|
||||||
// TODO: once we have Steam API support we can tell Steam to delay putting the Deck to sleep until our upload is complete
|
// TODO: once we have Steam API support we can tell Steam to delay putting the Deck to sleep until our upload is complete
|
||||||
if (m_settings->enableSync()) {
|
if (m_settings->enableSync()) {
|
||||||
|
@ -630,4 +642,40 @@ void LauncherCore::updateConfig(const Account *account)
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LauncherCore::inhibitSleep()
|
||||||
|
{
|
||||||
|
#ifdef HAS_DBUS
|
||||||
|
if (screenSaverDbusCookie != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.ScreenSaver"),
|
||||||
|
QStringLiteral("/ScreenSaver"),
|
||||||
|
QStringLiteral("org.freedesktop.ScreenSaver"),
|
||||||
|
QStringLiteral("Inhibit"));
|
||||||
|
message << QGuiApplication::desktopFileName();
|
||||||
|
message << i18n("Playing FFXIV");
|
||||||
|
|
||||||
|
const QDBusReply<uint> reply = QDBusConnection::sessionBus().call(message);
|
||||||
|
if (reply.isValid()) {
|
||||||
|
screenSaverDbusCookie = reply.value();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherCore::uninhibitSleep()
|
||||||
|
{
|
||||||
|
#ifdef HAS_DBUS
|
||||||
|
if (screenSaverDbusCookie == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.ScreenSaver"),
|
||||||
|
QStringLiteral("/ScreenSaver"),
|
||||||
|
QStringLiteral("org.freedesktop.ScreenSaver"),
|
||||||
|
QStringLiteral("UnInhibit"));
|
||||||
|
message << static_cast<uint>(screenSaverDbusCookie);
|
||||||
|
screenSaverDbusCookie = 0;
|
||||||
|
QDBusConnection::sessionBus().send(message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_launchercore.cpp"
|
#include "moc_launchercore.cpp"
|
Loading…
Add table
Reference in a new issue