1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

Windows: Register for suspend/resume notifications

This commit is contained in:
reuk 2022-12-08 16:03:23 +00:00
parent b70ab79173
commit 3fe8f8a86a
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -498,6 +498,31 @@ static double getGlobalDPI()
return (GetDeviceCaps (deviceContext.dc, LOGPIXELSX) + GetDeviceCaps (deviceContext.dc, LOGPIXELSY)) / 2.0;
}
//==============================================================================
class ScopedSuspendResumeNotificationRegistration
{
public:
ScopedSuspendResumeNotificationRegistration() = default;
explicit ScopedSuspendResumeNotificationRegistration (HWND window)
: handle (SystemStats::getOperatingSystemType() >= SystemStats::Windows8_0
? RegisterSuspendResumeNotification (window, DEVICE_NOTIFY_WINDOW_HANDLE)
: nullptr)
{}
private:
struct Destructor
{
void operator() (HPOWERNOTIFY ptr) const
{
if (ptr != nullptr)
UnregisterSuspendResumeNotification (ptr);
}
};
std::unique_ptr<std::remove_pointer_t<HPOWERNOTIFY>, Destructor> handle;
};
//==============================================================================
class ScopedThreadDPIAwarenessSetter::NativeImpl
{
@ -1659,10 +1684,14 @@ public:
if (updateCurrentMonitor())
VBlankDispatcher::getInstance()->updateDisplay (*this, currentMonitor);
suspendResumeRegistration = ScopedSuspendResumeNotificationRegistration { hwnd };
}
~HWNDComponentPeer() override
{
suspendResumeRegistration = {};
VBlankDispatcher::getInstance()->removeListener (*this);
// do this first to avoid messages arriving for this window before it's destroyed
@ -4595,6 +4624,7 @@ private:
bool shouldIgnoreModalDismiss = false;
RectangleList<int> deferredRepaints;
ScopedSuspendResumeNotificationRegistration suspendResumeRegistration;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HWNDComponentPeer)