aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/eg-sampler.lv2/sampler_ui.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/plugins/eg-sampler.lv2/sampler_ui.c b/plugins/eg-sampler.lv2/sampler_ui.c
index 1cb7553..0140e24 100644
--- a/plugins/eg-sampler.lv2/sampler_ui.c
+++ b/plugins/eg-sampler.lv2/sampler_ui.c
@@ -63,13 +63,16 @@ typedef struct {
GtkWidget* request_file_button;
GtkWidget* button_box;
GtkWidget* canvas;
- GtkWidget* window; /* For optional show interface. */
uint32_t width;
uint32_t requested_n_peaks;
char* filename;
uint8_t forge_buf[1024];
+
+ // Optional show/hide interface
+ GtkWidget* window;
+ bool did_init;
} SamplerUI;
static void
@@ -211,6 +214,18 @@ on_canvas_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
return TRUE;
}
+static gboolean
+on_window_closed(GtkWidget* widget, GdkEvent* event, gpointer data)
+{
+ SamplerUI* ui = (SamplerUI*)data;
+
+ // Remove widget so Gtk doesn't delete it when the window is closed
+ gtk_container_remove(GTK_CONTAINER(ui->window), ui->box);
+ ui->window = NULL;
+
+ return FALSE;
+}
+
static LV2UI_Handle
instantiate(const LV2UI_Descriptor* descriptor,
const char* plugin_uri,
@@ -229,6 +244,8 @@ instantiate(const LV2UI_Descriptor* descriptor,
ui->controller = controller;
ui->width = MIN_CANVAS_W;
*widget = NULL;
+ ui->window = NULL;
+ ui->did_init = false;
// Get host features
const char* missing = lv2_features_query(
@@ -350,11 +367,25 @@ ui_show(LV2UI_Handle handle)
{
SamplerUI* ui = (SamplerUI*)handle;
- int argc = 0;
- gtk_init(&argc, NULL);
+ if (ui->window) {
+ return 0;
+ }
+
+ if (!ui->did_init) {
+ int argc = 0;
+ gtk_init_check(&argc, NULL);
+ g_object_ref(ui->box);
+ ui->did_init = true;
+ }
ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_add(GTK_CONTAINER(ui->window), ui->box);
+
+ g_signal_connect(G_OBJECT(ui->window),
+ "delete-event",
+ G_CALLBACK(on_window_closed),
+ handle);
+
gtk_widget_show_all(ui->window);
gtk_window_present(GTK_WINDOW(ui->window));
@@ -365,6 +396,14 @@ ui_show(LV2UI_Handle handle)
static int
ui_hide(LV2UI_Handle handle)
{
+ SamplerUI* ui = (SamplerUI*)handle;
+
+ if (ui->window) {
+ gtk_container_remove(GTK_CONTAINER(ui->window), ui->box);
+ gtk_widget_destroy(ui->window);
+ ui->window = NULL;
+ }
+
return 0;
}
@@ -374,7 +413,7 @@ ui_idle(LV2UI_Handle handle)
{
SamplerUI* ui = (SamplerUI*)handle;
if (ui->window) {
- gtk_main_iteration();
+ gtk_main_iteration_do(false);
}
return 0;
}