From a8931698a4ef75e7ca065a7eb1022db6b1c503dc Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 12 Aug 2024 13:45:15 +0100 Subject: [PATCH] Fixes #3541. Checking if clipboard is available on windows. (#3657) --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 180745d9d..8fb1d52e8 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -2343,7 +2343,22 @@ internal class WindowsClipboard : ClipboardBase { private const uint CF_UNICODE_TEXT = 13; - public override bool IsSupported { get; } = IsClipboardFormatAvailable (CF_UNICODE_TEXT); + public override bool IsSupported { get; } = CheckClipboardIsAvailable (); + + private static bool CheckClipboardIsAvailable () + { + // Attempt to open the clipboard + if (OpenClipboard (nint.Zero)) + { + // Clipboard is available + // Close the clipboard after use + CloseClipboard (); + + return true; + } + // Clipboard is not available + return false; + } protected override string GetClipboardDataImpl () {