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:
parent
709d78d8e0
commit
7c85aee53b
|
@ -106,9 +106,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
Alt = 262144
|
||||
}
|
||||
|
||||
private static readonly Lazy<Input> _instance = new Lazy<Input>(() => new Input(() => GlobalWin.Config));
|
||||
|
||||
public static Input Instance => _instance.Value;
|
||||
public static Input Instance;
|
||||
|
||||
private readonly Thread _updateThread;
|
||||
|
||||
|
@ -116,9 +114,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private readonly Func<Config> _getConfigCallback;
|
||||
|
||||
private Input(Func<Config> getConfigCallback)
|
||||
internal Input(IntPtr mainFormHandle, Func<Config> getConfigCallback, Func<bool, AllowInput> mainFormInputAllowedCallback)
|
||||
{
|
||||
_getConfigCallback = getConfigCallback;
|
||||
MainFormInputAllowedCallback = mainFormInputAllowedCallback;
|
||||
|
||||
var config = _getConfigCallback();
|
||||
Adapter = config.HostInputMethod switch
|
||||
|
@ -128,6 +127,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_ => throw new Exception()
|
||||
};
|
||||
Adapter.UpdateConfig(config);
|
||||
Adapter.FirstInitAll(mainFormHandle);
|
||||
_updateThread = new Thread(UpdateThreadProc)
|
||||
{
|
||||
IsBackground = true,
|
||||
|
@ -327,7 +327,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <summary>
|
||||
/// Controls whether MainForm generates input events. should be turned off for most modal dialogs
|
||||
/// </summary>
|
||||
public Func<bool, AllowInput> MainFormInputAllowedCallback;
|
||||
public readonly Func<bool, AllowInput> MainFormInputAllowedCallback;
|
||||
|
||||
private void UpdateThreadProc()
|
||||
{
|
||||
|
|
|
@ -392,20 +392,23 @@ namespace BizHawk.Client.EmuHawk
|
|||
Sound?.StartSound();
|
||||
};
|
||||
|
||||
Input.Instance.MainFormInputAllowedCallback = yieldAlt => ActiveForm switch
|
||||
{
|
||||
null => Config.AcceptBackgroundInput // none of our forms are focused, check the background input config
|
||||
? Config.AcceptBackgroundInputControllerOnly
|
||||
? Input.AllowInput.OnlyController
|
||||
: Input.AllowInput.All
|
||||
: Input.AllowInput.None,
|
||||
TAStudio _ when yieldAlt => Input.AllowInput.None,
|
||||
FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All,
|
||||
ControllerConfig _ => Input.AllowInput.All,
|
||||
HotkeyConfig _ => Input.AllowInput.All,
|
||||
_ => Input.AllowInput.None
|
||||
};
|
||||
Input.Instance.Adapter.FirstInitAll(Handle);
|
||||
Input.Instance = new Input(
|
||||
Handle,
|
||||
() => Config,
|
||||
yieldAlt => ActiveForm switch
|
||||
{
|
||||
null => Config.AcceptBackgroundInput // none of our forms are focused, check the background input config
|
||||
? Config.AcceptBackgroundInputControllerOnly
|
||||
? Input.AllowInput.OnlyController
|
||||
: Input.AllowInput.All
|
||||
: Input.AllowInput.None,
|
||||
TAStudio _ when yieldAlt => Input.AllowInput.None,
|
||||
FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All,
|
||||
ControllerConfig _ => Input.AllowInput.All,
|
||||
HotkeyConfig _ => Input.AllowInput.All,
|
||||
_ => Input.AllowInput.None
|
||||
}
|
||||
);
|
||||
InitControls();
|
||||
|
||||
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
|
||||
|
|
|
@ -255,7 +255,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
GlobalWin.Sound?.Dispose();
|
||||
GlobalWin.Sound = null;
|
||||
workingGL.Dispose();
|
||||
Input.Instance.Adapter.DeInitAll();
|
||||
Input.Instance?.Adapter?.DeInitAll();
|
||||
}
|
||||
|
||||
//cleanup:
|
||||
|
|
Loading…
Reference in New Issue