[gnome-settings-daemon/rhel-6.9: 23/25] media-keys: Handle XF86AudioMicMute



commit 2c47138e430abef71fe96bd1138048030e3df455
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 18 15:51:42 2015 +0100

    media-keys: Handle XF86AudioMicMute
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1167519

 plugins/media-keys/acme.h                   |    3 +
 plugins/media-keys/gsd-media-keys-manager.c |  113 ++++++++++++++++++++-------
 plugins/media-keys/gsd-media-keys-window.c  |   37 +++++++++
 plugins/media-keys/gsd-media-keys-window.h  |    5 +-
 4 files changed, 127 insertions(+), 31 deletions(-)
---
diff --git a/plugins/media-keys/acme.h b/plugins/media-keys/acme.h
index de75e44..0986ba1 100644
--- a/plugins/media-keys/acme.h
+++ b/plugins/media-keys/acme.h
@@ -49,6 +49,7 @@ enum {
         VIDEO_OUT_KEY,
         VIDEO_OUT2_KEY,
         ROTATE_VIDEO_KEY,
+        MIC_MUTE_KEY,
         HANDLED_KEYS
 };
 
@@ -82,6 +83,8 @@ static struct {
         { VIDEO_OUT2_KEY, NULL, "XF86Display", NULL },
         /* Key code of the XF86RotateWindows key (present on some tablets) */
         { ROTATE_VIDEO_KEY, NULL, "XF86RotateWindows", NULL },
+        { MIC_MUTE_KEY, NULL, "XF86AudioMicMute", NULL },
+
 };
 
 #endif /* __ACME_H__ */
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 20f029f..7e02a7a 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -53,6 +53,7 @@
 #ifdef HAVE_PULSE
 #include <canberra-gtk.h>
 #include "gvc-mixer-control.h"
+#include "gvc-mixer-sink.h"
 #endif /* HAVE_PULSE */
 
 #define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
@@ -87,7 +88,8 @@ struct GsdMediaKeysManagerPrivate
 #ifdef HAVE_PULSE
         /* Volume bits */
         GvcMixerControl *volume;
-        GvcMixerStream  *stream;
+        GvcMixerStream  *sink;
+        GvcMixerStream  *source;
 #endif /* HAVE_PULSE */
         GtkWidget       *dialog;
         GConfClient     *conf_client;
@@ -625,18 +627,24 @@ do_eject_action (GsdMediaKeysManager *manager)
 #ifdef HAVE_PULSE
 static void
 update_dialog (GsdMediaKeysManager *manager,
+               GvcMixerStream *stream,
                guint vol,
                gboolean muted)
 {
+        GsdMediaKeysWindowAction action;
+
+        action = GVC_IS_MIXER_SINK (stream) ? GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME : 
GSD_MEDIA_KEYS_WINDOW_ACTION_MIC_VOLUME;
+
         vol = (int) (100 * (double) vol / PA_VOLUME_NORM);
         vol = CLAMP (vol, 0, 100);
 
         dialog_init (manager);
-        gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
-                                                muted);
+        if (action == GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME)
+                gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), 
muted);
+        else
+                gsd_media_keys_window_set_mic_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), 
muted);
         gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol);
-        gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
-                                          GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
+        gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), action);
         dialog_show (manager);
 
         ca_gtk_play_for_widget (manager->priv->dialog, 0,
@@ -648,13 +656,14 @@ update_dialog (GsdMediaKeysManager *manager,
 
 static void
 do_sound_action (GsdMediaKeysManager *manager,
+                 GvcMixerStream      *stream,
                  int                  type)
 {
         gboolean muted;
         guint vol, norm_vol_step;
         int vol_step;
 
-        if (manager->priv->stream == NULL)
+        if (stream == NULL)
                 return;
 
         vol_step = gconf_client_get_int (manager->priv->conf_client,
@@ -667,25 +676,26 @@ do_sound_action (GsdMediaKeysManager *manager,
         norm_vol_step = PA_VOLUME_NORM * vol_step / 100;
 
         /* FIXME: this is racy */
-        vol = gvc_mixer_stream_get_volume (manager->priv->stream);
-        muted = gvc_mixer_stream_get_is_muted (manager->priv->stream);
+        vol = gvc_mixer_stream_get_volume (stream);
+        muted = gvc_mixer_stream_get_is_muted (stream);
 
         switch (type) {
         case MUTE_KEY:
+        case MIC_MUTE_KEY:
                 muted = !muted;
-                gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
+                gvc_mixer_stream_change_is_muted (stream, muted);
                 break;
         case VOLUME_DOWN_KEY:
                 if (!muted && (vol <= norm_vol_step)) {
                         muted = !muted;
                         vol = 0;
-                        gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
-                        if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE)
-                                gvc_mixer_stream_push_volume (manager->priv->stream);
+                        gvc_mixer_stream_change_is_muted (stream, muted);
+                        if (gvc_mixer_stream_set_volume (stream, vol) != FALSE)
+                                gvc_mixer_stream_push_volume (stream);
                 } else if (!muted) {
                         vol = vol - norm_vol_step;
-                        if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE)
-                                gvc_mixer_stream_push_volume (manager->priv->stream);
+                        if (gvc_mixer_stream_set_volume (stream, vol) != FALSE)
+                                gvc_mixer_stream_push_volume (stream);
                 }
                 break;
         case VOLUME_UP_KEY:
@@ -693,11 +703,11 @@ do_sound_action (GsdMediaKeysManager *manager,
                         muted = !muted;
                         if (vol == 0) {
                                vol = vol + norm_vol_step;
-                               gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
-                               if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE)
-                                        gvc_mixer_stream_push_volume (manager->priv->stream);
+                               gvc_mixer_stream_change_is_muted (stream, muted);
+                               if (gvc_mixer_stream_set_volume (stream, vol) != FALSE)
+                                        gvc_mixer_stream_push_volume (stream);
                         } else {
-                                gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
+                                gvc_mixer_stream_change_is_muted (stream, muted);
                         }
                 } else {
                         if (vol < MAX_VOLUME) {
@@ -706,14 +716,35 @@ do_sound_action (GsdMediaKeysManager *manager,
                                 } else {
                                         vol = vol + norm_vol_step;
                                 }
-                                if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE)
-                                        gvc_mixer_stream_push_volume (manager->priv->stream);
+                                if (gvc_mixer_stream_set_volume (stream, vol) != FALSE)
+                                        gvc_mixer_stream_push_volume (stream);
                         }
                 }
                 break;
         }
 
-        update_dialog (manager, vol, muted);
+        update_dialog (manager, stream, vol, muted);
+}
+
+static void
+update_default_source (GsdMediaKeysManager *manager)
+{
+        GvcMixerStream *stream;
+
+        stream = gvc_mixer_control_get_default_source (manager->priv->volume);
+        if (stream == manager->priv->source)
+                return;
+
+        if (manager->priv->source != NULL) {
+                g_object_unref (manager->priv->source);
+                manager->priv->source = NULL;
+        }
+
+        if (stream != NULL) {
+                manager->priv->source = g_object_ref (stream);
+        } else {
+                g_warning ("Unable to get default sink");
+        }
 }
 
 static void
@@ -722,16 +753,16 @@ update_default_sink (GsdMediaKeysManager *manager)
         GvcMixerStream *stream;
 
         stream = gvc_mixer_control_get_default_sink (manager->priv->volume);
-        if (stream == manager->priv->stream)
+        if (stream == manager->priv->sink)
                 return;
 
-        if (manager->priv->stream != NULL) {
-                g_object_unref (manager->priv->stream);
-                manager->priv->stream = NULL;
+        if (manager->priv->sink != NULL) {
+                g_object_unref (manager->priv->sink);
+                manager->priv->sink = NULL;
         }
 
         if (stream != NULL) {
-                manager->priv->stream = g_object_ref (stream);
+                manager->priv->sink = g_object_ref (stream);
         } else {
                 g_warning ("Unable to get default sink");
         }
@@ -752,6 +783,14 @@ on_control_default_sink_changed (GvcMixerControl     *control,
         update_default_sink (manager);
 }
 
+static void
+on_control_default_source_changed (GvcMixerControl     *control,
+                                   guint                id,
+                                   GsdMediaKeysManager *manager)
+{
+        update_default_source (manager);
+}
+
 #endif /* HAVE_PULSE */
 
 static gint
@@ -953,9 +992,14 @@ do_action (GsdMediaKeysManager *manager,
         case VOLUME_DOWN_KEY:
         case VOLUME_UP_KEY:
 #ifdef HAVE_PULSE
-                do_sound_action (manager, type);
+                do_sound_action (manager, manager->priv->sink, type);
 #endif /* HAVE_PULSE */
                 break;
+        case MIC_MUTE_KEY:
+#ifdef HAVE_PULSE
+                do_sound_action (manager, manager->priv->source, type);
+#endif
+                break;
         case POWER_KEY:
                 do_exit_action (manager);
                 break;
@@ -1161,6 +1205,10 @@ gsd_media_keys_manager_start (GsdMediaKeysManager *manager,
                           "default-sink-changed",
                           G_CALLBACK (on_control_default_sink_changed),
                           manager);
+        g_signal_connect (manager->priv->volume,
+                          "default-source-changed",
+                          G_CALLBACK (on_control_default_source_changed),
+                          manager);
 
         gvc_mixer_control_open (manager->priv->volume);
 
@@ -1233,9 +1281,14 @@ gsd_media_keys_manager_stop (GsdMediaKeysManager *manager)
         priv->screens = NULL;
 
 #ifdef HAVE_PULSE
-        if (priv->stream) {
-                g_object_unref (priv->stream);
-                priv->stream = NULL;
+        if (priv->sink) {
+                g_object_unref (priv->sink);
+                priv->sink = NULL;
+        }
+
+        if (priv->source) {
+                g_object_unref (priv->source);
+                priv->source = NULL;
         }
 
         if (priv->volume) {
diff --git a/plugins/media-keys/gsd-media-keys-window.c b/plugins/media-keys/gsd-media-keys-window.c
index e2f7f17..5ef1871 100644
--- a/plugins/media-keys/gsd-media-keys-window.c
+++ b/plugins/media-keys/gsd-media-keys-window.c
@@ -49,6 +49,7 @@ struct GsdMediaKeysWindowPrivate
         double                   fade_out_alpha;
         GsdMediaKeysWindowAction action;
 
+        guint                    mic_volume_muted : 1;
         guint                    volume_muted : 1;
         int                      volume_level;
 
@@ -189,6 +190,16 @@ action_changed (GsdMediaKeysWindow *window)
                         volume_controls_set_visible (window, FALSE);
                         window_set_icon_name (window, "media-eject");
                         break;
+                case GSD_MEDIA_KEYS_WINDOW_ACTION_MIC_VOLUME:
+                        volume_controls_set_visible (window, TRUE);
+
+                        if (window->priv->volume_muted) {
+                                window_set_icon_name (window, "microphone-sensitivity-muted");
+                        } else {
+                                window_set_icon_name (window, "microphone-sensitivity-high");
+                        }
+
+                        break;
                 default:
                         break;
                 }
@@ -226,6 +237,20 @@ volume_muted_changed (GsdMediaKeysWindow *window)
         }
 }
 
+static void
+mic_volume_muted_changed (GsdMediaKeysWindow *window)
+{
+        update_window (window);
+
+        if (! window->priv->is_composited) {
+                if (window->priv->mic_volume_muted) {
+                        window_set_icon_name (window, "microphone-sensitivity-muted");
+                } else {
+                        window_set_icon_name (window, "microphone-sensitivity-high");
+                }
+        }
+}
+
 void
 gsd_media_keys_window_set_action (GsdMediaKeysWindow      *window,
                                   GsdMediaKeysWindowAction action)
@@ -251,6 +276,18 @@ gsd_media_keys_window_set_volume_muted (GsdMediaKeysWindow *window,
 }
 
 void
+gsd_media_keys_window_set_mic_volume_muted (GsdMediaKeysWindow *window,
+                                            gboolean            muted)
+{
+        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
+
+        if (window->priv->volume_muted != muted) {
+                window->priv->mic_volume_muted = muted;
+                mic_volume_muted_changed (window);
+        }
+}
+
+void
 gsd_media_keys_window_set_volume_level (GsdMediaKeysWindow *window,
                                         int                 level)
 {
diff --git a/plugins/media-keys/gsd-media-keys-window.h b/plugins/media-keys/gsd-media-keys-window.h
index ad75923..59f9ee4 100644
--- a/plugins/media-keys/gsd-media-keys-window.h
+++ b/plugins/media-keys/gsd-media-keys-window.h
@@ -49,7 +49,8 @@ struct GsdMediaKeysWindowClass {
 
 typedef enum {
         GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME,
-        GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT
+        GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT,
+        GSD_MEDIA_KEYS_WINDOW_ACTION_MIC_VOLUME
 } GsdMediaKeysWindowAction;
 
 GType                 gsd_media_keys_window_get_type          (void);
@@ -61,6 +62,8 @@ void                  gsd_media_keys_window_set_volume_muted  (GsdMediaKeysWindo
                                                                gboolean                 muted);
 void                  gsd_media_keys_window_set_volume_level  (GsdMediaKeysWindow      *window,
                                                                int                      level);
+void                  gsd_media_keys_window_set_mic_volume_muted  (GsdMediaKeysWindow      *window,
+                                                                   gboolean                 muted);
 gboolean              gsd_media_keys_window_is_valid          (GsdMediaKeysWindow      *window);
 
 G_END_DECLS


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