From 14b4536aad5651cf8586882090382d0b66b3504b Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 17 Aug 2019 22:19:30 +0100 Subject: [PATCH] Reorder some code and add stubs for HaikuOS support Signed-off-by: falkTX --- Makefile.base.mk | 19 ++- dgl/src/Window.cpp | 193 ++++++++++++++++------------ dgl/src/pugl/pugl_haiku.cpp | 123 ++++++++++++++++++ examples/CairoUI/Makefile | 2 +- examples/ExternalUI/Makefile | 2 + examples/Latency/Makefile | 2 +- examples/Meters/Makefile | 2 +- examples/Parameters/Makefile | 2 +- examples/States/Makefile | 2 +- utils/lv2-ttl-generator/GNUmakefile | 22 +++- 10 files changed, 271 insertions(+), 98 deletions(-) create mode 100644 dgl/src/pugl/pugl_haiku.cpp diff --git a/Makefile.base.mk b/Makefile.base.mk index 6c7d17aa..b3644cdc 100644 --- a/Makefile.base.mk +++ b/Makefile.base.mk @@ -208,18 +208,22 @@ HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true) # --------------------------------------------------------------------------------------------------------------------- # Set Generic DGL stuff +ifeq ($(HAIKU),true) +DGL_SYSTEM_LIBS += -lbe +endif + ifeq ($(MACOS),true) -DGL_SYSTEM_LIBS += -framework Cocoa +DGL_SYSTEM_LIBS += -framework Cocoa endif ifeq ($(WINDOWS),true) -DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32 +DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32 endif ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) ifeq ($(HAVE_X11),true) -DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11) +DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) +DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11) endif endif @@ -244,6 +248,11 @@ ifeq ($(HAVE_OPENGL),true) DGL_FLAGS += -DHAVE_OPENGL +ifeq ($(HAIKU),true) +OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl) +OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl) +endif + ifeq ($(MACOS),true) OPENGL_LIBS = -framework OpenGL endif @@ -252,7 +261,7 @@ ifeq ($(WINDOWS),true) OPENGL_LIBS = -lopengl32 endif -ifneq ($(MACOS_OR_WINDOWS),true) +ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11) OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11) endif diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index f715e549..477c8e53 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -37,14 +37,16 @@ # pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif -#if defined(DISTRHO_OS_WINDOWS) -# include "pugl/pugl_win.cpp" -# undef max -# undef min +#if defined(DISTRHO_OS_HAIKU) +# include "pugl/pugl_haiku.cpp" #elif defined(DISTRHO_OS_MAC) # define PuglWindow DISTRHO_JOIN_MACRO(PuglWindow, DGL_NAMESPACE) # define PuglOpenGLView DISTRHO_JOIN_MACRO(PuglOpenGLView, DGL_NAMESPACE) # include "pugl/pugl_osx.m" +#elif defined(DISTRHO_OS_WINDOWS) +# include "pugl/pugl_win.cpp" +# undef max +# undef min #else # include # include @@ -99,14 +101,16 @@ struct Window::PrivateData { fTitle(nullptr), fWidgets(), fModal(), -#if defined(DISTRHO_OS_WINDOWS) - hwnd(nullptr), - hwndParent(nullptr) +#if defined(DISTRHO_OS_HAIKU) + bWindow(nullptr) #elif defined(DISTRHO_OS_MAC) fNeedsIdle(true), mView(nullptr), mWindow(nullptr), mParentWindow(nullptr) +#elif defined(DISTRHO_OS_WINDOWS) + hwnd(nullptr), + hwndParent(nullptr) # ifndef DGL_FILE_BROWSER_DISABLED , fOpenFilePanel(nullptr), fFilePanelDelegate(nullptr) @@ -135,14 +139,16 @@ struct Window::PrivateData { fTitle(nullptr), fWidgets(), fModal(parent.pData), -#if defined(DISTRHO_OS_WINDOWS) - hwnd(nullptr), - hwndParent(nullptr) +#if defined(DISTRHO_OS_HAIKU) + bWindow(nullptr) #elif defined(DISTRHO_OS_MAC) fNeedsIdle(false), mView(nullptr), mWindow(nullptr), mParentWindow(nullptr) +#elif defined(DISTRHO_OS_WINDOWS) + hwnd(nullptr), + hwndParent(nullptr) # ifndef DGL_FILE_BROWSER_DISABLED , fOpenFilePanel(nullptr), fFilePanelDelegate(nullptr) @@ -158,11 +164,13 @@ struct Window::PrivateData { const PuglInternals* const parentImpl(parent.pData->fView->impl); // NOTE: almost a 1:1 copy of setTransientWinId() -#if defined(DISTRHO_OS_WINDOWS) - hwndParent = parentImpl->hwnd; - SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)hwndParent); +#if defined(DISTRHO_OS_HAIKU) + // TODO #elif defined(DISTRHO_OS_MAC) mParentWindow = parentImpl->window; +#elif defined(DISTRHO_OS_WINDOWS) + hwndParent = parentImpl->hwnd; + SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)hwndParent); #else XSetTransientForHint(xDisplay, xWindow, parentImpl->win); #endif @@ -183,14 +191,16 @@ struct Window::PrivateData { fTitle(nullptr), fWidgets(), fModal(), -#if defined(DISTRHO_OS_WINDOWS) - hwnd(nullptr), - hwndParent(nullptr) +#if defined(DISTRHO_OS_HAIKU) + bWindow(nullptr) #elif defined(DISTRHO_OS_MAC) fNeedsIdle(parentId == 0), mView(nullptr), mWindow(nullptr), mParentWindow(nullptr) +#elif defined(DISTRHO_OS_WINDOWS) + hwnd(nullptr), + hwndParent(nullptr) # ifndef DGL_FILE_BROWSER_DISABLED , fOpenFilePanel(nullptr), fFilePanelDelegate(nullptr) @@ -249,9 +259,8 @@ struct Window::PrivateData { PuglInternals* impl = fView->impl; -#if defined(DISTRHO_OS_WINDOWS) - hwnd = impl->hwnd; - DISTRHO_SAFE_ASSERT(hwnd != 0); +#if defined(DISTRHO_OS_HAIKU) + bWindow = impl->window; #elif defined(DISTRHO_OS_MAC) mView = impl->view; mWindow = impl->window; @@ -261,6 +270,9 @@ struct Window::PrivateData { } else { DISTRHO_SAFE_ASSERT(mWindow != nullptr); } +#elif defined(DISTRHO_OS_WINDOWS) + hwnd = impl->hwnd; + DISTRHO_SAFE_ASSERT(hwnd != 0); #else xDisplay = impl->display; xWindow = impl->win; @@ -327,11 +339,12 @@ struct Window::PrivateData { fTitle = nullptr; } -#if defined(DISTRHO_OS_WINDOWS) - hwnd = 0; +#if defined(DISTRHO_OS_HAIKU) #elif defined(DISTRHO_OS_MAC) mView = nullptr; mWindow = nullptr; +#elif defined(DISTRHO_OS_WINDOWS) + hwnd = 0; #else xDisplay = nullptr; xWindow = 0; @@ -419,10 +432,12 @@ struct Window::PrivateData { // the mouse position probably changed since the modal appeared, // so send a mouse motion event to the modal's parent window -#if defined(DISTRHO_OS_WINDOWS) +#if defined(DISTRHO_OS_HAIKU) // TODO #elif defined(DISTRHO_OS_MAC) // TODO +#elif defined(DISTRHO_OS_WINDOWS) + // TODO #else int i, wx, wy; uint u; @@ -440,13 +455,14 @@ struct Window::PrivateData { void focus() { DBG("Window focus\n"); -#if defined(DISTRHO_OS_WINDOWS) - SetForegroundWindow(hwnd); - SetActiveWindow(hwnd); - SetFocus(hwnd); +#if defined(DISTRHO_OS_HAIKU) #elif defined(DISTRHO_OS_MAC) if (mWindow != nullptr) [mWindow makeKeyWindow]; +#elif defined(DISTRHO_OS_WINDOWS) + SetForegroundWindow(hwnd); + SetActiveWindow(hwnd); + SetFocus(hwnd); #else XRaiseWindow(xDisplay, xWindow); XSetInputFocus(xDisplay, xWindow, RevertToPointerRoot, CurrentTime); @@ -476,7 +492,39 @@ struct Window::PrivateData { if (yesNo && fFirstInit) setSize(fWidth, fHeight, true); -#if defined(DISTRHO_OS_WINDOWS) +#if defined(DISTRHO_OS_HAIKU) + // TODO +#elif defined(DISTRHO_OS_MAC) + if (yesNo) + { + if (mWindow != nullptr) + { + if (mParentWindow != nullptr) + [mParentWindow addChildWindow:mWindow + ordered:NSWindowAbove]; + + [mWindow setIsVisible:YES]; + } + else + { + [mView setHidden:NO]; + } + } + else + { + if (mWindow != nullptr) + { + if (mParentWindow != nullptr) + [mParentWindow removeChildWindow:mWindow]; + + [mWindow setIsVisible:NO]; + } + else + { + [mView setHidden:YES]; + } + } +#elif defined(DISTRHO_OS_WINDOWS) if (yesNo) { if (fFirstInit) @@ -508,36 +556,6 @@ struct Window::PrivateData { } UpdateWindow(hwnd); -#elif defined(DISTRHO_OS_MAC) - if (yesNo) - { - if (mWindow != nullptr) - { - if (mParentWindow != nullptr) - [mParentWindow addChildWindow:mWindow - ordered:NSWindowAbove]; - - [mWindow setIsVisible:YES]; - } - else - { - [mView setHidden:NO]; - } - } - else - { - if (mWindow != nullptr) - { - if (mParentWindow != nullptr) - [mParentWindow removeChildWindow:mWindow]; - - [mWindow setIsVisible:NO]; - } - else - { - [mView setHidden:YES]; - } - } #else if (yesNo) XMapRaised(xDisplay, xWindow); @@ -579,13 +597,15 @@ struct Window::PrivateData { fResizable = yesNo; fView->user_resizable = yesNo; -#if defined(DISTRHO_OS_WINDOWS) - const int winFlags = fResizable ? GetWindowLong(hwnd, GWL_STYLE) | WS_SIZEBOX - : GetWindowLong(hwnd, GWL_STYLE) & ~WS_SIZEBOX; - SetWindowLong(hwnd, GWL_STYLE, winFlags); +#if defined(DISTRHO_OS_HAIKU) + // TODO #elif defined(DISTRHO_OS_MAC) const uint flags(yesNo ? (NSViewWidthSizable|NSViewHeightSizable) : 0x0); [mView setAutoresizingMask:flags]; +#elif defined(DISTRHO_OS_WINDOWS) + const int winFlags = fResizable ? GetWindowLong(hwnd, GWL_STYLE) | WS_SIZEBOX + : GetWindowLong(hwnd, GWL_STYLE) & ~WS_SIZEBOX; + SetWindowLong(hwnd, GWL_STYLE, winFlags); #endif setSize(fWidth, fHeight, true); @@ -624,16 +644,8 @@ struct Window::PrivateData { DBGp("Window setSize called %s, size %i %i, resizable %s\n", forced ? "(forced)" : "(not forced)", width, height, fResizable?"true":"false"); -#if defined(DISTRHO_OS_WINDOWS) - const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fResizable ? WS_SIZEBOX : 0x0); - RECT wr = { 0, 0, static_cast(width), static_cast(height) }; - AdjustWindowRectEx(&wr, fUsingEmbed ? WS_CHILD : winFlags, FALSE, WS_EX_TOPMOST); - - SetWindowPos(hwnd, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top, - SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); - - if (! forced) - UpdateWindow(hwnd); +#if defined(DISTRHO_OS_HAIKU) + // TODO #elif defined(DISTRHO_OS_MAC) [mView setFrame:NSMakeRect(0, 0, width, height)]; @@ -655,6 +667,16 @@ struct Window::PrivateData { [[mWindow standardWindowButton:NSWindowZoomButton] setHidden:YES]; } } +#elif defined(DISTRHO_OS_WINDOWS) + const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fResizable ? WS_SIZEBOX : 0x0); + RECT wr = { 0, 0, static_cast(width), static_cast(height) }; + AdjustWindowRectEx(&wr, fUsingEmbed ? WS_CHILD : winFlags, FALSE, WS_EX_TOPMOST); + + SetWindowPos(hwnd, 0, 0, 0, wr.right-wr.left, wr.bottom-wr.top, + SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); + + if (! forced) + UpdateWindow(hwnd); #else if (! fResizable) @@ -700,8 +722,9 @@ struct Window::PrivateData { fTitle = strdup(title); -#if defined(DISTRHO_OS_WINDOWS) - SetWindowTextA(hwnd, title); +#if defined(DISTRHO_OS_HAIKU) + if (bWindow != nullptr) + bWindow->SetTitle(title); #elif defined(DISTRHO_OS_MAC) if (mWindow != nullptr) { @@ -712,6 +735,8 @@ struct Window::PrivateData { [mWindow setTitle:titleString]; } +#elif defined(DISTRHO_OS_WINDOWS) + SetWindowTextA(hwnd, title); #else XStoreName(xDisplay, xWindow, title); Atom netWmName = XInternAtom(xDisplay, "_NET_WM_NAME", False); @@ -724,15 +749,17 @@ struct Window::PrivateData { { DISTRHO_SAFE_ASSERT_RETURN(winId != 0,); -#if defined(DISTRHO_OS_WINDOWS) - hwndParent = (HWND)winId; - SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)winId); +#if defined(DISTRHO_OS_HAIKU) + // TODO #elif defined(DISTRHO_OS_MAC) NSWindow* const parentWindow = [NSApp windowWithWindowNumber:winId]; DISTRHO_SAFE_ASSERT_RETURN(parentWindow != nullptr,); [parentWindow addChildWindow:mWindow ordered:NSWindowAbove]; +#elif defined(DISTRHO_OS_WINDOWS) + hwndParent = (HWND)winId; + SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)winId); #else XSetTransientForHint(xDisplay, xWindow, static_cast< ::Window>(winId)); #endif @@ -1164,12 +1191,8 @@ struct Window::PrivateData { DISTRHO_DECLARE_NON_COPY_STRUCT(Modal) } fModal; -#if defined(DISTRHO_OS_WINDOWS) - HWND hwnd; - HWND hwndParent; -# ifndef DGL_FILE_BROWSER_DISABLED - String fSelectedFile; -# endif +#if defined(DISTRHO_OS_HAIKU) + BWindow* bWindow; #elif defined(DISTRHO_OS_MAC) bool fNeedsIdle; NSView* mView; @@ -1179,6 +1202,12 @@ struct Window::PrivateData { NSOpenPanel* fOpenFilePanel; id fFilePanelDelegate; # endif +#elif defined(DISTRHO_OS_WINDOWS) + HWND hwnd; + HWND hwndParent; +# ifndef DGL_FILE_BROWSER_DISABLED + String fSelectedFile; +# endif #else Display* xDisplay; ::Window xWindow; diff --git a/dgl/src/pugl/pugl_haiku.cpp b/dgl/src/pugl/pugl_haiku.cpp new file mode 100644 index 00000000..a8a5e560 --- /dev/null +++ b/dgl/src/pugl/pugl_haiku.cpp @@ -0,0 +1,123 @@ +/* + Copyright 2019 Filipe Coelho + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file pugl_haiku.cpp BeOS/HaikuOS Pugl Implementation. +*/ + +#include + +#ifdef PUGL_CAIRO +#include +#endif +#ifdef PUGL_OPENGL +#include +#endif + +#include "pugl_internal.h" + +struct PuglInternalsImpl { + BWindow* window; +}; + +PuglInternals* +puglInitInternals() +{ + return (PuglInternals*)calloc(1, sizeof(PuglInternals)); +} + +void +puglEnterContext(PuglView* view) +{ +} + +void +puglLeaveContext(PuglView* view, bool flush) +{ +} + +class DWindow : public BWindow +{ +public: + DWindow(PuglInternals* const i) + : BWindow(BRect(), "", B_TITLED_WINDOW, 0x0), + impl(i) + { + } + +private: + PuglInternals* const impl; +}; + +int +puglCreateWindow(PuglView* view, const char* title) +{ + PuglInternals* impl = view->impl; + + impl->window = new DWindow(impl); + return 0; +} + +void +puglShowWindow(PuglView* view) +{ +} + +void +puglHideWindow(PuglView* view) +{ +} + +void +puglDestroy(PuglView* view) +{ +} + +PuglStatus +puglProcessEvents(PuglView* view) +{ + return PUGL_SUCCESS; +} + +void +puglPostRedisplay(PuglView* view) +{ + view->redisplay = true; +} + +PuglNativeWindow +puglGetNativeWindow(PuglView* view) +{ + return NULL; +} + +void* +puglGetContext(PuglView* view) +{ + return NULL; +} + +int +puglUpdateGeometryConstraints(PuglView* view, int min_width, int min_height, bool aspect) +{ + // TODO + return 1; + + (void)view; + (void)min_width; + (void)min_height; + (void)aspect; +} diff --git a/examples/CairoUI/Makefile b/examples/CairoUI/Makefile index 5a954bdb..828029e3 100644 --- a/examples/CairoUI/Makefile +++ b/examples/CairoUI/Makefile @@ -35,7 +35,7 @@ TARGETS += jack endif endif -ifeq ($(LINUX),true) +ifneq ($(MACOS_OR_WINDOWS),true) ifeq ($(HAVE_CAIRO),true) ifeq ($(HAVE_LIBLO),true) TARGETS += dssi diff --git a/examples/ExternalUI/Makefile b/examples/ExternalUI/Makefile index ba1df228..75ea517f 100644 --- a/examples/ExternalUI/Makefile +++ b/examples/ExternalUI/Makefile @@ -23,7 +23,9 @@ FILES_UI = \ include ../../Makefile.plugins.mk +ifneq ($(HAIKU),true) LINK_FLAGS += -ldl +endif # -------------------------------------------------------------- # Enable all possible plugin types diff --git a/examples/Latency/Makefile b/examples/Latency/Makefile index 1a61a70d..c0520530 100644 --- a/examples/Latency/Makefile +++ b/examples/Latency/Makefile @@ -23,7 +23,7 @@ include ../../Makefile.plugins.mk # -------------------------------------------------------------- # Enable all possible plugin types -ifeq ($(LINUX),true) +ifneq ($(MACOS_OR_WINDOWS),true) TARGETS += ladspa TARGETS += dssi endif diff --git a/examples/Meters/Makefile b/examples/Meters/Makefile index ac50f2f9..9ac485a5 100644 --- a/examples/Meters/Makefile +++ b/examples/Meters/Makefile @@ -32,7 +32,7 @@ TARGETS += jack endif endif -ifeq ($(LINUX),true) +ifneq ($(MACOS_OR_WINDOWS),true) ifeq ($(HAVE_LIBLO),true) ifeq ($(HAVE_OPENGL),true) TARGETS += dssi diff --git a/examples/Parameters/Makefile b/examples/Parameters/Makefile index f097b403..c8c7cafc 100644 --- a/examples/Parameters/Makefile +++ b/examples/Parameters/Makefile @@ -32,7 +32,7 @@ TARGETS += jack endif endif -ifeq ($(LINUX),true) +ifneq ($(MACOS_OR_WINDOWS),true) ifeq ($(HAVE_LIBLO),true) ifeq ($(HAVE_OPENGL),true) TARGETS += ladspa diff --git a/examples/States/Makefile b/examples/States/Makefile index 5f4a4811..e011bc30 100644 --- a/examples/States/Makefile +++ b/examples/States/Makefile @@ -32,7 +32,7 @@ TARGETS += jack endif endif -ifeq ($(LINUX),true) +ifneq ($(MACOS_OR_WINDOWS),true) ifeq ($(HAVE_LIBLO),true) ifeq ($(HAVE_OPENGL),true) TARGETS += dssi diff --git a/utils/lv2-ttl-generator/GNUmakefile b/utils/lv2-ttl-generator/GNUmakefile index 490e9343..460b04f9 100644 --- a/utils/lv2-ttl-generator/GNUmakefile +++ b/utils/lv2-ttl-generator/GNUmakefile @@ -1,19 +1,29 @@ #!/usr/bin/makefile -f +include ../../Makefile.base.mk + all: build ifeq ($(WINDOWS),true) -build: ../lv2_ttl_generator.exe -else -build: ../lv2_ttl_generator -endif -../lv2_ttl_generator: lv2_ttl_generator.c - $(CC) $< $(CFLAGS) -o $@ $(LDFLAGS) -ldl +build: ../lv2_ttl_generator.exe ../lv2_ttl_generator.exe: lv2_ttl_generator.c $(CC) $< $(CFLAGS) -o $@ $(LDFLAGS) -static touch ../lv2_ttl_generator +else # WINDOWS + +ifneq ($(HAIKU),true) +LDFLAGS += -ldl +endif + +build: ../lv2_ttl_generator + +../lv2_ttl_generator: lv2_ttl_generator.c + $(CC) $< $(CFLAGS) -o $@ $(LDFLAGS) + +endif # WINDOWS + clean: rm -f ../lv2_ttl_generator ../lv2_ttl_generator.exe