From 23433b856fceec42c0f0845bcee5a7237f7ca0c2 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sun, 20 Oct 2019 13:47:22 -0400 Subject: [PATCH] Hotkey/controller config: Fix issue where input events get queued and processed by the main form after the dialog is closed. For example if you opened the hotkey config, typed "-" in the search box, and closed the dialog, it would trigger Decrease Speed in the main form. Also redo an old hack fix the right way. --- BizHawk.Client.EmuHawk/Input/Input.cs | 1 - .../config/ControllerConfig.Designer.cs | 3 ++- .../config/ControllerConfig.cs | 24 +++++++++---------- .../config/HotkeyConfig.Designer.cs | 3 ++- BizHawk.Client.EmuHawk/config/HotkeyConfig.cs | 12 +++++----- BizHawk.Client.EmuHawk/config/InputWidget.cs | 7 ++++++ 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/BizHawk.Client.EmuHawk/Input/Input.cs b/BizHawk.Client.EmuHawk/Input/Input.cs index 4acea6455b..3e71096b13 100644 --- a/BizHawk.Client.EmuHawk/Input/Input.cs +++ b/BizHawk.Client.EmuHawk/Input/Input.cs @@ -293,7 +293,6 @@ namespace BizHawk.Client.EmuHawk private ModifierKey _Modifiers; private readonly List _NewEvents = new List(); - //do we need this? public void ClearEvents() { lock (this) diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig.Designer.cs index 20d7076fdf..cc024b4a27 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig.Designer.cs @@ -302,7 +302,8 @@ this.Name = "ControllerConfig"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Controller Config"; - this.Load += new System.EventHandler(this.NewControllerConfig_Load); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ControllerConfig_FormClosed); + this.Load += new System.EventHandler(this.ControllerConfig_Load); this.tabControl1.ResumeLayout(false); this.tableLayoutPanel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 25b246d55f..b930b136be 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -49,7 +49,11 @@ namespace BizHawk.Client.EmuHawk ControllerImages.Add("Apple IIe Keyboard", Properties.Resources.AppleIIKeyboard); ControllerImages.Add("VirtualBoy Controller", Properties.Resources.VBoyController); ControllerImages.Add("NeoGeo Portable Controller", Properties.Resources.NGPController); - + } + + private ControllerConfig() + { + InitializeComponent(); } protected override void OnActivated(EventArgs e) @@ -64,13 +68,14 @@ namespace BizHawk.Client.EmuHawk Input.Instance.ControlInputFocus(this, Input.InputFocus.Mouse, false); } - private ControllerConfig() + private void ControllerConfig_Load(object sender, EventArgs e) { - InitializeComponent(); - Closing += (o, e) => - { - buttonOK.Focus(); // A very dirty hack to avoid https://code.google.com/p/bizhawk/issues/detail?id=161 - }; + Text = $"{_theDefinition.Name} Configuration"; + } + + private void ControllerConfig_FormClosed(object sender, FormClosedEventArgs e) + { + Input.Instance.ClearEvents(); } private delegate Control PanelCreator(Dictionary settings, List buttons, Size size); @@ -365,11 +370,6 @@ namespace BizHawk.Client.EmuHawk Close(); } - private void NewControllerConfig_Load(object sender, EventArgs e) - { - Text = $"{_theDefinition.Name} Configuration"; - } - private static TabControl GetTabControl(IEnumerable controls) { if (controls != null) diff --git a/BizHawk.Client.EmuHawk/config/HotkeyConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/HotkeyConfig.Designer.cs index 7047ff8b90..d37183c230 100644 --- a/BizHawk.Client.EmuHawk/config/HotkeyConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/HotkeyConfig.Designer.cs @@ -228,7 +228,8 @@ this.Name = "HotkeyConfig"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Configure Hotkeys"; - this.Load += new System.EventHandler(this.NewHotkeyWindow_Load); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.HotkeyConfig_FormClosed); + this.Load += new System.EventHandler(this.HotkeyConfig_Load); this.HotkeyTabControl.ResumeLayout(false); this.clearBtnContextMenu.ResumeLayout(false); this.ResumeLayout(false); diff --git a/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs b/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs index 5ed5f999a0..79ee9abc29 100644 --- a/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs +++ b/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs @@ -14,11 +14,6 @@ namespace BizHawk.Client.EmuHawk { InitializeComponent(); - Closing += (o, e) => - { - IDB_SAVE.Focus(); // A very dirty hack to avoid https://code.google.com/p/bizhawk/issues/detail?id=161 - }; - tabPage1.Focus(); } @@ -34,7 +29,7 @@ namespace BizHawk.Client.EmuHawk Input.Instance.ControlInputFocus(this, Input.InputFocus.Mouse, false); } - private void NewHotkeyWindow_Load(object sender, EventArgs e) + private void HotkeyConfig_Load(object sender, EventArgs e) { var source = new AutoCompleteStringCollection(); source.AddRange(Global.Config.HotkeyBindings.Select(x => x.DisplayName).ToArray()); @@ -47,6 +42,11 @@ namespace BizHawk.Client.EmuHawk DoFocus(); } + private void HotkeyConfig_FormClosed(object sender, FormClosedEventArgs e) + { + Input.Instance.ClearEvents(); + } + private void IDB_CANCEL_Click(object sender, EventArgs e) { GlobalWin.OSD.AddMessage("Hotkey config aborted"); diff --git a/BizHawk.Client.EmuHawk/config/InputWidget.cs b/BizHawk.Client.EmuHawk/config/InputWidget.cs index 4e9d85e990..c34c500d5f 100644 --- a/BizHawk.Client.EmuHawk/config/InputWidget.cs +++ b/BizHawk.Client.EmuHawk/config/InputWidget.cs @@ -88,6 +88,7 @@ namespace BizHawk.Client.EmuHawk protected override void OnEnter(EventArgs e) { + Input.Instance.ClearEvents(); _lastPress = null; _timer.Start(); BackColor = Color.FromArgb(unchecked((int)0xFFC0FFFF)); // Color.LightCyan is too light on Windows 8, this is a bit darker @@ -101,6 +102,12 @@ namespace BizHawk.Client.EmuHawk base.OnLeave(e); } + protected override void OnHandleDestroyed(EventArgs e) + { + _timer.Stop(); + base.OnHandleDestroyed(e); + } + private void Timer_Tick(object sender, EventArgs e) { ReadKeys();