Skip to content

Commit

Permalink
Enhanced HyperHDR behavior when the system is locked or the monitor i…
Browse files Browse the repository at this point in the history
…s turned off (#756)

* Do not turn off LEDs on lock when the background effect is enabled

* Monitor on/off event listener (Win)

* merge master branch
  • Loading branch information
awawa-dev authored Feb 5, 2024
1 parent 35d77c5 commit 58920df
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
- JOB_RUNNER: macos-14
JOB_NAME: macOS 14 (arm64/M1/M2)
QT_VERSION: 6
NICE_NAME: arm64_M1
NICE_NAME: arm64_M1_M2
- JOB_RUNNER: macos-13
JOB_NAME: macOS 13 (x64)
QT_VERSION: 5
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
if: (startsWith(github.event.ref, 'refs/tags') != true) && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: Apple_macOS_@${{ matrix.NICE_NAME }}_DMG_installer
name: Apple_macOS_${{ matrix.NICE_NAME }}_DMG_installer
path: build/Hyper*.dmg

######################
Expand Down Expand Up @@ -257,7 +257,7 @@ jobs:
if: startsWith(github.event.ref, 'refs/tags') && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: release-artifact-${{ matrix.runs-on }}
name: release-artifact-windows
path: build/Hyper*

# Upload artifacts from commit
Expand Down
2 changes: 2 additions & 0 deletions include/base/ComponentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ComponentController : public QObject

public slots:
void setNewComponentState(hyperhdr::Components comp, bool activated);
void turnGrabbers(bool activated);

private slots:
void handleCompStateChangeRequest(hyperhdr::Components comps, bool activated);
Expand All @@ -35,5 +36,6 @@ private slots:
Logger* _log;
std::map<hyperhdr::Components, bool> _componentStates;
std::map<hyperhdr::Components, bool> _prevComponentStates;
std::map<hyperhdr::Components, bool> _prevGrabbers;
bool _disableOnStartup;
};
2 changes: 2 additions & 0 deletions include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class HyperHdrInstance : public QObject
public slots:
bool clear(int priority, bool forceClearAll = false);
QJsonObject getAverageColor();
bool hasPriority(int priority);
hyperhdr::Components getComponentForPriority(int priority);
hyperhdr::Components getCurrentPriorityActiveComponent();
int getCurrentPriority() const;
Expand Down Expand Up @@ -96,6 +97,7 @@ public slots:
bool setVisiblePriority(int priority);
bool sourceAutoSelectEnabled() const;
void start();
void turnGrabbers(bool active);
void update();
void updateAdjustments(const QJsonObject& config);
void updateResult(std::vector<ColorRgb> _ledBuffer);
Expand Down
4 changes: 3 additions & 1 deletion include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public slots:

void toggleStateAllInstances(bool pause = false);

void hibernate(bool wakeUp);
void toggleGrabbersAllInstances(bool pause = false);

void hibernate(bool wakeUp, hyperhdr::SystemComponent source);

bool createInstance(const QString& name, bool start = false);

Expand Down
2 changes: 2 additions & 0 deletions include/utils/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ namespace hyperhdr
if (cmp == "PROTOSERVER") return COMP_PROTOSERVER;
return COMP_INVALID;
}

enum SystemComponent { SUSPEND, LOCKER, MONITOR };
}
23 changes: 23 additions & 0 deletions sources/base/ComponentController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,26 @@ void ComponentController::setNewComponentState(hyperhdr::Components comp, bool a
emit SignalComponentStateChanged(comp, activated);
}
}

void ComponentController::turnGrabbers(bool activated)
{
if (_prevGrabbers.empty() && !activated)
{
_prevGrabbers.emplace(COMP_SYSTEMGRABBER, isComponentEnabled(COMP_SYSTEMGRABBER));
_prevGrabbers.emplace(COMP_VIDEOGRABBER, isComponentEnabled(COMP_VIDEOGRABBER));
for (const auto& comp : _prevGrabbers)
if (comp.second)
{
emit SignalRequestComponent(comp.first, false);
}
}
else if (!_prevGrabbers.empty() && activated)
{
for (const auto& comp : _prevGrabbers)
if (comp.second)
{
emit SignalRequestComponent(comp.first, true);
}
_prevGrabbers.clear();
}
}
11 changes: 11 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ int HyperHdrInstance::getCurrentPriority() const
return _muxer->getCurrentPriority();
}

bool HyperHdrInstance::hasPriority(int priority)
{
return _muxer->hasPriority(priority);
}

hyperhdr::Components HyperHdrInstance::getComponentForPriority(int priority)
{
return _muxer->getInputInfo(priority).componentId;
Expand Down Expand Up @@ -1032,3 +1037,9 @@ bool HyperHdrInstance::getScanParameters(size_t led, double& hscanBegin, double&
{
return _imageProcessor->getScanParameters(led, hscanBegin, hscanEnd, vscanBegin, vscanEnd);
}


void HyperHdrInstance::turnGrabbers(bool active)
{
_componentController->turnGrabbers(active);
}
36 changes: 35 additions & 1 deletion sources/base/HyperHdrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <db/InstanceTable.h>
#include <base/GrabberWrapper.h>
#include <base/AccessManager.h>
#include <base/Muxer.h>
#include <utils/GlobalSignals.h>

QString HyperHdrManager::getRootPath()
Expand Down Expand Up @@ -165,8 +166,41 @@ void HyperHdrManager::toggleStateAllInstances(bool pause)
}
}

void HyperHdrManager::hibernate(bool wakeUp)
void HyperHdrManager::toggleGrabbersAllInstances(bool pause)
{
for (const auto& instance : _runningInstances)
{
QUEUE_CALL_1(instance.get(), turnGrabbers, bool, pause);
}
}

void HyperHdrManager::hibernate(bool wakeUp, hyperhdr::SystemComponent source)
{
if (source == hyperhdr::SystemComponent::LOCKER || source == hyperhdr::SystemComponent::MONITOR)
{
Debug(_log, "OS event: %s", (source == hyperhdr::SystemComponent::LOCKER) ? ((wakeUp) ? "OS unlocked" : "OS locked") : ((wakeUp) ? "Monitor On" : "Monitor Off"));
bool _hasEffect = false;
for (const auto& instance : _runningInstances)
{
SAFE_CALL_1_RET(instance.get(), hasPriority, bool, _hasEffect, int, Muxer::LOWEST_EFFECT_PRIORITY);
if (_hasEffect)
{
break;
}
}

if (!wakeUp && _hasEffect)
{
Warning(_log, "The user has set a background effect, and therefore we will not turn off the LEDs when locking the operating system");
}

if (_hasEffect)
{
toggleGrabbersAllInstances(wakeUp);
return;
}
}

if (!wakeUp)
{
Warning(_log, "The system is going to sleep");
Expand Down
8 changes: 4 additions & 4 deletions sources/blackborder/BlackBorderDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ BlackBorder BlackBorderDetector::process(const Image<ColorRgb>& image) const
}

// Construct result
BlackBorder detectedBorder;
BlackBorder detectedBorder{};

detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
Expand Down Expand Up @@ -143,7 +143,7 @@ BlackBorder BlackBorderDetector::process_classic(const Image<ColorRgb>& image) c
}

// Construct result
BlackBorder detectedBorder;
BlackBorder detectedBorder{};

detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
Expand Down Expand Up @@ -202,7 +202,7 @@ BlackBorder BlackBorderDetector::process_osd(const Image<ColorRgb>& image) const
}

// Construct result
BlackBorder detectedBorder;
BlackBorder detectedBorder{};
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
Expand Down Expand Up @@ -244,7 +244,7 @@ BlackBorder BlackBorderDetector::process_letterbox(const Image<ColorRgb>& image)
}

// Construct result
BlackBorder detectedBorder;
BlackBorder detectedBorder{};

detectedBorder.unknown = firstNonBlackYPixelIndex == -1;
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
Expand Down
4 changes: 2 additions & 2 deletions sources/hyperhdr/SuspendHandlerLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ void SuspendHandler::sleeping(bool sleep)
if (sleep)
{
std::cout << "OS event: going sleep" << std::endl;
emit SignalHibernate(false);
emit SignalHibernate(false, hyperhdr::SystemComponent::SUSPEND);
}
else
{
std::cout << "OS event: wake up" << std::endl;
emit SignalHibernate(true);
emit SignalHibernate(true, hyperhdr::SystemComponent::SUSPEND);
}
}

5 changes: 3 additions & 2 deletions sources/hyperhdr/SuspendHandlerLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <QObject>
#include <QObject>
#include <utils/Components.h>

#define HAVE_POWER_MANAGEMENT

class SuspendHandler : public QObject {
Q_OBJECT

signals:
void SignalHibernate(bool wakeUp);
void SignalHibernate(bool wakeUp, hyperhdr::SystemComponent source);

public:
SuspendHandler(bool sessionLocker = false);
Expand Down
5 changes: 3 additions & 2 deletions sources/hyperhdr/SuspendHandlerMacOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <QObject>
#include <QObject>
#include <utils/Components.h>

#define HAVE_POWER_MANAGEMENT

class SuspendHandler : public QObject {
Q_OBJECT

signals:
void SignalHibernate(bool wakeUp);
void SignalHibernate(bool wakeUp, hyperhdr::SystemComponent source);

public:
SuspendHandler(bool sessionLocker = false);
Expand Down
4 changes: 2 additions & 2 deletions sources/hyperhdr/SuspendHandlerMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ - (id)init
- (void)goingSleep: (NSNotification*)note
{
if (_suspendHandler != nullptr)
emit _suspendHandler->SignalHibernate(false);
emit _suspendHandler->SignalHibernate(false, hyperhdr::SystemComponent::SUSPEND);
}


- (void)goingWake: (NSNotification*)note
{
if (_suspendHandler != nullptr)
emit _suspendHandler->SignalHibernate(true);
emit _suspendHandler->SignalHibernate(true, hyperhdr::SystemComponent::SUSPEND);
}

@end
Expand Down
44 changes: 35 additions & 9 deletions sources/hyperhdr/SuspendHandlerWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@

#pragma comment (lib, "WtsApi32.Lib")

SuspendHandler::SuspendHandler(bool sessionLocker)
SuspendHandler::SuspendHandler(bool sessionLocker):
_notifyHandle(NULL),
_notifyMonitorHandle(NULL),
_sessionLocker(sessionLocker)
{
auto handle = reinterpret_cast<HWND> (_widget.winId());
_notifyHandle = RegisterSuspendResumeNotification(handle, DEVICE_NOTIFY_WINDOW_HANDLE);
Expand All @@ -50,15 +53,19 @@ SuspendHandler::SuspendHandler(bool sessionLocker)
std::cout << "COULD NOT REGISTER SLEEP HANDLER!" << std::endl;
else
std::cout << "Sleep handler registered!" << std::endl;

_sessionLocker = sessionLocker;

if (_sessionLocker)
{
if (WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION))
_notifyMonitorHandle = RegisterPowerSettingNotification(handle, &GUID_SESSION_DISPLAY_STATUS, DEVICE_NOTIFY_WINDOW_HANDLE);

if (_notifyMonitorHandle != NULL && WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION))
std::cout << "Session handler registered!" << std::endl;
else
{
std::cout << "COULD NOT REGISTER SESSION HANDLER!" << std::endl;
std::cout << "COULD NOT REGISTER SESSION HANDLER!" << std::endl;
if (_notifyMonitorHandle != NULL)
UnregisterSuspendResumeNotification(_notifyMonitorHandle);
_notifyMonitorHandle = NULL;
_sessionLocker = false;
}
}
Expand All @@ -75,6 +82,13 @@ SuspendHandler::~SuspendHandler()

if (_sessionLocker)
{
if (_notifyMonitorHandle != NULL)
{
UnregisterSuspendResumeNotification(_notifyMonitorHandle);
std::cout << "Monitor state handler deregistered!" << std::endl;
}
_notifyMonitorHandle = NULL;

auto handle = reinterpret_cast<HWND> (_widget.winId());
WTSUnRegisterSessionNotification(handle);
}
Expand All @@ -93,14 +107,26 @@ bool SuspendHandler::nativeEventFilter(const QByteArray& eventType, void* messag
switch (msg->wParam)
{
case PBT_APMRESUMESUSPEND:
emit SignalHibernate(true);
emit SignalHibernate(true, hyperhdr::SystemComponent::SUSPEND);
return true;
break;
case PBT_APMSUSPEND:
emit SignalHibernate(false);
emit SignalHibernate(false, hyperhdr::SystemComponent::SUSPEND);
return true;
break;
}

if (_sessionLocker && msg->wParam == PBT_POWERSETTINGCHANGE && msg->lParam != 0)
{
POWERBROADCAST_SETTING* s = reinterpret_cast<POWERBROADCAST_SETTING*>(msg->lParam);
if (s != nullptr && s->PowerSetting == GUID_SESSION_DISPLAY_STATUS && s->DataLength > 0)
{
if (s->Data[0] == 1)
emit SignalHibernate(true, hyperhdr::SystemComponent::MONITOR);
else if (s->Data[0] == 0)
emit SignalHibernate(false, hyperhdr::SystemComponent::MONITOR);
}
}
}

if (_sessionLocker)
Expand All @@ -110,7 +136,7 @@ bool SuspendHandler::nativeEventFilter(const QByteArray& eventType, void* messag
switch (msg->wParam)
{
case WTS_SESSION_UNLOCK:
emit SignalHibernate(true);
emit SignalHibernate(true, hyperhdr::SystemComponent::LOCKER);
return true;
break;

Expand All @@ -122,7 +148,7 @@ bool SuspendHandler::nativeEventFilter(const QByteArray& eventType, void* messag
}
else
{
emit SignalHibernate(false);
emit SignalHibernate(false, hyperhdr::SystemComponent::LOCKER);
return true;
}
break;
Expand Down
Loading

0 comments on commit 58920df

Please sign in to comment.