From 43a25ed63a9144afe32a4fea520412770394822c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 18 Mar 2017 12:02:05 +0100 Subject: Add suil_init() This allows the actual host argc and argv to be passed to QApplication if it is created by Suil (for Qt in non-Qt cases), and initializes X11 threads to fix Qt5 in Gtk2. --- src/suil_internal.h | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/suil_internal.h') diff --git a/src/suil_internal.h b/src/suil_internal.h index 67f1412..4b7452f 100644 --- a/src/suil_internal.h +++ b/src/suil_internal.h @@ -1,5 +1,5 @@ /* - Copyright 2007-2012 David Robillard + Copyright 2007-2017 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -18,6 +18,7 @@ #define SUIL_INTERNAL_H #include +#include #include #include @@ -49,6 +50,8 @@ struct SuilHostImpl { SuilPortUnsubscribeFunc unsubscribe_func; SuilTouchFunc touch_func; void* gtk_lib; + int argc; + char** argv; }; struct _SuilWrapper; @@ -92,7 +95,7 @@ typedef SuilWrapper* (*SuilWrapperNewFunc)(SuilHost* host, LV2_Feature*** features, unsigned n_features); -/** Prototype for suil_wrapper_new in each module. */ +/** Prototype for suil_wrapper_new in each wrapper module. */ SUIL_LIB_EXPORT SuilWrapper* suil_wrapper_new(SuilHost* host, @@ -101,6 +104,37 @@ suil_wrapper_new(SuilHost* host, LV2_Feature*** features, unsigned n_features); +/** Prototype for suil_host_init in each init module. */ +SUIL_LIB_EXPORT +void +suil_host_init(void); + +/** Dynamically load the suil module with the given name. */ +static inline void* +suil_open_module(const char* module_name) +{ + const char* const env_dir = getenv("SUIL_MODULE_DIR"); + const char* const mod_dir = env_dir ? env_dir : SUIL_MODULE_DIR; + const size_t path_len = strlen(mod_dir) + + strlen(SUIL_DIR_SEP SUIL_MODULE_PREFIX SUIL_MODULE_EXT) + + strlen(module_name) + + 2; + + char* const path = (char*)calloc(path_len, 1); + snprintf(path, path_len, "%s%s%s%s%s", + mod_dir, SUIL_DIR_SEP, + SUIL_MODULE_PREFIX, module_name, SUIL_MODULE_EXT); + + dlerror(); + void* lib = dlopen(path, RTLD_NOW); + if (!lib) { + SUIL_ERRORF("Failed to open module %s (%s)\n", path, dlerror()); + } + + free(path); + return lib; +} + typedef void (*SuilVoidFunc)(void); /** dlsym wrapper to return a function pointer (without annoying warning) */ @@ -140,6 +174,9 @@ suil_add_feature(LV2_Feature*** features, *n += 1; } +extern int suil_argc; +extern char** suil_argv; + #ifdef __cplusplus } /* extern "C" */ #endif -- cgit v1.2.1