From c74a95ce50db5f82c2df961e49bf91f500d194ff Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Wed, 23 Nov 2016 09:10:12 +0100 Subject: [PATCH] OSX: disable AppNap for QmlStreamers, move AppNapSuspender to Deflect library. --- apps/DesktopStreamer/CMakeLists.txt | 4 +--- apps/DesktopStreamer/MainWindow.h | 4 ++-- apps/QmlStreamer/main.cpp | 5 +++-- {apps/DesktopStreamer => deflect}/AppNapSuspender.h | 11 ++++++++--- {apps/DesktopStreamer => deflect}/AppNapSuspender.mm | 5 +++++ deflect/CMakeLists.txt | 6 ++++++ deflect/qt/QmlStreamerImpl.cpp | 4 ++++ deflect/qt/QmlStreamerImpl.h | 7 +++++++ doc/Changelog.md | 3 +++ 9 files changed, 39 insertions(+), 10 deletions(-) rename {apps/DesktopStreamer => deflect}/AppNapSuspender.h (96%) rename {apps/DesktopStreamer => deflect}/AppNapSuspender.mm (99%) diff --git a/apps/DesktopStreamer/CMakeLists.txt b/apps/DesktopStreamer/CMakeLists.txt index c29d3e9..56a7bbb 100644 --- a/apps/DesktopStreamer/CMakeLists.txt +++ b/apps/DesktopStreamer/CMakeLists.txt @@ -46,13 +46,11 @@ if(APPLE) set(DESKTOPSTREAMER_COPYRIGHT "EPFL/Blue Brain Project ${_CURRENT_YEAR}") set(DESKTOPSTREAMER_ICON desktopstreamer.icns) - list(APPEND DESKTOPSTREAMER_SOURCES AppNapSuspender.mm) - list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework Foundation") if(TARGET Qt5::MacExtras) list(APPEND DESKTOPSTREAMER_HEADERS DesktopWindowsModel.h) list(APPEND DESKTOPSTREAMER_SOURCES DesktopWindowsModel.mm) list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES - Qt5::MacExtras "-framework AppKit" + Qt5::MacExtras "-framework AppKit" "-framework Foundation" ) endif() if(OSX_VERSION VERSION_LESS 10.9) diff --git a/apps/DesktopStreamer/MainWindow.h b/apps/DesktopStreamer/MainWindow.h index 71935e8..4c1a5b6 100644 --- a/apps/DesktopStreamer/MainWindow.h +++ b/apps/DesktopStreamer/MainWindow.h @@ -44,7 +44,7 @@ #include #ifdef __APPLE__ -# include "AppNapSuspender.h" +# include #endif #ifdef DEFLECT_USE_SERVUS @@ -89,7 +89,7 @@ private slots: float _averageUpdate; #ifdef __APPLE__ - AppNapSuspender _napSuspender; + deflect::AppNapSuspender _napSuspender; #endif void _showMultiWindowMode(); diff --git a/apps/QmlStreamer/main.cpp b/apps/QmlStreamer/main.cpp index 7f09976..b4bfa52 100644 --- a/apps/QmlStreamer/main.cpp +++ b/apps/QmlStreamer/main.cpp @@ -17,11 +17,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include #include #include +#include +#include + int main( int argc, char** argv ) { QGuiApplication app( argc,argv ); diff --git a/apps/DesktopStreamer/AppNapSuspender.h b/deflect/AppNapSuspender.h similarity index 96% rename from apps/DesktopStreamer/AppNapSuspender.h rename to deflect/AppNapSuspender.h index ea8d756..48808ce 100644 --- a/apps/DesktopStreamer/AppNapSuspender.h +++ b/deflect/AppNapSuspender.h @@ -37,8 +37,11 @@ /* or implied, of The Ecole Polytechnique Federale de Lausanne. */ /*********************************************************************/ -#ifndef APPNAPSUSPENDER_H -#define APPNAPSUSPENDER_H +#ifndef DEFLECT_APPNAPSUSPENDER_H +#define DEFLECT_APPNAPSUSPENDER_H + +namespace deflect +{ /** * Suspend AppNap on OSX >= 10.9. @@ -63,4 +66,6 @@ class AppNapSuspender Impl* _impl; }; -#endif // APPNAPSUSPENDER_H +} + +#endif diff --git a/apps/DesktopStreamer/AppNapSuspender.mm b/deflect/AppNapSuspender.mm similarity index 99% rename from apps/DesktopStreamer/AppNapSuspender.mm rename to deflect/AppNapSuspender.mm index 83f4231..bf8a35e 100644 --- a/apps/DesktopStreamer/AppNapSuspender.mm +++ b/deflect/AppNapSuspender.mm @@ -52,6 +52,9 @@ #endif #endif +namespace deflect +{ + class AppNapSuspender::Impl { public: @@ -97,3 +100,5 @@ _impl->activityId = nil; } } + +} diff --git a/deflect/CMakeLists.txt b/deflect/CMakeLists.txt index 0567979..07fa173 100644 --- a/deflect/CMakeLists.txt +++ b/deflect/CMakeLists.txt @@ -48,6 +48,12 @@ set(DEFLECT_SOURCES set(DEFLECT_LINK_LIBRARIES PRIVATE Qt5::Concurrent Qt5::Core Qt5::Network) +if(APPLE) + list(APPEND DEFLECT_PUBLIC_HEADERS AppNapSuspender.h) + list(APPEND DEFLECT_SOURCES AppNapSuspender.mm) + list(APPEND DEFLECT_LINK_LIBRARIES PRIVATE "-framework Foundation") +endif() + if(DEFLECT_USE_LIBJPEGTURBO) list(APPEND DEFLECT_PUBLIC_HEADERS SegmentDecoder.h diff --git a/deflect/qt/QmlStreamerImpl.cpp b/deflect/qt/QmlStreamerImpl.cpp index bf5a150..0e5c635 100644 --- a/deflect/qt/QmlStreamerImpl.cpp +++ b/deflect/qt/QmlStreamerImpl.cpp @@ -91,6 +91,10 @@ QmlStreamer::Impl::Impl( const QString& qmlFile, const std::string& streamHost, if( !_quickView->load( qmlFile ).get( )) throw std::runtime_error( "Failed to setup/load QML" ); + +#ifdef __APPLE__ + _napSuspender.suspend(); +#endif } QmlStreamer::Impl::~Impl() {} diff --git a/deflect/qt/QmlStreamerImpl.h b/deflect/qt/QmlStreamerImpl.h index de425ea..65c82e4 100644 --- a/deflect/qt/QmlStreamerImpl.h +++ b/deflect/qt/QmlStreamerImpl.h @@ -50,6 +50,9 @@ #include "QmlStreamer.h" #include "../SizeHints.h" +#ifdef __APPLE__ +# include +#endif #include namespace deflect @@ -127,6 +130,10 @@ private slots: bool _mouseMode{ false }; QPointF _touchStartPos; QPointF _touchCurrentPos; + +#ifdef __APPLE__ + AppNapSuspender _napSuspender; +#endif }; } diff --git a/doc/Changelog.md b/doc/Changelog.md index 2457912..45f4337 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -5,6 +5,9 @@ Changelog {#Changelog} ### 0.12.0 (git master) +* [139](https://github.com/BlueBrain/Deflect/pull/139): + OSX: AppNap is now disabled for all QmlStreamers. The AppNapSuspender class + is now available in Deflect library for use in external applications. * [137](https://github.com/BlueBrain/Deflect/pull/137): Deflect Qt: the offscreen Qml view used by the Qml streamer is now available as a separate class.