Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Windows Pointer Events? #3453

Open
acidicoala opened this issue Sep 3, 2020 · 2 comments
Open

Support for Windows Pointer Events? #3453

acidicoala opened this issue Sep 3, 2020 · 2 comments

Comments

@acidicoala
Copy link

Config/Build Information

Dear ImGui 1.78 (17800)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1927
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 1262.00,753.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

My Issue/Question:

Hello there. Some windows instead of sending typical mouse input messages that ImGui expects (MS docs reference), send pointer event messages (MS docs reference). Therefore mouse input does not get processed with ImGui_ImplWin32_WndProcHandler. On my end I am using a hacky fix in which I substitute pointer events with mouse input messages that ImGui expects. For example:

LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	// ...
	switch(uMsg)
	{
		case WM_POINTERDOWN:
			uMsg = WM_LBUTTONDOWN;
			break;
		case WM_POINTERUP:
			uMsg = WM_LBUTTONUP;
			break;
		case WM_POINTERWHEEL:
			uMsg = WM_MOUSEWHEEL;
			break;
		case WM_POINTERUPDATE:
			uMsg = WM_SETCURSOR;
			break;
	}
	ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
	// ...
}

I was wondering if there are any plans to support such pointer event messages in the future? Or does it already exist and I've just missed it?

@ocornut
Copy link
Owner

ocornut commented Sep 3, 2020

Hello,

I was wondering if there are any plans to support such pointer event messages in the future? Or does it already exist and I've just missed it?

It's not supported yet. I don't have such device and wouldn't be able to test for it.
Pull requests would be appreciated but I think they would need to be mindful of things discussed e.g. in #2334, #2372, #2729, #2650.

-Omar

@ocornut
Copy link
Owner

ocornut commented Apr 4, 2023

Hello there. Some windows instead of sending typical mouse input messages that ImGui expects

Could you elaborate on "some windows" ?
AFAIK the behavior is documented here:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablemouseinpointer

  • Window Store App default with EnableMouseInPointer = TRUE,
  • Other apps default with EnableMouseInPointer = FALSE, aka pointer events are not emitting mouse events.

Can you confirm your setup and if you are calling EnableMouseInPointer() and what is the result of IsMouseInPointerEnabled()?

If you have mouse-in-pointer enabled then I guess it means you are handling WM_POINTER events and you can convert them to mouse events.

This is wrong:

	switch(uMsg)
	{
		case WM_POINTERDOWN:
			uMsg = WM_LBUTTONDOWN;
			break;
		case WM_POINTERUP:
			uMsg = WM_LBUTTONUP;
			break;
		case WM_POINTERWHEEL:
			uMsg = WM_MOUSEWHEEL;
			break;
		case WM_POINTERUPDATE:
			uMsg = WM_SETCURSOR;
			break;
	}
	ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);

Because the meaning of wParam and lParam is different between WM_POINTER messages and Mouse equivalent, so this need so be remapped.

If there is a confirmation that you are using EnableMouseInPointer = TRUE; I am curious why.
We could consider adding that support in imgui_impl_win32 but it seems like a edge case for something you would normally already be able to do if EnableMouseInPointer = TRUE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants