Is there a way to get window under current mouse position? As far as i tested event poll isnt terribly reliable way at least under windows 10. Entering/leaving doesnt work reliably when moving real quick or when dragging (especially last event is tricky). So i decided to make workaround.
case SDL.SDL_EventType.SDL_MOUSEMOTION:
SDL.SDL_GetGlobalMouseState(out int x, out int y);
foreach (var win in windows)
{
var pos = win.Position;
var size = win.Size;
var xRel = x - pos.x;
var yRel = y - pos.y;
if (xRel > 0 && yRel > 0 && xRel < size.width && yRel < size.height)
{
InputHandler.input.Initialize(win.mainView.canvas);
InputHandler.winUnderMouse = win.windowId;
if (win.handle == SDL.SDL_GetMouseFocus())
break;
}
}
Sharp.InputHandler.ProcessMouseMove();
break;
Im using C# binding to SDL2. As you see every mouse move i test if ANY window is under mouse. Additionally, if foreach meet focused window that lie under mouse then immediately stop since focused window is practically guaranteed to be on top.
The problem is that this implementation is naive. It doesnt check “depth order” in case of overlapping windows.
Is there a way or workaround/hack to do so? via hit test or something else?
If it isnt supported, then consider it as feature request.
thanks for reading.