Skip to content

Commit

Permalink
MythScreenSaverDRM: Disable
Browse files Browse the repository at this point in the history
- this needs a re-write for up and coming atomic DRM operations and was
effectively useless anyway.
  • Loading branch information
mark-kendall committed Jan 12, 2021
1 parent 8e1b469 commit 0500fd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 141 deletions.
127 changes: 8 additions & 119 deletions mythtv/libs/libmythui/platforms/mythscreensaverdrm.cpp
@@ -1,6 +1,3 @@
// Qt
#include <QTimerEvent>

// MythTV
#include "mythlogging.h"
#include "platforms/mythscreensaverdrm.h"
Expand All @@ -9,8 +6,8 @@

MythScreenSaverDRM* MythScreenSaverDRM::Create(QObject *Parent, MythDisplay* mDisplay)
{
auto* result = new MythScreenSaverDRM(Parent, mDisplay);
if (result->IsValid())
auto * result = new MythScreenSaverDRM(Parent, mDisplay);
if (result->m_valid)
return result;
result->setParent(nullptr);
delete result;
Expand All @@ -22,138 +19,30 @@ MythScreenSaverDRM* MythScreenSaverDRM::Create(QObject *Parent, MythDisplay* mDi
* This is the screensaver 'of last resort' on most linux systems. It is only
* used when no others are available (no X, no Wayland etc).
*
* As such, it is assumed that there are no other daemons/processes monitoring
* power saving and/or screensavers.
*
* Hence this class actually implements its own power management (when authenticated) - *but* see below
*
* \todo Other screensavers assume system daemons are hooked into input events
* and reset when user activity is detected. Hence they only reset for 'external' inputs
* (e.g. network control, services API, cec, lirc etc). When authentication is available
* this class will also need to reset on each keypress, mouse action etc (probably just
* connect to a new signal from MythMainWindow).
*
* \note This class is of limited use. We do not yet have authenticated
* acccess to the drm device - which means we cannot update the DPMS state.
* Without authentication it will simply poll the DPMS state every 5 seconds and will
* block *external* input devices when the screen is not in the 'On' state (N.B.
* Asleep is only called from MythInputDeviceHandler which will block input from
* Joystick, lirc and appleremote devices ONLY).
* \note This class has been temporarily disabled whilst the DRM code is refactored
* for atomic operations.
*/
MythScreenSaverDRM::MythScreenSaverDRM(QObject* Parent, MythDisplay *mDisplay)
: MythScreenSaver(Parent)
{
auto* drmdisplay = dynamic_cast<MythDisplayDRM*>(mDisplay);
if (drmdisplay)
{
m_display = drmdisplay;
m_valid = true;
Init();
connect(m_display, &MythDisplayDRM::screenChanged, this, &MythScreenSaverDRM::ScreenChanged);
}
}

MythScreenSaverDRM::~MythScreenSaverDRM()
{
m_device = nullptr;
}

void MythScreenSaverDRM::Init()
{
m_device = m_display->GetDevice();
m_authenticated = m_device->Authenticated();
killTimer(m_dpmsTimer);
killTimer(m_inactiveTimer);
UpdateDPMS();
if (!m_authenticated)
{
LOG(VB_GENERAL, LOG_WARNING, LOC + "Not authenticated - cannot control DPMS");
m_dpmsTimer = startTimer(DRM_DPMS_POLL * 1000);
}
else
{
m_inactiveTimer = startTimer(m_timeout * 1000);
LOG(VB_GENERAL, LOG_WARNING, LOC + "Authenticated");
}

LOG(VB_GENERAL, LOG_INFO, LOC + QString("DPMS is %1").arg(m_asleep ? "disabled" : "enabled"));
}

void MythScreenSaverDRM::ScreenChanged()
: MythScreenSaver(Parent),
m_display(dynamic_cast<MythDisplayDRM*>(mDisplay))
{
Init();
}

bool MythScreenSaverDRM::IsValid() const
{
return m_valid;
}

void MythScreenSaverDRM::timerEvent(QTimerEvent* Event)
{
if (Event->timerId() == m_dpmsTimer)
UpdateDPMS();
else if (Event->timerId() == m_inactiveTimer)
TurnScreenOnOff(false /*turn off*/);
}

void MythScreenSaverDRM::TurnScreenOnOff(bool On)
{
if (m_asleep != On)
{
m_device->SetEnumProperty(DRM_DPMS, On ? m_dpmsOn : m_dpmsStandby);
UpdateDPMS();
}
}

void MythScreenSaverDRM::UpdateDPMS()
{
if (!m_device)
return;

m_asleep = true;
auto dpms = m_device->GetEnumProperty(DRM_DPMS);
for (const auto & value : qAsConst(dpms.m_enums))
{
if ((value.first == dpms.m_value) && (value.second == DRM_ON))
{
m_dpmsOn = value.first;
m_asleep = false;
}

if (value.second == DRM_STANDBY)
m_dpmsStandby = value.first;
}
m_valid = m_display != nullptr;
}

void MythScreenSaverDRM::Disable()
{
if (!m_authenticated)
return;

killTimer(m_inactiveTimer);
TurnScreenOnOff(true /*on*/);
}

void MythScreenSaverDRM::Restore()
{
if (!m_authenticated)
return;

Disable();
m_inactiveTimer = startTimer(m_timeout);
}

void MythScreenSaverDRM::Reset()
{
if (!m_authenticated)
return;

killTimer(m_inactiveTimer);
m_inactiveTimer = startTimer(m_timeout);
}

bool MythScreenSaverDRM::Asleep()
{
return m_asleep;
return false;
}
23 changes: 1 addition & 22 deletions mythtv/libs/libmythui/platforms/mythscreensaverdrm.h
Expand Up @@ -5,46 +5,25 @@
#include "platforms/mythdisplaydrm.h"
#include "mythscreensaver.h"

// 300 second default timeout
#define DRM_TIMEOUT 5
#define DRM_DPMS QString("DPMS")
#define DRM_ON QString("On")
#define DRM_STANDBY QString("Standby")
#define DRM_DPMS_POLL 5 // poll every 5 seconds

class MythScreenSaverDRM : public MythScreenSaver
{
Q_OBJECT

public:
static MythScreenSaverDRM* Create(QObject* Parent, MythDisplay* mDisplay);
~MythScreenSaverDRM() override;

bool IsValid() const;

public slots:
void Disable() override;
void Restore() override;
void Reset() override;
bool Asleep() override;
void ScreenChanged();
void timerEvent(QTimerEvent* Event) override;

private:
explicit MythScreenSaverDRM(QObject* Parent, MythDisplay* mDisplay);
void Init();
void UpdateDPMS();
void TurnScreenOnOff(bool On);
bool m_valid { false };
MythDisplayDRM* m_display { nullptr };
MythDRMPtr m_device { nullptr };
bool m_authenticated { false };
bool m_asleep { false };
int m_dpmsTimer { 0 };
int m_inactiveTimer { 0 };
int m_timeout { DRM_TIMEOUT };
uint64_t m_dpmsOn { 0 };
uint64_t m_dpmsStandby { 1 };

};

#endif

0 comments on commit 0500fd0

Please sign in to comment.