Skip to content

Commit d8a9bd1

Browse files
committed
Fix X11 maximise glitches
1 parent eca40f1 commit d8a9bd1

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

Source/Standalone/PlugDataWindow.h

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ class PlugDataWindow final : public DocumentWindow
502502

503503
bool isMaximised() const
504504
{
505-
#if JUCE_LINUX
505+
#if JUCE_LINUX || JUCE_BSD
506+
if (hasPendingLinuxMaximisedState)
507+
return pendingLinuxMaximisedState;
508+
506509
if (auto* peer = getPeer()) {
507510
return OSUtils::isLinuxWindowMaximised(peer);
508511
} else {
@@ -523,11 +526,12 @@ class PlugDataWindow final : public DocumentWindow
523526
#if JUCE_LINUX || JUCE_BSD
524527
if (auto* b = getMaximiseButton()) {
525528
if (auto* peer = getPeer()) {
526-
bool shouldBeMaximised = OSUtils::isLinuxWindowMaximised(peer);
527-
b->setToggleState(!shouldBeMaximised, dontSendNotification);
529+
bool shouldBeMaximised = !isMaximised();
530+
setPendingLinuxMaximisedState(shouldBeMaximised);
531+
b->setToggleState(shouldBeMaximised, dontSendNotification);
528532

529533
if (!useNativeTitlebar()) {
530-
OSUtils::maximiseLinuxWindow(peer, !shouldBeMaximised);
534+
OSUtils::maximiseLinuxWindow(peer, shouldBeMaximised);
531535
}
532536
} else {
533537
b->setToggleState(false, dontSendNotification);
@@ -619,6 +623,31 @@ class PlugDataWindow final : public DocumentWindow
619623
}
620624

621625
private:
626+
#if JUCE_LINUX || JUCE_BSD
627+
void setPendingLinuxMaximisedState(bool shouldBeMaximised)
628+
{
629+
hasPendingLinuxMaximisedState = true;
630+
pendingLinuxMaximisedState = shouldBeMaximised;
631+
auto const pendingStateSerial = ++pendingLinuxMaximisedStateSerial;
632+
633+
Timer::callAfterDelay(250, [_this = SafePointer(this), pendingStateSerial] {
634+
if (!_this)
635+
return;
636+
637+
if (_this->pendingLinuxMaximisedStateSerial != pendingStateSerial)
638+
return;
639+
640+
_this->hasPendingLinuxMaximisedState = false;
641+
642+
if (auto* b = _this->getMaximiseButton())
643+
b->setToggleState(_this->isMaximised(), dontSendNotification);
644+
645+
_this->resized();
646+
_this->repaint();
647+
});
648+
}
649+
#endif
650+
622651
class MainContentComponent final : public Component
623652
, private ComponentListener
624653
, public MenuBarModel {
@@ -784,5 +813,13 @@ class PlugDataWindow final : public DocumentWindow
784813
public:
785814
MainContentComponent* mainComponent = nullptr;
786815

816+
private:
817+
#if JUCE_LINUX || JUCE_BSD
818+
bool hasPendingLinuxMaximisedState = false;
819+
bool pendingLinuxMaximisedState = false;
820+
int pendingLinuxMaximisedStateSerial = 0;
821+
#endif
822+
823+
public:
787824
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PlugDataWindow)
788825
};

Source/Utility/OSUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool OSUtils::isLinuxWindowMaximised(ComponentPeer* peer)
286286
XFree(states);
287287
}
288288

289-
return state & WINDOW_STATE_MAXIMIZED;
289+
return (state & WINDOW_STATE_MAXIMIZED) != 0;
290290
}
291291

292292
void OSUtils::maximiseLinuxWindow(ComponentPeer* peer, bool shouldBeMaximised)

0 commit comments

Comments
 (0)