Repository: dotnet/Silk.NET

Issue #350: SDL events not working for multiple windows
Created: 2020-11-18T15:26:30Z
Summary
Currently all SDL events get blindly dispatched to the window polling the message loop. Instead the events should be dispatched to the window as provided by the event's window id or (if not set) to the window having focus.
Steps to reproduce

Platform: Desktop
Framework Version: .NET Core 3


Add a second window to the basic example in the 2.0 branch
Prioritize SDL
See all events getting routed to the window calling DoEvents

Comments
Maybe something like https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Graphics/SDL/Application.cs should be introduced? What would be the proper approach?
Sadly I can't really build the solution. It's complaining about files not being found under C:\Silk.NET\... - once I move everything there, Visual Studio goes completely nuts, eating up all of my memory and in git I see >2000 or more *.gen.cs files. I guess that's not how it's supposed to be?

Duplicate issue #1550: SDL multi-window event-based input is inconsistent
Created: 2023-07-02T02:15:32Z
Summary
When utilizing event-based input via SDL in a multi-window environment events appear to get "lost".  MouseDown/MouseUp and KeyDown/KeyUp events do not consistently fire.  Presumably other input events are equally affected.  This is especially visible when trying use the "Close" widget on the window where clicking multiple times may never get processed.
Steps to reproduce

Platform: Desktop (Windows)
Framework Version: .NET Core 7
API: SDL / OpenGL
API Version: OpenGL 4.5 Core


Instantiate multiple Silk windows using the SDL backend
Attempt to read mouse clicks in various windows
Observe inconsistent input event messages

Comments
This is specific to the SDL backend only.  GLFW does not appear to exhibit this issue.
Minimum reproduceable example (This should look somewhat familiar):
using Silk.NET.Windowing;
using Silk.NET.Windowing.Extensions;
using Silk.NET.Input;
using Silk.NET.OpenGL;

namespace ogl;

public class OpenGL
{
    private WindowManager windowManager;
    private List<IInputContext> inputContexts = new List<IInputContext>();

    public OpenGL()
    {
        windowManager = new WindowManager();

        Window.PrioritizeSdl();

        for (int i = 0; i < 4; i++)
        {
            windowManager.CreateWindow(WindowOptions.Default);
        }
    }


    public void Start()
    {
        foreach(var window in windowManager.Windows)
        {
            window.Load += () =>
            {
                var inputContext = window.CreateInput();
                inputContexts.Add(inputContext);

                inputContext.Mice[0].MouseDown += OnMouseDown;
                inputContext.Mice[0].MouseUp += OnMouseUp;

                inputContext.Keyboards[0].KeyDown += OnKeyDown;
                inputContext.Keyboards[0].KeyUp += OnKeyUp;
            };

            window.Render += (time) =>
            {
                var context = GL.GetApi(window.GLContext);

                context.Enable(EnableCap.DepthTest);
                context.ClearColor(0f, .2f, .2f, 1f);
                context.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
            };
        }

        windowManager.Run();
    }

    private void OnKeyUp(IKeyboard keyboard, Key key, int arg3)
    {
        System.Diagnostics.Debug.WriteLine("Key Up : " + key);
    }

    private void OnKeyDown(IKeyboard keyboard, Key key, int arg3)
    {
        System.Diagnostics.Debug.WriteLine("Key Down : " + key);
    }

    private void OnMouseUp(IMouse mouse, MouseButton button)
    {
        System.Diagnostics.Debug.WriteLine("Mouse Down : " + button);
    }

    private void OnMouseDown(IMouse mouse, MouseButton button)
    {
        System.Diagnostics.Debug.WriteLine("Mouse Up : " + button);
    }
}

Closing comment (2023-08-21T21:53:27Z): Possibly related to #350