Browse Source

Initial Cocoa Plugin UI support

tags/1.9.8
falkTX 7 years ago
parent
commit
027ec425b4
4 changed files with 185 additions and 17 deletions
  1. +7
    -0
      source/backend/Makefile
  2. +7
    -0
      source/backend/engine/Makefile
  3. +7
    -0
      source/bridges-plugin/Makefile
  4. +164
    -17
      source/utils/CarlaPluginUI.cpp

+ 7
- 0
source/backend/Makefile View File

@@ -105,6 +105,13 @@ $(BINDIR)/libcarla_utils$(LIB_EXT): $(OBJS_utils) $(UTILS_LIBS)

# ----------------------------------------------------------------------------------------------------------------------------

ifeq ($(MACOS),true)
$(OBJDIR)/CarlaStandalone.cpp.o: CarlaStandalone.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@
endif

$(OBJDIR)/%.cpp.o: %.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"


+ 7
- 0
source/backend/engine/Makefile View File

@@ -65,10 +65,17 @@ $(OBJDIR)/CarlaEngineRtAudio.cpp.o: CarlaEngineRtAudio.cpp
@echo "Compiling CarlaEngineRtAudio.cpp"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(RTAUDIO_FLAGS) $(RTMIDI_FLAGS) -c -o $@

ifeq ($(MACOS),true)
$(OBJDIR)/CarlaEngineNative.cpp.exp.o: CarlaEngineNative.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaEngineNative.cpp (plugin)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DCARLA_PLUGIN_EXPORT -ObjC++ -c -o $@
else
$(OBJDIR)/CarlaEngineNative.cpp.exp.o: CarlaEngineNative.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaEngineNative.cpp (plugin)"
@$(CXX) $< $(BUILD_CXX_FLAGS) -DCARLA_PLUGIN_EXPORT -c -o $@
endif

$(OBJDIR)/%.cpp.o: %.cpp
-@mkdir -p $(OBJDIR)


+ 7
- 0
source/bridges-plugin/Makefile View File

@@ -233,10 +233,17 @@ $(OBJDIR)/CarlaPlug%.cpp.o: $(CWD)/backend/plugin/CarlaPlug%.cpp
@echo "Compiling CarlaPlug$*.cpp (bridge)"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(NATIVE_BUILD_FLAGS) -c -o $@

ifeq ($(MACOS),true)
$(OBJDIR)/CarlaStandalone.cpp.o: $(CWD)/backend/CarlaStandalone.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaStandalone.cpp (bridge)"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(NATIVE_BUILD_FLAGS) -ObjC++ -c -o $@
else
$(OBJDIR)/CarlaStandalone.cpp.o: $(CWD)/backend/CarlaStandalone.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaStandalone.cpp (bridge)"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(NATIVE_BUILD_FLAGS) -c -o $@
endif

# ----------------------------------------------------------------------------------------------------------------------
# posix32


+ 164
- 17
source/utils/CarlaPluginUI.cpp View File

@@ -25,10 +25,12 @@
# include <X11/Xutil.h>
#endif

#ifdef CARLA_OS_MAC
# import <Cocoa/Cocoa.h>
#endif

#ifdef CARLA_OS_WIN
# include <ctime>
// # include <cstdio>
// # include <cstdlib>
#endif

// ---------------------------------------------------------------------------------------------------------------------
@@ -320,6 +322,157 @@ private:
};
#endif // HAVE_X11

// ---------------------------------------------------------------------------------------------------------------------
// MacOS / Cocoa

#ifdef CARLA_OS_MAC

class CocoaPluginUI : public CarlaPluginUI
{
public:
CocoaPluginUI(CloseCallback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
: CarlaPluginUI(cb, isResizable),
fView(nullptr),
fWindow(0)
{
[NSAutoreleasePool new];
[NSApplication sharedApplication];

fView = [NSView new];
CARLA_SAFE_ASSERT_RETURN(fView != nullptr,)

if (isResizable)
[fView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];

fWindow = [[NSWindow new]retain];

if (fWindow == 0)
{
[fView release];
fView = nullptr;
return;
}

[fWindow setIsVisible:NO];
[fWindow setContentView:fView];
[fWindow makeFirstResponder:fView];
[fWindow makeKeyAndOrderFront:fWindow];

[NSApp activateIgnoringOtherApps:YES];
[fWindow center];

#if 0
uint styleMask = NSClosableWindowMask | NSTitledWindowMask;

if (isResizable)
styleMask |= NSResizableWindowMask;

fWindow = [NSWindow initWithContentRect:contentRect
styleMask:flags
backing:NSBackingStoreBuffered defer:NO];

#endif
}

~CocoaPluginUI() override
{
if (fView == nullptr)
return;

[fWindow close];
[fView release];
[fWindow release];
}

void show() override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);

[fWindow setIsVisible:YES];
}

void hide() override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);

[fWindow setIsVisible:NO];
}

void idle() override
{
}

void focus() override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);

// TODO
}

void setSize(const uint width, const uint height, const bool forceUpdate) override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,);
CARLA_SAFE_ASSERT_RETURN(fView != nullptr,);

[fView setFrame:NSMakeRect(0, 0, width, height)];

const NSSize size = NSMakeSize(width, height);
[fWindow setContentSize:size];

#if 0
if (fResizable)
{
[fWindow setContentMinSize:NSMakeSize(1, 1)];
[fWindow setContentMaxSize:NSMakeSize(99999, 99999)];
[[fWindow standardWindowButton:NSWindowZoomButton] setHidden:NO];
}
else
{
[fWindow setContentMinSize:size];
[fWindow setContentMaxSize:size];
[[fWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
}
#endif
}

void setTitle(const char* const title) override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);

NSString* titleString = [[NSString alloc]
initWithBytes:title
length:strlen(title)
encoding:NSUTF8StringEncoding];

[fWindow setTitle:titleString];
}

void setTransientWinId(const uintptr_t winId) override
{
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);

// TODO
}

void* getPtr() const noexcept override
{
return (void*)fView;
}

void* getDisplay() const noexcept
{
return (void*)fWindow;
}

private:
NSView* fView;
id fWindow;

CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CocoaPluginUI)
};

#endif // CARLA_OS_MAC

// ---------------------------------------------------------------------------------------------------------------------
// Windows

@@ -549,13 +702,7 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons
CARLA_SAFE_ASSERT_RETURN(uiTitle != nullptr && uiTitle[0] != '\0', true);
CARLA_SAFE_ASSERT_RETURN(winId != 0, true);

#if defined(CARLA_OS_MAC)
return true;
(void)pid; (void)centerUI;
#elif defined(CARLA_OS_WIN)
return true;
(void)pid; (void)centerUI;
#elif defined(HAVE_X11)
#if defined(HAVE_X11)
struct ScopedDisplay {
Display* display;
ScopedDisplay() : display(XOpenDisplay(nullptr)) {}
@@ -762,10 +909,17 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons

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

#ifdef HAVE_X11
CarlaPluginUI* CarlaPluginUI::newX11(CloseCallback* cb, uintptr_t parentId, bool isResizable)
{
return new X11PluginUI(cb, parentId, isResizable);
}
#endif

#ifdef CARLA_OS_MAC
CarlaPluginUI* CarlaPluginUI::newCocoa(CloseCallback* cb, uintptr_t parentId, bool isResizable)
{
return nullptr;
return new CocoaPluginUI(cb, parentId, isResizable);
}
#endif

@@ -776,11 +930,4 @@ CarlaPluginUI* CarlaPluginUI::newWindows(CloseCallback* cb, uintptr_t parentId,
}
#endif

#ifdef HAVE_X11
CarlaPluginUI* CarlaPluginUI::newX11(CloseCallback* cb, uintptr_t parentId, bool isResizable)
{
return new X11PluginUI(cb, parentId, isResizable);
}
#endif

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

Loading…
Cancel
Save