Skip to content

Commit

Permalink
Merge pull request wang-bin#914 from cculianu/fork2
Browse files Browse the repository at this point in the history
Mac OSX: Fix to stop using deprecated API to turn off ScreenSaver in ScreenSaver.cpp
  • Loading branch information
wang-bin authored Jul 1, 2017
2 parents 42db9cb + 5aa5b27 commit f986d92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/common/ScreenSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ static fXResetScreenSaver XResetScreenSaver = 0;
static QLibrary xlib;
#endif //Q_OS_LINUX
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
#include <Availability.h>
# if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
//http://www.cocoachina.com/macdev/cocoa/2010/0201/453.html
#include <CoreServices/CoreServices.h>
# else
/* MAC OSX 10.8+ has deprecated the UpdateSystemActivity stuff in favor of a new API.. */
# include <IOKit/pwr_mgt/IOPMLib.h>
# endif
#endif //Q_OS_MAC
#ifdef Q_OS_WIN
#include <QAbstractEventDispatcher>
Expand Down Expand Up @@ -149,6 +155,7 @@ ScreenSaver::ScreenSaver()
}
#endif //Q_OS_LINUX
ssTimerId = 0;
osxIOPMAssertionId = 0U; // mac >=10.8 only
retrieveState();
}

Expand All @@ -158,6 +165,13 @@ ScreenSaver::~ScreenSaver()
#ifdef Q_OS_LINUX
if (xlib.isLoaded())
xlib.unload();
#elif defined(Q_OS_MAC) && !defined(Q_OS_IOS)
# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
if (osxIOPMAssertionId) {
IOPMAssertionRelease((IOPMAssertionID)osxIOPMAssertionId);
osxIOPMAssertionId = 0U;
}
# endif
#endif
}

Expand Down Expand Up @@ -310,7 +324,15 @@ void ScreenSaver::timerEvent(QTimerEvent *e)
if (e->timerId() != ssTimerId)
return;
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
# if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
UpdateSystemActivity(OverallAct);
# else // OSX >= 10.8, use new API
IOPMAssertionID assertionId = osxIOPMAssertionId;
IOReturn r = IOPMAssertionDeclareUserActivity(CFSTR("QtAVScreenSaver"),kIOPMUserActiveLocal,&assertionId);
if (r == kIOReturnSuccess) {
osxIOPMAssertionId = assertionId;
}
# endif
return;
#endif //Q_OS_MAC
#ifdef Q_OS_LINUX
Expand Down
1 change: 1 addition & 0 deletions examples/common/ScreenSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public slots:
int allowExposures;
#endif //Q_OS_LINUX
int ssTimerId; //for mac
quint32 osxIOPMAssertionId; // for mac OSX >= 10.8
};

#endif // SCREENSAVER_H

0 comments on commit f986d92

Please sign in to comment.