diff --git a/src/common/clipboard/Clipboard.h b/src/common/clipboard/Clipboard.h index 4a9d955c9..d7cb2c6cc 100644 --- a/src/common/clipboard/Clipboard.h +++ b/src/common/clipboard/Clipboard.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "common/String.h" class GameSave; @@ -13,4 +14,5 @@ namespace Clipboard bool GetEnabled(); void SetEnabled(bool newEnabled); void RecreateWindow(); + std::optional Explanation(); } diff --git a/src/common/clipboard/Cocoa.mm b/src/common/clipboard/Cocoa.mm index 20bb79577..1e1e504c3 100644 --- a/src/common/clipboard/Cocoa.mm +++ b/src/common/clipboard/Cocoa.mm @@ -62,6 +62,11 @@ namespace Clipboard } return gdc; } + + std::optional Explanation() final override + { + return std::nullopt; + } }; std::unique_ptr CocoaClipboardFactory() diff --git a/src/common/clipboard/Dynamic.cpp b/src/common/clipboard/Dynamic.cpp index 9b2e75ab6..40dfb9f71 100644 --- a/src/common/clipboard/Dynamic.cpp +++ b/src/common/clipboard/Dynamic.cpp @@ -24,7 +24,7 @@ namespace Clipboard }; std::unique_ptr clipboardData; - std::unique_ptr clipboard; + static std::unique_ptr clipboard; void InvokeClipboardSetClipboardData() { @@ -94,7 +94,7 @@ namespace Clipboard static bool enabled = false; void Init() { - enabled = GlobalPrefs::Ref().Get("NativeClipboard.Enabled", true); + enabled = GlobalPrefs::Ref().Get("NativeClipboard.Enabled", false); } bool GetEnabled() @@ -131,4 +131,9 @@ namespace Clipboard } InvokeClipboardSetClipboardData(); } + + std::optional Explanation() + { + return clipboard ? clipboard->Explanation() : std::nullopt; + } } diff --git a/src/common/clipboard/Dynamic.h b/src/common/clipboard/Dynamic.h index a7ae4caf1..dead52cc3 100644 --- a/src/common/clipboard/Dynamic.h +++ b/src/common/clipboard/Dynamic.h @@ -3,6 +3,7 @@ #include #include #include +#include class GameSave; @@ -35,6 +36,8 @@ namespace Clipboard GetClipboardDataUnknown >; virtual GetClipboardDataResult GetClipboardData() = 0; + + virtual std::optional Explanation() = 0; }; extern std::unique_ptr clipboardData; diff --git a/src/common/clipboard/External.cpp b/src/common/clipboard/External.cpp index 6b7191dc3..d8966405e 100644 --- a/src/common/clipboard/External.cpp +++ b/src/common/clipboard/External.cpp @@ -18,6 +18,7 @@ namespace Clipboard ByteString inCommand; ByteString formatsCommand; ByteString outCommand; + std::optional explanation; std::optional defaultForSubsystem; }; std::map builtInPresets = { @@ -25,12 +26,14 @@ namespace Clipboard "xclip -selection clipboard -target %s", "xclip -out -selection clipboard -target TARGETS", "xclip -out -selection clipboard -target %s", + "Requires the xclip utility to be installed", SDL_SYSWM_X11, } }, { "wl-clipboard", { "wl-copy --type %s", "wl-paste --list-types", "wl-paste --type %s", + "Requires the wl-clipboard utility to be installed", SDL_SYSWM_WAYLAND, } }, }; @@ -98,6 +101,7 @@ namespace Clipboard SubstFormat(it->second.inCommand), SubstFormat(it->second.formatsCommand), SubstFormat(it->second.outCommand), + it->second.explanation, }; } @@ -240,6 +244,12 @@ namespace Clipboard } return GetClipboardDataChanged{ std::move(*saveDataOpt) }; } + + std::optional Explanation() final override + { + auto preset = GetPreset(); + return preset ? preset->explanation : std::nullopt; + } }; std::unique_ptr ExternalClipboardFactory() diff --git a/src/common/clipboard/Null.cpp b/src/common/clipboard/Null.cpp index 42b72adb9..88d42eeae 100644 --- a/src/common/clipboard/Null.cpp +++ b/src/common/clipboard/Null.cpp @@ -28,4 +28,9 @@ namespace Clipboard void RecreateWindow() { } + + std::optional Explanation() + { + return std::nullopt; + } } diff --git a/src/common/clipboard/Windows.cpp b/src/common/clipboard/Windows.cpp index 2cb0235f3..7904e073e 100644 --- a/src/common/clipboard/Windows.cpp +++ b/src/common/clipboard/Windows.cpp @@ -217,6 +217,11 @@ namespace Clipboard auto base = reinterpret_cast(data.get()); return GetClipboardDataChanged{ std::vector(base, base + size) }; } + + std::optional Explanation() final override + { + return std::nullopt; + } }; std::unique_ptr WindowsClipboardFactory() diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index e3b2d8ae0..0b6e5d326 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -2,6 +2,7 @@ #include "Format.h" #include "OptionsController.h" #include "OptionsModel.h" +#include "common/clipboard/Clipboard.h" #include "common/platform/Platform.h" #include "graphics/Graphics.h" #include "graphics/Renderer.h" @@ -59,7 +60,18 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) AddComponent(scrollPanel); int currentY = 8; - auto addCheckbox = [this, ¤tY, &autoWidth](int indent, String text, String info, std::function action) { + auto addLabel = [this, ¤tY, &autoWidth](int indent, String text) { + auto *label = new ui::Label(ui::Point(22 + indent * 15, currentY), ui::Point(1, 16), ""); + autoWidth(label, 0); + label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + label->SetMultiline(true); + label->SetText("\bg" + text); // stupid hack because autoWidth just changes Size.X and that doesn't update the text wrapper + label->AutoHeight(); + scrollPanel->AddChild(label); + currentY += label->Size.Y - 1; + }; + auto addCheckbox = [this, ¤tY, &autoWidth, &addLabel](int indent, String text, String info, std::function action) { auto *checkbox = new ui::Checkbox(ui::Point(8 + indent * 15, currentY), ui::Point(1, 16), text, ""); autoWidth(checkbox, 0); checkbox->SetActionCallback({ action }); @@ -67,12 +79,7 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) currentY += 14; if (info.size()) { - auto *label = new ui::Label(ui::Point(22 + indent * 15, currentY), ui::Point(1, 16), "\bg" + info); - autoWidth(label, 0); - label->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; - label->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - scrollPanel->AddChild(label); - currentY += 14; + addLabel(indent, info); } currentY += 4; return checkbox; @@ -298,9 +305,16 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) }); if constexpr (PLATFORM_CLIPBOARD) { - nativeClipoard = addCheckbox(0, "Use platform clipboard", "Allows copying and pasting across TPT instances", [this] { + auto indent = 0; + nativeClipoard = addCheckbox(indent, "Use platform clipboard", "Allows copying and pasting across TPT instances", [this] { c->SetNativeClipoard(nativeClipoard->GetChecked()); }); + currentY -= 4; // temporarily undo the currentY += 4 at the end of addCheckbox + if (auto extra = Clipboard::Explanation()) + { + addLabel(indent, "\bg" + *extra); + } + currentY += 4; // and then undo the undo } decoSpace = addDropDown("Colour space used by decoration tools", { { "sRGB", 0 },