aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMichael Fisher <mfisher31@gmail.com>2019-11-18 20:21:04 -0500
committerDavid Robillard <d@drobilla.net>2020-03-17 11:38:17 +0100
commit517e8657e581b0c0abafe2fd2deb5182939c39e3 (patch)
tree8b4c4b3a05c4a7763bfde2cab53ed5a53926db41 /plugins
parent7f7f0fa97b8f5a4c20465950a8f89700f853a09b (diff)
downloadlv2-517e8657e581b0c0abafe2fd2deb5182939c39e3.tar.xz
eg-sampler: Improve UI show/hide handling
Ensures that gtk_init() is only called once, and that the idle callback does not block the UI thread.
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;
}