7
7
#include <memory.h>
8
8
#include <assert.h>
9
9
10
- void * application_main_thread_id = 0 ;
11
- void * main_browser_thread_id = 0 ;
10
+ pthread_t application_thread_id = 0 ;
11
+ pthread_t main_runtime_thread_id = 0 ;
12
12
13
- volatile int saw_keydown_event_on_enter_key_on_application_main_thread = 0 ;
14
- volatile int saw_keydown_event_on_enter_key_on_main_browser_thread = 0 ;
13
+ volatile int saw_keydown_event_on_enter_key_on_application_thread = 0 ;
14
+ volatile int saw_keydown_event_on_enter_key_on_main_runtime_thread = 0 ;
15
15
volatile int saw_keypress_event_on_enter_key = 0 ;
16
16
17
17
void ReportResult (int code )
@@ -23,41 +23,41 @@ void ReportResult(int code)
23
23
exit (code );
24
24
}
25
25
26
- EM_BOOL keydown_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
26
+ EM_BOOL keydown_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
27
27
{
28
28
int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
29
- printf ("keydown_callback_on_application_main_thread received on pthread: %p, application_main_thread_id : %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
30
- assert (( void * ) pthread_self () == application_main_thread_id );
29
+ printf ("keydown_callback_on_application_thread received on pthread: %p, application_thread_id : %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
30
+ assert (pthread_self () == application_thread_id );
31
31
32
- if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_application_main_thread = 1 ;
32
+ if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_application_thread = 1 ;
33
33
return 0 ;
34
34
}
35
35
36
- EM_BOOL keydown_callback_on_main_browser_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
36
+ EM_BOOL keydown_callback_on_main_runtime_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
37
37
{
38
38
int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
39
- printf ("keydown_callback_on_main_browser_thread received on pthread: %p, main_browser_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), main_browser_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
40
- assert (( void * ) pthread_self () == main_browser_thread_id );
39
+ printf ("keydown_callback_on_main_runtime_thread received on pthread: %p, main_runtime_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), main_runtime_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
40
+ assert (pthread_self () == main_runtime_thread_id );
41
41
42
42
#if __EMSCRIPTEN_PTHREADS__
43
43
EmscriptenKeyboardEvent * duplicatedEventStruct = malloc (sizeof (* e ));
44
44
memcpy (duplicatedEventStruct , e , sizeof (* e ));
45
- emscripten_dispatch_to_thread (application_main_thread_id , EM_FUNC_SIG_IIII , keydown_callback_on_application_main_thread , duplicatedEventStruct , eventType , duplicatedEventStruct , userData );
45
+ emscripten_dispatch_to_thread (application_thread_id , EM_FUNC_SIG_IIII , keydown_callback_on_application_thread , duplicatedEventStruct , eventType , duplicatedEventStruct , userData );
46
46
#else
47
- keydown_callback_on_application_main_thread (eventType , e , userData );
47
+ keydown_callback_on_application_thread (eventType , e , userData );
48
48
#endif
49
49
50
- if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_main_browser_thread = 1 ;
50
+ if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_main_runtime_thread = 1 ;
51
51
52
52
return dom_pk_code == DOM_PK_ENTER ; // Suppress default event handling for the enter/return key so that it should not generate the keypress event.
53
53
}
54
54
55
55
56
- EM_BOOL keypress_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
56
+ EM_BOOL keypress_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
57
57
{
58
58
int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
59
- printf ("keypress_callback_on_application_main_thread received on pthread: %p, application_main_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
60
- assert (( void * ) pthread_self () == application_main_thread_id );
59
+ printf ("keypress_callback_on_application_thread received on pthread: %p, application_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
60
+ assert (pthread_self () == application_thread_id );
61
61
62
62
if (dom_pk_code == DOM_PK_ENTER )
63
63
{
@@ -68,23 +68,23 @@ EM_BOOL keypress_callback_on_application_main_thread(int eventType, const Emscri
68
68
return 0 ;
69
69
}
70
70
71
- EM_BOOL keyup_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
71
+ EM_BOOL keyup_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
72
72
{
73
73
int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
74
- printf ("keyup_callback_on_application_main_thread received on pthread: %p, application_main_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
75
- assert (( void * ) pthread_self () == application_main_thread_id );
74
+ printf ("keyup_callback_on_application_thread received on pthread: %p, application_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
75
+ assert (pthread_self () == application_thread_id );
76
76
77
77
if (dom_pk_code == DOM_PK_ENTER )
78
78
{
79
- if (!saw_keydown_event_on_enter_key_on_application_main_thread )
79
+ if (!saw_keydown_event_on_enter_key_on_application_thread )
80
80
{
81
- printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the application main thread!\n" );
81
+ printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the application thread!\n" );
82
82
ReportResult (12346 ); // FAIL
83
83
}
84
- if (!saw_keydown_event_on_enter_key_on_main_browser_thread )
84
+ if (!saw_keydown_event_on_enter_key_on_main_runtime_thread )
85
85
{
86
- printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the main browser thread!\n" );
87
- ReportResult (12347 ); // FAIL
86
+ printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the main runtime thread!\n" );
87
+ ReportResult (12347 ); // FAIL
88
88
}
89
89
if (saw_keypress_event_on_enter_key )
90
90
{
@@ -101,14 +101,14 @@ int main()
101
101
{
102
102
main_runtime_thread_id = emscripten_main_runtime_thread_id ();
103
103
assert (main_runtime_thread_id );
104
- application_main_thread_id = ( void * ) pthread_self ();
105
- assert (application_main_thread_id );
104
+ application_thread_id = pthread_self ();
105
+ assert (application_thread_id );
106
106
107
- printf ("Main runtime thread ID: %p, application main thread ID: %p\n" , main_runtime_thread_id , application_main_thread_id );
107
+ printf ("Main runtime thread ID: %p, application thread ID: %p\n" , main_runtime_thread_id , application_thread_id );
108
108
109
- emscripten_set_keydown_callback_on_thread (0 , 0 , 1 , keydown_callback_on_main_browser_thread , EM_CALLBACK_THREAD_CONTEXT_MAIN_RUNTIME_THREAD );
110
- emscripten_set_keypress_callback_on_thread (0 , 0 , 1 , keypress_callback_on_application_main_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
111
- emscripten_set_keyup_callback_on_thread (0 , 0 , 1 , keyup_callback_on_application_main_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
109
+ emscripten_set_keydown_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keydown_callback_on_main_runtime_thread , EM_CALLBACK_THREAD_CONTEXT_MAIN_RUNTIME_THREAD );
110
+ emscripten_set_keypress_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keypress_callback_on_application_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
111
+ emscripten_set_keyup_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keyup_callback_on_application_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
112
112
113
113
printf ("Please press the Enter key.\n" );
114
114
0 commit comments