From 2972e1a55162b2f913d3209383f0cff72a800356 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 16:29:04 +0700 Subject: [PATCH 1/4] fix(caption): hold bright click face for one frame before native window action --- src/ArSonWindowChrome.h | 49 +++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/ArSonWindowChrome.h b/src/ArSonWindowChrome.h index e9c397ee1..ead5516d7 100644 --- a/src/ArSonWindowChrome.h +++ b/src/ArSonWindowChrome.h @@ -6,7 +6,7 @@ namespace armix::ui { // Only the main JUCE mixer window uses this caption. No WebView2 command // round trips for minimise, maximise, close, drag or OS window resizing. -class MixerCaptionButton final : public juce::Button +class MixerCaptionButton final : public juce::Button, private juce::Timer { public: explicit MixerCaptionButton (int kind) : Button ("ArSonMiX window control"), kind_ (kind) @@ -36,16 +36,19 @@ class MixerCaptionButton final : public juce::Button void paintButton (juce::Graphics& g, bool over, bool down) override { - // Native window caption: semantic, low-glare hover followed by a - // clearly lit pressed face. No animations, timers, CSS or WebView2. - // Keep the existing 34 px click target and original SVG geometry. - if (over || down) + // The caption action would normally run on mouse-up in the SAME + // message-loop turn, immediately minimising/closing before JUCE can + // paint its bright down state. Keep the accepted pressed colour + // visible for one bounded 160 ms feedback interval before dispatch. + // Inactive/hover appearance and original SVG geometry are unchanged. + const bool pressed = down || pendingClick_; + if (over || pressed) { const auto palette = paletteFor (kind_); const auto face = getLocalBounds().toFloat().reduced (2.0f, 3.0f); - g.setColour (down ? palette.pressedFace : palette.hoverFace); + g.setColour (pressed ? palette.pressedFace : palette.hoverFace); g.fillRoundedRectangle (face, 3.0f); - g.setColour (down ? palette.pressedEdge : palette.hoverEdge); + g.setColour (pressed ? palette.pressedEdge : palette.hoverEdge); g.drawRoundedRectangle (face.reduced (0.5f), 3.0f, 1.0f); } if (hasKeyboardFocus (true)) @@ -57,8 +60,8 @@ class MixerCaptionButton final : public juce::Button const bool restoring = kind_ == juce::DocumentWindow::maximiseButton && parent != nullptr && parent->isFullScreen(); auto* image = restoring - ? (down && pressedRestoreIcon_ != nullptr ? pressedRestoreIcon_.get() : restoreIcon_.get()) - : (down && pressedIcon_ != nullptr ? pressedIcon_.get() : icon_.get()); + ? (pressed && pressedRestoreIcon_ != nullptr ? pressedRestoreIcon_.get() : restoreIcon_.get()) + : (pressed && pressedIcon_ != nullptr ? pressedIcon_.get() : icon_.get()); if (image != nullptr) { const auto b = getLocalBounds().toFloat(); @@ -67,6 +70,32 @@ class MixerCaptionButton final : public juce::Button } } + void internalClickCallback (const juce::ModifierKeys& modifiers) override + { + // JUCE's Button::mouseUp invokes the document window listener + // immediately, before the down-state repaint is serviced. Keep the + // exact native button command but give the operator a perceptible + // lit-press frame first. Repeated clicks cannot queue duplicate + // minimise/maximise/quit commands. + if (!isEnabled() || pendingClick_) + return; + pendingModifiers_ = modifiers; + pendingClick_ = true; + repaint(); + startTimer (160); // one-shot JUCE message-thread feedback; no audio involvement + } + + void timerCallback() override + { + stopTimer(); + pendingClick_ = false; + repaint(); + // Dispatch through JUCE's original DocumentWindow listener *only* + // after the pressed face has had time to paint. The command may + // destroy this button (Close), so do nothing after this call. + juce::Button::internalClickCallback (pendingModifiers_); + } + private: struct CaptionPalette { @@ -100,6 +129,8 @@ class MixerCaptionButton final : public juce::Button return {}; } int kind_; + bool pendingClick_ = false; + juce::ModifierKeys pendingModifiers_; std::unique_ptr icon_, restoreIcon_, pressedIcon_, pressedRestoreIcon_; }; From 9f90d3b134762667aacbfdc19abdc641c027a616 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 16:29:33 +0700 Subject: [PATCH 2/4] test(caption): prove visible pressed-frame hold precedes real JUCE native command --- ...ve_caption_wire_geometry_contract.test.cjs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/native_caption_wire_geometry_contract.test.cjs b/tests/native_caption_wire_geometry_contract.test.cjs index c0c985b41..1f7f753cd 100644 --- a/tests/native_caption_wire_geometry_contract.test.cjs +++ b/tests/native_caption_wire_geometry_contract.test.cjs @@ -50,6 +50,29 @@ assert.doesNotMatch(palette, /0xff50d4e7|0xff67b9ff|0xff168fa7|0xff287abd/); assert.match(chrome, /drawRoundedRectangle/); assert.match(chrome, /parent->isFullScreen\(\)/); +/* JUCE 8 Button::mouseUp runs its listener before the message-loop's paint: + * Close/minimize vanish and maximize changes geometry before the bright click + * face is drawn. Test a real bounded, one-shot paint->dispatch handoff, not + * just the existence of red/green/amber palette hex values. */ +assert.match(chrome,/class MixerCaptionButton final : public juce::Button, private juce::Timer/); +assert.match(chrome,/const bool pressed = down \|\| pendingClick_/); +assert.match(chrome,/g\.setColour \(pressed \? palette\.pressedFace : palette\.hoverFace\)/); +assert.match(chrome,/g\.setColour \(pressed \? palette\.pressedEdge : palette\.hoverEdge\)/); +assert.match(chrome,/pressed && pressedRestoreIcon_ != nullptr/); +assert.match(chrome,/pressed && pressedIcon_ != nullptr/); +const defer=chrome.slice(chrome.indexOf('void internalClickCallback ('), + chrome.indexOf('private:\n struct CaptionPalette')); +assert.match(defer,/if \(!isEnabled\(\) \|\| pendingClick_\)\s*return/); +assert.match(defer,/pendingModifiers_ = modifiers/); +assert.match(defer,/pendingClick_ = true;\s*repaint\(\);\s*startTimer \(160\)/); +assert.match(defer,/void timerCallback\(\) override/); +assert.match(defer,/stopTimer\(\);\s*pendingClick_ = false;\s*repaint\(\);/); +assert.match(defer,/juce::Button::internalClickCallback \(pendingModifiers_\)/); +assert.equal((defer.match(/juce::Button::internalClickCallback/g)||[]).length,1, + 'a caption click must dispatch once, through the original JUCE listener'); +assert.doesNotMatch(defer,/engine_|WebView|setAlwaysOnTop|toFront|sleep|Thread::sleep|std::thread/); + + /* Dark-ink pressed glyphs are prebuilt once, not reparsed/recoloured when paintButton receives a hover or pointer-down transition. Maintain WCAG non-text graphic contrast against the luminous green/amber pressed faces. */ From bb8f98f9cc361d14a625e63b8b58406ba0f852e3 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 16:44:26 +0700 Subject: [PATCH 3/4] test(caption): assert visible latched pressed state, not obsolete down-only drawing --- tests/native_caption_wire_geometry_contract.test.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/native_caption_wire_geometry_contract.test.cjs b/tests/native_caption_wire_geometry_contract.test.cjs index 1f7f753cd..6df3bab92 100644 --- a/tests/native_caption_wire_geometry_contract.test.cjs +++ b/tests/native_caption_wire_geometry_contract.test.cjs @@ -26,7 +26,7 @@ assert.match(activation,/for \(auto\* control : \{ getMinimiseButton\(\), getMax assert.match(activation,/control->setEnabled \(true\)/); assert.doesNotMatch(activation,/startTimer|setAlwaysOnTop|toFront|SetForegroundWindow|engine_/); assert.match(chrome,/void paintButton \(juce::Graphics& g, bool over, bool down\) override/); -assert.match(chrome,/if \(over \|\| down\)/); +assert.match(chrome,/if \(over \|\| pressed\)/); assert.match(main, /setUsingNativeTitleBar \(false\)/); assert.match(main, /setTitleBarHeight \(31\)/); @@ -41,8 +41,8 @@ const palette = chrome.slice(chrome.indexOf('static CaptionPalette paletteFor'), chrome.indexOf('static std::unique_ptr load')); assert.ok(palette.length > 300, 'native caption must own one state palette'); assert.match(chrome, /const auto palette = paletteFor \(kind_\)/); -assert.match(chrome, /down \? palette\.pressedFace : palette\.hoverFace/); -assert.match(chrome, /down \? palette\.pressedEdge : palette\.hoverEdge/); +assert.match(chrome, /pressed \? palette\.pressedFace : palette\.hoverFace/); +assert.match(chrome, /pressed \? palette\.pressedEdge : palette\.hoverEdge/); assert.match(palette, /closeButton[\s\S]*?0xff5c3039[\s\S]*?0xffab5864[\s\S]*?0xffef3e50[\s\S]*?0xffff8993/); assert.match(palette, /minimiseButton[\s\S]*?0xff244e3a[\s\S]*?0xff4ead7a[\s\S]*?0xff1fb76b[\s\S]*?0xff8be2b4/); assert.match(palette, /0xff584929[\s\S]*?0xffbc9544[\s\S]*?0xffe5ae2b[\s\S]*?0xffffdf81/); From aacab317c407f25b1cedcc5642c122dce3148bd7 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 16:45:41 +0700 Subject: [PATCH 4/4] test(caption): update pressed-glyph assertions for native 160ms feedback hold --- tests/native_caption_wire_geometry_contract.test.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/native_caption_wire_geometry_contract.test.cjs b/tests/native_caption_wire_geometry_contract.test.cjs index 6df3bab92..8042978db 100644 --- a/tests/native_caption_wire_geometry_contract.test.cjs +++ b/tests/native_caption_wire_geometry_contract.test.cjs @@ -79,8 +79,8 @@ assert.doesNotMatch(defer,/engine_|WebView|setAlwaysOnTop|toFront|sleep|Thread:: assert.match(chrome, /pressedIcon_ = load \(iconPath, kind == juce::DocumentWindow::minimiseButton/); assert.match(chrome, /pressedRestoreIcon_ = load \(restorePath/); assert.match(chrome, /const bool restoring = kind_ == juce::DocumentWindow::maximiseButton/); -assert.match(chrome, /down && pressedRestoreIcon_ != nullptr/); -assert.match(chrome, /down && pressedIcon_ != nullptr/); +assert.match(chrome, /pressed && pressedRestoreIcon_ != nullptr/); +assert.match(chrome, /pressed && pressedIcon_ != nullptr/); assert.match(chrome, /static std::unique_ptr load \(const char\* path, const char\* ink/); const paint = chrome.slice(chrome.indexOf('void paintButton '), chrome.indexOf('private:\n struct CaptionPalette')); assert.doesNotMatch(paint, /Drawable::createFromSVG|XmlDocument::parse|std::make_unique|new juce::/);