Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] ScreenSaver - disable screensaver on Windows
QtWS25 Last Chance

[SOLVED] ScreenSaver - disable screensaver on Windows

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on 31 Mar 2015, 15:48 last edited by maximus 4 Jan 2015, 14:36
    #1

    Trying to disable screensaver on windows when a specific QDialog is open.

    I tried a lot of way but can't get it to work on Windows, with Mac I found a way.

    Even tried to send key event and mouse event to the QDialog, event works fine but don't stop the screensaver from coming

    Method 1 (hacky):

    void WorkoutDialog::postponeScreensaver() {
    
      QPoint toMove = this->mapFromGlobal(QCursor::pos());
      toMove.setX(toMove.x()+1);
    
      QTest::keyClick(this, Qt::Key_A); //doesnt postpone screensaver...
      QTest::mouseMove(this, toMove); //mouse move but screensaver still trigger
    }
    

    Method 2 (not working on all Windows platform):

    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
    

    Other Method?


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on 1 Apr 2015, 13:50 last edited by
      #2

      This Method seems to be working, require more testing:

      #ifdef Q_OS_MAC
        macUtil.disableScreensaver();
      #endif
      #ifdef Q_OS_WIN32
        SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
        //SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
      #endif
      

      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      1
      • M Offline
        M Offline
        maximus
        wrote on 1 Apr 2015, 14:29 last edited by maximus 4 Jan 2015, 14:29
        #3

        May be something worth to have by default in Qt to avoid #ifdef

        OSX: MacUtils.mm

        //http://stackoverflow.com/questions/5596319/how-to-programmatically-prevent-a-mac-from-going-to-sleep/5596946#5596946
        void MacUtils::disableScreensaver() {
        
        	 qDebug() << "disableScreenSaveronMAC!";
        
        	CFStringRef reasonForActivity = CFSTR("Maximum Trainer Workout");
        
        	IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
        										kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
        
        
        	if (success == kIOReturnSuccess)
        	{
        		//success = IOPMAssertionRelease(assertionID);
        		///return disable sucess? todo..
        	}
        
        	qDebug() << "disableScreenSaveronMAC end !";
        }
        void MacUtils::releaseScreensaverLock() {
        
        	IOPMAssertionRelease(assertionID);
        }
        

        Windows
        SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        1

        3/3

        1 Apr 2015, 14:29

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved