Skip to content

Commit fc4c45b

Browse files
committed
More iOS windowing fixes, clean up
1 parent d62d023 commit fc4c45b

File tree

11 files changed

+95
-89
lines changed

11 files changed

+95
-89
lines changed

Source/Components/ObjectDragAndDrop.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ class ObjectClickAndDrop final : public Component
102102
objectString = target->getObjectString();
103103
objectName = target->getPatchStringName();
104104

105-
#if JUCE_IOS
106-
addToDesktop(ComponentPeer::windowIsTemporary, editor->getPeer()->getNativeHandle());
107-
#else
108-
addToDesktop(ComponentPeer::windowIsTemporary);
109-
#endif
105+
addToDesktop(ComponentPeer::windowIsTemporary, OSUtils::getDesktopParentPeer(editor));
110106

111107
setAlwaysOnTop(true);
112108

Source/Components/SuggestionComponent.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,10 @@ class SuggestionComponent final : public Component
333333
editor->grabKeyboardFocus();
334334
};
335335
}
336+
337+
338+
addToDesktop(ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses, OSUtils::getDesktopParentPeer(object->editor));
336339

337-
#if JUCE_IOS
338-
addToDesktop(ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses, object->editor->getPeer()->getNativeHandle());
339-
#else
340-
addToDesktop(ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
341-
#endif
342340
if (canBeTransparent()) {
343341
stackDropShadow.setOwner(this);
344342
}

Source/PluginEditor.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ class CalloutArea final : public Component
6161

6262
void timerCallback() override
6363
{
64+
#if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
6465
setBounds(target->getScreenBounds() / getDesktopScaleFactor());
66+
#else
67+
setBounds(target->getScreenBounds());
68+
#endif
6569
}
6670

6771
void paint(Graphics& g) override
@@ -71,14 +75,12 @@ class CalloutArea final : public Component
7175
}
7276
}
7377

74-
78+
#if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
7579
float getDesktopScaleFactor() const override
7680
{
77-
#if JUCE_MAC
78-
return 1.0f; // macOS deals with this for us, otherwise this breaks with multi-display setups
79-
#endif
8081
return getApproximateScaleFactorForComponent(target);
8182
};
83+
#endif
8284

8385
private:
8486
WeakReference<Component> target;
@@ -552,11 +554,7 @@ CallOutBox& PluginEditor::showCalloutBox(std::unique_ptr<Component> content, Rec
552554

553555
if (ProjectInfo::canUseSemiTransparentWindows()) {
554556
content->addComponentListener(new CalloutDeletionListener(this));
555-
#if JUCE_IOS
556-
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary, getPeer()->getNativeHandle());
557-
#else
558-
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary);
559-
#endif
557+
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary, OSUtils::getDesktopParentPeer(this));
560558
calloutArea->toFront(true);
561559
auto const bounds = calloutArea->getLocalArea(nullptr, screenBounds);
562560
return CallOutBox::launchAsynchronously(std::move(content), bounds, calloutArea.get());
@@ -601,10 +599,14 @@ DragAndDropTarget* PluginEditor::findNextDragAndDropTarget(Point<int> screenPos)
601599
void PluginEditor::resized()
602600
{
603601
#if JUCE_IOS
604-
static bool alreadyFullscreen = false;
602+
static bool alreadyResized = false;
605603
if (auto* window = dynamic_cast<PlugDataWindow*>(getTopLevelComponent())) {
606-
if(!alreadyFullscreen) {
607-
ScopedValueSetter recursionBlock(alreadyFullscreen, true);
604+
if(!alreadyResized) {
605+
ScopedValueSetter recursionBlock(alreadyResized, true);
606+
607+
auto totalArea = Desktop::getInstance().getDisplays().getPrimaryDisplay()->totalArea;
608+
totalArea = OSUtils::getSafeAreaInsets().subtractedFrom(totalArea);
609+
setBounds(totalArea);
608610
window->setFullScreen(true);
609611
}
610612
}
@@ -1067,11 +1069,7 @@ void PluginEditor::showCalloutArea(bool shouldBeVisible)
10671069
{
10681070
if(shouldBeVisible)
10691071
{
1070-
#if JUCE_IOS
1071-
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary, getPeer()->getNativeHandle());
1072-
#else
1073-
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary);
1074-
#endif
1072+
calloutArea->addToDesktop(ComponentPeer::windowIsTemporary, OSUtils::getDesktopParentPeer(this));
10751073

10761074
}
10771075
else {

Source/Standalone/PlugDataApp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "Utility/Config.h"
2424
#include "Utility/Fonts.h"
25+
#include "Utility/OSUtils.h"
2526
#include "Utility/PatchInfo.h"
2627
#include "Pd/Setup.h"
2728

Source/Standalone/PlugDataWindow.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,6 @@ class PlugDataWindow final : public DocumentWindow
746746
void resized() override
747747
{
748748
auto r = getLocalBounds().reduced(getMargin());
749-
750749
#if JUCE_IOS
751750
if (auto* peer = getPeer()) {
752751
r = OSUtils::getSafeAreaInsets().subtractedFrom(r);
@@ -781,6 +780,13 @@ class PlugDataWindow final : public DocumentWindow
781780
private:
782781
Rectangle<int> getSizeToContainEditor() const
783782
{
783+
#if JUCE_IOS
784+
if (editor != nullptr) {
785+
auto totalArea = Desktop::getInstance().getDisplays().getPrimaryDisplay()->totalArea;
786+
totalArea = OSUtils::getSafeAreaInsets().addedTo(totalArea);
787+
return totalArea;
788+
}
789+
#endif
784790
if (editor != nullptr)
785791
return getLocalArea(editor.getComponent(), editor->getLocalBounds()).expanded(getMargin());
786792

Source/Utility/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ using namespace juce;
99
#include "Utility/Hash.h"
1010
#include "Utility/SynchronousValue.h"
1111
#include "Utility/SeqLock.h"
12-
#include "Utility/OSUtils.h"
1312

1413
namespace juce {
1514
class AudioDeviceManager;

Source/Utility/OSUtils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <juce_gui_basics/juce_gui_basics.h>
99

1010
#include "OSUtils.h"
11+
#include "Config.h"
1112

1213
#if !defined(__APPLE__)
1314
# undef JUCE_GUI_BASICS_INCLUDE_XHEADERS
@@ -485,6 +486,23 @@ unsigned int OSUtils::keycodeToHID(unsigned int scancode)
485486
#endif
486487
}
487488

489+
void* OSUtils::getDesktopParentPeer(Component* component)
490+
{
491+
// On iOS AUv3 plugins, all dialogs need to have a parent window specified
492+
#if JUCE_IOS
493+
if(!component || ProjectInfo::isStandalone)
494+
return nullptr;
495+
496+
if(auto* peer = component->getPeer())
497+
return peer->getNativeHandle();
498+
499+
return nullptr;
500+
#else
501+
return nullptr;
502+
#endif
503+
}
504+
505+
488506
bool OSUtils::is24HourTimeFormat()
489507
{
490508
#ifdef JUCE_WINDOWS

Source/Utility/OSUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct OSUtils {
2222
};
2323

2424
static unsigned int keycodeToHID(unsigned int scancode);
25+
static void* getDesktopParentPeer(juce::Component* component);
2526

2627
#if defined(_WIN32) || defined(_WIN64)
2728
static bool createJunction(std::string from, std::string to);

Source/Utility/OSUtils.mm

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ - (void)scrollEventOccurred:(UIPanGestureRecognizer*)gesture {
406406
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
407407
if (@available(iOS 11.0, *)) {
408408
UIEdgeInsets insets = window.safeAreaInsets;
409-
return juce::BorderSize<int>(insets.top + (isIPad() ? 26 : 0), insets.left, insets.bottom, insets.right);
409+
return juce::BorderSize<int>(insets.top + (isIPad() ? 26 : 0), insets.left, insets.bottom + (isIPad() ? -20 : 0), insets.right);
410410
}
411411

412412
// Fallback for older iOS versions or devices without safeAreaInsets
@@ -438,55 +438,55 @@ - (void)scrollEventOccurred:(UIPanGestureRecognizer*)gesture {
438438
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Main Menu"
439439
message:nil
440440
preferredStyle:UIAlertControllerStyleActionSheet];
441-
441+
442442
UIAlertAction *themeAction = [UIAlertAction actionWithTitle:@"Select Theme..."
443-
style:UIAlertActionStyleDefault
444-
handler:^(UIAlertAction * _Nonnull action) {
445-
// Create a second UIAlertController for the submenu
446-
UIAlertController *submenu = [UIAlertController alertControllerWithTitle:@"Themes"
447-
message:nil
448-
preferredStyle:UIAlertControllerStyleActionSheet];
449-
450-
// Add actions for the submenu
451-
UIAlertAction *subAction1 = [UIAlertAction actionWithTitle:@"First Theme (Light)"
452-
style:UIAlertActionStyleDefault
453-
handler:^(UIAlertAction * _Nonnull action) {
454-
callback(7);
455-
}];
456-
457-
UIAlertAction *subAction2 = [UIAlertAction actionWithTitle:@"Second Theme (dark)"
458-
style:UIAlertActionStyleDefault
459-
handler:^(UIAlertAction * _Nonnull action) {
460-
callback(8);
461-
}];
462-
463-
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
464-
style:UIAlertActionStyleCancel
465-
handler:^(UIAlertAction * _Nonnull action) {
466-
callback(-1);
467-
}];
443+
style:UIAlertActionStyleDefault
444+
handler:^(UIAlertAction * _Nonnull action) {
445+
// Create a second UIAlertController for the submenu
446+
UIAlertController *submenu = [UIAlertController alertControllerWithTitle:@"Themes"
447+
message:nil
448+
preferredStyle:UIAlertControllerStyleActionSheet];
468449

469-
if (isIPad())
470-
{
471-
472-
submenu.preferredContentSize = view.frame.size;
473-
474-
if (auto* popoverController = submenu.popoverPresentationController)
475-
{
476-
popoverController.sourceView = view;
477-
popoverController.sourceRect = CGRectMake (35.0f, 1.0f, 50.0f, 50.0f);
478-
popoverController.canOverlapSourceViewRect = YES;
479-
}
480-
}
450+
// Add actions for the submenu
451+
UIAlertAction *subAction1 = [UIAlertAction actionWithTitle:@"First Theme (Light)"
452+
style:UIAlertActionStyleDefault
453+
handler:^(UIAlertAction * _Nonnull action) {
454+
callback(7);
455+
}];
481456

482-
[submenu addAction:subAction1];
483-
[submenu addAction:subAction2];
484-
[submenu addAction:cancelAction];
457+
UIAlertAction *subAction2 = [UIAlertAction actionWithTitle:@"Second Theme (dark)"
458+
style:UIAlertActionStyleDefault
459+
handler:^(UIAlertAction * _Nonnull action) {
460+
callback(8);
461+
}];
485462

486-
487-
// Present the submenu
488-
[viewController presentViewController:submenu animated:YES completion:nil];
489-
}];
463+
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
464+
style:UIAlertActionStyleCancel
465+
handler:^(UIAlertAction * _Nonnull action) {
466+
callback(-1);
467+
}];
468+
469+
if (isIPad())
470+
{
471+
472+
submenu.preferredContentSize = view.frame.size;
473+
474+
if (auto* popoverController = submenu.popoverPresentationController)
475+
{
476+
popoverController.sourceView = view;
477+
popoverController.sourceRect = CGRectMake (35.0f, 1.0f, 50.0f, 50.0f);
478+
popoverController.canOverlapSourceViewRect = YES;
479+
}
480+
}
481+
482+
[submenu addAction:subAction1];
483+
[submenu addAction:subAction2];
484+
[submenu addAction:cancelAction];
485+
486+
487+
// Present the submenu
488+
[viewController presentViewController:submenu animated:YES completion:nil];
489+
}];
490490

491491

492492
UIAlertAction *newPatchAction = [UIAlertAction actionWithTitle:@"New Patch"
@@ -539,7 +539,6 @@ - (void)scrollEventOccurred:(UIPanGestureRecognizer*)gesture {
539539

540540
if (isIPad())
541541
{
542-
543542
alertController.preferredContentSize = view.frame.size;
544543

545544
if (auto* popoverController = alertController.popoverPresentationController)
@@ -623,7 +622,6 @@ - (void)scrollEventOccurred:(UIPanGestureRecognizer*)gesture {
623622

624623
if (isIPad())
625624
{
626-
627625
alertController.preferredContentSize = view.frame.size;
628626

629627
if (auto* popoverController = alertController.popoverPresentationController)

Source/Utility/StackDropShadower.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,8 @@ class StackDropShadower final : private ComponentListener {
215215
#endif
216216

217217
setSize(1, 1); // to keep the OS happy by not having zero-size windows
218-
#if JUCE_IOS
219218
addToDesktop(ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresMouseClicks
220-
| ComponentPeer::windowIgnoresKeyPresses, comp->getPeer()->getNativeHandle());
221-
#else
222-
addToDesktop(ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresMouseClicks
223-
| ComponentPeer::windowIgnoresKeyPresses);
224-
#endif
219+
| ComponentPeer::windowIgnoresKeyPresses, OSUtils::getDesktopParentPeer(comp));
225220
} else if (Component* const parent = comp->getParentComponent()) {
226221
parent->addChildComponent(this);
227222
}

0 commit comments

Comments
 (0)