Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume.h |
|
||||
| |
|
||||
| Suspend/resume common implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class SuspendResumeListenerBase
|
||||
{
|
||||
protected:
|
||||
virtual void OnSuspend() = 0;
|
||||
virtual void OnResume() = 0;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "SuspendResume_Windows.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "SuspendResume_MacOS.h"
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
#include "SuspendResume_Linux_FreeBSD.h"
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_Linux_FreeBSD.cpp |
|
||||
| |
|
||||
| Suspend/resume Linux/FreeBSD implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include "SuspendResume.h"
|
||||
|
||||
SuspendResumeLoginManager::SuspendResumeLoginManager(SuspendResumeListener *srl) : srl(srl), bus(QDBusConnection::systemBus())
|
||||
{
|
||||
bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(PrepareForSleep(bool)));
|
||||
}
|
||||
|
||||
SuspendResumeLoginManager::~SuspendResumeLoginManager()
|
||||
{
|
||||
bus.disconnect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(PrepareForSleep(bool)));
|
||||
}
|
||||
|
||||
void SuspendResumeLoginManager::PrepareForSleep(bool mode)
|
||||
{
|
||||
if(mode)
|
||||
{
|
||||
srl->OnSuspend();
|
||||
}
|
||||
else
|
||||
{
|
||||
srl->OnResume();
|
||||
}
|
||||
}
|
||||
|
||||
SuspendResumeListener::SuspendResumeListener() : login_manager(this)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_Linux_FreeBSD.h |
|
||||
| |
|
||||
| Suspend/resume Linux/FreeBSD implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QObject>
|
||||
#include "SuspendResume.h"
|
||||
|
||||
class SuspendResumeListener;
|
||||
|
||||
class SuspendResumeLoginManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SuspendResumeLoginManager(SuspendResumeListener *srl);
|
||||
~SuspendResumeLoginManager();
|
||||
|
||||
public slots:
|
||||
void PrepareForSleep(bool mode);
|
||||
|
||||
private:
|
||||
SuspendResumeListener *srl;
|
||||
QDBusConnection bus;
|
||||
};
|
||||
|
||||
class SuspendResumeListener : public SuspendResumeListenerBase
|
||||
{
|
||||
friend class SuspendResumeLoginManager;
|
||||
|
||||
protected:
|
||||
SuspendResumeListener();
|
||||
|
||||
private:
|
||||
SuspendResumeLoginManager login_manager;
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_MacOS.cpp |
|
||||
| |
|
||||
| Suspend/resume MacOS implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "SuspendResume.h"
|
||||
#include "IOKit/pwr_mgt/IOPMLib.h"
|
||||
#include "IOKit/IOMessage.h"
|
||||
|
||||
SuspendResumeListener::SuspendResumeListener()
|
||||
{
|
||||
root_port = IORegisterForSystemPower(this, &port_ref, &SuspendResumeListener::SystemPowerCallback, ¬ifier);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(port_ref), kCFRunLoopCommonModes);
|
||||
}
|
||||
|
||||
SuspendResumeListener::~SuspendResumeListener()
|
||||
{
|
||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(port_ref), kCFRunLoopCommonModes);
|
||||
IODeregisterForSystemPower(¬ifier);
|
||||
IOServiceClose(root_port);
|
||||
IONotificationPortDestroy(port_ref);
|
||||
}
|
||||
|
||||
void SuspendResumeListener::SystemPowerCallback(void *refcon, io_service_t service, uint32_t message_type, void *message_argument)
|
||||
{
|
||||
(void)service;
|
||||
SuspendResumeListener *spl = (SuspendResumeListener *)refcon;
|
||||
switch(message_type)
|
||||
{
|
||||
case kIOMessageSystemWillSleep:
|
||||
spl->OnSuspend();
|
||||
IOAllowPowerChange(spl->root_port, (intptr_t)message_argument);
|
||||
break;
|
||||
case kIOMessageSystemHasPoweredOn:
|
||||
spl->OnResume();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_MacOS.h |
|
||||
| |
|
||||
| Suspend/resume MacOS implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "SuspendResume.h"
|
||||
#include "IOKit/pwr_mgt/IOPMLib.h"
|
||||
#include "IOKit/IOMessage.h"
|
||||
|
||||
class SuspendResumeListener : public SuspendResumeListenerBase
|
||||
{
|
||||
protected:
|
||||
SuspendResumeListener();
|
||||
virtual ~SuspendResumeListener();
|
||||
|
||||
private:
|
||||
static void SystemPowerCallback(void *refcon, io_service_t service, uint32_t message_type, void *message_argument);
|
||||
|
||||
io_connect_t root_port;
|
||||
IONotificationPortRef port_ref;
|
||||
io_object_t notifier;
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_Windows.cpp |
|
||||
| |
|
||||
| Suspend/resume Windows implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QCoreApplication>
|
||||
#include "SuspendResume.h"
|
||||
#include "windows.h"
|
||||
|
||||
SuspendResumeListener::SuspendResumeListener()
|
||||
{
|
||||
QCoreApplication::instance()->installNativeEventFilter(this);
|
||||
}
|
||||
|
||||
SuspendResumeListener::~SuspendResumeListener()
|
||||
{
|
||||
QCoreApplication::instance()->removeNativeEventFilter(this);
|
||||
}
|
||||
|
||||
bool SuspendResumeListener::nativeEventFilter(const QByteArray &event_type, void *message, NEFResultType *result)
|
||||
{
|
||||
(void)result;
|
||||
if(event_type == "windows_generic_MSG")
|
||||
{
|
||||
switch(((MSG *)message)->message)
|
||||
{
|
||||
case WM_POWERBROADCAST:
|
||||
switch(((MSG *)message)->wParam)
|
||||
{
|
||||
case PBT_APMSUSPEND:
|
||||
OnSuspend();
|
||||
break;
|
||||
case PBT_APMRESUMEAUTOMATIC:
|
||||
OnResume();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SuspendResume_Windows.h |
|
||||
| |
|
||||
| Suspend/resume Windows implementation |
|
||||
| |
|
||||
| Zach Deibert (zachdeibert) 12 Nov 2024 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QByteArray>
|
||||
#include "SuspendResume.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#define NEFResultType long
|
||||
#else
|
||||
#define NEFResultType qintptr
|
||||
#endif
|
||||
|
||||
class SuspendResumeListener : public SuspendResumeListenerBase, private QAbstractNativeEventFilter
|
||||
{
|
||||
protected:
|
||||
SuspendResumeListener();
|
||||
virtual ~SuspendResumeListener();
|
||||
|
||||
private:
|
||||
bool nativeEventFilter(const QByteArray &event_type, void *message, NEFResultType *result);
|
||||
};
|
||||
Reference in New Issue
Block a user