From 29b5f51077f0d416cc7676488a7e4ed65d84c112 Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 28 Jan 2022 10:48:07 +0000 Subject: [PATCH] Try to work around Chrome's mouse-grab woes. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6172 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/web/ftejslib.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/engine/web/ftejslib.js b/engine/web/ftejslib.js index aa872a424..2d1600707 100644 --- a/engine/web/ftejslib.js +++ b/engine/web/ftejslib.js @@ -187,11 +187,27 @@ mergeInto(LibraryManager.library, if (!document.fullscreenElement) if (FTEC.evcb.wantfullscreen != 0) if ({{{makeDynCall('i')}}}(FTEC.evcb.wantfullscreen)) - Module['canvas'].requestFullscreen(); + { + try + { + Module['canvas'].requestFullscreen(); + } + catch(e) + { + console.log("requestFullscreen:"); + console.log(e); + } + } if (FTEC.pointerwantlock != 0 && FTEC.pointerislocked == 0) { FTEC.pointerislocked = -1; //don't repeat the request on every click. firefox has a fit at that, so require the mouse to leave the element or something before we retry. - Module['canvas'].requestPointerLock({unadjustedMovement: true}); + Module['canvas'].requestPointerLock({unadjustedMovement: true}).catch(()=>{ + Module['canvas'].requestPointerLock().then(()=>{ + console.log("Your shitty browser doesn't support disabling mouse acceleration."); + }).catch(()=>{ + FTEC.pointerislocked = 0; //failure. no real idea why. try again next frame though... + }); + }); } //fallthrough case 'mouseup': @@ -306,6 +322,7 @@ mergeInto(LibraryManager.library, {{{makeDynCall('viiii')}}}(FTEC.evcb.jbutton, gp.index, j, 0, true); console.log("Gamepad disconnected from index %d: %s", gp.index, gp.id); break; + case 'pointerlockerror': case 'pointerlockchange': case 'mozpointerlockchange': case 'webkitpointerlockchange': @@ -405,7 +422,7 @@ mergeInto(LibraryManager.library, 'touchstart', 'touchend', 'touchcancel', 'touchleave', 'touchmove', 'dragenter', 'dragover', 'drop', 'message', 'resize', - 'pointerlockchange', 'mozpointerlockchange', 'webkitpointerlockchange', + 'pointerlockerror', 'pointerlockchange', 'mozpointerlockchange', 'webkitpointerlockchange', 'focus', 'blur']; //try to fix alt-tab events.forEach(function(event) { @@ -413,7 +430,7 @@ mergeInto(LibraryManager.library, }); var docevents = ['keypress', 'keydown', 'keyup', - 'pointerlockchange', 'mozpointerlockchange', 'webkitpointerlockchange']; + 'pointerlockerror', 'pointerlockchange', 'mozpointerlockchange', 'webkitpointerlockchange']; docevents.forEach(function(event) { document.addEventListener(event, FTEC.handleevent, true);