diff --git a/ConfigurableReader/Services/GamepadService.cs b/ConfigurableReader/Services/GamepadService.cs index 4fba43d..009053c 100644 --- a/ConfigurableReader/Services/GamepadService.cs +++ b/ConfigurableReader/Services/GamepadService.cs @@ -51,6 +51,8 @@ public class GamepadService : IDisposable private DateTime _lastDPadUpTime = DateTime.MinValue; private DateTime _lastDPadDownTime = DateTime.MinValue; + public Func? IsActive { get; set; } + public bool HasActiveGamepads => _activeGamepads.Count > 0; public void Start() @@ -73,7 +75,11 @@ public void Start() gamepad.Changes.Subscribe(_ => { - Dispatcher.UIThread.Post(() => HandleGamepadInput(gamepad)); + Dispatcher.UIThread.Post(() => + { + if (IsActive != null && !IsActive()) return; + HandleGamepadInput(gamepad); + }); }); }); } diff --git a/ConfigurableReader/Views/InfoDialog.axaml.cs b/ConfigurableReader/Views/InfoDialog.axaml.cs index 02e14ae..047913d 100644 --- a/ConfigurableReader/Views/InfoDialog.axaml.cs +++ b/ConfigurableReader/Views/InfoDialog.axaml.cs @@ -28,7 +28,13 @@ public InfoDialog() if (gamepad.BButton || gamepad.AButton || gamepad.Start || gamepad.Select) { - Dispatcher.UIThread.Post(Close); + Dispatcher.UIThread.Post(() => + { + if (IsActive) + { + Close(); + } + }); } }); }); diff --git a/ConfigurableReader/Views/MainWindow.Gamepad.cs b/ConfigurableReader/Views/MainWindow.Gamepad.cs index 3dae4d8..88a27e1 100644 --- a/ConfigurableReader/Views/MainWindow.Gamepad.cs +++ b/ConfigurableReader/Views/MainWindow.Gamepad.cs @@ -55,6 +55,7 @@ private void InitializeGamepad() _ = HandlePositionAdjustmentAsync(delta); }; + _gamepadService.IsActive = () => IsActive; _gamepadService.Start(); } diff --git a/ConfigurableReader/Views/MessageDialog.axaml.cs b/ConfigurableReader/Views/MessageDialog.axaml.cs index 67a3352..8818e61 100644 --- a/ConfigurableReader/Views/MessageDialog.axaml.cs +++ b/ConfigurableReader/Views/MessageDialog.axaml.cs @@ -29,7 +29,13 @@ public MessageDialog() if (gamepad.BButton || gamepad.AButton || gamepad.Start || gamepad.Select) { - Dispatcher.UIThread.Post(Close); + Dispatcher.UIThread.Post(() => + { + if (IsActive) + { + Close(); + } + }); } }); }); diff --git a/Directory.Packages.props b/Directory.Packages.props index 9db4d01..137a4a3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,20 +4,20 @@ false - - - - - - + + + + + + - + - + diff --git a/README.md b/README.md index 1287ace..1937d38 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A highly customizable, cross-platform text reader designed for a comfortable and - Full-text search capability. - Automatic Table of Contents extraction for EPUB and PDF files. - Custom Bookmarks feature allows saving specific locations with personalized names. -- **Gamepad Support:** Control your reading experience from the comfort of your couch using any standard HID Gamepad (Xbox, PlayStation, Switch, etc.). +- **Gamepad Support:** Control your reading experience from the comfort of your couch using any standard HID Gamepad (Xbox, PlayStation, Switch, etc.). Gamepad inputs are only processed when the window is focused/active to avoid accidental inputs when using other applications. - **Visual Indicators:** Connection indicator shows whether you are in Keyboard (⌨️) or Gamepad (🎮) mode. ## Controls