mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:36:30 +02:00
Working on keyboard focus issues
This commit is contained in:
parent
cf8d2c5182
commit
5aa8398adb
5 changed files with 38 additions and 73 deletions
|
@ -6,14 +6,31 @@ import "dialogs"
|
||||||
|
|
||||||
// This is our primary 'desktop' object to which all VR dialogs and
|
// This is our primary 'desktop' object to which all VR dialogs and
|
||||||
// windows will be childed.
|
// windows will be childed.
|
||||||
Item {
|
FocusScope {
|
||||||
id: desktop
|
id: desktop
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
|
|
||||||
// Debugging help for figuring out focus issues
|
// Debugging help for figuring out focus issues
|
||||||
property var offscreenWindow;
|
property var offscreenWindow;
|
||||||
onOffscreenWindowChanged: offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged);
|
onOffscreenWindowChanged: offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged);
|
||||||
function onWindowFocusChanged() { console.log("Focus item is " + offscreenWindow.activeFocusItem); }
|
function onWindowFocusChanged() {
|
||||||
|
console.log("Focus item is " + offscreenWindow.activeFocusItem);
|
||||||
|
var focusedItem = offscreenWindow.activeFocusItem ;
|
||||||
|
if (DebugQML && focusedItem) {
|
||||||
|
var rect = desktop.mapToItem(desktop, focusedItem.x, focusedItem.y, focusedItem.width, focusedItem.height);
|
||||||
|
focusDebugger.visible = true
|
||||||
|
focusDebugger.x = rect.x;
|
||||||
|
focusDebugger.y = rect.y;
|
||||||
|
focusDebugger.width = rect.width
|
||||||
|
focusDebugger.height = rect.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: focusDebugger;
|
||||||
|
z: 9999; visible: false; color: "red"
|
||||||
|
ColorAnimation on color { from: "#7fffff00"; to: "#7f0000ff"; duration: 1000; loops: 9999 }
|
||||||
|
}
|
||||||
|
|
||||||
// Allows QML/JS to find the desktop through the parent chain
|
// Allows QML/JS to find the desktop through the parent chain
|
||||||
property bool desktopRoot: true
|
property bool desktopRoot: true
|
||||||
|
@ -184,76 +201,14 @@ Item {
|
||||||
var windows = getTopLevelWindows(predicate);
|
var windows = getTopLevelWindows(predicate);
|
||||||
fixupZOrder(windows, zBasis, targetWindow);
|
fixupZOrder(windows, zBasis, targetWindow);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function unfocusWindows() {
|
||||||
|
var windows = d.getTopLevelWindows();
|
||||||
//function findMenuChild(menu, childName) {
|
for (var i = 0; i < windows.length; ++i) {
|
||||||
// if (!menu) {
|
windows[i].focus = false;
|
||||||
// return null;
|
}
|
||||||
// }
|
desktop.focus = true;
|
||||||
|
|
||||||
// if (menu.type !== 2) {
|
|
||||||
// console.warn("Tried to find child of a non-menu");
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var items = menu.items;
|
|
||||||
// var count = items.length;
|
|
||||||
// for (var i = 0; i < count; ++i) {
|
|
||||||
// var child = items[i];
|
|
||||||
// var name;
|
|
||||||
// switch (child.type) {
|
|
||||||
// case 2:
|
|
||||||
// name = child.title;
|
|
||||||
// break;
|
|
||||||
// case 1:
|
|
||||||
// name = child.text;
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (name && name === childName) {
|
|
||||||
// return child;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//function findMenu(rootMenu, path) {
|
|
||||||
// if ('string' === typeof(path)) {
|
|
||||||
// path = [ path ]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var currentMenu = rootMenu;
|
|
||||||
// for (var i = 0; currentMenu && i < path.length; ++i) {
|
|
||||||
// currentMenu = findMenuChild(currentMenu, path[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return currentMenu;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//function findInRootMenu(item, path) {
|
|
||||||
// return findMenu(findRootMenu(item), path);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//function menuItemsToListModel(parent, items) {
|
|
||||||
// var newListModel = Qt.createQmlObject('import QtQuick 2.5; ListModel {}', parent);
|
|
||||||
// for (var i = 0; i < items.length; ++i) {
|
|
||||||
// var item = items[i];
|
|
||||||
// switch (item.type) {
|
|
||||||
// case 2:
|
|
||||||
// newListModel.append({"type":item.type, "name": item.title, "item": item})
|
|
||||||
// break;
|
|
||||||
// case 1:
|
|
||||||
// newListModel.append({"type":item.type, "name": item.text, "item": item})
|
|
||||||
// break;
|
|
||||||
// case 0:
|
|
||||||
// newListModel.append({"type":item.type, "name": "-----", "item": item})
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return newListModel;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2191,6 +2191,11 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
_altPressed = false;
|
_altPressed = false;
|
||||||
|
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
// If we get a mouse press event it means it wasn't consumed by the offscreen UI,
|
||||||
|
// hence, we should defocus all of the offscreen UI windows, in order to allow
|
||||||
|
// keyboard shortcuts not to be swallowed by them. In particular, WebEngineViews
|
||||||
|
// will consume all keyboard events.
|
||||||
|
offscreenUi->unfocusWindows();
|
||||||
QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget);
|
QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget);
|
||||||
QMouseEvent mappedEvent(event->type(),
|
QMouseEvent mappedEvent(event->type(),
|
||||||
transformedPos,
|
transformedPos,
|
||||||
|
|
|
@ -279,5 +279,10 @@ QVariant OffscreenUi::returnFromUiThread(std::function<QVariant()> function) {
|
||||||
return function();
|
return function();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OffscreenUi::unfocusWindows() {
|
||||||
|
bool invokeResult = QMetaObject::invokeMethod(_desktop, "unfocusWindows");
|
||||||
|
Q_ASSERT(invokeResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "OffscreenUi.moc"
|
#include "OffscreenUi.moc"
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
bool shouldSwallowShortcut(QEvent* event);
|
bool shouldSwallowShortcut(QEvent* event);
|
||||||
bool navigationFocused();
|
bool navigationFocused();
|
||||||
void setNavigationFocused(bool focused);
|
void setNavigationFocused(bool focused);
|
||||||
|
void unfocusWindows();
|
||||||
QQuickItem* getDesktop();
|
QQuickItem* getDesktop();
|
||||||
QQuickItem* getToolWindow();
|
QQuickItem* getToolWindow();
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ ApplicationWindow {
|
||||||
Root {
|
Root {
|
||||||
id: desktop
|
id: desktop
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
StubMenu { id: stubMenu }
|
StubMenu { id: stubMenu }
|
||||||
|
Component.onCompleted: offscreenWindow = appWindow
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
id: testButtons
|
id: testButtons
|
||||||
|
|
Loading…
Reference in a new issue