diff options
Diffstat (limited to 'Ryujinx.SDL2.Common/SDL2Driver.cs')
-rw-r--r-- | Ryujinx.SDL2.Common/SDL2Driver.cs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Ryujinx.SDL2.Common/SDL2Driver.cs b/Ryujinx.SDL2.Common/SDL2Driver.cs index edd634ee..cc8e7614 100644 --- a/Ryujinx.SDL2.Common/SDL2Driver.cs +++ b/Ryujinx.SDL2.Common/SDL2Driver.cs @@ -1,5 +1,7 @@ using Ryujinx.Common.Logging; using System; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; using System.Threading; using static SDL2.SDL; @@ -25,7 +27,7 @@ namespace Ryujinx.SDL2.Common } } - private const uint SdlInitFlags = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO; + private const uint SdlInitFlags = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_VIDEO; private bool _isRunning; private uint _refereceCount; @@ -34,6 +36,8 @@ namespace Ryujinx.SDL2.Common public event Action<int, int> OnJoyStickConnected; public event Action<int> OnJoystickDisconnected; + private ConcurrentDictionary<uint, Action<SDL_Event>> _registeredWindowHandlers; + private object _lock = new object(); private SDL2Driver() {} @@ -85,12 +89,23 @@ namespace Ryujinx.SDL2.Common SDL_GameControllerAddMappingsFromFile(gamepadDbPath); } + _registeredWindowHandlers = new ConcurrentDictionary<uint, Action<SDL_Event>>(); _worker = new Thread(EventWorker); _isRunning = true; _worker.Start(); } } + public bool RegisterWindow(uint windowId, Action<SDL_Event> windowEventHandler) + { + return _registeredWindowHandlers.TryAdd(windowId, windowEventHandler); + } + + public void UnregisterWindow(uint windowId) + { + _registeredWindowHandlers.Remove(windowId, out _); + } + private void HandleSDLEvent(ref SDL_Event evnt) { if (evnt.type == SDL_EventType.SDL_JOYDEVICEADDED) @@ -115,6 +130,13 @@ namespace Ryujinx.SDL2.Common OnJoystickDisconnected?.Invoke(evnt.cbutton.which); } + else if (evnt.type == SDL_EventType.SDL_WINDOWEVENT || evnt.type == SDL_EventType.SDL_MOUSEBUTTONDOWN || evnt.type == SDL_EventType.SDL_MOUSEBUTTONUP) + { + if (_registeredWindowHandlers.TryGetValue(evnt.window.windowID, out Action<SDL_Event> handler)) + { + handler(evnt); + } + } } private void EventWorker() |