Skip to content

Commit d891960

Browse files
authored
Fire GLFW joystick events (#1992)
* Fire GLFW joystick events * Sneak in a fix for #1862 as well
1 parent 7c38fa2 commit d891960

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,29 @@ public unsafe void Update()
5757

5858
for (var i = 0; i < btnCount; i++)
5959
{
60-
((Button[]) Buttons)[i] = new Button(ButtonName.Unknown, i, btn[i] == (int) InputAction.Press);
60+
var thisBtn = new Button(ButtonName.Unknown, i, btn[i] == (int) InputAction.Press);
61+
var shouldInvoke = ((Button[]) Buttons)[i].Pressed != thisBtn.Pressed;
62+
((Button[]) Buttons)[i] = thisBtn;
63+
if (shouldInvoke)
64+
{
65+
(thisBtn.Pressed ? ButtonDown : ButtonUp)?.Invoke(this, thisBtn);
66+
}
6167
}
6268

6369
for (var i = 0; i < axisCount; i++)
6470
{
65-
((Axis[]) Axes)[i] = new Axis(i, axes[i]);
71+
var thisAxis = new Axis(i, Deadzone.Apply(axes[i]));
72+
var shouldInvoke = ((Axis[]) Axes)[i].Position != thisAxis.Position;
73+
((Axis[]) Axes)[i] = thisAxis;
74+
if (shouldInvoke)
75+
{
76+
AxisMoved?.Invoke(this, thisAxis);
77+
}
6678
}
6779

6880
for (var i = 0; i < hatCount; i++)
6981
{
70-
((Hat[]) Hats)[i] = new Hat
82+
var thisHat = new Hat
7183
(
7284
i, hats[i] switch
7385
{
@@ -83,6 +95,12 @@ public unsafe void Update()
8395
_ => Position2D.Centered
8496
}
8597
);
98+
var shouldInvoke = ((Hat[]) Hats)[i].Position != thisHat.Position;
99+
((Hat[]) Hats)[i] = thisHat;
100+
if (shouldInvoke)
101+
{
102+
HatMoved?.Invoke(this, thisHat);
103+
}
86104
}
87105

88106
if (!_connected)

src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ protected override void CoreInitialize(ViewOptions opts)
451451
};
452452
CoreInitialize
453453
(
454-
opts, flags, InitialMonitor?.Bounds.Origin.X + Position.X,
455-
InitialMonitor?.Bounds.Origin.Y + Position.Y, Size.X, Size.Y, Title, SharedContext
454+
opts, flags, (InitialMonitor?.Bounds.Origin.X ?? 0) + _extendedOptionsCache.Position.X,
455+
(InitialMonitor?.Bounds.Origin.Y ?? 0) + _extendedOptionsCache.Position.Y, Size.X, Size.Y, Title, SharedContext
456456
);
457457
}
458458
}

0 commit comments

Comments
 (0)