Skip to content

Commit

Permalink
Fall back to trapping paste keyboard shortcuts on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kalimag committed Jun 18, 2023
1 parent d963fc7 commit c494fd8
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/BizHawk.Client.EmuHawk/CustomControls/ClipboardEventTextBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Windows.Forms;
using BizHawk.Common;

namespace BizHawk.Client.EmuHawk.CustomControls
{
Expand All @@ -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)
Expand Down

0 comments on commit c494fd8

Please sign in to comment.