From d891960064b71de47e9670d2bf398e9c1ee01930 Mon Sep 17 00:00:00 2001 From: Dylan Perks <11160611+Perksey@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:32:04 -0500 Subject: [PATCH] Fire GLFW joystick events (#1992) * Fire GLFW joystick events * Sneak in a fix for #1862 as well --- src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs | 24 ++++++++++++++++--- .../Silk.NET.Windowing.Sdl/SdlWindow.cs | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs b/src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs index de3caa346f..3ccfb7d164 100644 --- a/src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs +++ b/src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs @@ -57,17 +57,29 @@ public unsafe void Update() for (var i = 0; i < btnCount; i++) { - ((Button[]) Buttons)[i] = new Button(ButtonName.Unknown, i, btn[i] == (int) InputAction.Press); + var thisBtn = new Button(ButtonName.Unknown, i, btn[i] == (int) InputAction.Press); + var shouldInvoke = ((Button[]) Buttons)[i].Pressed != thisBtn.Pressed; + ((Button[]) Buttons)[i] = thisBtn; + if (shouldInvoke) + { + (thisBtn.Pressed ? ButtonDown : ButtonUp)?.Invoke(this, thisBtn); + } } for (var i = 0; i < axisCount; i++) { - ((Axis[]) Axes)[i] = new Axis(i, axes[i]); + var thisAxis = new Axis(i, Deadzone.Apply(axes[i])); + var shouldInvoke = ((Axis[]) Axes)[i].Position != thisAxis.Position; + ((Axis[]) Axes)[i] = thisAxis; + if (shouldInvoke) + { + AxisMoved?.Invoke(this, thisAxis); + } } for (var i = 0; i < hatCount; i++) { - ((Hat[]) Hats)[i] = new Hat + var thisHat = new Hat ( i, hats[i] switch { @@ -83,6 +95,12 @@ public unsafe void Update() _ => Position2D.Centered } ); + var shouldInvoke = ((Hat[]) Hats)[i].Position != thisHat.Position; + ((Hat[]) Hats)[i] = thisHat; + if (shouldInvoke) + { + HatMoved?.Invoke(this, thisHat); + } } if (!_connected) diff --git a/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs b/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs index 2a523600bb..c2d6d394ad 100644 --- a/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs +++ b/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs @@ -451,8 +451,8 @@ protected override void CoreInitialize(ViewOptions opts) }; CoreInitialize ( - opts, flags, InitialMonitor?.Bounds.Origin.X + Position.X, - InitialMonitor?.Bounds.Origin.Y + Position.Y, Size.X, Size.Y, Title, SharedContext + opts, flags, (InitialMonitor?.Bounds.Origin.X ?? 0) + _extendedOptionsCache.Position.X, + (InitialMonitor?.Bounds.Origin.Y ?? 0) + _extendedOptionsCache.Position.Y, Size.X, Size.Y, Title, SharedContext ); } }