Skip to content

Commit e53baa1

Browse files
Nell Waliczek (HOFFMAN)facebook-github-bot
authored andcommitted
Allows mouse clicks to be used for selection with Windows Mixed Reality Headsets in Edge
Summary: Adds support for Windows Mixed Reality mouse input by responding to pointer restriction events When pointer is restricted, the only way to recieve mouse clicks is via pointerLock Release pointerlock when not restricted to enable demo driver type scenarios ## Motivation (required) Allows mouse clicks to be used for selection with Windows Mixed Reality Headsets in Edge ## Test Plan (required) Load any React-based WebVR experience in Microsoft Edge, enter VR, and ensure mouse clicks function to select and click on 3D objects Press Win+Y and ensure pointerlock is released and the mouse moves freely on the desktop Closes facebookarchive#328 Differential Revision: D5819876 Pulled By: andrewimm fbshipit-source-id: 5f6a94f
1 parent 1db36de commit e53baa1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

OVRUI/src/Player/Player.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export default class Player {
186186
(this: any).handleFullscreenChange = this.handleFullscreenChange.bind(this);
187187
(this: any).exitVR = this.exitVR.bind(this);
188188
(this: any).resetAngles = this.resetAngles.bind(this);
189+
(this: any).handlePointerRestricted = this.handlePointerRestricted.bind(this);
190+
(this: any).handlePointerUnrestricted = this.handlePointerUnrestricted.bind(this);
189191

190192
this.isMobile = isMobile;
191193
this.allowCarmelDeeplink = !!options.allowCarmelDeeplink && isSamsung;
@@ -365,11 +367,37 @@ export default class Player {
365367
// Listen for headsets that connect / disconnect after the page has loaded
366368
window.addEventListener('vrdisplayconnect', this.onDisplayConnect);
367369
window.addEventListener('vrdisplaydisconnect', this.onDisplayDisconnect);
370+
// Listen for pointer becoming restricted / unrestricted
371+
window.addEventListener('vrdisplaypointerrestricted', this.handlePointerRestricted);
372+
window.addEventListener('vrdisplaypointerunrestricted', this.handlePointerUnrestricted);
368373

369374
// Detect any VR displays, so that we can pick the proper rAF and render
370375
this.initializeDisplay();
371376
}
372377

378+
/**
379+
* Handles taking ponterlock in response to pointer input being restricted
380+
*/
381+
handlePointerRestricted() {
382+
const pointerLockElement = this.glRenderer.domElement;
383+
if (pointerLockElement && typeof(pointerLockElement.requestPointerLock) === 'function') {
384+
pointerLockElement.requestPointerLock();
385+
}
386+
}
387+
388+
/**
389+
* Handles releasing ponterlock in response to pointer input being unrestricted
390+
*/
391+
handlePointerUnrestricted() {
392+
// $FlowFixMe
393+
const currentPointerLockElement = document.pointerLockElement;
394+
const expectedPointerLockElement = this.glRenderer.domElement;
395+
if (currentPointerLockElement && currentPointerLockElement === expectedPointerLockElement
396+
&& typeof(document.exitPointerLock) === 'function') {
397+
document.exitPointerLock();
398+
}
399+
}
400+
373401
/**
374402
* When WebGL is unsupported or disabled, render an error message.
375403
* @param width - The width of the parent container

0 commit comments

Comments
 (0)