Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 207f86b

Browse files
authored
Ensure only focused controller is used for resize and moving (#3149)
Fixes #2990 Fixes #3147 Note: This only fixes the crash from #3147. The issue of the resize not being saved is still issue #2862.
1 parent ee7d323 commit 207f86b

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,15 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
371371
VRBrowser::HandleBack();
372372
}
373373

374+
375+
const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
376+
controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
377+
const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
378+
controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;
379+
374380
if (!controller.focused) {
375381
const bool focusRequested =
376-
((controller.buttonState & ControllerDelegate::BUTTON_TRIGGER) && (controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER) == 0) ||
382+
(pressed && !wasPressed) ||
377383
((controller.buttonState & ControllerDelegate::BUTTON_A) && (controller.lastButtonState & ControllerDelegate::BUTTON_A) == 0) ||
378384
((controller.buttonState & ControllerDelegate::BUTTON_B) && (controller.lastButtonState & ControllerDelegate::BUTTON_B) == 0) ||
379385
((controller.buttonState & ControllerDelegate::BUTTON_X) && (controller.lastButtonState & ControllerDelegate::BUTTON_X) == 0) ||
@@ -391,34 +397,31 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
391397
vrb::Vector hitPoint;
392398
vrb::Vector hitNormal;
393399

394-
const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
395-
controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
396-
const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
397-
controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;
398-
399400
bool isResizing = resizingWidget && resizingWidget->IsResizingActive();
400-
bool isDragging = pressed && wasPressed && controller.widget && !isResizing;
401+
WidgetPtr previousWidget = controller.widget ? GetWidget(controller.widget) : nullptr;
402+
bool isDragging = pressed && wasPressed && previousWidget && !isResizing;
401403
if (isDragging) {
402-
WidgetPtr widget = GetWidget(controller.widget);
403404
vrb::Vector result;
404405
vrb::Vector normal;
405406
float distance = 0.0f;
406407
bool isInWidget = false;
407-
if (widget->TestControllerIntersection(start, direction, result, normal, false, isInWidget, distance)) {
408-
hitWidget = widget;
408+
if (previousWidget->TestControllerIntersection(start, direction, result, normal, false,
409+
isInWidget, distance)) {
410+
hitWidget = previousWidget;
409411
hitPoint = result;
410412
hitNormal = normal;
411413
}
412-
413414
} else {
414415
for (const WidgetPtr& widget: widgets) {
415-
if (isResizing && resizingWidget != widget) {
416-
// Don't interact with other widgets when resizing gesture is active.
417-
continue;
418-
}
419-
if (movingWidget && movingWidget->GetWidget() != widget) {
420-
// Don't interact with other widgets when moving gesture is active.
421-
continue;
416+
if (controller.focused) {
417+
if (isResizing && resizingWidget != widget) {
418+
// Don't interact with other widgets when resizing gesture is active.
419+
continue;
420+
}
421+
if (movingWidget && movingWidget->GetWidget() != widget) {
422+
// Don't interact with other widgets when moving gesture is active.
423+
continue;
424+
}
422425
}
423426
vrb::Vector result;
424427
vrb::Vector normal;
@@ -436,7 +439,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
436439
}
437440
}
438441

439-
if ((!hitWidget || !hitWidget->IsResizing()) && resizingWidget) {
442+
if (controller.focused && (!hitWidget || !hitWidget->IsResizing()) && resizingWidget) {
440443
resizingWidget->HoverExitResize();
441444
resizingWidget.reset();
442445
}
@@ -453,7 +456,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
453456
}
454457
}
455458

456-
if (movingWidget && movingWidget->IsMoving(controller.index)) {
459+
if (controller.focused && movingWidget && movingWidget->IsMoving(controller.index)) {
457460
if (!pressed && wasPressed) {
458461
movingWidget->EndMoving();
459462
} else {
@@ -463,7 +466,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
463466
aRelayoutWidgets = true;
464467
}
465468
}
466-
} else if (hitWidget && hitWidget->IsResizing() && controller.focused) {
469+
} else if (controller.focused && hitWidget && hitWidget->IsResizing()) {
467470
bool aResized = false, aResizeEnded = false;
468471
hitWidget->HandleResize(hitPoint, pressed, aResized, aResizeEnded);
469472

0 commit comments

Comments
 (0)