vcl/inc/win/saldata.hxx     |    1 -
 vcl/win/app/salinst.cxx     |    1 -
 vcl/win/window/salframe.cxx |   13 ++++---------
 3 files changed, 4 insertions(+), 11 deletions(-)

New commits:
commit ba42683fada2abafa18a49cd50ce8298b92851c8
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Oct 13 13:43:29 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Oct 13 16:21:15 2022 +0200

    tdf#120326: properly prevent Windows from entering power saving
    
    The previous call to SystemParametersInfoW with SPI_SETSCREENSAVEACTIVE
    only prevented screen saver from running (which is not often used these
    days), but screen was still turned off (and power saving was started).
    
    Despite SetThreadExecutionState documentation [1] claims that it does
    not stop the screen saver from executing, my experiments show that it
    does (on my Windows 10). So just use it, because it is designed exactly
    for this task (documentation discusses the presentation applications).
    
    [1] 
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
    
    Change-Id: I6eced8f0a7c17211a0b68851a40227eed9a22b1a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141289
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/vcl/inc/win/saldata.hxx b/vcl/inc/win/saldata.hxx
index 17e9411a3c8e..3145688e24be 100644
--- a/vcl/inc/win/saldata.hxx
+++ b/vcl/inc/win/saldata.hxx
@@ -111,7 +111,6 @@ public:
     bool                    mbObjClassInit;         // is SALOBJECTCLASS 
initialised
     bool                    mbInPalChange;          // is in WM_QUERYNEWPALETTE
     DWORD                   mnAppThreadId;          // Id from 
Application-Thread
-    BOOL                    mbScrSvrEnabled;        // ScreenSaver enabled
     SalIcon*                mpFirstIcon;            // icon cache, points to 
first icon, NULL if none
     TempFontItem*           mpSharedTempFontItem;   // LibreOffice shared fonts
     TempFontItem*           mpOtherTempFontItem;    // other temporary fonts 
(embedded?)
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index 24c4c508fe9a..56773808fea5 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -291,7 +291,6 @@ SalData::SalData()
     mbObjClassInit = false;     // is SALOBJECTCLASS initialised
     mbInPalChange = false;      // is in WM_QUERYNEWPALETTE
     mnAppThreadId = 0;          // Id from Application-Thread
-    mbScrSvrEnabled = FALSE;    // ScreenSaver enabled
     mpFirstIcon = nullptr;      // icon cache, points to first icon, NULL if 
none
     mpSharedTempFontItem = nullptr;
     mpOtherTempFontItem = nullptr;
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index d2d2f697aeb3..9871eba67edd 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -1887,20 +1887,15 @@ void WinSalFrame::StartPresentation( bool bStart )
 
     mbPresentation = bStart;
 
-    SalData* pSalData = GetSalData();
     if ( bStart )
     {
-        // turn off screen-saver when in Presentation mode
-        SystemParametersInfoW( SPI_GETSCREENSAVEACTIVE, 0,
-                              &(pSalData->mbScrSvrEnabled), 0 );
-        if ( pSalData->mbScrSvrEnabled )
-            SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0 
);
+        // turn off screen-saver / power saving when in Presentation mode
+        SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | 
ES_DISPLAY_REQUIRED);
     }
     else
     {
-        // turn on screen-saver
-        if ( pSalData->mbScrSvrEnabled )
-            SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE, 
pSalData->mbScrSvrEnabled, nullptr, 0 );
+        // turn on screen-saver / power saving back
+        SetThreadExecutionState(ES_CONTINUOUS);
     }
 }
 

Reply via email to