From 3e9c47d25694590b258e5d6c9f5679a5b114eec3 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 15 Apr 2026 16:16:54 +0900 Subject: [PATCH] Linux/macOS: collect mouse entropy from nested controls wxWidgets does not propagate mouse motion events from child controls to parent windows. The Linux/macOS GUI was binding the random-pool mouse handlers only to the dialog/page and its direct children, which left nested controls such as static-box contents and the wizard image as dead zones. Add a reusable recursive child-window event binder and use it in the keyfile generator, random pool enrichment dialog, and volume creation wizard. The root windows keep their existing generated bindings, while descendants are bound explicitly, avoiding duplicate handling on the root while covering all nested controls. This makes the entropy gauge and the random pool update consistently no matter where the pointer moves inside the affected windows. Fixes #1656. --- src/Main/Forms/KeyfileGeneratorDialog.cpp | 4 +-- src/Main/Forms/RandomPoolEnrichmentDialog.cpp | 4 +-- src/Main/Forms/WindowEventHandlers.h | 30 +++++++++++++++++++ src/Main/Forms/WizardFrame.cpp | 7 ++--- 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/Main/Forms/WindowEventHandlers.h diff --git a/src/Main/Forms/KeyfileGeneratorDialog.cpp b/src/Main/Forms/KeyfileGeneratorDialog.cpp index 2ebd46fa..ab7976db 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.cpp +++ b/src/Main/Forms/KeyfileGeneratorDialog.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Volume/Hash.h" #include "KeyfileGeneratorDialog.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -44,8 +45,7 @@ namespace VeraCrypt MouseEventsCounter = 0; - foreach (wxWindow *c, this->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (KeyfileGeneratorDialog::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (this, wxEVT_MOTION, wxMouseEventHandler (KeyfileGeneratorDialog::OnMouseMotion), this); } KeyfileGeneratorDialog::~KeyfileGeneratorDialog () diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp index bed15550..b846a60e 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Volume/Hash.h" #include "RandomPoolEnrichmentDialog.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -46,8 +47,7 @@ namespace VeraCrypt MouseEventsCounter = 0; - foreach (wxWindow *c, this->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (this, wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), this); } RandomPoolEnrichmentDialog::~RandomPoolEnrichmentDialog () diff --git a/src/Main/Forms/WindowEventHandlers.h b/src/Main/Forms/WindowEventHandlers.h new file mode 100644 index 00000000..087cedc7 --- /dev/null +++ b/src/Main/Forms/WindowEventHandlers.h @@ -0,0 +1,30 @@ +/* + Derived from source code of TrueCrypt 7.1a, which is + Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed + by the TrueCrypt License 3.0. + + Modifications and additions to the original source code (contained in this file) + and all other portions of this file are Copyright (c) 2013-2026 AM Crypto + and are governed by the Apache License 2.0 the full text of which is + contained in the file License.txt included in VeraCrypt binary and source + code distribution packages. +*/ + +#ifndef TC_HEADER_Main_Forms_WindowEventHandlers +#define TC_HEADER_Main_Forms_WindowEventHandlers + +#include "Main/Main.h" + +namespace VeraCrypt +{ + inline void ConnectEventToChildWindows (wxWindow *window, wxEventType eventType, wxObjectEventFunction handler, wxEvtHandler *eventSink) + { + foreach (wxWindow *child, window->GetChildren()) + { + child->Connect (eventType, handler, nullptr, eventSink); + ConnectEventToChildWindows (child, eventType, handler, eventSink); + } + } +} + +#endif // TC_HEADER_Main_Forms_WindowEventHandlers diff --git a/src/Main/Forms/WizardFrame.cpp b/src/Main/Forms/WizardFrame.cpp index 4717bcfc..503e6857 100644 --- a/src/Main/Forms/WizardFrame.cpp +++ b/src/Main/Forms/WizardFrame.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Main/Resources.h" #include "WizardFrame.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -40,8 +41,7 @@ namespace VeraCrypt this->SetDefaultItem (NextButton); NextButton->SetFocus(); - foreach (wxWindow *c, MainPanel->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (MainPanel, wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), this); } WizardFrame::~WizardFrame () @@ -145,8 +145,7 @@ namespace VeraCrypt CurrentPage->PageUpdatedEvent.Connect (EventConnector (this, &WizardFrame::OnPageUpdated)); CurrentPage->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); - foreach (wxWindow *c, CurrentPage->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (CurrentPage, wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), this); if (MaxStaticTextWidth > 0) CurrentPage->SetMaxStaticTextWidth (MaxStaticTextWidth);