From 2beab522aeec26e99f3274d83de98a97cb8593ff Mon Sep 17 00:00:00 2001
From: Berke Bakar <88384613+berke-bakar@users.noreply.github.com>
Date: Wed, 23 Sep 2026 00:24:11 +0300
Subject: [PATCH 1/2] Start of fix for unnecessary updates of joysticks and
gamepads in GLFW backend
From a557e0835d9264b5f6357d000e069f82857742d0 Mon Sep 17 00:00:00 2001
From: Berke Bakar <88384613+berke-bakar@users.noreply.github.com>
Date: Wed, 23 Sep 2026 12:54:08 +0300
Subject: [PATCH 2/2] Used `GLFW.SetJoystickCallback` to listen
connect/disconnect events from GLFW and cache connection states. Used cached
state where applicable to reduce native call count.
---
src/Input/Silk.NET.Input.Glfw/GlfwGamepad.cs | 13 ++++++++---
.../Silk.NET.Input.Glfw/GlfwInputContext.cs | 17 ++++++++++++++
.../Silk.NET.Input.Glfw/GlfwInputPlatform.cs | 22 +++++++++++++++++++
src/Input/Silk.NET.Input.Glfw/GlfwJoystick.cs | 9 +++++---
4 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/src/Input/Silk.NET.Input.Glfw/GlfwGamepad.cs b/src/Input/Silk.NET.Input.Glfw/GlfwGamepad.cs
index bd602be75f..6beb046fbe 100644
--- a/src/Input/Silk.NET.Input.Glfw/GlfwGamepad.cs
+++ b/src/Input/Silk.NET.Input.Glfw/GlfwGamepad.cs
@@ -23,7 +23,7 @@ public GlfwGamepad(int i)
Thumbsticks = new Thumbstick[GamepadThumbstickCount];
Triggers = new Trigger[GamepadTriggerCount];
- _connected = hasState;
+ IsConnected = _connected = hasState;
for (int j = 0; j < GamepadButtonCount; j++)
{
@@ -44,7 +44,12 @@ public GlfwGamepad(int i)
public string Name => GlfwProvider.GLFW.Value.GetGamepadName(Index) ?? "Silk.NET Gamepad (via GLFW)";
public int Index { get; }
- public bool IsConnected => GlfwProvider.GLFW.Value.JoystickIsGamepad(Index);
+
+ ///
+ /// Cached connection status from GLFW's joystick connection callback.
+ ///
+ public bool IsConnected { get; internal set; }
+
public IReadOnlyList