wait-events win32 implementation

This commit is contained in:
Doug Binks 2025-11-21 16:29:27 +00:00
parent 5cdd0b4cdf
commit 38011e1e07
7 changed files with 64 additions and 4 deletions

View File

@ -376,6 +376,8 @@ void _glfwInputError(int code, const char* format, ...)
if (_glfwErrorCallback)
_glfwErrorCallback(code, description);
_glfw.newEventsRcvd = GLFW_TRUE;
}

View File

@ -301,6 +301,8 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
if (window->callbacks.key)
window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a Unicode codepoint input event
@ -326,6 +328,8 @@ void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool
if (window->callbacks.character)
window->callbacks.character((GLFWwindow*) window, codepoint);
}
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a scroll event
@ -340,6 +344,8 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
if (window->callbacks.scroll)
window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a mouse button click event
@ -367,6 +373,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
if (window->callbacks.mouseButton)
window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a cursor motion event
@ -388,6 +396,8 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
if (window->callbacks.cursorPos)
window->callbacks.cursorPos((GLFWwindow*) window, xpos, ypos);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a cursor enter/leave event
@ -399,6 +409,8 @@ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered)
if (window->callbacks.cursorEnter)
window->callbacks.cursorEnter((GLFWwindow*) window, entered);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of files or directories dropped on a window
@ -411,6 +423,8 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
if (window->callbacks.drop)
window->callbacks.drop((GLFWwindow*) window, count, paths);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of a joystick connection or disconnection
@ -427,6 +441,8 @@ void _glfwInputJoystick(_GLFWjoystick* js, int event)
if (_glfw.callbacks.joystick)
_glfw.callbacks.joystick((int) (js - _glfw.joysticks), event);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of the new value of a joystick axis
@ -450,6 +466,8 @@ void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
assert(value == GLFW_PRESS || value == GLFW_RELEASE);
js->buttons[button] = value;
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code of the new value of a joystick hat
@ -476,6 +494,8 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
js->buttons[base + 3] = (value & 0x08) ? GLFW_PRESS : GLFW_RELEASE;
js->hats[hat] = value;
_glfw.newEventsRcvd = GLFW_TRUE;
}

View File

@ -793,6 +793,8 @@ struct _GLFWlibrary
_GLFWtls contextSlot;
_GLFWmutex errorLock;
GLFWbool newEventsRcvd;
struct {
uint64_t offset;
// This is defined in platform.h

View File

@ -150,6 +150,8 @@ void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement)
if (action == GLFW_DISCONNECTED)
_glfwFreeMonitor(monitor);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a full screen window has acquired or released
@ -159,6 +161,8 @@ void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window)
{
assert(monitor != NULL);
monitor->window = window;
_glfw.newEventsRcvd = GLFW_TRUE;
}

View File

@ -357,6 +357,9 @@ static LRESULT CALLBACK helperWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
break;
}
case WM_NULL:
_glfw.newEventsRcvd = GLFW_TRUE;
return 0;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);

View File

@ -2171,16 +2171,23 @@ void _glfwPollEventsWin32(void)
void _glfwWaitEventsWin32(void)
{
WaitMessage();
while (_glfw.newEventsRcvd == GLFW_FALSE)
{
WaitMessage();
_glfwPollEventsWin32();
_glfwPollEventsWin32();
}
}
void _glfwWaitEventsTimeoutWin32(double timeout)
{
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLINPUT);
DWORD ret;
do
{
ret = MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLINPUT);
_glfwPollEventsWin32();
_glfwPollEventsWin32();
} while (_glfw.newEventsRcvd == GLFW_FALSE || ret == WAIT_TIMEOUT);
}
void _glfwPostEmptyEventWin32(void)

View File

@ -67,6 +67,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused)
_glfwInputMouseClick(window, button, GLFW_RELEASE, 0);
}
}
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window has moved
@ -78,6 +80,8 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
if (window->callbacks.pos)
window->callbacks.pos((GLFWwindow*) window, x, y);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window has been resized
@ -91,6 +95,8 @@ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
if (window->callbacks.size)
window->callbacks.size((GLFWwindow*) window, width, height);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window has been iconified or restored
@ -102,6 +108,8 @@ void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified)
if (window->callbacks.iconify)
window->callbacks.iconify((GLFWwindow*) window, iconified);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window has been maximized or restored
@ -113,6 +121,8 @@ void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized)
if (window->callbacks.maximize)
window->callbacks.maximize((GLFWwindow*) window, maximized);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window framebuffer has been resized
@ -126,6 +136,8 @@ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
if (window->callbacks.fbsize)
window->callbacks.fbsize((GLFWwindow*) window, width, height);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window content scale has changed
@ -141,6 +153,8 @@ void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscal
if (window->callbacks.scale)
window->callbacks.scale((GLFWwindow*) window, xscale, yscale);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that the window contents needs updating
@ -151,6 +165,8 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
if (window->callbacks.refresh)
window->callbacks.refresh((GLFWwindow*) window);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that the user wishes to close a window
@ -163,6 +179,8 @@ void _glfwInputWindowCloseRequest(_GLFWwindow* window)
if (window->callbacks.close)
window->callbacks.close((GLFWwindow*) window);
_glfw.newEventsRcvd = GLFW_TRUE;
}
// Notifies shared code that a window has changed its desired monitor
@ -171,6 +189,8 @@ void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor)
{
assert(window != NULL);
window->monitor = monitor;
_glfw.newEventsRcvd = GLFW_TRUE;
}
//////////////////////////////////////////////////////////////////////////
@ -1172,6 +1192,7 @@ GLFWAPI void glfwPollEvents(void)
GLFWAPI void glfwWaitEvents(void)
{
_GLFW_REQUIRE_INIT();
_glfw.newEventsRcvd = GLFW_FALSE;
_glfw.platform.waitEvents();
}
@ -1188,6 +1209,7 @@ GLFWAPI void glfwWaitEventsTimeout(double timeout)
return;
}
_glfw.platform.waitEvents();
_glfw.platform.waitEventsTimeout(timeout);
}