Init global Input instance from MainForm ctor

* Input.MainFormInputAllowedCallback is now readonly, set in ctor
* call to Input.Adapter.FirstInitAll is also in the Input ctor
This commit is contained in:
YoshiRulz 2020-11-30 19:48:13 +10:00
parent 709d78d8e0
commit 7c85aee53b
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 23 additions and 20 deletions

View File

@ -106,9 +106,7 @@ namespace BizHawk.Client.EmuHawk
Alt = 262144 Alt = 262144
} }
private static readonly Lazy<Input> _instance = new Lazy<Input>(() => new Input(() => GlobalWin.Config)); public static Input Instance;
public static Input Instance => _instance.Value;
private readonly Thread _updateThread; private readonly Thread _updateThread;
@ -116,9 +114,10 @@ namespace BizHawk.Client.EmuHawk
private readonly Func<Config> _getConfigCallback; private readonly Func<Config> _getConfigCallback;
private Input(Func<Config> getConfigCallback) internal Input(IntPtr mainFormHandle, Func<Config> getConfigCallback, Func<bool, AllowInput> mainFormInputAllowedCallback)
{ {
_getConfigCallback = getConfigCallback; _getConfigCallback = getConfigCallback;
MainFormInputAllowedCallback = mainFormInputAllowedCallback;
var config = _getConfigCallback(); var config = _getConfigCallback();
Adapter = config.HostInputMethod switch Adapter = config.HostInputMethod switch
@ -128,6 +127,7 @@ namespace BizHawk.Client.EmuHawk
_ => throw new Exception() _ => throw new Exception()
}; };
Adapter.UpdateConfig(config); Adapter.UpdateConfig(config);
Adapter.FirstInitAll(mainFormHandle);
_updateThread = new Thread(UpdateThreadProc) _updateThread = new Thread(UpdateThreadProc)
{ {
IsBackground = true, IsBackground = true,
@ -327,7 +327,7 @@ namespace BizHawk.Client.EmuHawk
/// <summary> /// <summary>
/// Controls whether MainForm generates input events. should be turned off for most modal dialogs /// Controls whether MainForm generates input events. should be turned off for most modal dialogs
/// </summary> /// </summary>
public Func<bool, AllowInput> MainFormInputAllowedCallback; public readonly Func<bool, AllowInput> MainFormInputAllowedCallback;
private void UpdateThreadProc() private void UpdateThreadProc()
{ {

View File

@ -392,20 +392,23 @@ namespace BizHawk.Client.EmuHawk
Sound?.StartSound(); Sound?.StartSound();
}; };
Input.Instance.MainFormInputAllowedCallback = yieldAlt => ActiveForm switch Input.Instance = new Input(
{ Handle,
null => Config.AcceptBackgroundInput // none of our forms are focused, check the background input config () => Config,
? Config.AcceptBackgroundInputControllerOnly yieldAlt => ActiveForm switch
? Input.AllowInput.OnlyController {
: Input.AllowInput.All null => Config.AcceptBackgroundInput // none of our forms are focused, check the background input config
: Input.AllowInput.None, ? Config.AcceptBackgroundInputControllerOnly
TAStudio _ when yieldAlt => Input.AllowInput.None, ? Input.AllowInput.OnlyController
FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All, : Input.AllowInput.All
ControllerConfig _ => Input.AllowInput.All, : Input.AllowInput.None,
HotkeyConfig _ => Input.AllowInput.All, TAStudio _ when yieldAlt => Input.AllowInput.None,
_ => Input.AllowInput.None FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All,
}; ControllerConfig _ => Input.AllowInput.All,
Input.Instance.Adapter.FirstInitAll(Handle); HotkeyConfig _ => Input.AllowInput.All,
_ => Input.AllowInput.None
}
);
InitControls(); InitControls();
InputManager.ActiveController = new Controller(NullController.Instance.Definition); InputManager.ActiveController = new Controller(NullController.Instance.Definition);

View File

@ -255,7 +255,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Sound?.Dispose(); GlobalWin.Sound?.Dispose();
GlobalWin.Sound = null; GlobalWin.Sound = null;
workingGL.Dispose(); workingGL.Dispose();
Input.Instance.Adapter.DeInitAll(); Input.Instance?.Adapter?.DeInitAll();
} }
//cleanup: //cleanup: