From e6eb1d9f574ff8d94acba1bc77619bc7899adb98 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 21 Jun 2026 10:29:31 +0200 Subject: [PATCH] macOS: add screen protection preference Persist a macOS-only preference for disabling wx content protection while keeping protection enabled by default. Add a Preferences checkbox that reuses IDC_DISABLE_SCREEN_PROTECTION and reapply the protection state after preference changes. Apply content-protection updates to all current top-level wx windows so changing the preference while a modal dialog is active does not leave the main frame or other windows with stale protection state. --- src/Main/Forms/MainFrame.cpp | 7 ++++++- src/Main/Forms/PreferencesDialog.cpp | 15 +++++++++++++++ src/Main/Forms/PreferencesDialog.h | 3 +++ src/Main/GraphicUserInterface.cpp | 7 ++++++- src/Main/UserPreferences.cpp | 6 ++++++ src/Main/UserPreferences.h | 2 ++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Main/Forms/MainFrame.cpp b/src/Main/Forms/MainFrame.cpp index afd53c53..c2f1e141 100644 --- a/src/Main/Forms/MainFrame.cpp +++ b/src/Main/Forms/MainFrame.cpp @@ -479,7 +479,11 @@ namespace VeraCrypt void MainFrame::InitWindowPrivacy () { - Gui->SetContentProtection(!CmdLine->ArgAllowScreencapture); + bool enableContentProtection = !CmdLine->ArgAllowScreencapture; +#ifdef TC_MACOSX + enableContentProtection = enableContentProtection && !GetPreferences().DisableScreenProtection; +#endif + Gui->SetContentProtection (enableContentProtection); } void MainFrame::InitPreferences () @@ -1296,6 +1300,7 @@ namespace VeraCrypt if (Gui->IsInBackgroundMode() && !prefs.BackgroundTaskEnabled) Close (true); + InitWindowPrivacy(); SavePreferences(); } diff --git a/src/Main/Forms/PreferencesDialog.cpp b/src/Main/Forms/PreferencesDialog.cpp index bfd7b222..879394ca 100644 --- a/src/Main/Forms/PreferencesDialog.cpp +++ b/src/Main/Forms/PreferencesDialog.cpp @@ -94,6 +94,21 @@ namespace VeraCrypt TC_CHECK_BOX_VALIDATOR (WipeCacheOnAutoDismount); TC_CHECK_BOX_VALIDATOR (WipeCacheOnClose); +#ifdef TC_MACOSX + wxStaticBoxSizer *screenProtectionSizer = new wxStaticBoxSizer (new wxStaticBox (SecurityPage, wxID_ANY, LangString["IDT_SECURITY_OPTIONS"]), wxVERTICAL); + DisableScreenProtectionCheckBox = new wxCheckBox (screenProtectionSizer->GetStaticBox(), wxID_ANY, LangString["IDC_DISABLE_SCREEN_PROTECTION"]); + DisableScreenProtectionCheckBox->SetToolTip (LangString["DISABLE_SCREEN_PROTECTION_WARNING"]); + screenProtectionSizer->Add (DisableScreenProtectionCheckBox, 0, wxALL, 5); + SecurityPage->GetSizer()->Add (screenProtectionSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10); + TC_CHECK_BOX_VALIDATOR (DisableScreenProtection); + DisableScreenProtectionCheckBox->Bind (wxEVT_CHECKBOX, + [] (wxCommandEvent& event) + { + if (event.IsChecked()) + Gui->ShowWarning ("DISABLE_SCREEN_PROTECTION_WARNING"); + }); +#endif + // Mount options CachePasswordsCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.CachePassword)); MountReadOnlyCheckBox->SetValue (Preferences.DefaultMountOptions.Protection == VolumeProtection::ReadOnly); diff --git a/src/Main/Forms/PreferencesDialog.h b/src/Main/Forms/PreferencesDialog.h index 55c7a85b..17a88d87 100644 --- a/src/Main/Forms/PreferencesDialog.h +++ b/src/Main/Forms/PreferencesDialog.h @@ -57,6 +57,9 @@ namespace VeraCrypt KeyfilesPanel *DefaultKeyfilesPanel; #ifdef TC_LINUX wxCheckBox *MountNtfsWithKernelDriverCheckBox; +#endif +#ifdef TC_MACOSX + wxCheckBox *DisableScreenProtectionCheckBox; #endif int LastVirtualKeyPressed; unique_ptr mTimer; diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 7aded309..d58fd97e 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -2053,7 +2053,12 @@ namespace VeraCrypt void GraphicUserInterface::SetContentProtection (bool enable) const { #if defined(TC_WINDOWS) || defined(TC_MACOSX) - GetActiveWindow()->SetContentProtection(enable ? wxCONTENT_PROTECTION_ENABLED : wxCONTENT_PROTECTION_NONE); + foreach (wxWindow *window, wxTopLevelWindows) + { + wxTopLevelWindow *topLevelWindow = dynamic_cast (window); + if (topLevelWindow) + topLevelWindow->SetContentProtection (enable ? wxCONTENT_PROTECTION_ENABLED : wxCONTENT_PROTECTION_NONE); + } #endif } diff --git a/src/Main/UserPreferences.cpp b/src/Main/UserPreferences.cpp index 7a61e798..a626efc3 100644 --- a/src/Main/UserPreferences.cpp +++ b/src/Main/UserPreferences.cpp @@ -84,6 +84,9 @@ namespace VeraCrypt TC_CONFIG_SET (CloseSecurityTokenSessionsAfterMount); TC_CONFIG_SET (EMVSupportEnabled); TC_CONFIG_SET (DisableKernelEncryptionModeWarning); +#ifdef TC_MACOSX + TC_CONFIG_SET (DisableScreenProtection); +#endif TC_CONFIG_SET (DismountOnInactivity); TC_CONFIG_SET (DismountOnLogOff); TC_CONFIG_SET (DismountOnPowerSaving); @@ -212,6 +215,9 @@ namespace VeraCrypt TC_CONFIG_ADD (CloseSecurityTokenSessionsAfterMount); TC_CONFIG_ADD (EMVSupportEnabled); TC_CONFIG_ADD (DisableKernelEncryptionModeWarning); +#ifdef TC_MACOSX + TC_CONFIG_ADD (DisableScreenProtection); +#endif TC_CONFIG_ADD (DismountOnInactivity); TC_CONFIG_ADD (DismountOnLogOff); TC_CONFIG_ADD (DismountOnPowerSaving); diff --git a/src/Main/UserPreferences.h b/src/Main/UserPreferences.h index 17e23818..07ab4176 100644 --- a/src/Main/UserPreferences.h +++ b/src/Main/UserPreferences.h @@ -33,6 +33,7 @@ namespace VeraCrypt CloseSecurityTokenSessionsAfterMount (false), EMVSupportEnabled (false), DisableKernelEncryptionModeWarning (false), + DisableScreenProtection (false), DismountOnInactivity (false), DismountOnLogOff (true), DismountOnPowerSaving (false), @@ -76,6 +77,7 @@ namespace VeraCrypt bool CloseSecurityTokenSessionsAfterMount; bool EMVSupportEnabled; bool DisableKernelEncryptionModeWarning; + bool DisableScreenProtection; bool DismountOnInactivity; bool DismountOnLogOff; bool DismountOnPowerSaving;