From c494fd83f6b9d87982af26196bc73b798a4ae05c Mon Sep 17 00:00:00 2001 From: kalimag Date: Sun, 18 Jun 2023 18:05:46 +0200 Subject: [PATCH] Fall back to trapping paste keyboard shortcuts on Linux --- .../CustomControls/ClipboardEventTextBox.cs | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/ClipboardEventTextBox.cs b/src/BizHawk.Client.EmuHawk/CustomControls/ClipboardEventTextBox.cs index f31339221a1..860d9768abf 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/ClipboardEventTextBox.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/ClipboardEventTextBox.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using BizHawk.Common; namespace BizHawk.Client.EmuHawk.CustomControls { @@ -9,30 +10,46 @@ protected override void WndProc(ref Message m) { const int WM_PASTE = 0x302; - if (m.Msg == WM_PASTE) + if (m.Msg == WM_PASTE && !OSTailoredCode.IsUnixHost) { - bool containsText; - string text; - - try - { - containsText = Clipboard.ContainsText(); - text = containsText ? Clipboard.GetText() : ""; - } - catch (Exception) + if (OnPasteInternal()) { - // Clipboard is busy? No idea if this ever happens in practice return; } + } - var args = new PasteEventArgs(containsText, text); - OnPaste(args); + base.WndProc(ref m); + } - if (args.Handled) - return; + protected override bool ProcessCmdKey(ref Message m, Keys keyData) + { + if (OSTailoredCode.IsUnixHost && keyData is (Keys.Control | Keys.V) or (Keys.Shift | Keys.Insert) && !ReadOnly) + { + return OnPasteInternal(); } - base.WndProc(ref m); + return base.ProcessCmdKey(ref m, keyData); + } + + private bool OnPasteInternal() + { + bool containsText; + string text; + + try + { + containsText = Clipboard.ContainsText(); + text = containsText ? Clipboard.GetText() : ""; + } + catch (Exception) + { + // Clipboard is busy? No idea if this ever happens in practice + return true; + } + + var args = new PasteEventArgs(containsText, text); + OnPaste(args); + return args.Handled; } protected virtual void OnPaste(PasteEventArgs e)