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:
parent
b70ab79173
commit
3fe8f8a86a
1 changed files with 30 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue