Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all
Unified · Split
| @@ -673,12 +673,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 672 unmodified lines | ||
| 673 | 673 | auto& packetReceiver = nodeList->getPacketReceiver(); |
| 674 | 674 | packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); |
| 675 | 675 | |
| 676 | + // If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it | |
| 676 | 677 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 677 | 678 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, |
| 678 | 679 | [this, entityScriptingInterface](const EntityItemID& entityItemID, const MouseEvent& event) { |
| 679 | 680 | if (_keyboardFocusedItem != entityItemID) { |
| 680 | 681 | _keyboardFocusedItem = UNKNOWN_ENTITY_ID; |
| 681 | − qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; | |
| 682 | + qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; | |
| 682 | 683 | auto properties = entityScriptingInterface->getEntityProperties(entityItemID); |
| 683 | 684 | if (EntityTypes::Web == properties.getType() && !properties.getLocked()) { |
| 684 | 685 | auto entity = entityScriptingInterface->getEntityTree()->findEntityByID(entityItemID); |
| @@ -686,21 +687,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 1 unmodified line | ||
| 686 | 687 | if (webEntity) { |
| 687 | 688 | webEntity->setProxyWindow(_window->windowHandle()); |
| 688 | 689 | _keyboardFocusedItem = entityItemID; |
| 689 | − qDebug() << "_keyboardFocusedItem:" << entityItemID; | |
| 690 | + _lastAcceptedKeyPress = usecTimestampNow(); | |
| 691 | + qDebug() << "clickDownOnEntity.... _keyboardFocusedItem:" << entityItemID; | |
| 690 | 692 | } |
| 691 | 693 | } |
| 692 | 694 | } |
| 693 | 695 | }); |
| 694 | 696 | |
| 695 | − /* | |
| 696 | − // FIXME - need a solution for unfocusing on delayed time | |
| 697 | − connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const MouseEvent& event) { | |
| 698 | − if (_keyboardFocusedItem == entityItemID) { | |
| 699 | − _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | |
| 700 | − qDebug() << "_keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; | |
| 701 | − } | |
| 697 | + // If the user clicks somewhere where there is NO entity at all, we will release focus | |
| 698 | + connect(getEntities(), &EntityTreeRenderer::mousePressOffEntity, | |
| 699 | + [=](const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId) { | |
| 700 | + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | |
| 701 | + qDebug() << "mousePressOffEntity... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; | |
| 702 | 702 | }); |
| 703 | − */ | |
| 704 | 703 | } |
| 705 | 704 | |
| 706 | 705 | void Application::aboutToQuit() { |
| @@ -1277,6 +1276,7 @@ bool Application::event(QEvent* event) { · 570 unmodified lines | ||
| 1277 | 1276 | event->setAccepted(false); |
| 1278 | 1277 | QCoreApplication::sendEvent(webEntity->getEventHandler(), event); |
| 1279 | 1278 | if (event->isAccepted()) { |
| 1279 | + _lastAcceptedKeyPress = usecTimestampNow(); | |
| 1280 | 1280 | return true; |
| 1281 | 1281 | } |
| 1282 | 1282 | } |
| @@ -1286,6 +1286,16 @@ bool Application::event(QEvent* event) { · 3 unmodified lines | ||
| 1286 | 1286 | default: |
| 1287 | 1287 | break; |
| 1288 | 1288 | } |
| 1289 | + | |
| 1290 | + const quint64 LOSE_FOCUS_AFTER_ELAPSED_TIME = 30 * USECS_PER_SECOND; // if idle for 30 seconds, drop focus | |
| 1291 | + quint64 elapsedSinceAcceptedKeyPress = usecTimestampNow() - _lastAcceptedKeyPress; | |
| 1292 | + if (elapsedSinceAcceptedKeyPress > LOSE_FOCUS_AFTER_ELAPSED_TIME) { | |
| 1293 | + _keyboardFocusedItem = UNKNOWN_ENTITY_ID; | |
| 1294 | + qDebug() << "idle for 30 seconds.... _keyboardFocusedItem:" << UNKNOWN_ENTITY_ID; | |
| 1295 | + } else { | |
| 1296 | + qDebug() << "elapsedSinceAcceptedKeyPress:" << elapsedSinceAcceptedKeyPress; | |
| 1297 | + } | |
| 1298 | + | |
| 1289 | 1299 | } |
| 1290 | 1300 | |
| 1291 | 1301 | switch (event->type()) { |