diff --git a/build/linux/platform_specific_code/juce_linux_Windowing.cpp b/build/linux/platform_specific_code/juce_linux_Windowing.cpp index b99c786142..061c7f5840 100644 --- a/build/linux/platform_specific_code/juce_linux_Windowing.cpp +++ b/build/linux/platform_specific_code/juce_linux_Windowing.cpp @@ -2562,6 +2562,18 @@ void Desktop::setMousePosition (int x, int y) throw() XWarpPointer (display, None, root, 0, 0, 0, 0, x, y); } + +//============================================================================== +void Desktop::setScreenSaverEnabled (const bool isEnabled) throw() +{ + jassertfalse // anyone know how to do this?? +} + +bool Desktop::isScreenSaverEnabled() throw() +{ + return true; +} + //============================================================================== void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { diff --git a/build/macosx/platform_specific_code/juce_mac_Windowing.cpp b/build/macosx/platform_specific_code/juce_mac_Windowing.cpp index 8bed02bccb..f0403607a0 100644 --- a/build/macosx/platform_specific_code/juce_mac_Windowing.cpp +++ b/build/macosx/platform_specific_code/juce_mac_Windowing.cpp @@ -2257,6 +2257,40 @@ const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw() return ModifierKeys (currentModifiers); } +//============================================================================== +class ScreenSaverDefeater : public Timer, + public DeletedAtShutdown +{ +public: + ScreenSaverDefeater() throw() + { + startTimer (10000); + timerCallback(); + } + + ~ScreenSaverDefeater() + { + } + + void timerCallback() + { + UpdateSystemActivity (UsrActivity); + } +}; + +static ScreenSaverDefeater* screenSaverDefeater = 0; + +void Desktop::setScreenSaverEnabled (const bool isEnabled) throw() +{ + if (screenSaverDefeater == 0) + screenSaverDefeater = new ScreenSaverDefeater(); +} + +bool Desktop::isScreenSaverEnabled() throw() +{ + return screenSaverDefeater == 0; +} + //============================================================================== void juce_updateMultiMonitorInfo (Array & monitorCoords, const bool clipToWorkArea) throw() { diff --git a/build/win32/platform_specific_code/juce_win32_Windowing.cpp b/build/win32/platform_specific_code/juce_win32_Windowing.cpp index a7a7803e5d..b5969a3e7d 100644 --- a/build/win32/platform_specific_code/juce_win32_Windowing.cpp +++ b/build/win32/platform_specific_code/juce_win32_Windowing.cpp @@ -110,6 +110,7 @@ const int juce_windowIsSemiTransparentFlag = (1 << 31); // also in component.cpp static HPALETTE palette = 0; static bool createPaletteIfNeeded = true; static bool shouldDeactivateTitleBar = true; +static bool screenSaverAllowed = true; static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw(); #define WM_TRAYNOTIFY WM_USER + 100 @@ -2123,45 +2124,45 @@ private: break; case WM_SYSCOMMAND: - if (hasTitleBar()) + switch (wParam & 0xfff0) { - switch (wParam & 0xfff0) + case SC_CLOSE: + if (hasTitleBar()) { - case SC_CLOSE: PostMessage (h, WM_CLOSE, 0, 0); return 0; + } + break; - case SC_KEYMENU: - if (h == GetCapture()) - ReleaseCapture(); - break; + case SC_KEYMENU: + if (hasTitleBar() && h == GetCapture()) + ReleaseCapture(); - case SC_MAXIMIZE: - setFullScreen (true); + break; + + case SC_MAXIMIZE: + setFullScreen (true); + return 0; + + case SC_MINIMIZE: + if (! hasTitleBar()) + { + setMinimised (true); return 0; + } + break; - case SC_RESTORE: + case SC_RESTORE: + if (hasTitleBar()) + { if (isFullScreen()) { setFullScreen (false); return 0; } - break; } - } - else - { - switch (wParam & 0xfff0) + else { - case SC_MINIMIZE: - setMinimised(true); - return 0; - - case SC_MAXIMIZE: - setFullScreen(true); - return 0; - - case SC_RESTORE: if (isMinimised()) setMinimised (false); else if (isFullScreen()) @@ -2169,6 +2170,15 @@ private: return 0; } + + break; + + case SC_MONITORPOWER: + case SC_SCREENSAVE: + if (! screenSaverAllowed) + return 0; + + break; } break; @@ -2232,7 +2242,7 @@ void SystemTrayIconComponent::setIconTooltip (const String& tooltip) } //============================================================================== -void juce_setWindowStyleBit (HWND h, int styleType, int feature, bool bitIsSet) +void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw() { DWORD val = GetWindowLong (h, styleType); @@ -2276,6 +2286,17 @@ void Desktop::setMousePosition (int x, int y) throw() SetCursorPos (x, y); } +//============================================================================== +void Desktop::setScreenSaverEnabled (const bool isEnabled) throw() +{ + screenSaverAllowed = isEnabled; +} + +bool Desktop::isScreenSaverEnabled() throw() +{ + return screenSaverAllowed; +} + //============================================================================== static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo) { @@ -3180,21 +3201,21 @@ public: ULONG __stdcall AddRef() { return ++refCount; } ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; } - HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; } - HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; } + HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; } + HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; } + HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; } HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; } - HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; } + HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; } HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; } - HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; } - HRESULT __stdcall Revert() { return E_NOTIMPL; } - HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; } - HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; } - HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; } + HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; } + HRESULT __stdcall Revert() { return E_NOTIMPL; } + HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; } + HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; } + HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; } HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; } - HRESULT __stdcall SetClass (REFCLSID) { return S_OK; } - HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; } - HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; } + HRESULT __stdcall SetClass (REFCLSID) { return S_OK; } + HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; } + HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; } juce_UseDebuggingNewOperator }; @@ -3355,12 +3376,12 @@ public: ULONG __stdcall AddRef() { return ++refCount; } ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall SaveObject() { return E_NOTIMPL; } - HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; } + HRESULT __stdcall SaveObject() { return E_NOTIMPL; } + HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; } HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; } - HRESULT __stdcall ShowObject() { return S_OK; } - HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; } - HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; } + HRESULT __stdcall ShowObject() { return S_OK; } + HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; } + HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; } juce_UseDebuggingNewOperator }; diff --git a/src/juce_appframework/gui/components/juce_Desktop.h b/src/juce_appframework/gui/components/juce_Desktop.h index e897088c90..2fd106f97a 100644 --- a/src/juce_appframework/gui/components/juce_Desktop.h +++ b/src/juce_appframework/gui/components/juce_Desktop.h @@ -124,6 +124,28 @@ public: */ static int getMouseButtonClickCounter() throw(); + //============================================================================== + /** This lets you prevent the screensaver from becoming active. + + Handy if you're running some sort of presentation app where having a screensaver + appear would be annoying. + + Pass false to disable the screensaver, and true to re-enable it. + + @see isScreenSaverEnabled + */ + static void setScreenSaverEnabled (const bool isEnabled) throw(); + + /** Returns true if the screensaver has not been turned off. + + This will return the last value passed into setScreenSaverEnabled(). Note that + it won't tell you whether the user is actually using a screen saver, just + whether this app is deliberately preventing one from running. + + @see setScreenSaverEnabled + */ + static bool isScreenSaverEnabled() throw(); + //============================================================================== /** Registers a MouseListener that will receive all mouse events that occur on any component.