From b4241912379b321a1a2ec0d192faff12f8db2101 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 1 Jun 2011 19:14:25 +0000 Subject: Fix GtkBuilder using (and likely other) Gtk UIs in Qt4 hosts that do not link to Gtk (fix ticket #696). git-svn-id: http://svn.drobilla.net/lad/trunk/suil@3345 a436a847-0d15-0410-975c-d299462d15a1 --- src/gtk2_in_qt4.cpp | 20 ++++++++++++++++++-- src/host.c | 4 ++++ src/instance.c | 2 +- src/qt4_in_gtk2.cpp | 3 ++- src/suil_internal.h | 16 ++++++++++------ 5 files changed, 35 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gtk2_in_qt4.cpp b/src/gtk2_in_qt4.cpp index 91fa3b1..585d1d5 100644 --- a/src/gtk2_in_qt4.cpp +++ b/src/gtk2_in_qt4.cpp @@ -21,16 +21,32 @@ #include #include "suil_internal.h" +#include "suil-config.h" extern "C" { SUIL_API int -suil_wrap_init(const char* host_type_uri, +suil_wrap_init(SuilHost* host, + const char* host_type_uri, const char* ui_type_uri, const LV2_Feature* const* features) { - gtk_init(0, NULL); + /* We have to open libgtk here, so Gtk type symbols are present and will be + found by the introspection stuff. This is required at least to make + GtkBuilder use in UIs work, otherwise they will cause "Invalid object + type" errors. + */ + if (!host->gtk_lib) { + dlerror(); + host->gtk_lib = dlopen(SUIL_GTK2_LIB_NAME, RTLD_LAZY|RTLD_GLOBAL); + if (!host->gtk_lib) { + fprintf(stderr, "Failed to open %s (%s)\n", + SUIL_GTK2_LIB_NAME, dlerror()); + } + return 1; + } + return 0; } diff --git a/src/host.c b/src/host.c index 48b0b6a..c57b1c6 100644 --- a/src/host.c +++ b/src/host.c @@ -28,6 +28,7 @@ suil_host_new(SuilPortWriteFunc write_func, host->index_func = index_func; host->subscribe_func = subscribe_func; host->unsubscribe_func = unsubscribe_func; + host->gtk_lib = NULL; return host; } @@ -35,5 +36,8 @@ SUIL_API void suil_host_free(SuilHost* host) { + if (host->gtk_lib) { + dlclose(host->gtk_lib); + } free(host); } diff --git a/src/instance.c b/src/instance.c index d619d74..e1f8e8e 100644 --- a/src/instance.c +++ b/src/instance.c @@ -170,7 +170,7 @@ suil_instance_new(SuilHost* host, SuilModule module = get_wrap_module(container_type_uri, ui_type_uri); if (module) { - module->init(container_type_uri, ui_type_uri, features); + module->init(host, container_type_uri, ui_type_uri, features); } // Instantiate UI diff --git a/src/qt4_in_gtk2.cpp b/src/qt4_in_gtk2.cpp index e056b65..191215e 100644 --- a/src/qt4_in_gtk2.cpp +++ b/src/qt4_in_gtk2.cpp @@ -29,7 +29,8 @@ static QApplication application(argc, NULL, true); SUIL_API int -suil_wrap_init(const char* host_type_uri, +suil_wrap_init(SuilHost* host, + const char* host_type_uri, const char* ui_type_uri, const LV2_Feature* const* features) { diff --git a/src/suil_internal.h b/src/suil_internal.h index 53ee0a8..5987f1c 100644 --- a/src/suil_internal.h +++ b/src/suil_internal.h @@ -42,6 +42,7 @@ struct SuilHostImpl { SuilPortIndexFunc index_func; SuilPortSubscribeFunc subscribe_func; SuilPortUnsubscribeFunc unsubscribe_func; + void* gtk_lib; }; struct SuilInstanceImpl { @@ -52,12 +53,15 @@ struct SuilInstanceImpl { SuilWidget host_widget; }; -/** Type of a module's suil_wrap_init function. - * This initialisation function must be called before instantiating any - * UI that will need to be wrapped by this wrapper (e.g. it will perform any - * initialisation required to create a widget for the given toolkit). - */ -typedef int (*SuilWrapInitFunc)(const char* host_type_uri, +/** + Type of a module's suil_wrap_init function. + + This initialisation function must be called before instantiating any UI that + will need to be wrapped by this wrapper (e.g. it will perform any + initialisation required to create a widget for the given toolkit). +*/ +typedef int (*SuilWrapInitFunc)(SuilHost* host, + const char* host_type_uri, const char* ui_type_uri, const LV2_Feature* const* features); -- cgit v1.2.1