Add support for loading profiles on suspend/resume
This commit is contained in:
parent
7d96b27f28
commit
bd3cc94212
17 changed files with 612 additions and 91 deletions
31
SuspendResume/SuspendResume.h
Normal file
31
SuspendResume/SuspendResume.h
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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
|
||||
39
SuspendResume/SuspendResume_Linux_FreeBSD.cpp
Normal file
39
SuspendResume/SuspendResume_Linux_FreeBSD.cpp
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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()));
|
||||
}
|
||||
|
||||
SuspendResumeLoginManager::~SuspendResumeLoginManager()
|
||||
{
|
||||
bus.disconnect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(PrepareForSleep()));
|
||||
}
|
||||
|
||||
void SuspendResumeLoginManager::PrepareForSleep(bool mode)
|
||||
{
|
||||
if(mode)
|
||||
{
|
||||
srl->OnSuspend();
|
||||
}
|
||||
else
|
||||
{
|
||||
srl->OnResume();
|
||||
}
|
||||
}
|
||||
|
||||
SuspendResumeListener::SuspendResumeListener() : login_manager(this)
|
||||
{
|
||||
}
|
||||
45
SuspendResume/SuspendResume_Linux_FreeBSD.h
Normal file
45
SuspendResume/SuspendResume_Linux_FreeBSD.h
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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;
|
||||
};
|
||||
45
SuspendResume/SuspendResume_MacOS.cpp
Normal file
45
SuspendResume/SuspendResume_MacOS.cpp
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
31
SuspendResume/SuspendResume_MacOS.h
Normal file
31
SuspendResume/SuspendResume_MacOS.h
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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;
|
||||
};
|
||||
48
SuspendResume/SuspendResume_Windows.cpp
Normal file
48
SuspendResume/SuspendResume_Windows.cpp
Normal file
|
|
@ -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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#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, long *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;
|
||||
}
|
||||
26
SuspendResume/SuspendResume_Windows.h
Normal file
26
SuspendResume/SuspendResume_Windows.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| 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-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QByteArray>
|
||||
#include "SuspendResume.h"
|
||||
|
||||
class SuspendResumeListener : public SuspendResumeListenerBase, private QAbstractNativeEventFilter
|
||||
{
|
||||
protected:
|
||||
SuspendResumeListener();
|
||||
virtual ~SuspendResumeListener();
|
||||
|
||||
private:
|
||||
bool nativeEventFilter(const QByteArray &event_type, void *message, long *result);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue