JUCE v8.0.10
Hi, this is a strange problem: when Windows wakes up after Sleep (or hibernation), the Content component in my window (instance of DocumentWindow)is shifted up and to the left as if there was no window decoration. The bottom and right areas are transparent. The mouse is acting on the correct positions, so button hover messages are happening with an offset to what you see. GUI updates (repaint, resized() etc.) will not fix that the origin of the components are shifted (screenshot 2).
Moving the window (by dragging the title bar) will reposition the content component so that the bottom and right areas are correct, but now the area which was covered by the title bar is transparent (screenshot 3).
Resizing the window will finally fix it.
I was not able to find a work-around. I tried, for example, calling resized() after sleep mode, but it would just re-layout using the shifted origin.
- Correct screenshot:
- After Sleep:
(there is stuff visible that is behind the Test window)
- After moving window:
Here is that minimal application to reproduce the issue:
#include "JuceLibraryCode/JuceHeader.h"
class NewProjectApplication : public juce::JUCEApplication
{
public:
NewProjectApplication() {}
const juce::String getApplicationName() override { return "Test"; }
const juce::String getApplicationVersion() override { return "0.1"; }
bool moreThanOneInstanceAllowed() override { return true; }
void initialise (const juce::String& commandLine) override
{
mainWindow.reset (new MainWindow (getApplicationName()));
}
void shutdown() override
{
mainWindow = nullptr;
}
void systemRequestedQuit() override
{
quit();
}
void anotherInstanceStarted (const juce::String& commandLine) override
{
(void)commandLine; // satisfy compiler
}
class MainComponent : public juce::Component
{
public:
MainComponent()
{
// add four buttons
for (int i = 0; i <= 4; ++i)
{
auto* button = new juce::TextButton("Button " + juce::String(i + 1));
addAndMakeVisible(button);
}
}
~MainComponent() override
{
deleteAllChildren();
}
void adjustButton(int index, int x, int y)
{
juce::TextButton* button = dynamic_cast<juce::TextButton*>(getChildComponent(index));
button->setBounds(x, y, buttonWidth, buttonHeight);
button->setButtonText("Button " + juce::String(index + 1) + ": " + juce::String(x) + "," + juce::String(y));
}
void resized() override
{
if (getNumChildComponents() < 4)
return;
// position the four components in the corners of the window
auto area = getLocalBounds();
adjustButton(0, 0, 0);
adjustButton(1, area.getWidth() - buttonWidth, 0);
adjustButton(2, 0, area.getHeight() - buttonHeight);
adjustButton(3, area.getWidth() - buttonWidth, area.getHeight() - buttonHeight);
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
const int buttonHeight = 40;
const int buttonWidth = 130;
};
class MainWindow : public juce::DocumentWindow
{
public:
MainWindow (juce::String name)
: DocumentWindow (name,
juce::Desktop::getInstance().getDefaultLookAndFeel()
.findColour (juce::ResizableWindow::backgroundColourId),
DocumentWindow::allButtons)
{
setUsingNativeTitleBar (true);
setContentOwned(new MainComponent(), true);
setResizable(true, false);
setVisible(true);
setBounds(300, 300, 300, 100);
}
void closeButtonPressed() override
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
std::unique_ptr<MainWindow> mainWindow;
};
START_JUCE_APPLICATION (NewProjectApplication)
This problem started happening when I switched to JUCE 8.
Has anyone else encountered this? Am I doing something wrong?





