Pass MainForm.AllowInput to Input instance as delegate
This commit is contained in:
parent
b972b8a771
commit
d2e20a7a1e
|
@ -331,6 +331,11 @@ 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;
|
||||
|
||||
private void UpdateThreadProc()
|
||||
{
|
||||
while (true)
|
||||
|
@ -390,12 +395,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (_newEvents.Count != 0)
|
||||
{
|
||||
//WHAT!? WE SHOULD NOT BE SO NAIVELY TOUCHING MAINFORM FROM THE INPUTTHREAD. ITS BUSY RUNNING.
|
||||
AllowInput allowInput = GlobalWin.MainForm.AllowInput(false);
|
||||
AllowInput allowInput = MainFormInputAllowedCallback(false);
|
||||
|
||||
foreach (var ie in _newEvents)
|
||||
{
|
||||
//events are swallowed in some cases:
|
||||
if (ie.LogicalButton.Alt && ShouldSwallow(GlobalWin.MainForm.AllowInput(true), ie))
|
||||
if (ie.LogicalButton.Alt && ShouldSwallow(MainFormInputAllowedCallback(true), ie))
|
||||
continue;
|
||||
if (ie.EventType == InputEventType.Press && ShouldSwallow(allowInput, ie))
|
||||
continue;
|
||||
|
@ -461,7 +466,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
lock (this)
|
||||
{
|
||||
if (_inputEvents.Count == 0) return null;
|
||||
AllowInput allowInput = GlobalWin.MainForm.AllowInput(false);
|
||||
AllowInput allowInput = MainFormInputAllowedCallback(false);
|
||||
|
||||
//wait for the first release after a press to complete input binding, because we need to distinguish pure modifierkeys from modified keys
|
||||
//if you just pressed ctrl, wanting to bind ctrl, we'd see: pressed:ctrl, unpressed:ctrl
|
||||
|
|
|
@ -372,6 +372,40 @@ namespace BizHawk.Client.EmuHawk
|
|||
Sound?.StartSound();
|
||||
};
|
||||
|
||||
Input.Instance.MainFormInputAllowedCallback = yieldAlt => {
|
||||
// the main form gets input
|
||||
if (ActiveForm == this)
|
||||
{
|
||||
return Input.AllowInput.All;
|
||||
}
|
||||
|
||||
// even more special logic for TAStudio:
|
||||
// TODO - implement by event filter in TAStudio
|
||||
if (ActiveForm is TAStudio maybeTAStudio)
|
||||
{
|
||||
if (yieldAlt || maybeTAStudio.IsInMenuLoop)
|
||||
{
|
||||
return Input.AllowInput.None;
|
||||
}
|
||||
}
|
||||
|
||||
// modals that need to capture input for binding purposes get input, of course
|
||||
if (ActiveForm is HotkeyConfig
|
||||
|| ActiveForm is ControllerConfig
|
||||
|| ActiveForm is TAStudio
|
||||
|| ActiveForm is VirtualpadTool)
|
||||
{
|
||||
return Input.AllowInput.All;
|
||||
}
|
||||
|
||||
// if no form is active on this process, then the background input setting applies
|
||||
if (ActiveForm == null && Config.AcceptBackgroundInput)
|
||||
{
|
||||
return Config.AcceptBackgroundInputControllerOnly ? Input.AllowInput.OnlyController : Input.AllowInput.All;
|
||||
}
|
||||
|
||||
return Input.AllowInput.None;
|
||||
};
|
||||
Input.Instance.Adapter.FirstInitAll(Handle);
|
||||
InitControls();
|
||||
|
||||
|
@ -798,45 +832,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
AddOnScreenMessage("Core reboot needed for this setting");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether the app generates input events. should be turned off for most modal dialogs
|
||||
/// </summary>
|
||||
public Input.AllowInput AllowInput(bool yieldAlt)
|
||||
{
|
||||
// the main form gets input
|
||||
if (ActiveForm == this)
|
||||
{
|
||||
return Input.AllowInput.All;
|
||||
}
|
||||
|
||||
// even more special logic for TAStudio:
|
||||
// TODO - implement by event filter in TAStudio
|
||||
if (ActiveForm is TAStudio maybeTAStudio)
|
||||
{
|
||||
if (yieldAlt || maybeTAStudio.IsInMenuLoop)
|
||||
{
|
||||
return Input.AllowInput.None;
|
||||
}
|
||||
}
|
||||
|
||||
// modals that need to capture input for binding purposes get input, of course
|
||||
if (ActiveForm is HotkeyConfig
|
||||
|| ActiveForm is ControllerConfig
|
||||
|| ActiveForm is TAStudio
|
||||
|| ActiveForm is VirtualpadTool)
|
||||
{
|
||||
return Input.AllowInput.All;
|
||||
}
|
||||
|
||||
// if no form is active on this process, then the background input setting applies
|
||||
if (ActiveForm == null && Config.AcceptBackgroundInput)
|
||||
{
|
||||
return Config.AcceptBackgroundInputControllerOnly ? Input.AllowInput.OnlyController : Input.AllowInput.All;
|
||||
}
|
||||
|
||||
return Input.AllowInput.None;
|
||||
}
|
||||
|
||||
// TODO: make these actual properties
|
||||
// This is a quick hack to reduce the dependency on Globals
|
||||
public IEmulator Emulator
|
||||
|
|
Loading…
Reference in New Issue