Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions src/ArSonWindowChrome.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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();
Expand All @@ -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
{
Expand Down Expand Up @@ -100,6 +129,8 @@ class MixerCaptionButton final : public juce::Button
return {};
}
int kind_;
bool pendingClick_ = false;
juce::ModifierKeys pendingModifiers_;
std::unique_ptr<juce::Drawable> icon_, restoreIcon_, pressedIcon_, pressedRestoreIcon_;
};

Expand Down
33 changes: 28 additions & 5 deletions tests/native_caption_wire_geometry_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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\)/);
Expand All @@ -41,23 +41,46 @@ const palette = chrome.slice(chrome.indexOf('static CaptionPalette paletteFor'),
chrome.indexOf('static std::unique_ptr<juce::Drawable> 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/);
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. */
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<juce::Drawable> 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::/);
Expand Down
Loading