summaryrefslogtreecommitdiff
path: root/plugins/media-keys/msd-media-keys-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/media-keys/msd-media-keys-manager.c')
-rw-r--r--plugins/media-keys/msd-media-keys-manager.c370
1 files changed, 149 insertions, 221 deletions
diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c
index cc819c5..6c12274 100644
--- a/plugins/media-keys/msd-media-keys-manager.c
+++ b/plugins/media-keys/msd-media-keys-manager.c
@@ -41,6 +41,14 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#ifdef HAVE_LIBMATEMIXER
+#include <libmatemixer/matemixer.h>
+#endif
+
+#ifdef HAVE_LIBCANBERRA
+#include <canberra-gtk.h>
+#endif
+
#include "mate-settings-profile.h"
#include "msd-marshal.h"
#include "msd-media-keys-manager.h"
@@ -50,13 +58,6 @@
#include "acme.h"
#include "msd-media-keys-window.h"
-#ifdef HAVE_PULSE
-#include <canberra-gtk.h>
-#include "gvc-mixer-control.h"
-#elif defined(HAVE_GSTREAMER)
-#include "gvc-gstreamer-acme-vol.h"
-#endif /* HAVE_PULSE */
-
#define MSD_DBUS_PATH "/org/mate/SettingsDaemon"
#define MSD_DBUS_NAME "org.mate.SettingsDaemon"
#define MSD_MEDIA_KEYS_DBUS_PATH MSD_DBUS_PATH "/MediaKeys"
@@ -65,8 +66,7 @@
#define TOUCHPAD_SCHEMA "org.mate.peripherals-touchpad"
#define TOUCHPAD_ENABLED_KEY "touchpad-enabled"
-#define VOLUME_STEP 6 /* percents for one volume button press */
-#define MAX_VOLUME 65536.0
+#define VOLUME_STEP 6
#define MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerPrivate))
@@ -77,25 +77,23 @@ typedef struct {
struct MsdMediaKeysManagerPrivate
{
-#ifdef HAVE_PULSE
+#ifdef HAVE_LIBMATEMIXER
/* Volume bits */
- GvcMixerControl *volume;
- GvcMixerStream *stream;
-#elif defined(HAVE_GSTREAMER)
- AcmeVolume *volume;
-#endif /* HAVE_PULSE */
- GtkWidget *dialog;
- GSettings *settings;
- GVolumeMonitor *volume_monitor;
+ MateMixerControl *control;
+ MateMixerStream *stream;
+#endif
+ GtkWidget *dialog;
+ GSettings *settings;
+ GVolumeMonitor *volume_monitor;
/* Multihead stuff */
- GdkScreen *current_screen;
- GSList *screens;
+ GdkScreen *current_screen;
+ GSList *screens;
- GList *media_players;
+ GList *media_players;
- DBusGConnection *connection;
- guint notify[HANDLED_KEYS];
+ DBusGConnection *connection;
+ guint notify[HANDLED_KEYS];
};
enum {
@@ -113,7 +111,6 @@ G_DEFINE_TYPE (MsdMediaKeysManager, msd_media_keys_manager, G_TYPE_OBJECT)
static gpointer manager_object = NULL;
-
static void
init_screens (MsdMediaKeysManager *manager)
{
@@ -134,7 +131,6 @@ init_screens (MsdMediaKeysManager *manager)
manager->priv->current_screen = manager->priv->screens->data;
}
-
static void
acme_error (char * msg)
{
@@ -612,219 +608,169 @@ do_touchpad_action (MsdMediaKeysManager *manager)
g_object_unref (settings);
}
-#ifdef HAVE_PULSE
+#ifdef HAVE_LIBMATEMIXER
static void
update_dialog (MsdMediaKeysManager *manager,
- guint vol,
- gboolean muted,
- gboolean sound_changed)
+ guint volume,
+ gboolean muted,
+ gboolean sound_changed)
{
- vol = (int) (100 * (double) vol / PA_VOLUME_NORM);
- vol = CLAMP (vol, 0, 100);
-
dialog_init (manager);
+
msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
muted);
- msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol);
+ msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
+ volume);
+
msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
dialog_show (manager);
+#ifdef HAVE_LIBCANBERRA
if (sound_changed != FALSE && muted == FALSE)
ca_gtk_play_for_widget (manager->priv->dialog, 0,
CA_PROP_EVENT_ID, "audio-volume-change",
- CA_PROP_EVENT_DESCRIPTION, "volume changed through key press",
- CA_PROP_APPLICATION_ID, "org.mate.VolumeControl",
+ CA_PROP_EVENT_DESCRIPTION, "Volume changed through key press",
+ CA_PROP_APPLICATION_NAME, PACKAGE_NAME,
+ CA_PROP_APPLICATION_VERSION, PACKAGE_VERSION,
+ CA_PROP_APPLICATION_ID, "org.mate.SettingsDaemon",
NULL);
+#endif
}
-#endif /* HAVE_PULSE */
-
-#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER)
+
static void
-do_sound_action (MsdMediaKeysManager *manager,
- int type)
+do_sound_action (MsdMediaKeysManager *manager, int type)
{
gboolean muted;
- guint vol, norm_vol_step;
- int vol_step;
- gboolean sound_changed;
+ gboolean muted_last;
+ gboolean sound_changed = FALSE;
+ guint volume;
+ guint volume_min, volume_max;
+ guint volume_step;
+ guint volume_last;
-#ifdef HAVE_PULSE
if (manager->priv->stream == NULL)
return;
-#elif defined(HAVE_GSTREAMER)
- if (manager->priv->volume == NULL)
- return;
-#endif
- vol_step = g_settings_get_int (manager->priv->settings, "volume-step");
+ /* Theoretically the volume limits might be different for different
+ * streams, also the minimum might not always start at 0 */
+ volume_min = mate_mixer_stream_get_min_volume (manager->priv->stream);
+ volume_max = mate_mixer_stream_get_normal_volume (manager->priv->stream);
- if (vol_step <= 0 || vol_step > 100)
- vol_step = VOLUME_STEP;
+ volume_step = g_settings_get_int (manager->priv->settings, "volume-step");
+ if (volume_step <= 0 ||
+ volume_step > 100)
+ volume_step = VOLUME_STEP;
-#ifdef HAVE_PULSE
- norm_vol_step = PA_VOLUME_NORM * vol_step / 100;
+ /* Scale the volume step size accordingly to the range used by the stream */
+ volume_step = (volume_max - volume_min) * volume_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);
-#else
- if (vol_step > 0) {
- gint threshold = acme_volume_get_threshold (manager->priv->volume);
- if (vol_step < threshold)
- vol_step = threshold;
- g_debug ("Using volume step of %d", vol_step);
- }
- vol = acme_volume_get_volume (manager->priv->volume);
- muted = acme_volume_get_mute (manager->priv->volume);
-#endif
- sound_changed = FALSE;
+ volume = volume_last =
+ mate_mixer_stream_get_volume (manager->priv->stream);
+ muted = muted_last =
+ mate_mixer_stream_get_mute (manager->priv->stream);
switch (type) {
case MUTE_KEY:
-#ifdef HAVE_PULSE
muted = !muted;
- gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
- sound_changed = TRUE;
-#else
- acme_volume_mute_toggle (manager->priv->volume);
-#endif
break;
case VOLUME_DOWN_KEY:
-#ifdef HAVE_PULSE
- 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);
- sound_changed = TRUE;
- }
- } 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);
- sound_changed = TRUE;
- }
+ if (!muted) {
+ if (volume <= (volume_min + volume_step)) {
+ volume = volume_min;
+ muted = TRUE;
+ } else
+ volume -= volume_step;
}
-#else
- if (!muted && (vol <= vol_step))
- acme_volume_mute_toggle (manager->priv->volume);
- acme_volume_set_volume (manager->priv->volume, vol - vol_step);
-#endif
break;
case VOLUME_UP_KEY:
if (muted) {
- muted = !muted;
- if (vol == 0) {
-#ifdef HAVE_PULSE
- 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);
- sound_changed = TRUE;
- }
- } else {
- gvc_mixer_stream_change_is_muted (manager->priv->stream, muted);
- sound_changed = TRUE;
- }
-#else
- /* We need to unmute otherwise vol is blocked (and muted) */
- acme_volume_set_mute (manager->priv->volume, FALSE);
- }
- acme_volume_set_volume (manager->priv->volume, vol + vol_step);
-#endif
- } else {
-#ifdef HAVE_PULSE
- if (vol < MAX_VOLUME) {
- if (vol + norm_vol_step >= MAX_VOLUME) {
- vol = MAX_VOLUME;
- } 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);
- sound_changed = TRUE;
- }
- }
-#else
- acme_volume_set_volume (manager->priv->volume, vol + vol_step);
-#endif
- }
+ muted = FALSE;
+ if (volume <= volume_min)
+ volume = volume_min + volume_step;
+ } else
+ volume = CLAMP (volume + volume_step,
+ volume_min,
+ volume_max);
break;
}
-#ifdef HAVE_PULSE
- update_dialog (manager, vol, muted, sound_changed);
-#else
- muted = acme_volume_get_mute (manager->priv->volume);
- vol = acme_volume_get_volume (manager->priv->volume);
+ if (muted != muted_last) {
+ if (mate_mixer_stream_set_mute (manager->priv->stream, muted))
+ sound_changed = TRUE;
+ else
+ muted = muted_last;
+ }
+ if (volume != mate_mixer_stream_get_volume (manager->priv->stream)) {
+ if (mate_mixer_stream_set_volume (manager->priv->stream, volume))
+ sound_changed = TRUE;
+ else
+ volume = volume_last;
+ }
- /* FIXME: AcmeVolume should probably emit signals
- instead of doing it like this */
- dialog_init (manager);
- msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
- muted);
- msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
- vol);
- msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
- MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
- dialog_show (manager);
-#endif /* HAVE_PULSE */
+ update_dialog (manager,
+ CLAMP (100 * volume / (volume_max - volume_min), 0, 100),
+ muted,
+ sound_changed);
}
-#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */
-#ifdef HAVE_PULSE
static void
-update_default_sink (MsdMediaKeysManager *manager)
+update_default_output (MsdMediaKeysManager *manager)
{
- GvcMixerStream *stream;
+ MateMixerStream *stream;
- stream = gvc_mixer_control_get_default_sink (manager->priv->volume);
+ stream = mate_mixer_control_get_default_output_stream (manager->priv->control);
if (stream == manager->priv->stream)
return;
- if (manager->priv->stream != NULL) {
- g_object_unref (manager->priv->stream);
- manager->priv->stream = NULL;
- }
+ g_clear_object (&manager->priv->stream);
if (stream != NULL) {
+ MateMixerStreamFlags flags = mate_mixer_stream_get_flags (stream);
+
+ /* Do not use the stream if it is not possible to mute it or
+ * change the volume */
+ if (!(flags & MATE_MIXER_STREAM_HAS_MUTE) &&
+ !(flags & MATE_MIXER_STREAM_HAS_VOLUME))
+ return;
+
manager->priv->stream = g_object_ref (stream);
- } else {
- g_warning ("Unable to get default sink");
- }
+ g_debug ("Default output stream updated to %s",
+ mate_mixer_stream_get_name (manager->priv->stream));
+ } else
+ g_debug ("Default output stream unset");
}
static void
-on_control_ready (GvcMixerControl *control,
- MsdMediaKeysManager *manager)
+on_control_state_notify (MateMixerControl *control,
+ GParamSpec *pspec,
+ MsdMediaKeysManager *manager)
{
- update_default_sink (manager);
+ update_default_output (manager);
}
static void
-on_control_default_sink_changed (GvcMixerControl *control,
- guint id,
- MsdMediaKeysManager *manager)
+on_control_default_output_notify (MateMixerControl *control,
+ GParamSpec *pspec,
+ MsdMediaKeysManager *manager)
{
- update_default_sink (manager);
+ update_default_output (manager);
}
static void
-on_control_stream_removed (GvcMixerControl *control,
- guint id,
+on_control_stream_removed (MateMixerControl *control,
+ const gchar *name,
MsdMediaKeysManager *manager)
{
if (manager->priv->stream != NULL) {
- if (gvc_mixer_stream_get_id (manager->priv->stream) == id) {
- g_object_unref (manager->priv->stream);
- manager->priv->stream = NULL;
- }
+ MateMixerStream *stream =
+ mate_mixer_control_get_stream (manager->priv->control, name);
+
+ if (stream == manager->priv->stream)
+ g_clear_object (&manager->priv->stream);
}
}
-
-#endif /* HAVE_PULSE */
+#endif /* HAVE_LIBMATEMIXER */
static gint
find_by_application (gconstpointer a,
@@ -949,9 +895,9 @@ do_action (MsdMediaKeysManager *manager,
case MUTE_KEY:
case VOLUME_DOWN_KEY:
case VOLUME_UP_KEY:
-#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER)
+#ifdef HAVE_LIBMATEMIXER
do_sound_action (manager, type);
-#endif /* HAVE_PULSE || HAVE_GSTREAMER */
+#endif
break;
case POWER_KEY:
do_exit_action (manager);
@@ -1127,43 +1073,34 @@ start_media_keys_idle_cb (MsdMediaKeysManager *manager)
}
gboolean
-msd_media_keys_manager_start (MsdMediaKeysManager *manager,
- GError **error)
+msd_media_keys_manager_start (MsdMediaKeysManager *manager, GError **error)
{
mate_settings_profile_start (NULL);
-#ifdef HAVE_PULSE
- /* initialise Volume handler
- *
- * We do this one here to force checking gstreamer cache, etc.
- * The rest (grabbing and setting the keys) can happen in an
- * idle.
- */
- mate_settings_profile_start ("gvc_mixer_control_new");
-
- manager->priv->volume = gvc_mixer_control_new ("MATE Volume Control Media Keys");
-
- g_signal_connect (manager->priv->volume,
- "ready",
- G_CALLBACK (on_control_ready),
- manager);
- g_signal_connect (manager->priv->volume,
- "default-sink-changed",
- G_CALLBACK (on_control_default_sink_changed),
- manager);
- g_signal_connect (manager->priv->volume,
- "stream-removed",
- G_CALLBACK (on_control_stream_removed),
- manager);
-
- gvc_mixer_control_open (manager->priv->volume);
-
- mate_settings_profile_end ("gvc_mixer_control_new");
-#elif defined(HAVE_GSTREAMER)
- mate_settings_profile_start ("acme_volume_new");
- manager->priv->volume = acme_volume_new ();
- mate_settings_profile_end ("acme_volume_new");
-#endif /* HAVE_PULSE */
+#ifdef HAVE_LIBMATEMIXER
+ if (G_LIKELY (mate_mixer_is_initialized ())) {
+ mate_settings_profile_start ("mate_mixer_control_new");
+
+ manager->priv->control = mate_mixer_control_new ();
+
+ g_signal_connect (manager->priv->control,
+ "notify::state",
+ G_CALLBACK (on_control_state_notify),
+ manager);
+ g_signal_connect (manager->priv->control,
+ "notify::default-output",
+ G_CALLBACK (on_control_default_output_notify),
+ manager);
+ g_signal_connect (manager->priv->control,
+ "stream-removed",
+ G_CALLBACK (on_control_stream_removed),
+ manager);
+
+ mate_mixer_control_open (manager->priv->control);
+
+ mate_settings_profile_end ("mate_mixer_control_new");
+ }
+#endif
g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager);
mate_settings_profile_end (NULL);
@@ -1224,19 +1161,10 @@ msd_media_keys_manager_stop (MsdMediaKeysManager *manager)
g_slist_free (priv->screens);
priv->screens = NULL;
-#ifdef HAVE_PULSE
- if (priv->stream) {
- g_object_unref (priv->stream);
- priv->stream = NULL;
- }
-#endif /* HAVE_PULSE */
-
-#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER)
- if (priv->volume) {
- g_object_unref (priv->volume);
- priv->volume = NULL;
- }
-#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */
+#ifdef HAVE_LIBMATEMIXER
+ g_clear_object (&priv->stream);
+ g_clear_object (&priv->control);
+#endif
if (priv->dialog != NULL) {
gtk_widget_destroy (priv->dialog);