From 39fd16fc9e9a2f7f212b7843aead634803f31164 Mon Sep 17 00:00:00 2001 From: amer cerkic Date: Wed, 3 Jul 2019 11:05:38 -0700 Subject: [PATCH 1/4] adding a null check escape to the activeItem. On right click back to root window active item becomes null instead of root item --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8ecb16b65f..0f499adf7d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5109,7 +5109,7 @@ void Application::idle() { // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus. if (offscreenUi && offscreenUi->getWindow()) { auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem(); - if (_keyboardDeviceHasFocus && activeFocusItem != offscreenUi->getRootItem()) { + if (_keyboardDeviceHasFocus && (activeFocusItem != NULL && activeFocusItem != offscreenUi->getRootItem())) { _keyboardMouseDevice->pluginFocusOutEvent(); _keyboardDeviceHasFocus = false; synthesizeKeyReleasEvents(); From 9384c5b3a35b016bd3e4d09bae9b0cacf1d19a1f Mon Sep 17 00:00:00 2001 From: amer cerkic Date: Wed, 3 Jul 2019 16:02:56 -0700 Subject: [PATCH 2/4] testing what happens (for mac specifically) when we specify the focus item to be the root, not NULL as sometimes happens when toggling between modal popups and the main window --- interface/src/Application.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d014f19770..6dc093954c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4161,6 +4161,19 @@ bool Application::event(QEvent* event) { case QEvent::FocusOut: focusOutEvent(static_cast(event)); return true; + case QEvent::FocusIn: + { //testing to see if we can set focus when focus is not set to root window. + auto offscreenUi = getOffscreenUI(); + auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem(); + + if (activeFocusItem == NULL) { + offscreenUi->getRootItem()->setEnabled(true); + offscreenUi->getRootItem()->setFocus(true, Qt::FocusReason::ActiveWindowFocusReason); + } + + return true; + } + case QEvent::TouchBegin: touchBeginEvent(static_cast(event)); event->accept(); From 84055a6f0d99740d40ce01876ad6b7e68e85d95f Mon Sep 17 00:00:00 2001 From: amerhifi Date: Mon, 8 Jul 2019 11:12:50 -0700 Subject: [PATCH 3/4] adding focus back on _glWidget --- interface/src/Application.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6dc093954c..c550c91f87 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4162,15 +4162,9 @@ bool Application::event(QEvent* event) { focusOutEvent(static_cast(event)); return true; case QEvent::FocusIn: - { //testing to see if we can set focus when focus is not set to root window. - auto offscreenUi = getOffscreenUI(); - auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem(); - - if (activeFocusItem == NULL) { - offscreenUi->getRootItem()->setEnabled(true); - offscreenUi->getRootItem()->setFocus(true, Qt::FocusReason::ActiveWindowFocusReason); - } - + { //testing to see if we can set focus when focus is not set to root window. + _glWidget->activateWindow(); + _glWidget->setFocus(); return true; } @@ -8782,6 +8776,8 @@ bool Application::isThrottleRendering() const { bool Application::hasFocus() const { bool result = (QApplication::activeWindow() != nullptr); + + #if defined(Q_OS_WIN) // On Windows, QWidget::activateWindow() - as called in setFocus() - makes the application's taskbar icon flash but doesn't // take user focus away from their current window. So also check whether the application is the user's current foreground From 335119cb58698d73745c22c32a1183b92ee37826 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Mon, 8 Jul 2019 16:50:36 -0700 Subject: [PATCH 4/4] log wakeup (on client and report to DS) during connection on Windows --- domain-server/src/DomainGatekeeper.cpp | 3 ++- domain-server/src/DomainServer.cpp | 2 +- interface/src/Application.cpp | 7 +++++++ libraries/networking/src/LimitedNodeList.cpp | 10 +++++----- libraries/networking/src/LimitedNodeList.h | 8 +++++--- libraries/networking/src/NodeList.cpp | 12 ++++++++---- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/domain-server/src/DomainGatekeeper.cpp b/domain-server/src/DomainGatekeeper.cpp index 6aaa348f6c..09a0446468 100644 --- a/domain-server/src/DomainGatekeeper.cpp +++ b/domain-server/src/DomainGatekeeper.cpp @@ -121,12 +121,13 @@ void DomainGatekeeper::processConnectRequestPacket(QSharedPointersetNodeInterestSet(safeInterestSet); nodeData->setPlaceName(nodeConnection.placeName); + QMetaEnum metaEnum = QMetaEnum::fromType(); qDebug() << "Allowed connection from node" << uuidStringWithoutCurlyBraces(node->getUUID()) << "on" << message->getSenderSockAddr() << "with MAC" << nodeConnection.hardwareAddress << "and machine fingerprint" << nodeConnection.machineFingerprint << "user" << username - << "reason" << QString(nodeConnection.connectReason ? "SilentDomainDisconnect" : "Connect") + << "reason" << QString(metaEnum.valueToKey(nodeConnection.connectReason)) << "previous connection uptime" << nodeConnection.previousConnectionUpTime/USECS_PER_MSEC << "msec" << "sysinfo" << nodeConnection.SystemInfo; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index c3a4a94c7c..b7c723ab48 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -2498,7 +2498,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } else if (allNodesDeleteRegex.indexIn(url.path()) != -1) { qDebug() << "Received request to kill all nodes."; - nodeList->eraseAllNodes(); + nodeList->eraseAllNodes(url.path()); return true; } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3c37bb6a6f..e86ade0a50 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -548,6 +548,13 @@ public: return true; } + if (message->message == WM_POWERBROADCAST) { + if (message->wParam == PBT_APMRESUMEAUTOMATIC) { + qCInfo(interfaceapp) << "Waking up from sleep or hybernation."; + QMetaObject::invokeMethod(DependencyManager::get().data(), "noteAwakening", Qt::QueuedConnection); + } + } + if (message->message == WM_COPYDATA) { COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam); QUrl url = QUrl((const char*)(pcds->lpData)); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 3519408960..7d2f085d6f 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -584,7 +584,7 @@ SharedNodePointer LimitedNodeList::nodeWithLocalID(Node::LocalID localID) const return idIter == _localIDMap.cend() ? nullptr : idIter->second; } -void LimitedNodeList::eraseAllNodes() { +void LimitedNodeList::eraseAllNodes(QString reason) { std::vector killedNodes; { @@ -593,7 +593,7 @@ void LimitedNodeList::eraseAllNodes() { QWriteLocker writeLocker(&_nodeMutex); if (_nodeHash.size() > 0) { - qCDebug(networking) << "LimitedNodeList::eraseAllNodes() removing all nodes from NodeList."; + qCDebug(networking) << "LimitedNodeList::eraseAllNodes() removing all nodes from NodeList:" << reason; killedNodes.reserve(_nodeHash.size()); for (auto& pair : _nodeHash) { @@ -611,8 +611,8 @@ void LimitedNodeList::eraseAllNodes() { _delayedNodeAdds.clear(); } -void LimitedNodeList::reset() { - eraseAllNodes(); +void LimitedNodeList::reset(QString reason) { + eraseAllNodes(reason); // we need to make sure any socket connections are gone so wait on that here _nodeSocket.clearConnections(); @@ -1258,7 +1258,7 @@ void LimitedNodeList::setLocalSocket(const HifiSockAddr& sockAddr) { qCInfo(networking) << "Local socket has changed from" << _localSockAddr << "to" << sockAddr; _localSockAddr = sockAddr; if (_hasTCPCheckedLocalSocket) { // Force a port change for NAT: - reset(); + reset("local socket change"); _nodeSocket.rebind(0); _localSockAddr.setPort(_nodeSocket.localPort()); qCInfo(networking) << "Local port changed to" << _localSockAddr.getPort(); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 5f24401b10..a61deeef96 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -111,7 +111,8 @@ public: enum ConnectReason : quint32 { Connect = 0, - SilentDomainDisconnect + SilentDomainDisconnect, + Awake }; Q_ENUM(ConnectReason); @@ -347,8 +348,8 @@ public: }; public slots: - void reset(); - void eraseAllNodes(); + void reset(QString reason); + void eraseAllNodes(QString reason); void removeSilentNodes(); @@ -358,6 +359,7 @@ public slots: virtual void sendSTUNRequest(); bool killNodeWithUUID(const QUuid& nodeUUID, ConnectionID newConnectionID = NULL_CONNECTION_ID); + void noteAwakening() { _connectReason = Awake; } private slots: void sampleConnectionStats(); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 9dd7716823..306e0155d3 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -116,7 +116,11 @@ NodeList::NodeList(char newOwnerType, int socketListenPort, int dtlsListenPort) connect(&_domainHandler, SIGNAL(connectedToDomain(QUrl)), &_keepAlivePingTimer, SLOT(start())); connect(&_domainHandler, &DomainHandler::disconnectedFromDomain, &_keepAlivePingTimer, &QTimer::stop); - connect(&_domainHandler, &DomainHandler::limitOfSilentDomainCheckInsReached, this, [this]() { _connectReason = LimitedNodeList::SilentDomainDisconnect; }); + connect(&_domainHandler, &DomainHandler::limitOfSilentDomainCheckInsReached, this, [this]() { + if (_connectReason != Awake) { + _connectReason = SilentDomainDisconnect; + } + }); // set our sockAddrBelongsToDomainOrNode method as the connection creation filter for the udt::Socket using std::placeholders::_1; @@ -259,8 +263,7 @@ void NodeList::reset(QString reason, bool skipDomainHandlerReset) { Q_ARG(bool, skipDomainHandlerReset)); return; } - - LimitedNodeList::reset(); + LimitedNodeList::reset(reason); // lock and clear our set of ignored IDs _ignoredSetLock.lockForWrite(); @@ -337,7 +340,8 @@ void NodeList::sendDomainServerCheckIn() { if (!domainIsConnected) { auto hostname = _domainHandler.getHostname(); - qCDebug(networking_ice) << "Sending connect request to domain-server at" << hostname; + QMetaEnum metaEnum = QMetaEnum::fromType(); + qCDebug(networking_ice) << "Sending connect request ( REASON:" << QString(metaEnum.valueToKey(_connectReason)) << ") to domain-server at" << hostname; // is this our localhost domain-server? // if so we need to make sure we have an up-to-date local port in case it restarted