Skip to content

Commit

Permalink
Fire GLFW joystick events (#1992)
Browse files Browse the repository at this point in the history
* Fire GLFW joystick events

* Sneak in a fix for #1862 as well
  • Loading branch information
Perksey authored Mar 21, 2024
1 parent 7c38fa2 commit d891960
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down

0 comments on commit d891960

Please sign in to comment.