diff options
author | Mary <me@thog.eu> | 2021-07-06 22:08:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 22:08:44 +0200 |
commit | 31cbd09a75a9d5f4814c3907a060e0961eb2bb15 (patch) | |
tree | 094863555b29fcb254e023e9bf9a46f929b04fc2 /Ryujinx.SDL2.Common/SDL2Driver.cs | |
parent | d125fce3e8c780c042040ac8064155cd6751d353 (diff) |
frontend: Add a SDL2 headless window (#2310)
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() |