From 2c1cdb0573a92254fef50a2aeed36cf9d8cc7f89 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 10 Sep 2008 19:48:45 +0200 Subject: [PATCH] Running "midori" should open a new window --- midori/main.c | 6 +++--- midori/midori-app.c | 43 +++++++++++++++++++++++++++++++++++++++++++ midori/midori-app.h | 3 +++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/midori/main.c b/midori/main.c index 270e61a0..84eb844b 100644 --- a/midori/main.c +++ b/midori/main.c @@ -546,10 +546,10 @@ main (int argc, if (midori_app_instance_is_running (app)) { /* TODO: Open as many tabs as we have uris, seperated by pipes */ - if (argc > 1) - result = midori_app_instance_send_uris (app, argv+1); + if (uris) + result = midori_app_instance_send_uris (app, uris); else - result = midori_app_instance_send_activate (app); + result = midori_app_instance_send_new_browser (app); if (result) return 0; diff --git a/midori/midori-app.c b/midori/midori-app.c index b463775c..38e3d4bf 100644 --- a/midori/midori-app.c +++ b/midori/midori-app.c @@ -195,6 +195,7 @@ midori_browser_message_received_cb (UniqueApp* instance, MidoriApp* app) { UniqueResponse response; + MidoriBrowser* browser; gchar** uris; switch (command) @@ -205,6 +206,21 @@ midori_browser_message_received_cb (UniqueApp* instance, gtk_window_present (GTK_WINDOW (app->browser)); response = UNIQUE_RESPONSE_OK; break; + case UNIQUE_NEW: + browser = g_object_new (MIDORI_TYPE_BROWSER, + "settings", app->settings, + "bookmarks", app->bookmarks, + "trash", app->trash, + "search-engines", app->search_engines, + NULL); + /* FIXME: Should open the homepage according to settings */ + midori_browser_add_uri (browser, "about:blank"); + midori_app_add_browser (app, browser); + gtk_window_set_screen (GTK_WINDOW (app->browser), + unique_message_data_get_screen (message)); + gtk_widget_show (GTK_WIDGET (browser)); + response = UNIQUE_RESPONSE_OK; + break; case UNIQUE_OPEN: uris = unique_message_data_get_uris (message); if (!uris) @@ -483,6 +499,33 @@ midori_app_instance_send_activate (MidoriApp* app) return FALSE; } +/** + * midori_app_instance_send_new_browser: + * @app: a #MidoriApp + * + * Sends a message to an instance of Midori already + * running on the default display, asking to open a new browser. + * + * Return value: %TRUE if the message was sent successfully + **/ +gboolean +midori_app_instance_send_new_browser (MidoriApp* app) +{ + #if HAVE_UNIQUE + UniqueResponse response; + #endif + + g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); + g_return_val_if_fail (midori_app_instance_is_running (app), FALSE); + + #if HAVE_UNIQUE + response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL); + if (response == UNIQUE_RESPONSE_OK) + return TRUE; + #endif + return FALSE; +} + /** * midori_app_instance_send_uris: * @app: a #MidoriApp diff --git a/midori/midori-app.h b/midori/midori-app.h index 641aa2f7..361b9d66 100644 --- a/midori/midori-app.h +++ b/midori/midori-app.h @@ -59,6 +59,9 @@ midori_app_instance_is_running (MidoriApp* app); gboolean midori_app_instance_send_activate (MidoriApp* app); +gboolean +midori_app_instance_send_new_browser (MidoriApp* app); + gboolean midori_app_instance_send_uris (MidoriApp* app, gchar** uris);