Skip to content

glfwSetCursor effect not visible until mouse moves #2843

@malytomas

Description

@malytomas

Changing cursor (the picture of the mouse) is not immediately applied, and only becomes visible when mouse moves (or another mouse event, eg. button press/release).

My use case is to change the cursor while holding LMB when hovering a button. The observed behavior is that the cursor was changing after next event, eg. pressed cursor visible when not holding a button, and released cursor visible while holding a button, the exact opposite of the intend.

This issue was observed on windows 10, with glfw 9352d8f (2026-01-12).

My solution is to send new message after changing the cursor:

	void Window::cursor(Holder<Cursor> &&c)
	{
		WindowImpl *impl = (WindowImpl *)this;
		if (+impl->currentCursor == +c)
			return;

		if (c)
			glfwSetCursor(impl->window, getCursor(+c));
		else
			glfwSetCursor(impl->window, nullptr);
		impl->currentCursor = std::move(c);

		// force glfw to update the cursor
		cageGlfwPokeCursor(this);
	}


	void cageGlfwPokeCursor(Window *w)
	{
		//double x = 0, y = 0;
		//glfwGetCursorPos(impl->window, &x, &y);
		//glfwSetCursorPos(impl->window, x + 1, y);
		//glfwSetCursorPos(impl->window, x, y);
#ifdef _WIN32
		HWND hwnd = getWindowHwnd(w);
		SendMessage(hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
#endif
	}

This solves the problem. My understanding is that this message requests the application to update the cursor, as if it just entered the client area. I am unsure if there are any undesirable side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsWin32 specific (not Cygwin or WSL)bugBug reports and bugfix pull requestsinputKeyboard, joystick or mouse

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions