Showing the changes to interface/src/Application.cpp (1 of 28 files). Show all
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | |||
| 19 | #include <glm/gtc/type_ptr.hpp> | 19 | #include <glm/gtc/type_ptr.hpp> |
| 20 | 20 | ||
| 21 | #include <QtCore/QAbstractNativeEventFilter> | 21 | #include <QtCore/QAbstractNativeEventFilter> |
| 22 | #include <QtCore/QCommandLineParser> | ||
| 22 | #include <QtCore/QMimeData> | 23 | #include <QtCore/QMimeData> |
| 23 | #include <QtCore/QThreadPool> | 24 | #include <QtCore/QThreadPool> |
| 24 | 25 | ||
| @@ -197,7 +198,6 @@ static const float PHYSICS_READY_RANGE = 3.0f; // how far from avatar to check f · 172 unmodified lines | |||
| 197 | 198 | ||
| 198 | static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | 199 | static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 199 | 200 | ||
| 200 | static const QString INPUT_DEVICE_MENU_PREFIX = "Device: "; | ||
| 201 | Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); | 201 | Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); |
| 202 | 202 | ||
| 203 | const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions { | 203 | const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions { |
| @@ -999,7 +999,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 795 unmodified lines | |||
| 999 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); | 999 | RenderableWebEntityItem* webEntity = dynamic_cast<RenderableWebEntityItem*>(entity.get()); |
| 1000 | if (webEntity) { | 1000 | if (webEntity) { |
| 1001 | webEntity->setProxyWindow(_window->windowHandle()); | 1001 | webEntity->setProxyWindow(_window->windowHandle()); |
| 1002 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 1002 | if (_keyboardMouseDevice->isActive()) { |
| 1003 | _keyboardMouseDevice->pluginFocusOutEvent(); | 1003 | _keyboardMouseDevice->pluginFocusOutEvent(); |
| 1004 | } | 1004 | } |
| 1005 | _keyboardFocusedItem = entityItemID; | 1005 | _keyboardFocusedItem = entityItemID; |
| @@ -1152,9 +1152,7 @@ void Application::aboutToQuit() { · 146 unmodified lines | |||
| 1152 | emit beforeAboutToQuit(); | 1152 | emit beforeAboutToQuit(); |
| 1153 | 1153 | ||
| 1154 | foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) { | 1154 | foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) { |
| 1155 | QString name = INPUT_DEVICE_MENU_PREFIX + inputPlugin->getName(); | 1155 | if (inputPlugin->isActive()) { |
| 1156 | QAction* action = Menu::getInstance()->getActionForOption(name); | ||
| 1157 | if (action->isChecked()) { | ||
| 1158 | inputPlugin->deactivate(); | 1156 | inputPlugin->deactivate(); |
| 1159 | } | 1157 | } |
| 1160 | } | 1158 | } |
| @@ -1476,7 +1474,6 @@ void Application::initializeUi() { · 315 unmodified lines | |||
| 1476 | } | 1474 | } |
| 1477 | } | 1475 | } |
| 1478 | _window->setMenuBar(new Menu()); | 1476 | _window->setMenuBar(new Menu()); |
| 1479 | updateInputModes(); | ||
| 1480 | 1477 | ||
| 1481 | auto compositorHelper = DependencyManager::get<CompositorHelper>(); | 1478 | auto compositorHelper = DependencyManager::get<CompositorHelper>(); |
| 1482 | connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, [=] { | 1479 | connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, [=] { |
| @@ -2024,7 +2021,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 541 unmodified lines | |||
| 2024 | } | 2021 | } |
| 2025 | 2022 | ||
| 2026 | if (hasFocus()) { | 2023 | if (hasFocus()) { |
| 2027 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2024 | if (_keyboardMouseDevice->isActive()) { |
| 2028 | _keyboardMouseDevice->keyPressEvent(event); | 2025 | _keyboardMouseDevice->keyPressEvent(event); |
| 2029 | } | 2026 | } |
| 2030 | 2027 | ||
| @@ -2359,7 +2356,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 328 unmodified lines | |||
| 2359 | return; | 2356 | return; |
| 2360 | } | 2357 | } |
| 2361 | 2358 | ||
| 2362 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2359 | if (_keyboardMouseDevice->isActive()) { |
| 2363 | _keyboardMouseDevice->keyReleaseEvent(event); | 2360 | _keyboardMouseDevice->keyReleaseEvent(event); |
| 2364 | } | 2361 | } |
| 2365 | 2362 | ||
| @@ -2391,9 +2388,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 25 unmodified lines | |||
| 2391 | void Application::focusOutEvent(QFocusEvent* event) { | 2388 | void Application::focusOutEvent(QFocusEvent* event) { |
| 2392 | auto inputPlugins = PluginManager::getInstance()->getInputPlugins(); | 2389 | auto inputPlugins = PluginManager::getInstance()->getInputPlugins(); |
| 2393 | foreach(auto inputPlugin, inputPlugins) { | 2390 | foreach(auto inputPlugin, inputPlugins) { |
| 2394 | QString name = INPUT_DEVICE_MENU_PREFIX + inputPlugin->getName(); | 2391 | if (inputPlugin->isActive()) { |
| 2395 | QAction* action = Menu::getInstance()->getActionForOption(name); | ||
| 2396 | if (action && action->isChecked()) { | ||
| 2397 | inputPlugin->pluginFocusOutEvent(); | 2392 | inputPlugin->pluginFocusOutEvent(); |
| 2398 | } | 2393 | } |
| 2399 | } | 2394 | } |
| @@ -2478,7 +2473,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 78 unmodified lines | |||
| 2478 | return; | 2473 | return; |
| 2479 | } | 2474 | } |
| 2480 | 2475 | ||
| 2481 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2476 | if (_keyboardMouseDevice->isActive()) { |
| 2482 | _keyboardMouseDevice->mouseMoveEvent(event); | 2477 | _keyboardMouseDevice->mouseMoveEvent(event); |
| 2483 | } | 2478 | } |
| 2484 | 2479 | ||
| @@ -2515,7 +2510,7 @@ void Application::mousePressEvent(QMouseEvent* event) { · 30 unmodified lines | |||
| 2515 | 2510 | ||
| 2516 | 2511 | ||
| 2517 | if (hasFocus()) { | 2512 | if (hasFocus()) { |
| 2518 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2513 | if (_keyboardMouseDevice->isActive()) { |
| 2519 | _keyboardMouseDevice->mousePressEvent(event); | 2514 | _keyboardMouseDevice->mousePressEvent(event); |
| 2520 | } | 2515 | } |
| 2521 | 2516 | ||
| @@ -2560,7 +2555,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { · 38 unmodified lines | |||
| 2560 | } | 2555 | } |
| 2561 | 2556 | ||
| 2562 | if (hasFocus()) { | 2557 | if (hasFocus()) { |
| 2563 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2558 | if (_keyboardMouseDevice->isActive()) { |
| 2564 | _keyboardMouseDevice->mouseReleaseEvent(event); | 2559 | _keyboardMouseDevice->mouseReleaseEvent(event); |
| 2565 | } | 2560 | } |
| 2566 | 2561 | ||
| @@ -2587,7 +2582,7 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 20 unmodified lines | |||
| 2587 | return; | 2582 | return; |
| 2588 | } | 2583 | } |
| 2589 | 2584 | ||
| 2590 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2585 | if (_keyboardMouseDevice->isActive()) { |
| 2591 | _keyboardMouseDevice->touchUpdateEvent(event); | 2586 | _keyboardMouseDevice->touchUpdateEvent(event); |
| 2592 | } | 2587 | } |
| 2593 | } | 2588 | } |
| @@ -2605,7 +2600,7 @@ void Application::touchBeginEvent(QTouchEvent* event) { · 11 unmodified lines | |||
| 2605 | return; | 2600 | return; |
| 2606 | } | 2601 | } |
| 2607 | 2602 | ||
| 2608 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2603 | if (_keyboardMouseDevice->isActive()) { |
| 2609 | _keyboardMouseDevice->touchBeginEvent(event); | 2604 | _keyboardMouseDevice->touchBeginEvent(event); |
| 2610 | } | 2605 | } |
| 2611 | 2606 | ||
| @@ -2622,7 +2617,7 @@ void Application::touchEndEvent(QTouchEvent* event) { · 10 unmodified lines | |||
| 2622 | return; | 2617 | return; |
| 2623 | } | 2618 | } |
| 2624 | 2619 | ||
| 2625 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2620 | if (_keyboardMouseDevice->isActive()) { |
| 2626 | _keyboardMouseDevice->touchEndEvent(event); | 2621 | _keyboardMouseDevice->touchEndEvent(event); |
| 2627 | } | 2622 | } |
| 2628 | 2623 | ||
| @@ -2638,7 +2633,7 @@ void Application::wheelEvent(QWheelEvent* event) const { · 9 unmodified lines | |||
| 2638 | return; | 2633 | return; |
| 2639 | } | 2634 | } |
| 2640 | 2635 | ||
| 2641 | if (Menu::getInstance()->isOptionChecked(INPUT_DEVICE_MENU_PREFIX + KeyboardMouseDevice::NAME)) { | 2636 | if (_keyboardMouseDevice->isActive()) { |
| 2642 | _keyboardMouseDevice->wheelEvent(event); | 2637 | _keyboardMouseDevice->wheelEvent(event); |
| 2643 | } | 2638 | } |
| 2644 | } | 2639 | } |
| @@ -2771,9 +2766,7 @@ void Application::idle(float nsecsElapsed) { · 126 unmodified lines | |||
| 2771 | getActiveDisplayPlugin()->idle(); | 2766 | getActiveDisplayPlugin()->idle(); |
| 2772 | auto inputPlugins = PluginManager::getInstance()->getInputPlugins(); | 2767 | auto inputPlugins = PluginManager::getInstance()->getInputPlugins(); |
| 2773 | foreach(auto inputPlugin, inputPlugins) { | 2768 | foreach(auto inputPlugin, inputPlugins) { |
| 2774 | QString name = INPUT_DEVICE_MENU_PREFIX + inputPlugin->getName(); | 2769 | if (inputPlugin->isActive()) { |
| 2775 | QAction* action = Menu::getInstance()->getActionForOption(name); | ||
| 2776 | if (action && action->isChecked()) { | ||
| 2777 | inputPlugin->idle(); | 2770 | inputPlugin->idle(); |
| 2778 | } | 2771 | } |
| 2779 | } | 2772 | } |
| @@ -2957,6 +2950,27 @@ void Application::loadSettings() { · 177 unmodified lines | |||
| 2957 | //DependencyManager::get<LODManager>()->setAutomaticLODAdjust(false); | 2950 | //DependencyManager::get<LODManager>()->setAutomaticLODAdjust(false); |
| 2958 | 2951 | ||
| 2959 | Menu::getInstance()->loadSettings(); | 2952 | Menu::getInstance()->loadSettings(); |
| 2953 | |||
| 2954 | // If there is a preferred plugin, we probably messed it up with the menu settings, so fix it. | ||
| 2955 | auto pluginManager = PluginManager::getInstance(); | ||
| 2956 | auto plugins = pluginManager->getPreferredDisplayPlugins(); | ||
| 2957 | for (auto plugin : plugins) { | ||
| 2958 | auto menu = Menu::getInstance(); | ||
| 2959 | if (auto action = menu->getActionForOption(plugin->getName())) { | ||
| 2960 | action->setChecked(true); | ||
| 2961 | action->trigger(); | ||
| 2962 | // Find and activated highest priority plugin, bail for the rest | ||
| 2963 | break; | ||
| 2964 | } | ||
| 2965 | } | ||
| 2966 | |||
| 2967 | auto inputs = pluginManager->getInputPlugins(); | ||
| 2968 | for (auto plugin : inputs) { | ||
| 2969 | if (!plugin->isActive()) { | ||
| 2970 | plugin->activate(); | ||
| 2971 | } | ||
| 2972 | } | ||
| 2973 | |||
| 2960 | getMyAvatar()->loadData(); | 2974 | getMyAvatar()->loadData(); |
| 2961 | 2975 | ||
| 2962 | _settingsLoaded = true; | 2976 | _settingsLoaded = true; |
| @@ -4937,7 +4951,34 @@ void Application::postLambdaEvent(std::function<void()> f) { · 1974 unmodified lines | |||
| 4937 | } | 4951 | } |
| 4938 | } | 4952 | } |
| 4939 | 4953 | ||
| 4940 | void Application::initPlugins() { | 4954 | void Application::initPlugins(const QStringList& arguments) { |
| 4955 | QCommandLineOption display("display", "Preferred displays", "displays"); | ||
| 4956 | QCommandLineOption disableDisplays("disable-displays", "Displays to disable", "displays"); | ||
| 4957 | QCommandLineOption disableInputs("disable-inputs", "Inputs to disable", "inputs"); | ||
| 4958 | |||
| 4959 | QCommandLineParser parser; | ||
| 4960 | parser.addOption(display); | ||
| 4961 | parser.addOption(disableDisplays); | ||
| 4962 | parser.addOption(disableInputs); | ||
| 4963 | parser.parse(arguments); | ||
| 4964 | |||
| 4965 | if (parser.isSet(display)) { | ||
| 4966 | auto preferredDisplays = parser.value(display).split(',', QString::SkipEmptyParts); | ||
| 4967 | qInfo() << "Setting prefered display plugins:" << preferredDisplays; | ||
| 4968 | PluginManager::getInstance()->setPreferredDisplayPlugins(preferredDisplays); | ||
| 4969 | } | ||
| 4970 | |||
| 4971 | if (parser.isSet(disableDisplays)) { | ||
| 4972 | auto disabledDisplays = parser.value(disableDisplays).split(',', QString::SkipEmptyParts); | ||
| 4973 | qInfo() << "Disabling following display plugins:" << disabledDisplays; | ||
| 4974 | PluginManager::getInstance()->disableDisplays(disabledDisplays); | ||
| 4975 | } | ||
| 4976 | |||
| 4977 | if (parser.isSet(disableInputs)) { | ||
| 4978 | auto disabledInputs = parser.value(disableInputs).split(',', QString::SkipEmptyParts); | ||
| 4979 | qInfo() << "Disabling following input plugins:" << disabledInputs; | ||
| 4980 | PluginManager::getInstance()->disableInputs(disabledInputs); | ||
| 4981 | } | ||
| 4941 | } | 4982 | } |
| 4942 | 4983 | ||
| 4943 | void Application::shutdownPlugins() { | 4984 | void Application::shutdownPlugins() { |
| @@ -5207,81 +5248,6 @@ void Application::updateDisplayMode() { · 263 unmodified lines | |||
| 5207 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); | 5248 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); |
| 5208 | } | 5249 | } |
| 5209 | 5250 | ||
| 5210 | static void addInputPluginToMenu(InputPluginPointer inputPlugin) { | ||
| 5211 | auto menu = Menu::getInstance(); | ||
| 5212 | QString name = INPUT_DEVICE_MENU_PREFIX + inputPlugin->getName(); | ||
| 5213 | Q_ASSERT(!menu->menuItemExists(MenuOption::InputMenu, name)); | ||
| 5214 | |||
| 5215 | static QActionGroup* inputPluginGroup = nullptr; | ||
| 5216 | if (!inputPluginGroup) { | ||
| 5217 | inputPluginGroup = new QActionGroup(menu); | ||
| 5218 | inputPluginGroup->setExclusive(false); | ||
| 5219 | } | ||
| 5220 | |||
| 5221 | auto parent = menu->getMenu(MenuOption::InputMenu); | ||
| 5222 | auto action = menu->addCheckableActionToQMenuAndActionHash(parent, | ||
| 5223 | name, 0, true, qApp, | ||
| 5224 | SLOT(updateInputModes())); | ||
| 5225 | |||
| 5226 | inputPluginGroup->addAction(action); | ||
| 5227 | Q_ASSERT(menu->menuItemExists(MenuOption::InputMenu, name)); | ||
| 5228 | } | ||
| 5229 | |||
| 5230 | |||
| 5231 | void Application::updateInputModes() { | ||
| 5232 | auto menu = Menu::getInstance(); | ||
| 5233 | auto inputPlugins = PluginManager::getInstance()->getInputPlugins(); | ||
| 5234 | static std::once_flag once; | ||
| 5235 | std::call_once(once, [&] { | ||
| 5236 | foreach(auto inputPlugin, inputPlugins) { | ||
| 5237 | addInputPluginToMenu(inputPlugin); | ||
| 5238 | } | ||
| 5239 | }); | ||
| 5240 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | ||
| 5241 | |||
| 5242 | InputPluginList newInputPlugins; | ||
| 5243 | InputPluginList removedInputPlugins; | ||
| 5244 | foreach(auto inputPlugin, inputPlugins) { | ||
| 5245 | QString name = INPUT_DEVICE_MENU_PREFIX + inputPlugin->getName(); | ||
| 5246 | QAction* action = menu->getActionForOption(name); | ||
| 5247 | |||
| 5248 | auto it = std::find(std::begin(_activeInputPlugins), std::end(_activeInputPlugins), inputPlugin); | ||
| 5249 | if (action->isChecked() && it == std::end(_activeInputPlugins)) { | ||
| 5250 | _activeInputPlugins.push_back(inputPlugin); | ||
| 5251 | newInputPlugins.push_back(inputPlugin); | ||
| 5252 | } else if (!action->isChecked() && it != std::end(_activeInputPlugins)) { | ||
| 5253 | _activeInputPlugins.erase(it); | ||
| 5254 | removedInputPlugins.push_back(inputPlugin); | ||
| 5255 | } | ||
| 5256 | } | ||
| 5257 | |||
| 5258 | // A plugin was checked | ||
| 5259 | if (newInputPlugins.size() > 0) { | ||
| 5260 | foreach(auto newInputPlugin, newInputPlugins) { | ||
| 5261 | newInputPlugin->activate(); | ||
| 5262 | //newInputPlugin->installEventFilter(qApp); | ||
| 5263 | //newInputPlugin->installEventFilter(offscreenUi.data()); | ||
| 5264 | } | ||
| 5265 | } | ||
| 5266 | if (removedInputPlugins.size() > 0) { // A plugin was unchecked | ||
| 5267 | foreach(auto removedInputPlugin, removedInputPlugins) { | ||
| 5268 | removedInputPlugin->deactivate(); | ||
| 5269 | //removedInputPlugin->removeEventFilter(qApp); | ||
| 5270 | //removedInputPlugin->removeEventFilter(offscreenUi.data()); | ||
| 5271 | } | ||
| 5272 | } | ||
| 5273 | |||
| 5274 | //if (newInputPlugins.size() > 0 || removedInputPlugins.size() > 0) { | ||
| 5275 | // if (!_currentInputPluginActions.isEmpty()) { | ||
| 5276 | // auto menu = Menu::getInstance(); | ||
| 5277 | // foreach(auto itemInfo, _currentInputPluginActions) { | ||
| 5278 | // menu->removeMenuItem(itemInfo.first, itemInfo.second); | ||
| 5279 | // } | ||
| 5280 | // _currentInputPluginActions.clear(); | ||
| 5281 | // } | ||
| 5282 | //} | ||
| 5283 | } | ||
| 5284 | |||
| 5285 | mat4 Application::getEyeProjection(int eye) const { | 5251 | mat4 Application::getEyeProjection(int eye) const { |
| 5286 | QMutexLocker viewLocker(&_viewMutex); | 5252 | QMutexLocker viewLocker(&_viewMutex); |
| 5287 | if (isHMDMode()) { | 5253 | if (isHMDMode()) { |