Skip to content

Commit eedd22e

Browse files
authored
Merge pull request #358 from tesonep/Cog
Win32 Events when using SDL
2 parents f472104 + 231a175 commit eedd22e

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

platforms/win32/vm/sqWin32Window.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ LRESULT CALLBACK MainWndProcA(HWND hwnd,
251251
UINT message,
252252
WPARAM wParam,
253253
LPARAM lParam) {
254+
254255
return DefWindowProc(hwnd, message, wParam, lParam);
255256
}
256257

@@ -265,6 +266,30 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
265266
UINT timeNow = 0;
266267
UINT timeDelta = 0;
267268

269+
MSG localMessage;
270+
LPMSG messageTouse = NULL;
271+
272+
/*
273+
* Newspeak uses the lastMessage pointer.
274+
*/
275+
#if NewspeakVM
276+
messageTouse = lastMessage;
277+
#else
278+
messageTouse = &localMessage;
279+
280+
localMessage.hwnd = hwnd;
281+
localMessage.message = message;
282+
localMessage.wParam = wParam;
283+
localMessage.lParam = lParam;
284+
localMessage.time = GetMessageTime();
285+
286+
DWORD point = GetMessagePos();
287+
288+
localMessage.pt.x = MAKEPOINTS(point).x;
289+
localMessage.pt.y = MAKEPOINTS(point).y;
290+
#endif /*NewspeakVM */
291+
292+
268293
/* Intercept any messages if wanted */
269294
if(preMessageHook)
270295
if((*preMessageHook)(hwnd, message,wParam, lParam))
@@ -285,7 +310,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
285310
if(inputSemaphoreIndex) {
286311
sqKeyboardEvent *evt = (sqKeyboardEvent*) sqNextEventPut();
287312
evt->type = EventTypeKeyboard;
288-
evt->timeStamp = lastMessage->time;
313+
evt->timeStamp = messageTouse->time;
289314
evt->charCode = (zDelta > 0) ? 30 : 31;
290315
evt->pressCode = EventKeyChar;
291316
/* N.B. on iOS & X11 all meta bits are set to distinguish mouse wheel
@@ -366,7 +391,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
366391
nrClicks = 0;
367392

368393
if(inputSemaphoreIndex) {
369-
recordMouseEvent(lastMessage, nrClicks);
394+
recordMouseEvent(messageTouse, nrClicks);
370395
break;
371396
}
372397
/* state based stuff */
@@ -393,7 +418,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
393418
lastClickTime = timeNow;
394419

395420
if(inputSemaphoreIndex) {
396-
recordMouseEvent(lastMessage, nrClicks);
421+
recordMouseEvent(messageTouse, nrClicks);
397422
break;
398423
}
399424
/* state based stuff */
@@ -425,7 +450,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
425450
if(GetFocus() != stWindow) SetFocus(stWindow);
426451
ReleaseCapture(); /* release mouse capture */
427452
if(inputSemaphoreIndex) {
428-
recordMouseEvent(lastMessage, nrClicks);
453+
recordMouseEvent(messageTouse, nrClicks);
429454
break;
430455
}
431456
/* state based stuff */
@@ -445,7 +470,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
445470
if(GetFocus() == consoleWindow)
446471
return DefWindowProcW(hwnd, message, wParam, lParam);
447472
if(inputSemaphoreIndex) {
448-
recordKeyboardEvent(lastMessage);
473+
recordKeyboardEvent(messageTouse);
449474
if(wParam == VK_F2 && prefsEnableF2Menu()) {
450475
TrackPrefsMenu();
451476
}
@@ -465,7 +490,7 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
465490
if(GetFocus() == consoleWindow)
466491
return DefWindowProcW(hwnd, message, wParam, lParam);
467492
if(inputSemaphoreIndex) {
468-
recordKeyboardEvent(lastMessage);
493+
recordKeyboardEvent(messageTouse);
469494
break;
470495
}
471496
/* state based stuff */
@@ -475,11 +500,13 @@ LRESULT CALLBACK MainWndProcW(HWND hwnd,
475500
case WM_CHAR:
476501
case WM_SYSCHAR:
477502
if(GetFocus() == consoleWindow)
478-
return DefWindowProcW(hwnd, message, wParam, lParam);
503+
return DefWindowProcW(hwnd, message, wParam, lParam);
504+
479505
if(inputSemaphoreIndex) {
480-
recordKeyboardEvent(lastMessage);
506+
recordKeyboardEvent(messageTouse);
481507
break;
482508
}
509+
483510
/* state based stuff */
484511
recordModifierButtons();
485512
recordKeystroke(message,wParam,lParam);
@@ -1623,6 +1650,7 @@ sqInt ioRelinquishProcessorForMicroseconds(sqInt microSeconds)
16231650
return microSeconds;
16241651
}
16251652

1653+
16261654
sqInt ioProcessEvents(void)
16271655
{ static MSG msg;
16281656
int result;
@@ -1652,26 +1680,21 @@ sqInt ioProcessEvents(void)
16521680
if (inIOProcessEvents) return -1;
16531681
inIOProcessEvents += 1;
16541682

1655-
/* WinCE doesn't retrieve WM_PAINTs from the queue with PeekMessage,
1656-
so we won't get anything painted unless we use GetMessage() if there
1657-
is a dirty rect. */
1658-
lastMessage = &msg;
1659-
16601683
#ifdef PharoVM
16611684
if(ioCheckForEventsHooks) {
16621685
/* HACK for SDL 2 */
16631686
ioCheckForEventsHooks();
16641687
}
16651688
else {
16661689

1667-
while(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) {
1668-
GetMessage(&msg,NULL,0,0);
1690+
while(PeekMessageW(&msg,NULL,0,0,PM_NOREMOVE)) {
1691+
GetMessageW(&msg,NULL,0,0);
16691692
# ifndef NO_PLUGIN_SUPPORT
16701693
if (msg.hwnd == NULL)
16711694
pluginHandleEvent(&msg);
16721695
# endif
16731696
TranslateMessage(&msg);
1674-
DispatchMessage(&msg);
1697+
DispatchMessageW(&msg);
16751698

16761699
}
16771700
}
@@ -1698,8 +1721,6 @@ sqInt ioProcessEvents(void)
16981721
&& !IsWindow(browserWindow))
16991722
ioExit();
17001723

1701-
lastMessage = NULL;
1702-
17031724
if (inIOProcessEvents > 0)
17041725
inIOProcessEvents -= 1;
17051726

0 commit comments

Comments
 (0)