mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 14:53:58 +02:00
Allow env disabling of the keyboard. Show keyboard after short delay to avoid flickers
This commit is contained in:
parent
79c68b2ecb
commit
40778d7f29
1 changed files with 47 additions and 17 deletions
|
@ -99,19 +99,33 @@ static char textArray[8192];
|
||||||
static QMetaObject::Connection _focusConnection, _focusTextConnection;
|
static QMetaObject::Connection _focusConnection, _focusTextConnection;
|
||||||
extern bool _openVrDisplayActive;
|
extern bool _openVrDisplayActive;
|
||||||
static vr::IVROverlay* _overlay { nullptr };
|
static vr::IVROverlay* _overlay { nullptr };
|
||||||
static QObject* _focusObject { nullptr };
|
static QObject* _keyboardFocusObject { nullptr };
|
||||||
static QString _existingText;
|
static QString _existingText;
|
||||||
static Qt::InputMethodHints _currentHints;
|
static Qt::InputMethodHints _currentHints;
|
||||||
extern vr::TrackedDevicePose_t _trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
|
extern vr::TrackedDevicePose_t _trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
|
||||||
|
static bool _keyboardShown { false };
|
||||||
|
static const uint32_t SHOW_KEYBOARD_DELAY_MS = 100;
|
||||||
|
|
||||||
void showOpenVrKeyboard(bool show = true) {
|
void showOpenVrKeyboard(bool show = true) {
|
||||||
if (_overlay) {
|
if (!_overlay) {
|
||||||
if (show) {
|
return;
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
}
|
||||||
_focusObject = offscreenUi->getWindow()->focusObject();
|
|
||||||
|
|
||||||
QInputMethodQueryEvent query(Qt::ImQueryInput | Qt::ImHints);
|
if (show) {
|
||||||
qApp->sendEvent(_focusObject, &query);
|
// To avoid flickering the keyboard when a text element is only briefly selected,
|
||||||
|
// show the keyboard asynchrnously after a very short delay, but only after we check
|
||||||
|
// that the current focus object is still one that is text enabled
|
||||||
|
QTimer::singleShot(SHOW_KEYBOARD_DELAY_MS, [] {
|
||||||
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
auto currentFocus = offscreenUi->getWindow()->focusObject();
|
||||||
|
QInputMethodQueryEvent query(Qt::ImEnabled | Qt::ImQueryInput | Qt::ImHints);
|
||||||
|
qApp->sendEvent(currentFocus, &query);
|
||||||
|
// Current focus isn't text enabled, bail early.
|
||||||
|
if (!query.value(Qt::ImEnabled).toBool()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// We're going to show the keyboard now...
|
||||||
|
_keyboardFocusObject = currentFocus;
|
||||||
_currentHints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt());
|
_currentHints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt());
|
||||||
vr::EGamepadTextInputMode inputMode = vr::k_EGamepadTextInputModeNormal;
|
vr::EGamepadTextInputMode inputMode = vr::k_EGamepadTextInputModeNormal;
|
||||||
if (_currentHints & Qt::ImhHiddenText) {
|
if (_currentHints & Qt::ImhHiddenText) {
|
||||||
|
@ -123,17 +137,24 @@ void showOpenVrKeyboard(bool show = true) {
|
||||||
}
|
}
|
||||||
_existingText = query.value(Qt::ImSurroundingText).toString();
|
_existingText = query.value(Qt::ImSurroundingText).toString();
|
||||||
|
|
||||||
auto showKeyboardResult = _overlay->ShowKeyboard(inputMode, lineMode, "Keyboard", 1024,
|
auto showKeyboardResult = _overlay->ShowKeyboard(inputMode, lineMode, "Keyboard", 1024,
|
||||||
_existingText.toLocal8Bit().toStdString().c_str(), false, 0);
|
_existingText.toLocal8Bit().toStdString().c_str(), false, 0);
|
||||||
|
|
||||||
mat4 headPose = toGlm(_trackedDevicePose[0].mDeviceToAbsoluteTracking);
|
if (vr::VROverlayError_None == showKeyboardResult) {
|
||||||
mat4 keyboardTransform = glm::translate(headPose, vec3(0, -0.5, -1));
|
_keyboardShown = true;
|
||||||
keyboardTransform = keyboardTransform * glm::rotate(mat4(), 3.14159f / 4.0f, vec3(-1, 0, 0));
|
// Try to position the keyboard slightly below where the user is looking.
|
||||||
auto keyboardTransformVr = toOpenVr(keyboardTransform);
|
mat4 headPose = toGlm(_trackedDevicePose[0].mDeviceToAbsoluteTracking);
|
||||||
_overlay->SetKeyboardTransformAbsolute(vr::ETrackingUniverseOrigin::TrackingUniverseStanding, &keyboardTransformVr);
|
mat4 keyboardTransform = glm::translate(headPose, vec3(0, -0.5, -1));
|
||||||
} else {
|
keyboardTransform = keyboardTransform * glm::rotate(mat4(), 3.14159f / 4.0f, vec3(-1, 0, 0));
|
||||||
_focusObject = nullptr;
|
auto keyboardTransformVr = toOpenVr(keyboardTransform);
|
||||||
|
_overlay->SetKeyboardTransformAbsolute(vr::ETrackingUniverseOrigin::TrackingUniverseStanding, &keyboardTransformVr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_keyboardFocusObject = nullptr;
|
||||||
|
if (_keyboardShown) {
|
||||||
_overlay->HideKeyboard();
|
_overlay->HideKeyboard();
|
||||||
|
_keyboardShown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +168,7 @@ void finishOpenVrKeyboardInput() {
|
||||||
// ImhDialableCharactersOnly ImhEmailCharactersOnly ImhUrlCharactersOnly ImhLatinOnly
|
// ImhDialableCharactersOnly ImhEmailCharactersOnly ImhUrlCharactersOnly ImhLatinOnly
|
||||||
QInputMethodEvent event(_existingText, QList<QInputMethodEvent::Attribute>());
|
QInputMethodEvent event(_existingText, QList<QInputMethodEvent::Attribute>());
|
||||||
event.setCommitString(newText, 0, _existingText.size());
|
event.setCommitString(newText, 0, _existingText.size());
|
||||||
qApp->sendEvent(_focusObject, &event);
|
qApp->sendEvent(_keyboardFocusObject, &event);
|
||||||
// Simulate an enter press on the top level window to trigger the action
|
// Simulate an enter press on the top level window to trigger the action
|
||||||
if (0 == (_currentHints & Qt::ImhMultiLine)) {
|
if (0 == (_currentHints & Qt::ImhMultiLine)) {
|
||||||
qApp->sendEvent(offscreenUi->getWindow(), &QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::KeyboardModifiers(), QString("\n")));
|
qApp->sendEvent(offscreenUi->getWindow(), &QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::KeyboardModifiers(), QString("\n")));
|
||||||
|
@ -155,12 +176,18 @@ void finishOpenVrKeyboardInput() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const QString DEBUG_FLAG("HIFI_DISABLE_STEAM_VR_KEYBOARD");
|
||||||
|
bool disableSteamVrKeyboard = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG);
|
||||||
|
|
||||||
void enableOpenVrKeyboard() {
|
void enableOpenVrKeyboard() {
|
||||||
|
if (disableSteamVrKeyboard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
_overlay = vr::VROverlay();
|
_overlay = vr::VROverlay();
|
||||||
|
|
||||||
_focusConnection = QObject::connect(offscreenUi->getWindow(), &QQuickWindow::focusObjectChanged, [](QObject* object) {
|
_focusConnection = QObject::connect(offscreenUi->getWindow(), &QQuickWindow::focusObjectChanged, [](QObject* object) {
|
||||||
if (object != _focusObject && _overlay) {
|
if (object != _keyboardFocusObject) {
|
||||||
showOpenVrKeyboard(false);
|
showOpenVrKeyboard(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -174,6 +201,9 @@ void enableOpenVrKeyboard() {
|
||||||
|
|
||||||
|
|
||||||
void disableOpenVrKeyboard() {
|
void disableOpenVrKeyboard() {
|
||||||
|
if (disableSteamVrKeyboard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QObject::disconnect(_focusTextConnection);
|
QObject::disconnect(_focusTextConnection);
|
||||||
QObject::disconnect(_focusConnection);
|
QObject::disconnect(_focusConnection);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue