diff options
author | Brian Pepple <bpepple@fedoraproject.org> | 2010-02-07 19:44:23 -0500 |
---|---|---|
committer | Brian Pepple <bpepple@fedoraproject.org> | 2010-02-07 19:44:23 -0500 |
commit | 8d8311d97caf63f95cd988c08a004c7f45a46582 (patch) | |
tree | 26f2c6a07455ab7f83a871ce7e6131e1b11a068c | |
parent | 360690d46cff89cc4cc9fbce328aa6562e484087 (diff) | |
download | sonancy-8d8311d97caf63f95cd988c08a004c7f45a46582.tar.gz sonancy-8d8311d97caf63f95cd988c08a004c7f45a46582.tar.xz sonancy-8d8311d97caf63f95cd988c08a004c7f45a46582.zip |
Use libunique to handle single app instance.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/sonancy-main.c | 83 |
3 files changed, 67 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac index 4beb890..d7b708b 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ PKG_CHECK_MODULES(SONANCY, gobject-2.0 gtk+-2.0 >= $GTK_REQUIRED gstreamer-0.10 >= $GSTREAMER_REQUIRED + unique-1.0 ]) AC_SUBST(SONANCY_CFLAGS) AC_SUBST(SONANCY_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index ab88c40..daa1b95 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,6 @@ AM_CPPFLAGS = \ bin_PROGRAMS = sonancy sonancy_SOURCES = \ - sonancy-app.c sonancy-app.h \ sonancy-main.c \ sonancy-window.c sonancy-window.h \ sonancy-xml.c sonancy-xml.h diff --git a/src/sonancy-main.c b/src/sonancy-main.c index 778c023..b5a373d 100644 --- a/src/sonancy-main.c +++ b/src/sonancy-main.c @@ -27,31 +27,80 @@ #include <stdlib.h> #include <glib.h> +#include <gtk/gtk.h> +#include <unique/unique.h> -#include "sonancy-app.h" +static void +on_window_destroy (GtkWidget *widget, + gpointer user_data) +{ + gtk_main_quit (); +} + +static UniqueResponse +unique_app_message_cb (UniqueApp *unique_app, + gint command, + UniqueMessageData *data, + guint timestamp, + gpointer user_data) +{ + GtkWindow *window = user_data; + UniqueResponse res; + + switch (command) { + case UNIQUE_ACTIVATE: + gtk_window_set_screen (GTK_WINDOW (window), + unique_message_data_get_screen (data)); + gtk_window_set_startup_id (GTK_WINDOW (window), + unique_message_data_get_startup_id (data)); + gtk_window_present_with_time (GTK_WINDOW (window), + timestamp); + res = UNIQUE_RESPONSE_OK; + break; + default: + res = UNIQUE_RESPONSE_OK; + break; + } + return res; +} int main (int argc, char *argv[]) { - SonancyApp *app; - GError *error; - int res = EXIT_FAILURE; - - error = NULL; - app = sonancy_app_get_default (&argc, &argv, &error); - if (error) { - g_warning ("Unable to launch %s: %s", PACKAGE, error->message); - g_error_free (error); - return res; + UniqueApp *unique_app; + GtkWidget *window; + + gtk_init (&argc, &argv); + + unique_app = unique_app_new ("org.gnome.Sonancy", NULL); + + if (unique_app_is_running (unique_app)) { + UniqueResponse response; + + response = unique_app_send_message (unique_app, + UNIQUE_ACTIVATE, + NULL); + g_object_unref (unique_app); + + return EXIT_SUCCESS; } - if (sonancy_app_is_running (app)) - res = EXIT_SUCCESS; - else - res = sonancy_app_run (app); + window = (GtkWidget *) sonancy_window_new (); + g_signal_connect (window, + "destroy", G_CALLBACK (on_window_destroy), + NULL); - g_object_unref (app); - return res; + unique_app_watch_window (unique_app, GTK_WINDOW (window)); + + g_signal_connect (unique_app, "message-received", + G_CALLBACK (unique_app_message_cb), + window); + + gtk_main (); + + g_object_unref (unique_app); + + return EXIT_SUCCESS; } |