src/video/emscripten/SDL_emscriptenevents.c
author Charlie Birks <charlie@daftgames.net>
Tue, 29 Jan 2019 12:18:56 +0000
changeset 12574 109c919d61f6
parent 12573 296d155a8ce5
child 12652 b3c652757f97
permissions -rw-r--r--
Emscripten: Use set_canvas_element_size
This will be needed for supporting multiple canvases and set_canvas_size
is deprecated anyway.
icculus@9278
     1
/*
icculus@9278
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
icculus@9278
     4
icculus@9278
     5
  This software is provided 'as-is', without any express or implied
icculus@9278
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@9278
     7
  arising from the use of this software.
icculus@9278
     8
icculus@9278
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@9278
    10
  including commercial applications, and to alter it and redistribute it
icculus@9278
    11
  freely, subject to the following restrictions:
icculus@9278
    12
icculus@9278
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@9278
    14
     claim that you wrote the original software. If you use this software
icculus@9278
    15
     in a product, an acknowledgment in the product documentation would be
icculus@9278
    16
     appreciated but is not required.
icculus@9278
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@9278
    18
     misrepresented as being the original software.
icculus@9278
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@9278
    20
*/
icculus@9278
    21
icculus@9278
    22
icculus@9278
    23
#include "../../SDL_internal.h"
icculus@9278
    24
icculus@9278
    25
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
icculus@9278
    26
icculus@9278
    27
#include <emscripten/html5.h>
icculus@9278
    28
icculus@9278
    29
#include "../../events/SDL_events_c.h"
icculus@9278
    30
#include "../../events/SDL_keyboard_c.h"
icculus@9278
    31
#include "../../events/SDL_touch_c.h"
icculus@9278
    32
icculus@9278
    33
#include "SDL_emscriptenevents.h"
icculus@9278
    34
#include "SDL_emscriptenvideo.h"
icculus@9278
    35
icculus@9278
    36
#include "SDL_hints.h"
icculus@9278
    37
icculus@9278
    38
#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
icculus@9278
    39
icculus@9278
    40
/*
philipp@9601
    41
.keyCode to scancode
philipp@9601
    42
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
philipp@9601
    43
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
icculus@9278
    44
*/
icculus@9278
    45
static const SDL_Scancode emscripten_scancode_table[] = {
icculus@9278
    46
    /*  0 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    47
    /*  1 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    48
    /*  2 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    49
    /*  3 */    SDL_SCANCODE_CANCEL,
icculus@9278
    50
    /*  4 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    51
    /*  5 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    52
    /*  6 */    SDL_SCANCODE_HELP,
icculus@9278
    53
    /*  7 */    SDL_SCANCODE_UNKNOWN,
icculus@9278
    54
    /*  8 */    SDL_SCANCODE_BACKSPACE,
icculus@9278
    55
    /*  9 */    SDL_SCANCODE_TAB,
icculus@9278
    56
    /*  10 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    57
    /*  11 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    58
    /*  12 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    59
    /*  13 */   SDL_SCANCODE_RETURN,
icculus@9278
    60
    /*  14 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    61
    /*  15 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    62
    /*  16 */   SDL_SCANCODE_LSHIFT,
icculus@9278
    63
    /*  17 */   SDL_SCANCODE_LCTRL,
icculus@9278
    64
    /*  18 */   SDL_SCANCODE_LALT,
icculus@9278
    65
    /*  19 */   SDL_SCANCODE_PAUSE,
icculus@9278
    66
    /*  20 */   SDL_SCANCODE_CAPSLOCK,
icculus@9278
    67
    /*  21 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    68
    /*  22 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    69
    /*  23 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    70
    /*  24 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    71
    /*  25 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    72
    /*  26 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    73
    /*  27 */   SDL_SCANCODE_ESCAPE,
icculus@9278
    74
    /*  28 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    75
    /*  29 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    76
    /*  30 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    77
    /*  31 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    78
    /*  32 */   SDL_SCANCODE_SPACE,
icculus@9278
    79
    /*  33 */   SDL_SCANCODE_PAGEUP,
icculus@9278
    80
    /*  34 */   SDL_SCANCODE_PAGEDOWN,
icculus@9278
    81
    /*  35 */   SDL_SCANCODE_END,
icculus@9278
    82
    /*  36 */   SDL_SCANCODE_HOME,
icculus@9278
    83
    /*  37 */   SDL_SCANCODE_LEFT,
icculus@9278
    84
    /*  38 */   SDL_SCANCODE_UP,
icculus@9278
    85
    /*  39 */   SDL_SCANCODE_RIGHT,
icculus@9278
    86
    /*  40 */   SDL_SCANCODE_DOWN,
icculus@9278
    87
    /*  41 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    88
    /*  42 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    89
    /*  43 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    90
    /*  44 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    91
    /*  45 */   SDL_SCANCODE_INSERT,
icculus@9278
    92
    /*  46 */   SDL_SCANCODE_DELETE,
icculus@9278
    93
    /*  47 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
    94
    /*  48 */   SDL_SCANCODE_0,
icculus@9278
    95
    /*  49 */   SDL_SCANCODE_1,
icculus@9278
    96
    /*  50 */   SDL_SCANCODE_2,
icculus@9278
    97
    /*  51 */   SDL_SCANCODE_3,
icculus@9278
    98
    /*  52 */   SDL_SCANCODE_4,
icculus@9278
    99
    /*  53 */   SDL_SCANCODE_5,
icculus@9278
   100
    /*  54 */   SDL_SCANCODE_6,
icculus@9278
   101
    /*  55 */   SDL_SCANCODE_7,
icculus@9278
   102
    /*  56 */   SDL_SCANCODE_8,
icculus@9278
   103
    /*  57 */   SDL_SCANCODE_9,
icculus@9278
   104
    /*  58 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   105
    /*  59 */   SDL_SCANCODE_SEMICOLON,
icculus@9278
   106
    /*  60 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   107
    /*  61 */   SDL_SCANCODE_EQUALS,
icculus@9278
   108
    /*  62 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   109
    /*  63 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   110
    /*  64 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   111
    /*  65 */   SDL_SCANCODE_A,
icculus@9278
   112
    /*  66 */   SDL_SCANCODE_B,
icculus@9278
   113
    /*  67 */   SDL_SCANCODE_C,
icculus@9278
   114
    /*  68 */   SDL_SCANCODE_D,
icculus@9278
   115
    /*  69 */   SDL_SCANCODE_E,
icculus@9278
   116
    /*  70 */   SDL_SCANCODE_F,
icculus@9278
   117
    /*  71 */   SDL_SCANCODE_G,
icculus@9278
   118
    /*  72 */   SDL_SCANCODE_H,
icculus@9278
   119
    /*  73 */   SDL_SCANCODE_I,
icculus@9278
   120
    /*  74 */   SDL_SCANCODE_J,
icculus@9278
   121
    /*  75 */   SDL_SCANCODE_K,
icculus@9278
   122
    /*  76 */   SDL_SCANCODE_L,
icculus@9278
   123
    /*  77 */   SDL_SCANCODE_M,
icculus@9278
   124
    /*  78 */   SDL_SCANCODE_N,
icculus@9278
   125
    /*  79 */   SDL_SCANCODE_O,
icculus@9278
   126
    /*  80 */   SDL_SCANCODE_P,
icculus@9278
   127
    /*  81 */   SDL_SCANCODE_Q,
icculus@9278
   128
    /*  82 */   SDL_SCANCODE_R,
icculus@9278
   129
    /*  83 */   SDL_SCANCODE_S,
icculus@9278
   130
    /*  84 */   SDL_SCANCODE_T,
icculus@9278
   131
    /*  85 */   SDL_SCANCODE_U,
icculus@9278
   132
    /*  86 */   SDL_SCANCODE_V,
icculus@9278
   133
    /*  87 */   SDL_SCANCODE_W,
icculus@9278
   134
    /*  88 */   SDL_SCANCODE_X,
icculus@9278
   135
    /*  89 */   SDL_SCANCODE_Y,
icculus@9278
   136
    /*  90 */   SDL_SCANCODE_Z,
icculus@9278
   137
    /*  91 */   SDL_SCANCODE_LGUI,
icculus@9278
   138
    /*  92 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   139
    /*  93 */   SDL_SCANCODE_APPLICATION,
icculus@9278
   140
    /*  94 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   141
    /*  95 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   142
    /*  96 */   SDL_SCANCODE_KP_0,
icculus@9278
   143
    /*  97 */   SDL_SCANCODE_KP_1,
icculus@9278
   144
    /*  98 */   SDL_SCANCODE_KP_2,
icculus@9278
   145
    /*  99 */   SDL_SCANCODE_KP_3,
icculus@9278
   146
    /* 100 */   SDL_SCANCODE_KP_4,
icculus@9278
   147
    /* 101 */   SDL_SCANCODE_KP_5,
icculus@9278
   148
    /* 102 */   SDL_SCANCODE_KP_6,
icculus@9278
   149
    /* 103 */   SDL_SCANCODE_KP_7,
icculus@9278
   150
    /* 104 */   SDL_SCANCODE_KP_8,
icculus@9278
   151
    /* 105 */   SDL_SCANCODE_KP_9,
icculus@9278
   152
    /* 106 */   SDL_SCANCODE_KP_MULTIPLY,
icculus@9278
   153
    /* 107 */   SDL_SCANCODE_KP_PLUS,
icculus@9278
   154
    /* 108 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   155
    /* 109 */   SDL_SCANCODE_KP_MINUS,
icculus@9278
   156
    /* 110 */   SDL_SCANCODE_KP_PERIOD,
icculus@9278
   157
    /* 111 */   SDL_SCANCODE_KP_DIVIDE,
icculus@9278
   158
    /* 112 */   SDL_SCANCODE_F1,
icculus@9278
   159
    /* 113 */   SDL_SCANCODE_F2,
icculus@9278
   160
    /* 114 */   SDL_SCANCODE_F3,
icculus@9278
   161
    /* 115 */   SDL_SCANCODE_F4,
icculus@9278
   162
    /* 116 */   SDL_SCANCODE_F5,
icculus@9278
   163
    /* 117 */   SDL_SCANCODE_F6,
icculus@9278
   164
    /* 118 */   SDL_SCANCODE_F7,
icculus@9278
   165
    /* 119 */   SDL_SCANCODE_F8,
icculus@9278
   166
    /* 120 */   SDL_SCANCODE_F9,
icculus@9278
   167
    /* 121 */   SDL_SCANCODE_F10,
icculus@9278
   168
    /* 122 */   SDL_SCANCODE_F11,
icculus@9278
   169
    /* 123 */   SDL_SCANCODE_F12,
icculus@9278
   170
    /* 124 */   SDL_SCANCODE_F13,
icculus@9278
   171
    /* 125 */   SDL_SCANCODE_F14,
icculus@9278
   172
    /* 126 */   SDL_SCANCODE_F15,
icculus@9278
   173
    /* 127 */   SDL_SCANCODE_F16,
icculus@9278
   174
    /* 128 */   SDL_SCANCODE_F17,
icculus@9278
   175
    /* 129 */   SDL_SCANCODE_F18,
icculus@9278
   176
    /* 130 */   SDL_SCANCODE_F19,
icculus@9278
   177
    /* 131 */   SDL_SCANCODE_F20,
icculus@9278
   178
    /* 132 */   SDL_SCANCODE_F21,
icculus@9278
   179
    /* 133 */   SDL_SCANCODE_F22,
icculus@9278
   180
    /* 134 */   SDL_SCANCODE_F23,
icculus@9278
   181
    /* 135 */   SDL_SCANCODE_F24,
icculus@9278
   182
    /* 136 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   183
    /* 137 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   184
    /* 138 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   185
    /* 139 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   186
    /* 140 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   187
    /* 141 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   188
    /* 142 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   189
    /* 143 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   190
    /* 144 */   SDL_SCANCODE_NUMLOCKCLEAR,
icculus@9278
   191
    /* 145 */   SDL_SCANCODE_SCROLLLOCK,
icculus@9278
   192
    /* 146 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   193
    /* 147 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   194
    /* 148 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   195
    /* 149 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   196
    /* 150 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   197
    /* 151 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   198
    /* 152 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   199
    /* 153 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   200
    /* 154 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   201
    /* 155 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   202
    /* 156 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   203
    /* 157 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   204
    /* 158 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   205
    /* 159 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   206
    /* 160 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   207
    /* 161 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   208
    /* 162 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   209
    /* 163 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   210
    /* 164 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   211
    /* 165 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   212
    /* 166 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   213
    /* 167 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   214
    /* 168 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   215
    /* 169 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   216
    /* 170 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   217
    /* 171 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   218
    /* 172 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   219
    /* 173 */   SDL_SCANCODE_MINUS, /*FX*/
admin@10337
   220
    /* 174 */   SDL_SCANCODE_VOLUMEDOWN, /*IE, Chrome*/
admin@10337
   221
    /* 175 */   SDL_SCANCODE_VOLUMEUP, /*IE, Chrome*/
admin@10337
   222
    /* 176 */   SDL_SCANCODE_AUDIONEXT, /*IE, Chrome*/
admin@10337
   223
    /* 177 */   SDL_SCANCODE_AUDIOPREV, /*IE, Chrome*/
icculus@9278
   224
    /* 178 */   SDL_SCANCODE_UNKNOWN,
admin@10337
   225
    /* 179 */   SDL_SCANCODE_AUDIOPLAY, /*IE, Chrome*/
icculus@9278
   226
    /* 180 */   SDL_SCANCODE_UNKNOWN,
admin@10337
   227
    /* 181 */   SDL_SCANCODE_AUDIOMUTE, /*FX*/
admin@10337
   228
    /* 182 */   SDL_SCANCODE_VOLUMEDOWN, /*FX*/
admin@10337
   229
    /* 183 */   SDL_SCANCODE_VOLUMEUP, /*FX*/
icculus@9278
   230
    /* 184 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   231
    /* 185 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   232
    /* 186 */   SDL_SCANCODE_SEMICOLON, /*IE, Chrome, D3E legacy*/
icculus@9278
   233
    /* 187 */   SDL_SCANCODE_EQUALS, /*IE, Chrome, D3E legacy*/
icculus@9278
   234
    /* 188 */   SDL_SCANCODE_COMMA,
icculus@9278
   235
    /* 189 */   SDL_SCANCODE_MINUS, /*IE, Chrome, D3E legacy*/
icculus@9278
   236
    /* 190 */   SDL_SCANCODE_PERIOD,
icculus@9278
   237
    /* 191 */   SDL_SCANCODE_SLASH,
icculus@9278
   238
    /* 192 */   SDL_SCANCODE_GRAVE, /*FX, D3E legacy (SDL_SCANCODE_APOSTROPHE in IE/Chrome)*/
icculus@9278
   239
    /* 193 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   240
    /* 194 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   241
    /* 195 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   242
    /* 196 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   243
    /* 197 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   244
    /* 198 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   245
    /* 199 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   246
    /* 200 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   247
    /* 201 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   248
    /* 202 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   249
    /* 203 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   250
    /* 204 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   251
    /* 205 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   252
    /* 206 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   253
    /* 207 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   254
    /* 208 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   255
    /* 209 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   256
    /* 210 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   257
    /* 211 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   258
    /* 212 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   259
    /* 213 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   260
    /* 214 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   261
    /* 215 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   262
    /* 216 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   263
    /* 217 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   264
    /* 218 */   SDL_SCANCODE_UNKNOWN,
icculus@9278
   265
    /* 219 */   SDL_SCANCODE_LEFTBRACKET,
icculus@9278
   266
    /* 220 */   SDL_SCANCODE_BACKSLASH,
icculus@9278
   267
    /* 221 */   SDL_SCANCODE_RIGHTBRACKET,
icculus@9278
   268
    /* 222 */   SDL_SCANCODE_APOSTROPHE, /*FX, D3E legacy*/
icculus@9278
   269
};
icculus@9278
   270
icculus@9278
   271
icculus@9278
   272
/* "borrowed" from SDL_windowsevents.c */
philipp@11002
   273
static int
icculus@9278
   274
Emscripten_ConvertUTF32toUTF8(Uint32 codepoint, char * text)
icculus@9278
   275
{
icculus@9278
   276
    if (codepoint <= 0x7F) {
icculus@9278
   277
        text[0] = (char) codepoint;
icculus@9278
   278
        text[1] = '\0';
icculus@9278
   279
    } else if (codepoint <= 0x7FF) {
icculus@9278
   280
        text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
icculus@9278
   281
        text[1] = 0x80 | (char) (codepoint & 0x3F);
icculus@9278
   282
        text[2] = '\0';
icculus@9278
   283
    } else if (codepoint <= 0xFFFF) {
icculus@9278
   284
        text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
icculus@9278
   285
        text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
icculus@9278
   286
        text[2] = 0x80 | (char) (codepoint & 0x3F);
icculus@9278
   287
        text[3] = '\0';
icculus@9278
   288
    } else if (codepoint <= 0x10FFFF) {
icculus@9278
   289
        text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
icculus@9278
   290
        text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
icculus@9278
   291
        text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
icculus@9278
   292
        text[3] = 0x80 | (char) (codepoint & 0x3F);
icculus@9278
   293
        text[4] = '\0';
icculus@9278
   294
    } else {
icculus@9278
   295
        return SDL_FALSE;
icculus@9278
   296
    }
icculus@9278
   297
    return SDL_TRUE;
icculus@9278
   298
}
icculus@9278
   299
icculus@10976
   300
static EM_BOOL
icculus@10976
   301
Emscripten_HandlePointerLockChange(int eventType, const EmscriptenPointerlockChangeEvent *changeEvent, void *userData)
icculus@10976
   302
{
icculus@10976
   303
    SDL_WindowData *window_data = (SDL_WindowData *) userData;
icculus@10976
   304
    /* keep track of lock losses, so we can regrab if/when appropriate. */
icculus@10976
   305
    window_data->has_pointer_lock = changeEvent->isActive;
icculus@10976
   306
    return 0;
icculus@10976
   307
}
icculus@10976
   308
icculus@10976
   309
philipp@11002
   310
static EM_BOOL
icculus@9278
   311
Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
icculus@9278
   312
{
icculus@9278
   313
    SDL_WindowData *window_data = userData;
icculus@10976
   314
    const int isPointerLocked = window_data->has_pointer_lock;
boris@10325
   315
    int mx, my;
boris@10325
   316
    static double residualx = 0, residualy = 0;
icculus@9278
   317
boris@10325
   318
    /* rescale (in case canvas is being scaled)*/
boris@10325
   319
    double client_w, client_h, xscale, yscale;
boris@10325
   320
    emscripten_get_element_css_size(NULL, &client_w, &client_h);
boris@10326
   321
    xscale = window_data->window->w / client_w;
boris@10326
   322
    yscale = window_data->window->h / client_h;
boris@10325
   323
telpe@10324
   324
    if (isPointerLocked) {
boris@10325
   325
        residualx += mouseEvent->movementX * xscale;
boris@10325
   326
        residualy += mouseEvent->movementY * yscale;
boris@10325
   327
        /* Let slow sub-pixel motion accumulate. Don't lose it. */
boris@10325
   328
        mx = residualx;
boris@10325
   329
        residualx -= mx;
boris@10325
   330
        my = residualy;
boris@10325
   331
        residualy -= my;
boris@10325
   332
    } else {
boris@10325
   333
        mx = mouseEvent->canvasX * xscale;
boris@10325
   334
        my = mouseEvent->canvasY * yscale;
icculus@9278
   335
    }
icculus@9278
   336
telpe@10324
   337
    SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
icculus@9278
   338
    return 0;
icculus@9278
   339
}
icculus@9278
   340
philipp@11002
   341
static EM_BOOL
icculus@9278
   342
Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
icculus@9278
   343
{
icculus@9278
   344
    SDL_WindowData *window_data = userData;
philipp@10629
   345
    Uint8 sdl_button;
philipp@10629
   346
    Uint8 sdl_button_state;
philipp@10629
   347
    SDL_EventType sdl_event_type;
KichikuouChrome@12573
   348
    double css_w, css_h;
philipp@10629
   349
icculus@9278
   350
    switch (mouseEvent->button) {
icculus@9278
   351
        case 0:
icculus@9278
   352
            sdl_button = SDL_BUTTON_LEFT;
icculus@9278
   353
            break;
icculus@9278
   354
        case 1:
icculus@9278
   355
            sdl_button = SDL_BUTTON_MIDDLE;
icculus@9278
   356
            break;
icculus@9278
   357
        case 2:
icculus@9278
   358
            sdl_button = SDL_BUTTON_RIGHT;
icculus@9278
   359
            break;
icculus@9278
   360
        default:
icculus@9278
   361
            return 0;
icculus@9278
   362
    }
slouken@10338
   363
philipp@10629
   364
    if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN) {
icculus@10976
   365
        if (SDL_GetMouse()->relative_mode && !window_data->has_pointer_lock) {
icculus@10976
   366
            emscripten_request_pointerlock(NULL, 0);  /* try to regrab lost pointer lock. */
icculus@10976
   367
        }
philipp@10629
   368
        sdl_button_state = SDL_PRESSED;
philipp@10629
   369
        sdl_event_type = SDL_MOUSEBUTTONDOWN;
philipp@10629
   370
    } else {
philipp@10629
   371
        sdl_button_state = SDL_RELEASED;
philipp@10629
   372
        sdl_event_type = SDL_MOUSEBUTTONUP;
philipp@10629
   373
    }
philipp@10629
   374
    SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
KichikuouChrome@12573
   375
KichikuouChrome@12573
   376
    /* Do not consume the event if the mouse is outside of the canvas. */
KichikuouChrome@12573
   377
    emscripten_get_element_css_size(NULL, &css_w, &css_h);
KichikuouChrome@12573
   378
    if (mouseEvent->canvasX < 0 || mouseEvent->canvasX >= css_w ||
KichikuouChrome@12573
   379
        mouseEvent->canvasY < 0 || mouseEvent->canvasY >= css_h) {
KichikuouChrome@12573
   380
        return 0;
KichikuouChrome@12573
   381
    }
KichikuouChrome@12573
   382
slouken@10338
   383
    return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
icculus@9278
   384
}
icculus@9278
   385
philipp@11002
   386
static EM_BOOL
icculus@9278
   387
Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
icculus@9278
   388
{
icculus@9278
   389
    SDL_WindowData *window_data = userData;
admin@10318
   390
admin@10320
   391
    int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
icculus@10976
   392
    const int isPointerLocked = window_data->has_pointer_lock;
admin@10320
   393
telpe@10324
   394
    if (!isPointerLocked) {
admin@10320
   395
        /* rescale (in case canvas is being scaled)*/
admin@10320
   396
        double client_w, client_h;
admin@10320
   397
        emscripten_get_element_css_size(NULL, &client_w, &client_h);
admin@10320
   398
boris@10326
   399
        mx = mx * (window_data->window->w / client_w);
boris@10326
   400
        my = my * (window_data->window->h / client_h);
telpe@10324
   401
        SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
admin@10320
   402
    }
admin@10320
   403
admin@10318
   404
    SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
slouken@10338
   405
    return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
icculus@9278
   406
}
icculus@9278
   407
philipp@11002
   408
static EM_BOOL
icculus@9278
   409
Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData)
icculus@9278
   410
{
icculus@9278
   411
    SDL_WindowData *window_data = userData;
slouken@11300
   412
    SDL_SendMouseWheel(window_data->window, 0, (float)wheelEvent->deltaX, (float)-wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL);
slouken@10338
   413
    return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE;
icculus@9278
   414
}
icculus@9278
   415
philipp@11002
   416
static EM_BOOL
icculus@9278
   417
Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, void *userData)
icculus@9278
   418
{
icculus@9278
   419
    SDL_WindowData *window_data = userData;
boris@10328
   420
    /* If the user switches away while keys are pressed (such as
boris@10328
   421
     * via Alt+Tab), key release events won't be received. */
boris@10328
   422
    if (eventType == EMSCRIPTEN_EVENT_BLUR) {
boris@10328
   423
        SDL_ResetKeyboard();
boris@10328
   424
    }
slouken@10338
   425
slouken@10338
   426
icculus@9278
   427
    SDL_SendWindowEvent(window_data->window, eventType == EMSCRIPTEN_EVENT_FOCUS ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
slouken@10338
   428
    return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
icculus@9278
   429
}
icculus@9278
   430
philipp@11002
   431
static EM_BOOL
icculus@9278
   432
Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
icculus@9278
   433
{
philipp@9591
   434
    SDL_WindowData *window_data = userData;
icculus@9278
   435
    int i;
admin@10316
   436
    double client_w, client_h;
slouken@10338
   437
    int preventDefault = 0;
icculus@9278
   438
philipp@9725
   439
    SDL_TouchID deviceId = 1;
slime73@12404
   440
    if (SDL_AddTouch(deviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
slouken@9679
   441
         return 0;
icculus@9278
   442
    }
icculus@9278
   443
admin@10316
   444
    emscripten_get_element_css_size(NULL, &client_w, &client_h);
admin@10316
   445
icculus@9278
   446
    for (i = 0; i < touchEvent->numTouches; i++) {
philipp@9591
   447
        SDL_FingerID id;
philipp@9591
   448
        float x, y;
pat@11024
   449
        int mx, my;
icculus@9278
   450
icculus@9278
   451
        if (!touchEvent->touches[i].isChanged)
icculus@9278
   452
            continue;
icculus@9278
   453
icculus@9278
   454
        id = touchEvent->touches[i].identifier;
admin@10316
   455
        x = touchEvent->touches[i].canvasX / client_w;
admin@10316
   456
        y = touchEvent->touches[i].canvasY / client_h;
icculus@9278
   457
pat@11024
   458
        mx = x * window_data->window->w;
pat@11024
   459
        my = y * window_data->window->h;
pat@11024
   460
icculus@10284
   461
        if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
icculus@10284
   462
            if (!window_data->finger_touching) {
icculus@10284
   463
                window_data->finger_touching = SDL_TRUE;
icculus@10284
   464
                window_data->first_finger = id;
pat@11024
   465
                SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
icculus@10284
   466
                SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
icculus@10284
   467
            }
icculus@10284
   468
            SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
slouken@10338
   469
beuc@12572
   470
            /* disable browser scrolling/pinch-to-zoom if app handles touch events */
slouken@10338
   471
            if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
slouken@10338
   472
                preventDefault = 1;
slouken@10338
   473
            }
icculus@10284
   474
        } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
icculus@10284
   475
            if ((window_data->finger_touching) && (window_data->first_finger == id)) {
pat@11024
   476
                SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
icculus@10284
   477
            }
icculus@9278
   478
            SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
icculus@9278
   479
        } else {
icculus@10284
   480
            if ((window_data->finger_touching) && (window_data->first_finger == id)) {
icculus@10284
   481
                SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
icculus@10284
   482
                window_data->finger_touching = SDL_FALSE;
icculus@10284
   483
            }
icculus@9278
   484
            SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
slouken@10338
   485
beuc@12572
   486
            /* block browser's simulated mousedown/mouseup on touchscreen devices */
beuc@12572
   487
            preventDefault = 1;
icculus@9278
   488
        }
icculus@9278
   489
    }
icculus@9278
   490
slouken@10338
   491
    return preventDefault;
icculus@9278
   492
}
icculus@9278
   493
philipp@11002
   494
static EM_BOOL
icculus@9278
   495
Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
icculus@9278
   496
{
icculus@9278
   497
    Uint32 scancode;
philipp@11034
   498
    SDL_bool prevent_default;
philipp@11034
   499
    SDL_bool is_nav_key;
icculus@9278
   500
icculus@9278
   501
    /* .keyCode is deprecated, but still the most reliable way to get keys */
icculus@9278
   502
    if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
icculus@9278
   503
        scancode = emscripten_scancode_table[keyEvent->keyCode];
icculus@9278
   504
icculus@9278
   505
        if (scancode != SDL_SCANCODE_UNKNOWN) {
icculus@9278
   506
icculus@9278
   507
            if (keyEvent->location == DOM_KEY_LOCATION_RIGHT) {
icculus@9278
   508
                switch (scancode) {
icculus@9278
   509
                    case SDL_SCANCODE_LSHIFT:
icculus@9278
   510
                        scancode = SDL_SCANCODE_RSHIFT;
icculus@9278
   511
                        break;
icculus@9278
   512
                    case SDL_SCANCODE_LCTRL:
icculus@9278
   513
                        scancode = SDL_SCANCODE_RCTRL;
icculus@9278
   514
                        break;
icculus@9278
   515
                    case SDL_SCANCODE_LALT:
icculus@9278
   516
                        scancode = SDL_SCANCODE_RALT;
icculus@9278
   517
                        break;
icculus@9278
   518
                    case SDL_SCANCODE_LGUI:
icculus@9278
   519
                        scancode = SDL_SCANCODE_RGUI;
icculus@9278
   520
                        break;
icculus@9278
   521
                }
icculus@9278
   522
            }
slouken@10338
   523
            SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode);
icculus@9278
   524
        }
icculus@9278
   525
    }
icculus@9278
   526
philipp@11034
   527
    prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
slouken@10338
   528
slouken@10338
   529
    /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
slouken@10338
   530
     * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
icculus@9278
   531
     */
philipp@11034
   532
    is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
philipp@11034
   533
                 keyEvent->keyCode == 9 /* tab */ ||
philipp@11034
   534
                 keyEvent->keyCode == 37 /* left */ ||
philipp@11034
   535
                 keyEvent->keyCode == 38 /* up */ ||
philipp@11034
   536
                 keyEvent->keyCode == 39 /* right */ ||
philipp@11034
   537
                 keyEvent->keyCode == 40 /* down */;
admin@11025
   538
admin@11025
   539
    if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
slouken@10338
   540
        prevent_default = SDL_FALSE;
slouken@10338
   541
slouken@10338
   542
    return prevent_default;
icculus@9278
   543
}
icculus@9278
   544
philipp@11002
   545
static EM_BOOL
icculus@9278
   546
Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
icculus@9278
   547
{
icculus@9278
   548
    char text[5];
philipp@9378
   549
    if (Emscripten_ConvertUTF32toUTF8(keyEvent->charCode, text)) {
philipp@9378
   550
        SDL_SendKeyboardText(text);
philipp@9378
   551
    }
slouken@10338
   552
    return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
icculus@9278
   553
}
icculus@9278
   554
philipp@11002
   555
static EM_BOOL
icculus@9278
   556
Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
icculus@9278
   557
{
icculus@9278
   558
    SDL_WindowData *window_data = userData;
charlie@12570
   559
    SDL_VideoDisplay *display;
charlie@12570
   560
icculus@9278
   561
    if(fullscreenChangeEvent->isFullscreen)
icculus@9278
   562
    {
icculus@9278
   563
        window_data->window->flags |= window_data->requested_fullscreen_mode;
icculus@9278
   564
icculus@9278
   565
        window_data->requested_fullscreen_mode = 0;
icculus@9278
   566
slouken@10317
   567
        if(!window_data->requested_fullscreen_mode)
slouken@10317
   568
            window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't reqest fullscreen*/
icculus@9278
   569
    }
icculus@9278
   570
    else
icculus@9278
   571
    {
icculus@9278
   572
        window_data->window->flags &= ~FULLSCREEN_MASK;
charlie@12570
   573
charlie@12570
   574
        /* reset fullscreen window if the browser left fullscreen */
charlie@12570
   575
        display = SDL_GetDisplayForWindow(window_data->window);
charlie@12570
   576
charlie@12570
   577
        if (display->fullscreen_window == window_data->window) {
charlie@12570
   578
            display->fullscreen_window = NULL;
charlie@12570
   579
        }
icculus@9278
   580
    }
icculus@9278
   581
icculus@9278
   582
    return 0;
icculus@9278
   583
}
icculus@9278
   584
philipp@11002
   585
static EM_BOOL
icculus@9278
   586
Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
icculus@9278
   587
{
icculus@9278
   588
    SDL_WindowData *window_data = userData;
csongor@10541
   589
csongor@10541
   590
    /* update pixel ratio */
admin@10895
   591
    if (window_data->window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
admin@10895
   592
        window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
admin@10895
   593
    }
csongor@10541
   594
slouken@10317
   595
    if(!(window_data->window->flags & FULLSCREEN_MASK))
icculus@9278
   596
    {
icculus@9278
   597
        /* this will only work if the canvas size is set through css */
icculus@9278
   598
        if(window_data->window->flags & SDL_WINDOW_RESIZABLE)
icculus@9278
   599
        {
icculus@9278
   600
            double w = window_data->window->w;
icculus@9278
   601
            double h = window_data->window->h;
icculus@9278
   602
icculus@9278
   603
            if(window_data->external_size) {
icculus@9278
   604
                emscripten_get_element_css_size(NULL, &w, &h);
icculus@9278
   605
            }
icculus@9278
   606
charlie@12574
   607
            emscripten_set_canvas_element_size(NULL, w * window_data->pixel_ratio, h * window_data->pixel_ratio);
icculus@9278
   608
icculus@9278
   609
            /* set_canvas_size unsets this */
icculus@9278
   610
            if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
icculus@9278
   611
                emscripten_set_element_css_size(NULL, w, h);
icculus@9278
   612
            }
icculus@9278
   613
icculus@9278
   614
            SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
icculus@9278
   615
        }
icculus@9278
   616
    }
icculus@9278
   617
icculus@9278
   618
    return 0;
icculus@9278
   619
}
icculus@9278
   620
philipp@9352
   621
EM_BOOL
slouken@10317
   622
Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData)
slouken@10317
   623
{
slouken@10317
   624
    /*this is used during fullscreen changes*/
slouken@10317
   625
    SDL_WindowData *window_data = userData;
slouken@10317
   626
slouken@10317
   627
    if(window_data->fullscreen_resize)
slouken@10317
   628
    {
slouken@10317
   629
        double css_w, css_h;
slouken@10317
   630
        emscripten_get_element_css_size(NULL, &css_w, &css_h);
slouken@10317
   631
        SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
slouken@10317
   632
    }
slouken@10317
   633
slouken@10317
   634
    return 0;
slouken@10317
   635
}
slouken@10317
   636
philipp@11002
   637
static EM_BOOL
icculus@9278
   638
Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChangeEvent *visEvent, void *userData)
icculus@9278
   639
{
icculus@9278
   640
    SDL_WindowData *window_data = userData;
icculus@9278
   641
    SDL_SendWindowEvent(window_data->window, visEvent->hidden ? SDL_WINDOWEVENT_HIDDEN : SDL_WINDOWEVENT_SHOWN, 0, 0);
icculus@9278
   642
    return 0;
icculus@9278
   643
}
icculus@9278
   644
icculus@9278
   645
void
icculus@9278
   646
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
icculus@9278
   647
{
philipp@11034
   648
    const char *keyElement;
philipp@11034
   649
icculus@9278
   650
    /* There is only one window and that window is the canvas */
icculus@9278
   651
    emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
icculus@9278
   652
icculus@9278
   653
    emscripten_set_mousedown_callback("#canvas", data, 0, Emscripten_HandleMouseButton);
admin@10319
   654
    emscripten_set_mouseup_callback("#document", data, 0, Emscripten_HandleMouseButton);
icculus@9278
   655
icculus@9278
   656
    emscripten_set_mouseenter_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
icculus@9278
   657
    emscripten_set_mouseleave_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
icculus@9278
   658
icculus@9278
   659
    emscripten_set_wheel_callback("#canvas", data, 0, Emscripten_HandleWheel);
icculus@9278
   660
boris@10327
   661
    emscripten_set_focus_callback("#window", data, 0, Emscripten_HandleFocus);
boris@10327
   662
    emscripten_set_blur_callback("#window", data, 0, Emscripten_HandleFocus);
icculus@9278
   663
icculus@9278
   664
    emscripten_set_touchstart_callback("#canvas", data, 0, Emscripten_HandleTouch);
icculus@9278
   665
    emscripten_set_touchend_callback("#canvas", data, 0, Emscripten_HandleTouch);
icculus@9278
   666
    emscripten_set_touchmove_callback("#canvas", data, 0, Emscripten_HandleTouch);
icculus@9278
   667
    emscripten_set_touchcancel_callback("#canvas", data, 0, Emscripten_HandleTouch);
icculus@9278
   668
icculus@11067
   669
    emscripten_set_pointerlockchange_callback("#document", data, 0, Emscripten_HandlePointerLockChange);
icculus@10976
   670
icculus@9278
   671
    /* Keyboard events are awkward */
philipp@11034
   672
    keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
icculus@9278
   673
    if (!keyElement) keyElement = "#window";
icculus@9278
   674
icculus@9278
   675
    emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
icculus@9278
   676
    emscripten_set_keyup_callback(keyElement, data, 0, Emscripten_HandleKey);
icculus@9278
   677
    emscripten_set_keypress_callback(keyElement, data, 0, Emscripten_HandleKeyPress);
icculus@9278
   678
icculus@9278
   679
    emscripten_set_fullscreenchange_callback("#document", data, 0, Emscripten_HandleFullscreenChange);
icculus@9278
   680
icculus@9278
   681
    emscripten_set_resize_callback("#window", data, 0, Emscripten_HandleResize);
icculus@9278
   682
icculus@9278
   683
    emscripten_set_visibilitychange_callback(data, 0, Emscripten_HandleVisibilityChange);
icculus@9278
   684
}
icculus@9278
   685
icculus@9278
   686
void
icculus@9278
   687
Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
icculus@9278
   688
{
philipp@11034
   689
    const char *target;
philipp@11034
   690
icculus@9278
   691
    /* only works due to having one window */
icculus@9278
   692
    emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
icculus@9278
   693
icculus@9278
   694
    emscripten_set_mousedown_callback("#canvas", NULL, 0, NULL);
admin@10319
   695
    emscripten_set_mouseup_callback("#document", NULL, 0, NULL);
icculus@9278
   696
icculus@9278
   697
    emscripten_set_mouseenter_callback("#canvas", NULL, 0, NULL);
icculus@9278
   698
    emscripten_set_mouseleave_callback("#canvas", NULL, 0, NULL);
icculus@9278
   699
icculus@9278
   700
    emscripten_set_wheel_callback("#canvas", NULL, 0, NULL);
icculus@9278
   701
boris@10327
   702
    emscripten_set_focus_callback("#window", NULL, 0, NULL);
boris@10327
   703
    emscripten_set_blur_callback("#window", NULL, 0, NULL);
icculus@9278
   704
icculus@9278
   705
    emscripten_set_touchstart_callback("#canvas", NULL, 0, NULL);
icculus@9278
   706
    emscripten_set_touchend_callback("#canvas", NULL, 0, NULL);
icculus@9278
   707
    emscripten_set_touchmove_callback("#canvas", NULL, 0, NULL);
icculus@9278
   708
    emscripten_set_touchcancel_callback("#canvas", NULL, 0, NULL);
icculus@9278
   709
icculus@11067
   710
    emscripten_set_pointerlockchange_callback("#document", NULL, 0, NULL);
philipp@11003
   711
philipp@11034
   712
    target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
philipp@9377
   713
    if (!target) {
philipp@9377
   714
        target = "#window";
philipp@9377
   715
    }
icculus@9278
   716
philipp@9377
   717
    emscripten_set_keydown_callback(target, NULL, 0, NULL);
philipp@9377
   718
    emscripten_set_keyup_callback(target, NULL, 0, NULL);
philipp@9377
   719
    emscripten_set_keypress_callback(target, NULL, 0, NULL);
icculus@9278
   720
icculus@9278
   721
    emscripten_set_fullscreenchange_callback("#document", NULL, 0, NULL);
icculus@9278
   722
icculus@9278
   723
    emscripten_set_resize_callback("#window", NULL, 0, NULL);
icculus@9278
   724
icculus@9278
   725
    emscripten_set_visibilitychange_callback(NULL, 0, NULL);
icculus@9278
   726
}
icculus@9278
   727
icculus@9278
   728
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
icculus@9278
   729
icculus@9278
   730
/* vi: set ts=4 sw=4 expandtab: */