Revert "Remove non-dbus X11 power management"

This reverts commit 7b067a751b.
This commit is contained in:
Andrew Rabert committed 2025-11-30 22:11:53 -05:00
1 parent 7b067a751b
commit 107ab1affc
6 files changed
+103 -3

No files matched your search

+2 -1
View File
@@ -12,13 +12,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE)
option(CHECK_FOR_UPDATES "Enable checking for new versions of Jellyfin Media Player" ON)
option(OPENELEC "Make an OpenELEC build" OFF)
option(LINUX_X11POWER "Enable non D-Bus screensaver management" OFF)
option(USE_STATIC_MPVQT "Build MpvQt from bundled submodule instead of using system library" ON)
if (NOT CHECK_FOR_UPDATES)
add_definitions(-DDISABLE_UPDATE_CHECK)
endif()
if(UNIX AND (NOT APPLE))
if((NOT LINUX_X11POWER) AND (UNIX AND (NOT APPLE)))
set(LINUX_DBUS ON)
endif()
+7 -2
View File
@@ -10,8 +10,13 @@ else()
set(X11_Xrandr_LIB "")
endif()
add_definitions(-DLINUX_DBUS=1)
Message(STATUS "Enabling D-Bus power management")
if(LINUX_X11POWER)
add_definitions(-DUSE_X11POWER)
Message(STATUS "Enabling X11/XDG screensaver management")
else()
add_definitions(-DLINUX_DBUS=1)
Message(STATUS "Enabling D-Bus power management")
endif()
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR})
set(INSTALL_RESOURCE_DIR ${CMAKE_INSTALL_DATADIR}/jellyfinmediaplayer)
+4
View File
@@ -4,6 +4,10 @@ if(APPLE)
add_sources(PowerComponentMac.cpp PowerComponentMac.h)
endif(APPLE)
if(LINUX_X11POWER)
add_sources(PowerComponentX11.cpp PowerComponentX11.h)
endif(LINUX_X11POWER)
if(LINUX_DBUS)
add_sources(PowerComponentDBus.cpp PowerComponentDBus.h)
endif(LINUX_DBUS)
+5
View File
@@ -10,6 +10,8 @@
#include "PowerComponentMac.h"
#elif defined(LINUX_DBUS)
#include "PowerComponentDBus.h"
#elif defined(USE_X11POWER)
#include "PowerComponentX11.h"
#elif defined(Q_OS_WIN32)
#include "PowerComponentWin.h"
#endif
@@ -23,6 +25,9 @@ PowerComponent& PowerComponent::Get()
#elif defined(LINUX_DBUS)
static PowerComponentDBus instance;
return instance;
#elif defined(USE_X11POWER)
static PowerComponentX11 instance;
return instance;
#elif defined(Q_OS_WIN32)
static PowerComponentWin instance;
return instance;
+54
View File
@@ -0,0 +1,54 @@
#include <stdlib.h>
#include "PowerComponentX11.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
PowerComponentX11::PowerComponentX11() : PowerComponent(0)
{
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &PowerComponentX11::onTimer);
m_timer->setInterval(15 * 1000);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void PowerComponentX11::onTimer()
{
if (!m_process && !m_broken)
{
m_process = new QProcess(this);
m_process->setProcessChannelMode(QProcess::ForwardedChannels);
connect(m_process, (void (QProcess::*)(int,QProcess::ExitStatus))&QProcess::finished,
this, &PowerComponentX11::onProcessFinished);
connect(m_process, (void (QProcess::*)(QProcess::ProcessError))&QProcess::errorOccurred,
this, &PowerComponentX11::onProcessError);
m_process->start("xdg-screensaver", {"reset"});
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void PowerComponentX11::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (m_process)
m_process->deleteLater();
m_process = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void PowerComponentX11::onProcessError(QProcess::ProcessError error)
{
qCritical() << "Disabling screensaver is not working. Make sure xdg-screensaver is installed.";
m_broken = true;
onProcessFinished(-1, QProcess::CrashExit);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void PowerComponentX11::doDisableScreensaver()
{
m_timer->start();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void PowerComponentX11::doEnableScreensaver()
{
m_timer->stop();
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef POWERCOMPONENTX11_H
#define POWERCOMPONENTX11_H
#include <QTimer>
#include <QProcess>
#include "PowerComponent.h"
class PowerComponentX11 : public PowerComponent
{
Q_OBJECT
public:
PowerComponentX11();
protected:
virtual void doDisableScreensaver();
virtual void doEnableScreensaver();
private slots:
void onTimer();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void onProcessError(QProcess::ProcessError error);
private:
bool m_broken = false;
QTimer* m_timer = 0;
QProcess* m_process = 0;
};
#endif // POWERCOMPONENTX11_H