From ce54f1b1d12dda0ff2b9ea14fff0d6f9d2a01311 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 30 Jun 2016 15:18:14 -0700 Subject: [PATCH] Improve desktop 'unfocus' functionality --- interface/resources/qml/desktop/Desktop.qml | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 27fa9692b9..59d5b435ba 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -30,6 +30,7 @@ FocusScope { if (!repositionLocked) { d.handleSizeChanged(); } + } onHeightChanged: d.handleSizeChanged(); @@ -66,7 +67,6 @@ FocusScope { if (desktop.repositionLocked) { return; } - var oldRecommendedRect = recommendedRect; var newRecommendedRectJS = (typeof Controller === "undefined") ? Qt.rect(0,0,0,0) : Controller.getRecommendedOverlayRect(); var newRecommendedRect = Qt.rect(newRecommendedRectJS.x, newRecommendedRectJS.y, @@ -311,8 +311,8 @@ FocusScope { onPinnedChanged: { if (pinned) { - nullFocus.focus = true; - nullFocus.forceActiveFocus(); + desktop.focus = true; + desktop.forceActiveFocus(); // recalculate our non-pinned children hiddenChildren = d.findMatchingChildren(desktop, function(child){ @@ -486,17 +486,31 @@ FocusScope { } function unfocusWindows() { + // First find the active focus item, and unfocus it, all the way + // up the parent chain to the window + var currentFocus = offscreenWindow.activeFocusItem; + var targetWindow = d.getDesktopWindow(currentFocus); + while (currentFocus) { + if (currentFocus === targetWindow) { + break; + } + currentFocus.focus = false; + currentFocus = currentFocus.parent; + } + + // Unfocus all windows var windows = d.getTopLevelWindows(); for (var i = 0; i < windows.length; ++i) { windows[i].focus = false; } + + // For the desktop to have active focus desktop.focus = true; + desktop.forceActiveFocus(); } FocusHack { id: focusHack; } - FocusScope { id: nullFocus; } - Rectangle { id: focusDebugger; objectName: "focusDebugger" @@ -510,5 +524,5 @@ FocusScope { enabled: DebugQML onTriggered: focusDebugger.visible = !focusDebugger.visible } - + }