Browse Source

Set transient window on macOS

tags/v2.1-alpha1-winvst
parent
commit
63c27fe30b
4 changed files with 56 additions and 28 deletions
  1. +3
    -2
      source/backend/plugin/CarlaPluginJuce.cpp
  2. +5
    -0
      source/backend/plugin/Makefile
  3. +1
    -1
      source/backend/utils/CachedPlugins.cpp
  4. +47
    -25
      source/utils/JucePluginWindow.hpp

+ 3
- 2
source/backend/plugin/CarlaPluginJuce.cpp View File

@@ -314,7 +314,7 @@ public:
juce::String uiName(pData->name); juce::String uiName(pData->name);
uiName += " (GUI)"; uiName += " (GUI)";


fWindow = new JucePluginWindow();
fWindow = new JucePluginWindow(pData->engine->getOptions().frontendWinId);
fWindow->setName(uiName); fWindow->setName(uiName);
} }


@@ -1232,7 +1232,8 @@ public:
else else
pData->name = pData->engine->getUniquePluginName(fInstance->getName().toRawUTF8()); pData->name = pData->engine->getUniquePluginName(fInstance->getName().toRawUTF8());


pData->filename = carla_strdup(filename);
if (filename != nullptr && pData->filename[0] != '\0')
pData->filename = carla_strdup(filename);


// --------------------------------------------------------------- // ---------------------------------------------------------------
// register client // register client


+ 5
- 0
source/backend/plugin/Makefile View File

@@ -60,6 +60,11 @@ $(OBJDIR)/CarlaPluginVST2.cpp.o: CarlaPluginVST2.cpp
-@mkdir -p $(OBJDIR) -@mkdir -p $(OBJDIR)
@echo "Compiling $<" @echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@ @$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@

$(OBJDIR)/CarlaPluginJuce.cpp.o: CarlaPluginJuce.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@
endif endif


$(OBJDIR)/%.cpp.o: %.cpp $(OBJDIR)/%.cpp.o: %.cpp


+ 1
- 1
source/backend/utils/CachedPlugins.cpp View File

@@ -1,6 +1,6 @@
/* /*
* Carla Plugin Host * Carla Plugin Host
* Copyright (C) 2011-2018 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2011-2019 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as


+ 47
- 25
source/utils/JucePluginWindow.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Juce Plugin Window Helper * Juce Plugin Window Helper
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@@ -23,24 +23,27 @@
#include "AppConfig.h" #include "AppConfig.h"
#include "juce_gui_basics/juce_gui_basics.h" #include "juce_gui_basics/juce_gui_basics.h"


#ifdef HAVE_X11
#if JUCE_LINUX && defined(HAVE_X11)
# include <X11/Xlib.h> # include <X11/Xlib.h>
#elif JUCE_MAC
# import <Cocoa/Cocoa.h>
#endif #endif


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


namespace juce { namespace juce {


#ifdef HAVE_X11
#if JUCE_LINUX && defined(HAVE_X11)
extern Display* display; extern Display* display;
#endif #endif


class JucePluginWindow : public DocumentWindow
class JucePluginWindow : public DialogWindow
{ {
public: public:
JucePluginWindow()
: DocumentWindow("JucePluginWindow", Colour(50, 50, 200), DocumentWindow::closeButton, false),
fClosed(false)
JucePluginWindow(const uintptr_t parentId)
: DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
fClosed(false),
fTransientId(parentId)
{ {
setVisible(false); setVisible(false);
//setAlwaysOnTop(true); //setAlwaysOnTop(true);
@@ -49,21 +52,18 @@ public:
setUsingNativeTitleBar(true); setUsingNativeTitleBar(true);
} }


void show(Component* const comp, const bool useContentOwned = false)
void show(Component* const comp)
{ {
fClosed = false; fClosed = false;


centreWithSize(comp->getWidth(), comp->getHeight()); centreWithSize(comp->getWidth(), comp->getHeight());

if (useContentOwned)
setContentOwned(comp, false);
else
setContentNonOwned(comp, true);
setContentNonOwned(comp, true);


if (! isOnDesktop()) if (! isOnDesktop())
addToDesktop(); addToDesktop();


setVisible(true); setVisible(true);
setTransient();
} }


void hide() void hide()
@@ -81,29 +81,51 @@ public:
return fClosed; return fClosed;
} }


void setTransientWinId(const uintptr_t winId) const
protected:
void closeButtonPressed() override
{
fClosed = true;
}

bool escapeKeyPressed() override
{
fClosed = true;
return true;
}

private:
volatile bool fClosed;
const uintptr_t fTransientId;

void setTransient()
{ {
CARLA_SAFE_ASSERT_RETURN(winId != 0,);
if (fTransientId == 0)
return;


#ifdef HAVE_X11
#if JUCE_LINUX && defined(HAVE_X11)
CARLA_SAFE_ASSERT_RETURN(display != nullptr,); CARLA_SAFE_ASSERT_RETURN(display != nullptr,);


::Window window = (::Window)getWindowHandle(); ::Window window = (::Window)getWindowHandle();


CARLA_SAFE_ASSERT_RETURN(window != 0,); CARLA_SAFE_ASSERT_RETURN(window != 0,);


XSetTransientForHint(display, window, static_cast<Window>(winId));
XSetTransientForHint(display, window, static_cast<::Window>(fTransientId));
#endif #endif
}


protected:
void closeButtonPressed() override
{
fClosed = true;
}
#if JUCE_MAC
NSView* const view = (NSView*)getWindowHandle();
CARLA_SAFE_ASSERT_RETURN(view != nullptr,);


private:
volatile bool fClosed;
NSWindow* const window = [view window];
CARLA_SAFE_ASSERT_RETURN(window != nullptr,);

NSWindow* const parentWindow = [NSApp windowWithWindowNumber:fTransientId];
CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);

[parentWindow addChildWindow:window
ordered:NSWindowAbove];
#endif
}


CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow) CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
}; };


Loading…
Cancel
Save