From a2fc8f405c7aeb97734e7d6ad873790bfdc38ecd Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Tue, 19 Apr 2011 23:16:34 +0200 Subject: [PATCH] Show a notification upon opening a tab or window The notification is shown when in fullscreen mode or the window is maximised, and a window is opened or a tab is opened while the tab bar is not visible. --- midori/marshal.list | 2 +- midori/midori-browser.c | 21 +++++++++++++++++++-- midori/midori-view.c | 14 +++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/midori/marshal.list b/midori/marshal.list index 10da7979..b0808f8a 100644 --- a/midori/marshal.list +++ b/midori/marshal.list @@ -4,7 +4,7 @@ BOOLEAN:OBJECT,UINT BOOLEAN:VOID OBJECT:OBJECT VOID:BOOLEAN,STRING -VOID:OBJECT,ENUM +VOID:OBJECT,ENUM,BOOLEAN VOID:OBJECT,INT,INT VOID:POINTER,INT VOID:STRING,BOOLEAN diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 9234a966..c557179a 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1325,6 +1325,7 @@ static void midori_view_new_view_cb (GtkWidget* view, GtkWidget* new_view, MidoriNewView where, + gboolean user_initiated, MidoriBrowser* browser) { midori_browser_view_copy_history (new_view, view, TRUE); @@ -1341,6 +1342,22 @@ midori_view_new_view_cb (GtkWidget* view, if (where != MIDORI_NEW_VIEW_BACKGROUND) midori_browser_set_current_page (browser, n); } + + if (!user_initiated) + { + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (browser)); + GdkWindowState state = gdk_window_get_state (window); + if ((state | GDK_WINDOW_STATE_MAXIMIZED) + || (state | GDK_WINDOW_STATE_FULLSCREEN)) + { + if (where == MIDORI_NEW_VIEW_WINDOW) + g_signal_emit (browser, signals[SEND_NOTIFICATION], 0, + _("New Window"), _("A new window has been opened")); + else if (!browser->show_tabs) + g_signal_emit (browser, signals[SEND_NOTIFICATION], 0, + _("New Tab"), _("A new tab has been opened")); + } + } } #if WEBKIT_CHECK_VERSION (1, 1, 3) @@ -1817,7 +1834,7 @@ midori_browser_class_init (MidoriBrowserClass* class) * @message: the message for the notification * * Emitted when a browser wants to display a notification message, - * e.g. when a download has been completed. + * e.g. when a download has been completed or a new tab was opened. * * Since: 0.1.7 */ @@ -4544,7 +4561,7 @@ _action_tab_duplicate_activate (GtkAction* action, GtkWidget* new_view = midori_view_new_with_title ( NULL, browser->settings, FALSE); const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view)); - g_signal_emit_by_name (view, "new-view", new_view, where); + g_signal_emit_by_name (view, "new-view", new_view, where, TRUE); midori_view_set_uri (MIDORI_VIEW (new_view), uri); } diff --git a/midori/midori-view.c b/midori/midori-view.c index ade06f86..6de6f74b 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -337,12 +337,15 @@ midori_view_class_init (MidoriViewClass* class) * @view: the object on which the signal is emitted * @new_view: a newly created view * @where: where to open the view + * @user_initiated: %TRUE if the user actively opened the new view * * Emitted when a new view is created. The value of * @where determines where to open the view according * to how it was opened and user preferences. * * Since: 0.1.2 + * + * Since 0.3.4 a boolean argument was added. */ signals[NEW_VIEW] = g_signal_new ( "new-view", @@ -351,10 +354,11 @@ midori_view_class_init (MidoriViewClass* class) 0, 0, NULL, - midori_cclosure_marshal_VOID__OBJECT_ENUM, - G_TYPE_NONE, 2, + midori_cclosure_marshal_VOID__OBJECT_ENUM_BOOLEAN, + G_TYPE_NONE, 3, MIDORI_TYPE_VIEW, - MIDORI_TYPE_NEW_VIEW); + MIDORI_TYPE_NEW_VIEW, + G_TYPE_BOOLEAN); /** * MidoriView::download-requested: @@ -2885,7 +2889,7 @@ webkit_web_view_web_view_ready_cb (GtkWidget* web_view, where = MIDORI_NEW_VIEW_WINDOW; gtk_widget_show (new_view); - g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where); + g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where, FALSE); return TRUE; } @@ -4607,7 +4611,7 @@ midori_view_tab_label_menu_duplicate_tab_cb (GtkWidget* menuitem, GtkWidget* new_view = midori_view_new_with_title ( NULL, view->settings, FALSE); const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view)); - g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where); + g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where, TRUE); midori_view_set_uri (MIDORI_VIEW (new_view), uri); }