diff options
author | David Robillard <d@drobilla.net> | 2020-12-26 19:24:15 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-12-31 13:37:55 +0100 |
commit | 9f5fb1cf1b3df6a86d6571886169455d9d9ec393 (patch) | |
tree | 0e7515a3d319eb06b5450e3482055fc269503f1c /src/qt5_in_gtk.cpp | |
parent | 1fece68f494158fff81fd3dca5a928860d5a6376 (diff) | |
download | suil-9f5fb1cf1b3df6a86d6571886169455d9d9ec393.tar.gz suil-9f5fb1cf1b3df6a86d6571886169455d9d9ec393.tar.bz2 suil-9f5fb1cf1b3df6a86d6571886169455d9d9ec393.zip |
Format all code with clang-format
Diffstat (limited to 'src/qt5_in_gtk.cpp')
-rw-r--r-- | src/qt5_in_gtk.cpp | 239 |
1 files changed, 120 insertions, 119 deletions
diff --git a/src/qt5_in_gtk.cpp b/src/qt5_in_gtk.cpp index 5ce272c..5ae92df 100644 --- a/src/qt5_in_gtk.cpp +++ b/src/qt5_in_gtk.cpp @@ -37,7 +37,7 @@ #include <gtk/gtk.h> #if GTK_MAJOR_VERSION == 3 -#include <gtk/gtkx.h> +# include <gtk/gtkx.h> #endif #include <cstdlib> @@ -46,149 +46,150 @@ extern "C" { struct SuilQtWrapper { - GtkSocket socket; - QWidget* qembed; - SuilWrapper* wrapper; - SuilInstance* instance; - const LV2UI_Idle_Interface* idle_iface; - guint idle_id; - guint idle_ms; + GtkSocket socket; + QWidget* qembed; + SuilWrapper* wrapper; + SuilInstance* instance; + const LV2UI_Idle_Interface* idle_iface; + guint idle_id; + guint idle_ms; }; struct SuilQtWrapperClass { - GtkSocketClass parent_class; + GtkSocketClass parent_class; }; -GType suil_qt_wrapper_get_type(void); // Accessor for SUIL_TYPE_QT_WRAPPER +GType +suil_qt_wrapper_get_type(void); // Accessor for SUIL_TYPE_QT_WRAPPER #define SUIL_TYPE_QT_WRAPPER (suil_qt_wrapper_get_type()) -#define SUIL_QT_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SUIL_TYPE_QT_WRAPPER, SuilQtWrapper)) +#define SUIL_QT_WRAPPER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), SUIL_TYPE_QT_WRAPPER, SuilQtWrapper)) G_DEFINE_TYPE(SuilQtWrapper, suil_qt_wrapper, GTK_TYPE_SOCKET) static void suil_qt_wrapper_finalize(GObject* gobject) { - SuilQtWrapper* const self = SUIL_QT_WRAPPER(gobject); + SuilQtWrapper* const self = SUIL_QT_WRAPPER(gobject); - if (self->idle_id) { - g_source_remove(self->idle_id); - self->idle_id = 0; - } + if (self->idle_id) { + g_source_remove(self->idle_id); + self->idle_id = 0; + } - if (self->instance->handle) { - self->instance->descriptor->cleanup(self->instance->handle); - self->instance->handle = nullptr; - } + if (self->instance->handle) { + self->instance->descriptor->cleanup(self->instance->handle); + self->instance->handle = nullptr; + } - if (self->qembed) { - self->qembed->deleteLater(); - } + if (self->qembed) { + self->qembed->deleteLater(); + } - self->qembed = nullptr; - self->idle_iface = nullptr; - self->wrapper->impl = nullptr; + self->qembed = nullptr; + self->idle_iface = nullptr; + self->wrapper->impl = nullptr; - G_OBJECT_CLASS(suil_qt_wrapper_parent_class)->finalize(gobject); + G_OBJECT_CLASS(suil_qt_wrapper_parent_class)->finalize(gobject); } static void suil_qt_wrapper_class_init(SuilQtWrapperClass* klass) { - GObjectClass* const gobject_class = G_OBJECT_CLASS(klass); + GObjectClass* const gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = suil_qt_wrapper_finalize; + gobject_class->finalize = suil_qt_wrapper_finalize; } static void suil_qt_wrapper_init(SuilQtWrapper* self) { - self->qembed = nullptr; - self->wrapper = nullptr; - self->instance = nullptr; - self->idle_iface = nullptr; - self->idle_id = 0; - self->idle_ms = 1000 / 30; // 30 Hz default + self->qembed = nullptr; + self->wrapper = nullptr; + self->instance = nullptr; + self->idle_iface = nullptr; + self->idle_id = 0; + self->idle_ms = 1000 / 30; // 30 Hz default } static void suil_qt_wrapper_realize(GtkWidget* w, gpointer) { - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(w); - GtkSocket* const s = GTK_SOCKET(w); - const WId id = (WId)gtk_socket_get_id(s); + SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(w); + GtkSocket* const s = GTK_SOCKET(w); + const WId id = (WId)gtk_socket_get_id(s); - wrap->qembed->winId(); - wrap->qembed->windowHandle()->setParent(QWindow::fromWinId(id)); - wrap->qembed->show(); + wrap->qembed->winId(); + wrap->qembed->windowHandle()->setParent(QWindow::fromWinId(id)); + wrap->qembed->show(); } static int suil_qt_wrapper_resize(LV2UI_Feature_Handle handle, int width, int height) { - gtk_widget_set_size_request(GTK_WIDGET(handle), width, height); + gtk_widget_set_size_request(GTK_WIDGET(handle), width, height); - return 0; + return 0; } static gboolean suil_qt_wrapper_idle(void* data) { - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(data); + SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(data); - if (wrap->idle_iface) { - wrap->idle_iface->idle(wrap->instance->handle); - return TRUE; // Continue calling - } + if (wrap->idle_iface) { + wrap->idle_iface->idle(wrap->instance->handle); + return TRUE; // Continue calling + } - return FALSE; + return FALSE; } static int -wrapper_wrap(SuilWrapper* wrapper, - SuilInstance* instance) +wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) { - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); + SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); - wrap->qembed = new QWidget(nullptr, Qt::WindowFlags()); - wrap->wrapper = wrapper; - wrap->instance = instance; + wrap->qembed = new QWidget(nullptr, Qt::WindowFlags()); + wrap->wrapper = wrapper; + wrap->instance = instance; - auto* qwidget = (QWidget*)instance->ui_widget; - auto* layout = new QVBoxLayout(); - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(qwidget, 0, Qt::Alignment()); + auto* qwidget = (QWidget*)instance->ui_widget; + auto* layout = new QVBoxLayout(); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(qwidget, 0, Qt::Alignment()); - wrap->qembed->setLayout(layout); + wrap->qembed->setLayout(layout); - g_signal_connect_after(G_OBJECT(wrap), "realize", - G_CALLBACK(suil_qt_wrapper_realize), nullptr); + g_signal_connect_after( + G_OBJECT(wrap), "realize", G_CALLBACK(suil_qt_wrapper_realize), nullptr); - instance->host_widget = GTK_WIDGET(wrap); + instance->host_widget = GTK_WIDGET(wrap); - const LV2UI_Idle_Interface* idle_iface = nullptr; - if (instance->descriptor->extension_data) { - idle_iface = (const LV2UI_Idle_Interface*) - instance->descriptor->extension_data(LV2_UI__idleInterface); - } + const LV2UI_Idle_Interface* idle_iface = nullptr; + if (instance->descriptor->extension_data) { + idle_iface = + (const LV2UI_Idle_Interface*)instance->descriptor->extension_data( + LV2_UI__idleInterface); + } - if (idle_iface) { - wrap->idle_iface = idle_iface; - wrap->idle_id = g_timeout_add( - wrap->idle_ms, suil_qt_wrapper_idle, wrap); - } + if (idle_iface) { + wrap->idle_iface = idle_iface; + wrap->idle_id = g_timeout_add(wrap->idle_ms, suil_qt_wrapper_idle, wrap); + } - return 0; + return 0; } static void wrapper_free(SuilWrapper* wrapper) { - if (wrapper->impl) { - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); - gtk_widget_destroy(GTK_WIDGET(wrap)); - } + if (wrapper->impl) { + SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); + gtk_widget_destroy(GTK_WIDGET(wrap)); + } } SUIL_LIB_EXPORT @@ -199,45 +200,45 @@ suil_wrapper_new(SuilHost*, LV2_Feature*** features, unsigned n_features) { - auto* wrapper = (SuilWrapper*)calloc(1, sizeof(SuilWrapper)); - wrapper->wrap = wrapper_wrap; - wrapper->free = wrapper_free; - - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER( - g_object_new(SUIL_TYPE_QT_WRAPPER, nullptr)); - - wrap->wrapper = nullptr; - wrapper->impl = wrap; - - wrapper->resize.handle = wrap; - wrapper->resize.ui_resize = suil_qt_wrapper_resize; - - suil_add_feature(features, &n_features, LV2_UI__resize, &wrapper->resize); - suil_add_feature(features, &n_features, LV2_UI__idleInterface, nullptr); - - // Scan for URID map and options - LV2_URID_Map* map = nullptr; - LV2_Options_Option* options = nullptr; - for (LV2_Feature** f = *features; *f && (!map || !options); ++f) { - if (!strcmp((*f)->URI, LV2_OPTIONS__options)) { - options = (LV2_Options_Option*)(*f)->data; - } else if (!strcmp((*f)->URI, LV2_URID__map)) { - map = (LV2_URID_Map*)(*f)->data; - } - } - - if (map && options) { - // Set UI update rate if given - LV2_URID ui_updateRate = map->map(map->handle, LV2_UI__updateRate); - for (LV2_Options_Option* o = options; o->key; ++o) { - if (o->key == ui_updateRate) { - wrap->idle_ms = (guint)(1000.0f / *(const float*)o->value); - break; - } - } - } - - return wrapper; + auto* wrapper = (SuilWrapper*)calloc(1, sizeof(SuilWrapper)); + wrapper->wrap = wrapper_wrap; + wrapper->free = wrapper_free; + + SuilQtWrapper* const wrap = + SUIL_QT_WRAPPER(g_object_new(SUIL_TYPE_QT_WRAPPER, nullptr)); + + wrap->wrapper = nullptr; + wrapper->impl = wrap; + + wrapper->resize.handle = wrap; + wrapper->resize.ui_resize = suil_qt_wrapper_resize; + + suil_add_feature(features, &n_features, LV2_UI__resize, &wrapper->resize); + suil_add_feature(features, &n_features, LV2_UI__idleInterface, nullptr); + + // Scan for URID map and options + LV2_URID_Map* map = nullptr; + LV2_Options_Option* options = nullptr; + for (LV2_Feature** f = *features; *f && (!map || !options); ++f) { + if (!strcmp((*f)->URI, LV2_OPTIONS__options)) { + options = (LV2_Options_Option*)(*f)->data; + } else if (!strcmp((*f)->URI, LV2_URID__map)) { + map = (LV2_URID_Map*)(*f)->data; + } + } + + if (map && options) { + // Set UI update rate if given + LV2_URID ui_updateRate = map->map(map->handle, LV2_UI__updateRate); + for (LV2_Options_Option* o = options; o->key; ++o) { + if (o->key == ui_updateRate) { + wrap->idle_ms = (guint)(1000.0f / *(const float*)o->value); + break; + } + } + } + + return wrapper; } -} // extern "C" +} // extern "C" |