From 1d61239879e12ccbd0ac80fabfd272e8b785e8cf Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 28 Aug 2013 22:00:28 +0200 Subject: osx: cleanup, use of proper APIs; added new GUI plugin type to the enum in deadbeef.h --- deadbeef.h | 1 + main.c | 46 ++++++++++++++++++++-------------------------- plugins.c | 4 ++-- plugins/gtkui/gtkui.c | 10 ++-------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/deadbeef.h b/deadbeef.h index 8a98ff4e..3a0d754b 100644 --- a/deadbeef.h +++ b/deadbeef.h @@ -190,6 +190,7 @@ enum { DB_PLUGIN_MISC = 4, DB_PLUGIN_VFS = 5, DB_PLUGIN_PLAYLIST = 6, + DB_PLUGIN_GUI = 7, }; // output plugin states diff --git a/main.c b/main.c index 38492360..26671058 100644 --- a/main.c +++ b/main.c @@ -697,31 +697,29 @@ restore_resume_state (void) { } } -typedef struct { - int argc; - char **argv; - char *cmdline; - int size; -} main_args_t; - -//uintptr_t gui_cond, gui_mutex; uintptr_t mainloop_tid; +DB_plugin_t * +plug_get_gui (void) { + struct DB_plugin_s **plugs = plug_get_list (); + for (int i = 0; plugs[i]; i++) { + if (plugs[i]->type == DB_PLUGIN_GUI) { + return plugs[i]; + } + } + return NULL; +} + static void mainloop_thread (void *ctx) { - main_args_t *args = ctx; - int argc = args->argc; - char **argv = args->argv; - char *cmdline = args->cmdline; - int size = args->size; - // this runs until DB_EV_TERMINATE is sent (blocks right here) player_mainloop (); // tell the gui thread to finish - DB_plugin_t *gui = plug_get_for_id ("gtkui3_1"); - gui->stop (); - //cond_signal (gui_cond); + DB_plugin_t *gui = plug_get_gui (); + if (gui) { + gui->stop (); + } return; } @@ -1014,16 +1012,12 @@ main (int argc, char *argv[]) { server_tid = thread_start (server_loop, NULL); - //gui_cond = cond_create (); - //gui_mutex = mutex_create (); - main_args_t args = {argc,argv,cmdline,size}; - mainloop_tid = thread_start (mainloop_thread, &args); -// fprintf (stderr, "waiting for GUI\n"); -// cond_wait (gui_cond, gui_mutex); -// mutex_unlock (gui_mutex); + mainloop_tid = thread_start (mainloop_thread, NULL); - DB_plugin_t *gui = plug_get_for_id ("gtkui3_1"); - gui->command (10, 0); + DB_plugin_t *gui = plug_get_gui (); + if (gui) { + gui->start (); + } fprintf (stderr, "gui plugin has quit; waiting for mainloop thread to finish\n"); thread_join (mainloop_tid); diff --git a/plugins.c b/plugins.c index 54515491..6b032c05 100644 --- a/plugins.c +++ b/plugins.c @@ -942,7 +942,7 @@ plug_load_all (void) { // start plugins plugin_t *prev = NULL; for (plug = plugins; plug;) { - if (plug->plugin->start) { + if (plug->plugin->type != DB_PLUGIN_GUI && plug->plugin->start) { if (plug->plugin->start () < 0) { fprintf (stderr, "plugin %s failed to start, deactivated.\n", plug->plugin->name); if (plug->plugin->stop) { @@ -995,7 +995,7 @@ plug_connect_all (void) { if (plug->plugin->disconnect) { plug->plugin->disconnect (); } - if (plug->plugin->stop) { + if (plug->plugin->type != DB_PLUGIN_GUI && plug->plugin->stop) { plug->plugin->stop (); } if (plug->handle) { diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index e932915b..c4ed1f74 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -815,12 +815,6 @@ gtkui_pl_add_files_end (void); DB_playItem_t * gtkui_plt_load (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); -int -gtkui_command (int n, ...) { - gtkui_thread (NULL); - return 0; -} - int gtkui_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { ddb_gtkui_widget_t *rootwidget = w_get_rootwidget (); @@ -1273,6 +1267,7 @@ gtkui_quit (void) { static int gtkui_start (void) { fprintf (stderr, "gtkui plugin compiled for gtk version: %d.%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); + gtkui_thread (NULL); return 0; } @@ -1710,7 +1705,7 @@ static ddb_gtkui_t plugin = { .gui.plugin.api_vminor = 5, .gui.plugin.version_major = 2, .gui.plugin.version_minor = DDB_GTKUI_API_VERSION, - .gui.plugin.type = DB_PLUGIN_MISC, + .gui.plugin.type = DB_PLUGIN_GUI, .gui.plugin.id = DDB_GTKUI_PLUGIN_ID, #if GTK_CHECK_VERSION(3,0,0) .gui.plugin.name = "GTK3 user interface", @@ -1758,6 +1753,5 @@ static ddb_gtkui_t plugin = { .w_append = w_append, .w_replace = w_replace, .w_remove = w_remove, - .gui.plugin.command = gtkui_command, .create_pltmenu = gtkui_create_pltmenu, }; -- cgit v1.2.3