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] QDialog in fullscreen - disable OS screensaver?

[SOLVED] QDialog in fullscreen - disable OS screensaver?

Scheduled Pinned Locked Moved General and Desktop
29 Posts 5 Posters 15.2k 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 17 Dec 2014, 00:59 last edited by
    #15

    [quote author="MarianMMX" date="1397293908"]Ok, tested on Windows XP:

    DisableScreenSaver.c
    @
    #include <Windows.h>
    #pragma comment(lib, "user32.lib")

    int main()
    {
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
    return 0;
    }

    @
    [/quote]

    Tested and works on windows 7 too. thanks
    Update: not really what I wanted, it still disable the ScreenSaver after you leave the app.. don't want to mess with personal settings..

    I gave up trying to emulate a key press, will use this code instead.
    Trying to find an equivalent for Mac OS X now


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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on 17 Dec 2014, 00:59 last edited by
      #16

      [quote author="MarianMMX" date="1397293908"]Ok, tested on Windows XP:

      DisableScreenSaver.c
      @
      #include <Windows.h>
      #pragma comment(lib, "user32.lib")

      int main()
      {
      SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
      return 0;
      }

      @
      [/quote]

      Tested and works on windows 7 too. thanks
      Update: not really what I wanted, it still disable the ScreenSaver after you leave the app.. don't want to mess with personal settings..

      I gave up trying to emulate a key press, will use this code instead.
      Trying to find an equivalent for Mac OS X now


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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on 17 Dec 2014, 01:38 last edited by
        #17

        I read you can call Objective-C from Qt

        I want "to use this method":http://stackoverflow.com/questions/5596319/how-to-programmatically-prevent-a-mac-from-going-to-sleep/5596946#5596946

        I made a header file named "MacUtil.h" and a "MacUtil.mm" that will call the Objective-C code. Will see if I can get it to work and post result


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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on 17 Dec 2014, 01:38 last edited by
          #18

          I read you can call Objective-C from Qt

          I want "to use this method":http://stackoverflow.com/questions/5596319/how-to-programmatically-prevent-a-mac-from-going-to-sleep/5596946#5596946

          I made a header file named "MacUtil.h" and a "MacUtil.mm" that will call the Objective-C code. Will see if I can get it to work and post result


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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maximus
            wrote on 17 Dec 2014, 01:52 last edited by
            #19

            On the way, will edit this post with solution
            MacUtil.h

            @class MacUtil
            {

            public:
            MacUtil();
            ~MacUtil();

            void disableScreensaver();
            void releaseScreensaverLock();
            

            private:
            IOPMAssertionID assertionID;

            };

            #endif // MACUTIL_H@

            MacUtil.mm
            @//http://stackoverflow.com/questions/5596319/how-to-programmatically-prevent-a-mac-from-going-to-sleep/5596946#5596946
            void MacUtil::disableScreensaver() {

            CFStringRef* reasonForActivity= CFSTR("MaximumTrainer FullScreen Workout");
            IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
                                                kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
            if (success == kIOReturnSuccess)
            {
                //return sucess? todo..
            }
            

            }

            void MacUtil::releaseScreensaverLock() {

            IOPMAssertionRelease(assertionID);
            

            }
            @


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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maximus
              wrote on 17 Dec 2014, 01:52 last edited by
              #20

              On the way, will edit this post with solution
              MacUtil.h

              @class MacUtil
              {

              public:
              MacUtil();
              ~MacUtil();

              void disableScreensaver();
              void releaseScreensaverLock();
              

              private:
              IOPMAssertionID assertionID;

              };

              #endif // MACUTIL_H@

              MacUtil.mm
              @//http://stackoverflow.com/questions/5596319/how-to-programmatically-prevent-a-mac-from-going-to-sleep/5596946#5596946
              void MacUtil::disableScreensaver() {

              CFStringRef* reasonForActivity= CFSTR("MaximumTrainer FullScreen Workout");
              IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
                                                  kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
              if (success == kIOReturnSuccess)
              {
                  //return sucess? todo..
              }
              

              }

              void MacUtil::releaseScreensaverLock() {

              IOPMAssertionRelease(assertionID);
              

              }
              @


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

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maximus
                wrote on 17 Dec 2014, 02:53 last edited by
                #21

                Anyone good with Objective-C?

                I'm getting theses error tryings to compile the new class (mm file) I just added:

                duplicate symbol __ZN8MacUtilsC2Ev in:
                MacUtils.o
                macutils.o
                duplicate symbol __ZN8MacUtilsC1Ev in:
                MacUtils.o
                macutils.o

                Seems like a conflict with
                @#import <IOKit/pwr_mgt/IOPMLib.h> in MacUtil.mm@
                and my .pro has already theses:
                @ LIBS += -framework IOKit
                LIBS += -framework CoreFoundation@


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

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maximus
                  wrote on 17 Dec 2014, 02:53 last edited by
                  #22

                  Anyone good with Objective-C?

                  I'm getting theses error tryings to compile the new class (mm file) I just added:

                  duplicate symbol __ZN8MacUtilsC2Ev in:
                  MacUtils.o
                  macutils.o
                  duplicate symbol __ZN8MacUtilsC1Ev in:
                  MacUtils.o
                  macutils.o

                  Seems like a conflict with
                  @#import <IOKit/pwr_mgt/IOPMLib.h> in MacUtil.mm@
                  and my .pro has already theses:
                  @ LIBS += -framework IOKit
                  LIBS += -framework CoreFoundation@


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

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maximus
                    wrote on 17 Dec 2014, 03:02 last edited by
                    #23

                    Solved, I had 2 times the OBJECTIVE_SOURCES directive in my pro file pointing to the same .mm file.
                    Will have to go learn Objective-C now, sigh.. :)


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

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maximus
                      wrote on 17 Dec 2014, 03:02 last edited by
                      #24

                      Solved, I had 2 times the OBJECTIVE_SOURCES directive in my pro file pointing to the same .mm file.
                      Will have to go learn Objective-C now, sigh.. :)


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

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        maximus
                        wrote on 17 Dec 2014, 04:12 last edited by
                        #25

                        Working for both Windows and OS X!

                        On dialog open (constructor):
                        @// Disable ScreenSaver
                        #ifdef Q_OS_MAC
                        macUtil.disableScreensaver();
                        #else
                        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
                        #endif@

                        On dialog close (destructor):
                        @#ifdef Q_OS_MAC
                        macUtil.releaseScreensaverLock();
                        #else
                        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE , NULL, SPIF_SENDWININICHANGE);
                        #endif@

                        Tested and work for Windows, if you have no screensaver, it will not put one with the the destructor, all possible cases seems to work


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

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          maximus
                          wrote on 17 Dec 2014, 04:12 last edited by
                          #26

                          Working for both Windows and OS X!

                          On dialog open (constructor):
                          @// Disable ScreenSaver
                          #ifdef Q_OS_MAC
                          macUtil.disableScreensaver();
                          #else
                          SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
                          #endif@

                          On dialog close (destructor):
                          @#ifdef Q_OS_MAC
                          macUtil.releaseScreensaverLock();
                          #else
                          SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE , NULL, SPIF_SENDWININICHANGE);
                          #endif@

                          Tested and work for Windows, if you have no screensaver, it will not put one with the the destructor, all possible cases seems to work


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

                          W 1 Reply Last reply 2 Feb 2016, 20:37
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 17 Dec 2014, 23:40 last edited by
                            #27

                            You should rather use a elif defined(Q_OS_WIN) since it's completely platform specific

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 17 Dec 2014, 23:40 last edited by
                              #28

                              You should rather use a elif defined(Q_OS_WIN) since it's completely platform specific

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • M maximus
                                17 Dec 2014, 04:12

                                Working for both Windows and OS X!

                                On dialog open (constructor):
                                @// Disable ScreenSaver
                                #ifdef Q_OS_MAC
                                macUtil.disableScreensaver();
                                #else
                                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
                                #endif@

                                On dialog close (destructor):
                                @#ifdef Q_OS_MAC
                                macUtil.releaseScreensaverLock();
                                #else
                                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE , NULL, SPIF_SENDWININICHANGE);
                                #endif@

                                Tested and work for Windows, if you have no screensaver, it will not put one with the the destructor, all possible cases seems to work

                                W Offline
                                W Offline
                                wesblake
                                wrote on 2 Feb 2016, 20:37 last edited by
                                #29

                                @maximus said:

                                Working for both Windows and OS X!

                                On dialog open (constructor):
                                @// Disable ScreenSaver
                                #ifdef Q_OS_MAC
                                macUtil.disableScreensaver();
                                #else
                                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE , NULL, SPIF_SENDWININICHANGE);
                                #endif@

                                On dialog close (destructor):
                                @#ifdef Q_OS_MAC
                                macUtil.releaseScreensaverLock();
                                #else
                                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE , NULL, SPIF_SENDWININICHANGE);
                                #endif@

                                Tested and work for Windows, if you have no screensaver, it will not put one with the the destructor, all possible cases seems to work

                                Can you share your source or at least the relevant part? I've been using the same code for my app to disable/re-enable on Windows, but now need to do the same for Mac clients. Thanks.

                                1 Reply Last reply
                                0

                                • Login

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