diff options
author | Anthony Pesch <inolen@gmail.com> | 2013-08-27 16:19:39 -0700 |
---|---|---|
committer | Anthony Pesch <inolen@gmail.com> | 2013-08-27 16:19:39 -0700 |
commit | 263626010d4ef55f29ebb53d481df902eb160e6d (patch) | |
tree | eff7a921c61f753a5604e24aa353551011492792 /src | |
parent | 63e5aee15fae754383edfd9f3faa5b161efeeef3 (diff) |
support SDL_WM_ToggleFullScreen when initiated by key input
Diffstat (limited to 'src')
-rw-r--r-- | src/library_sdl.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 5b2f8379..7b1837e8 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -46,6 +46,9 @@ var LibrarySDL = { keyboardState: null, keyboardMap: {}, + canRequestFullscreen: false, + isRequestingFullscreen: false, + textInput: false, startTime: null, @@ -467,6 +470,23 @@ var LibrarySDL = { SDL.DOMButtons[event.button] = 0; } + // We can only request fullscreen as the result of user input. + // Due to this limitation, we toggle a boolean on keydown which + // SDL_WM_ToggleFullScreen will check and subsequently set another + // flag indicating for us to request fullscreen on the following + // keyup. This isn't perfect, but it enables SDL_WM_ToggleFullScreen + // to work as the result of a keypress (which is an extremely + // common use case). + if (event.type === 'keydown') { + SDL.canRequestFullscreen = true; + } else if (event.type === 'keyup') { + if (SDL.isRequestingFullscreen) { + Module['requestFullScreen'](true, true); + SDL.isRequestingFullscreen = false; + } + SDL.canRequestFullscreen = false; + } + // SDL expects a unicode character to be passed to its keydown events. // Unfortunately, the browser APIs only provide a charCode property on // keypress events, so we must backfill in keydown events with their @@ -1277,7 +1297,11 @@ var LibrarySDL = { Module['canvas'].cancelFullScreen(); return 1; } else { - return 0; + if (!SDL.canRequestFullscreen) { + return 0; + } + SDL.isRequestingFullscreen = true; + return 1; } }, |