diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 4bcd7aaf0f..bcd3f269e8 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -70,12 +70,16 @@ file(GLOB_RECURSE INTERFACE_SRCS "src/*.cpp" "src/*.h") GroupSources("src") list(APPEND INTERFACE_SRCS ${RESOURCES_RCC}) +# grab the Objective-C sources on OS X +if (APPLE) + file(GLOB_RECURSE INTERFACE_OBJCPP_SRCS "src/*.m" "src/*.mm") + list(APPEND INTERFACE_SRCS ${INTERFACE_OBJCPP_SRCS}) +endif () + # Add SpeechRecognizer if on Windows or OS X, otherwise remove if (WIN32) # Use .cpp and .h files as is. elseif (APPLE) - file(GLOB INTERFACE_OBJCPP_SRCS "src/SpeechRecognizer.mm") - set(INTERFACE_SRCS ${INTERFACE_SRCS} ${INTERFACE_OBJCPP_SRCS}) get_filename_component(SPEECHRECOGNIZER_CPP "src/SpeechRecognizer.cpp" ABSOLUTE) list(REMOVE_ITEM INTERFACE_SRCS ${SPEECHRECOGNIZER_CPP}) else () diff --git a/interface/src/AppNapDisabler.h b/interface/src/AppNapDisabler.h new file mode 100644 index 0000000000..b3cfc3038d --- /dev/null +++ b/interface/src/AppNapDisabler.h @@ -0,0 +1,24 @@ +// +// AppNapDisabler.h +// interface/src +// +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AppNapDisabler_h +#define hifi_AppNapDisabler_h + +#import + +class AppNapDisabler { +public: + AppNapDisabler(); + ~AppNapDisabler(); +private: + id _activity; +}; + +#endif // hifi_AppNapDisabler_h diff --git a/interface/src/AppNapDisabler.mm b/interface/src/AppNapDisabler.mm new file mode 100644 index 0000000000..0c760fad5f --- /dev/null +++ b/interface/src/AppNapDisabler.mm @@ -0,0 +1,28 @@ +// +// AppNapDisabler.mm +// interface/src +// +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#ifdef Q_OS_MAC + +#include "AppNapDisabler.h" + +#import + +AppNapDisabler::AppNapDisabler() { + _activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiated reason:@"Audio is in use"]; + [_activity retain]; +} + +AppNapDisabler::~AppNapDisabler() { + [[NSProcessInfo processInfo] endActivity:_activity]; + [_activity release]; +} + +#endif // Q_OS_MAC diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4002cca0c1..b4a37519a6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -265,6 +265,12 @@ extern "C" { #include "AndroidHelper.h" #endif +#if defined(Q_OS_MAC) +// On Mac OS, disable App Nap to prevent audio glitches while running in the background +#include "AppNapDisabler.h" +static AppNapDisabler appNapDisabler; // disabled, while in scope +#endif + #include "graphics/RenderEventHandler.h" Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse")