diff --git a/src/Config.template.h b/src/Config.template.h index 8962bb543..22b2fcf2a 100644 --- a/src/Config.template.h +++ b/src/Config.template.h @@ -18,6 +18,7 @@ constexpr bool INSTALL_CHECK = @INSTALL_CHECK@; constexpr bool IGNORE_UPDATES = @IGNORE_UPDATES@; constexpr bool ENFORCE_HTTPS = @ENFORCE_HTTPS@; constexpr bool SECURE_CIPHERS_ONLY = @SECURE_CIPHERS_ONLY@; +constexpr bool PLATFORM_CLIPBOARD = @PLATFORM_CLIPBOARD@; constexpr bool USE_SYSTEM_CERT_PROVIDER = @USE_SYSTEM_CERT_PROVIDER@; constexpr bool FFTW_PLAN_MEASURE = @FFTW_PLAN_MEASURE@; constexpr bool ALLOW_QUIT = @ALLOW_QUIT@; diff --git a/src/common/clipboard/Clipboard.h b/src/common/clipboard/Clipboard.h index a25c7047e..4a9d955c9 100644 --- a/src/common/clipboard/Clipboard.h +++ b/src/common/clipboard/Clipboard.h @@ -10,5 +10,7 @@ namespace Clipboard void SetClipboardData(std::unique_ptr data); const GameSave *GetClipboardData(); void Init(); + bool GetEnabled(); + void SetEnabled(bool newEnabled); void RecreateWindow(); } diff --git a/src/common/clipboard/Dynamic.cpp b/src/common/clipboard/Dynamic.cpp index f4910fc00..9b2e75ab6 100644 --- a/src/common/clipboard/Dynamic.cpp +++ b/src/common/clipboard/Dynamic.cpp @@ -1,4 +1,5 @@ #include "Dynamic.h" +#include "Clipboard.h" #include "client/GameSave.h" #include "prefs/GlobalPrefs.h" #include "PowderToySDL.h" @@ -90,8 +91,21 @@ namespace Clipboard return clipboardData.get(); } + static bool enabled = false; void Init() { + enabled = GlobalPrefs::Ref().Get("NativeClipboard.Enabled", true); + } + + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newEnabled) + { + enabled = newEnabled; + RecreateWindow(); } int currentSubsystem; @@ -104,7 +118,7 @@ namespace Clipboard SDL_GetWindowWMInfo(sdl_window, &info); clipboard.reset(); currentSubsystem = info.subsystem; - if (GlobalPrefs::Ref().Get("NativeClipboard.Enabled", true)) + if (enabled) { for (auto *impl = clipboardImpls; impl->factory; ++impl) { diff --git a/src/common/clipboard/Null.cpp b/src/common/clipboard/Null.cpp index 99d07ce2a..42b72adb9 100644 --- a/src/common/clipboard/Null.cpp +++ b/src/common/clipboard/Null.cpp @@ -16,6 +16,15 @@ namespace Clipboard { } + bool GetEnabled() + { + return false; + } + + void SetEnabled(bool) + { + } + void RecreateWindow() { } diff --git a/src/common/clipboard/meson.build b/src/common/clipboard/meson.build index 1c6626838..d7e3871bf 100644 --- a/src/common/clipboard/meson.build +++ b/src/common/clipboard/meson.build @@ -1,4 +1,4 @@ -if get_option('platform_clipboard') +if platform_clipboard clipboard_impl_factories = [] if host_platform == 'windows' powder_files += files('Windows.cpp') diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index 9cc876f4e..fc92a5bfa 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -107,6 +107,11 @@ void OptionsController::SetGraveExitsConsole(bool graveExitsConsole) model->SetGraveExitsConsole(graveExitsConsole); } +void OptionsController::SetNativeClipoard(bool nativeClipoard) +{ + model->SetNativeClipoard(nativeClipoard); +} + void OptionsController::SetResizable(bool resizable) { model->SetResizable(resizable); diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index 56bc30678..fa9467eaa 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -30,6 +30,7 @@ public: void SetBlurryScaling(bool newBlurryScaling); void SetScale(int scale); void SetGraveExitsConsole(bool graveExitsConsole); + void SetNativeClipoard(bool nativeClipoard); void SetResizable(bool resizable); void SetFastQuit(bool fastquit); void SetDecoSpace(int decoSpace); diff --git a/src/gui/options/OptionsModel.cpp b/src/gui/options/OptionsModel.cpp index 9cce68ac0..7118bc0e6 100644 --- a/src/gui/options/OptionsModel.cpp +++ b/src/gui/options/OptionsModel.cpp @@ -1,13 +1,10 @@ #include "OptionsModel.h" - #include "OptionsView.h" - #include "simulation/Simulation.h" #include "simulation/Air.h" #include "simulation/gravity/Gravity.h" - #include "prefs/GlobalPrefs.h" - +#include "common/clipboard/Clipboard.h" #include "gui/interface/Engine.h" #include "gui/game/GameModel.h" @@ -168,6 +165,18 @@ void OptionsModel::SetGraveExitsConsole(bool graveExitsConsole) notifySettingsChanged(); } +bool OptionsModel::GetNativeClipoard() +{ + return Clipboard::GetEnabled(); +} + +void OptionsModel::SetNativeClipoard(bool nativeClipoard) +{ + Clipboard::SetEnabled(nativeClipoard); + GlobalPrefs::Ref().Set("NativeClipboard.Enabled", nativeClipoard); + notifySettingsChanged(); +} + bool OptionsModel::GetResizable() { return ui::Engine::Ref().GetResizable(); diff --git a/src/gui/options/OptionsModel.h b/src/gui/options/OptionsModel.h index 1e39d6c17..bb155f75b 100644 --- a/src/gui/options/OptionsModel.h +++ b/src/gui/options/OptionsModel.h @@ -41,6 +41,8 @@ public: void SetScale(int scale); bool GetGraveExitsConsole(); void SetGraveExitsConsole(bool graveExitsConsole); + bool GetNativeClipoard(); + void SetNativeClipoard(bool nativeClipoard); bool GetResizable(); void SetResizable(bool resizable); bool GetFullscreen(); diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index 0bebe8a57..e3b2d8ae0 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -296,6 +296,12 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340)) graveExitsConsole = addCheckbox(0, "Key under Esc exits console", "Disable if that key is 0 on your keyboard", [this] { c->SetGraveExitsConsole(graveExitsConsole->GetChecked()); }); + if constexpr (PLATFORM_CLIPBOARD) + { + nativeClipoard = addCheckbox(0, "Use platform clipboard", "Allows copying and pasting across TPT instances", [this] { + c->SetNativeClipoard(nativeClipoard->GetChecked()); + }); + } decoSpace = addDropDown("Colour space used by decoration tools", { { "sRGB", 0 }, { "Linear", 1 }, @@ -459,6 +465,10 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender) { fastquit->SetChecked(sender->GetFastQuit()); } + if (nativeClipoard) + { + nativeClipoard->SetChecked(sender->GetNativeClipoard()); + } showAvatars->SetChecked(sender->GetShowAvatars()); mouseClickRequired->SetChecked(sender->GetMouseClickRequired()); includePressure->SetChecked(sender->GetIncludePressure()); diff --git a/src/gui/options/OptionsView.h b/src/gui/options/OptionsView.h index 409f8fa09..b9f30dbcb 100644 --- a/src/gui/options/OptionsView.h +++ b/src/gui/options/OptionsView.h @@ -40,6 +40,7 @@ class OptionsView: public ui::Window ui::Checkbox *includePressure{}; ui::Checkbox *perfectCircle{}; ui::Checkbox *graveExitsConsole{}; + ui::Checkbox *nativeClipoard{}; ui::ScrollPanel *scrollPanel{}; float customGravityX, customGravityY; void UpdateAmbientAirTempPreview(float airTemp, bool isValid); diff --git a/src/meson.build b/src/meson.build index 87cd5301e..737d8adc1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ update_server = get_option('update_server') conf_data.set('UPDATESERVER', update_server) conf_data.set('USE_UPDATESERVER', (update_server != '').to_string()) +platform_clipboard = get_option('platform_clipboard') enforce_https = get_option('enforce_https') allow_quit = true force_window_frame_ops = 'forceWindowFrameOpsNone' @@ -52,6 +53,7 @@ conf_data.set('DEFAULT_TOUCH_UI', default_touch_ui.to_string()) conf_data.set('ALLOW_DATA_FOLDER', allow_data_folder.to_string()) conf_data.set('ENFORCE_HTTPS', enforce_https.to_string()) conf_data.set('SECURE_CIPHERS_ONLY', secure_ciphers_only.to_string()) +conf_data.set('PLATFORM_CLIPBOARD', platform_clipboard.to_string()) conf_data.set('IGNORE_UPDATES', get_option('ignore_updates').to_string()) conf_data.set('SERVER', get_option('server')) @@ -176,17 +178,19 @@ configure_file( configuration: elements_conf_data ) -clipboard_impl_defs = [] -foreach impl_subsys_factory : clipboard_impl_factories - clipboard_impl_defs += 'IMPL_DEFINE(' + impl_subsys_factory[0] + ', ' + impl_subsys_factory[1] + ')' -endforeach -clipboard_impls_data = configuration_data() -clipboard_impls_data.set('impl_defs', '\n'.join(clipboard_impl_defs)) -configure_file( - input: 'common/clipboard/ClipboardImpls.template.h', - output: 'ClipboardImpls.h', - configuration: clipboard_impls_data -) +if platform_clipboard + clipboard_impl_defs = [] + foreach impl_subsys_factory : clipboard_impl_factories + clipboard_impl_defs += 'IMPL_DEFINE(' + impl_subsys_factory[0] + ', ' + impl_subsys_factory[1] + ')' + endforeach + clipboard_impls_data = configuration_data() + clipboard_impls_data.set('impl_defs', '\n'.join(clipboard_impl_defs)) + configure_file( + input: 'common/clipboard/ClipboardImpls.template.h', + output: 'ClipboardImpls.h', + configuration: clipboard_impls_data + ) +endif simulation_tool_defs = [] foreach tool_name_id : simulation_tool_ids