[SOLVED] QDialog in fullscreen - disable OS screensaver?
-
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
-
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
-
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);
}
@ -
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);
}
@ -
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.oSeems 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@ -
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.oSeems 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@ -
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
-
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
-
You should rather use a elif defined(Q_OS_WIN) since it's completely platform specific
-
You should rather use a elif defined(Q_OS_WIN) since it's completely platform specific
-
@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.