[epiphany/wip/exalm/menu: 6/6] Add mute and unmute items to the tab context menu




commit 35a0806d6da051f40f2a18f16f35039fe62b22b2
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Sep 7 23:15:43 2020 +0500

    Add mute and unmute items to the tab context menu
    
    The tab button is inaccessible from keyboard, so it must be in the menu.

 src/ephy-window.c                          | 17 +++++++++++++++
 src/resources/gtk/notebook-context-menu.ui | 10 +++++++++
 src/window-commands.c                      | 34 ++++++++++++++++++++++++++++++
 src/window-commands.h                      |  6 ++++++
 4 files changed, 67 insertions(+)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 249adea6d..c5d785e38 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -887,6 +887,8 @@ static const GActionEntry tab_entries [] = {
   { "reload-all", window_cmd_tabs_reload_all_tabs },
   { "pin", window_cmd_tabs_pin },
   { "unpin", window_cmd_tabs_unpin },
+  { "mute", window_cmd_tabs_mute },
+  { "unmute", window_cmd_tabs_unmute },
 };
 
 static const GActionEntry toolbar_entries [] = {
@@ -2689,15 +2691,22 @@ show_notebook_popup_menu (GtkNotebook    *notebook,
   action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
 
   if (event != NULL) {
+    EphyWebView *view;
     int n_pages;
     int page_num;
     gboolean pinned;
+    gboolean audio_playing;
+    gboolean muted;
 
     tab = GTK_WIDGET (window->active_embed);
     n_pages = gtk_notebook_get_n_pages (notebook);
     page_num = gtk_notebook_page_num (notebook, tab);
     pinned = ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), EPHY_EMBED (tab));
 
+    view = ephy_embed_get_web_view (EPHY_EMBED (tab));
+    audio_playing = webkit_web_view_is_playing_audio (WEBKIT_WEB_VIEW (view));
+    muted = webkit_web_view_get_is_muted (WEBKIT_WEB_VIEW (view));
+
     /* enable/disable close others/left/right */
     action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
                                          "close-left");
@@ -2723,6 +2732,14 @@ show_notebook_popup_menu (GtkNotebook    *notebook,
                                          "unpin");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), pinned);
 
+    action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                         "mute");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), audio_playing && !muted);
+
+    action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                         "unmute");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), audio_playing && muted);
+
     action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
                                          "close");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !pinned);
diff --git a/src/resources/gtk/notebook-context-menu.ui b/src/resources/gtk/notebook-context-menu.ui
index bc6e33af1..ad926614d 100644
--- a/src/resources/gtk/notebook-context-menu.ui
+++ b/src/resources/gtk/notebook-context-menu.ui
@@ -27,6 +27,16 @@
         <attribute name="action">tab.unpin</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">_Mute Tab</attribute>
+        <attribute name="action">tab.mute</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Un_mute Tab</attribute>
+        <attribute name="action">tab.unmute</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+      </item>
     </section>
     <section>
       <item>
diff --git a/src/window-commands.c b/src/window-commands.c
index a64107a80..5f02bb861 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -3039,3 +3039,37 @@ window_cmd_tabs_unpin (GSimpleAction *action,
 
   ephy_notebook_tab_set_pinned (notebook, GTK_WIDGET (embed), FALSE);
 }
+
+void
+window_cmd_tabs_mute (GSimpleAction *action,
+                      GVariant      *parameter,
+                      gpointer       user_data)
+{
+  EphyWindow *window = EPHY_WINDOW (user_data);
+  EphyEmbed *embed;
+  EphyWebView *view;
+
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  g_assert (embed != NULL);
+
+  view = ephy_embed_get_web_view (embed);
+
+  webkit_web_view_set_is_muted (WEBKIT_WEB_VIEW (view), TRUE);
+}
+
+void
+window_cmd_tabs_unmute (GSimpleAction *action,
+                        GVariant      *parameter,
+                        gpointer       user_data)
+{
+  EphyWindow *window = EPHY_WINDOW (user_data);
+  EphyEmbed *embed;
+  EphyWebView *view;
+
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  g_assert (embed != NULL);
+
+  view = ephy_embed_get_web_view (embed);
+
+  webkit_web_view_set_is_muted (WEBKIT_WEB_VIEW (view), FALSE);
+}
diff --git a/src/window-commands.h b/src/window-commands.h
index c11a66cfe..ee9a1adc6 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -236,6 +236,12 @@ void window_cmd_tabs_pin                        (GSimpleAction *action,
 void window_cmd_tabs_unpin                      (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);
+void window_cmd_tabs_mute                       (GSimpleAction *action,
+                                                 GVariant      *parameter,
+                                                 gpointer       user_data);
+void window_cmd_tabs_unmute                     (GSimpleAction *action,
+                                                 GVariant      *parameter,
+                                                 gpointer       user_data);
 void window_cmd_import_passwords                (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]