diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | configure.ac | 107 | ||||
-rw-r--r-- | plugins/media-keys/Makefile.am | 17 | ||||
-rw-r--r-- | plugins/media-keys/msd-media-keys-manager.c | 511 | ||||
-rw-r--r-- | plugins/media-keys/msd-media-keys-manager.h | 22 | ||||
-rw-r--r-- | plugins/media-keys/msd-media-keys-plugin.c | 37 | ||||
-rw-r--r-- | plugins/media-keys/msd-media-keys-plugin.h | 29 | ||||
-rw-r--r-- | plugins/media-keys/msd-media-keys-window.c | 4 | ||||
-rw-r--r-- | plugins/media-keys/test-media-keys.c | 6 |
10 files changed, 280 insertions, 459 deletions
@@ -2,6 +2,7 @@ MATE: Perberos <[email protected]> Steve Zesch <[email protected]> Stefano Karapetsas <[email protected]> +Michal Ratajsky <[email protected]> GNOME: Jonathan Blandford <[email protected]> @@ -1,10 +1,11 @@ 1.9.2 - * + * Port media-keys plugin to libmatemixer + * Remove GStreamer bits, make libmatemixer, libcanberra and PulseAudio + optional dependencies 1.8.0 * Add GTK3 support * Add Middle Click Emulation to mouse manager 1.6.0 - * Migration to gsettings diff --git a/configure.ac b/configure.ac index 350c0e7..33ef97b 100644 --- a/configure.ac +++ b/configure.ac @@ -55,6 +55,7 @@ GIO_REQUIRED_VERSION=2.26.0 MATE_DESKTOP_REQUIRED_VERSION=1.9.1 LIBMATEKBD_REQUIRED_VERSION=1.7.0 LIBNOTIFY_REQUIRED_VERSION=0.7.0 +LIBMATEMIXER_REQUIRED_VERSION=1.9.0 EXTRA_COMPILE_WARNINGS(yes) @@ -251,22 +252,12 @@ AC_SUBST(LIBMATEKBDUI_CFLAGS) AC_SUBST(LIBMATEKBDUI_LIBS) dnl --------------------------------------------------------------------------- -dnl - Housekeeping plugin stuff +dnl - Check for sound & mixer libraries dnl --------------------------------------------------------------------------- -PKG_CHECK_MODULES(GIOUNIX, [gio-unix-2.0]) -AC_SUBST(GIOUNIX_CFLAGS) -AC_SUBST(GIOUNIX_LIBS) - -dnl ============================================== -dnl PulseAudio section -dnl ============================================== - - have_pulse=false AC_ARG_ENABLE(pulse, - AC_HELP_STRING([--disable-pulse], - [turn off PulseAudio support]), + AC_HELP_STRING([--disable-pulse], [Disable PulseAudio support]), [case "${enableval}" in yes) WANT_PULSE=yes ;; no) WANT_PULSE=no ;; @@ -276,9 +267,9 @@ AC_ARG_ENABLE(pulse, if test x$WANT_PULSE = xyes ; then PA_REQUIRED_VERSION=0.9.16 - PKG_CHECK_MODULES(PULSE, glib-2.0 libpulse >= $PA_REQUIRED_VERSION libpulse-mainloop-glib >= $PA_REQUIRED_VERSION $LIBCANBERRA_PC, + PKG_CHECK_MODULES(PULSE, libpulse >= $PA_REQUIRED_VERSION, [have_pulse=true - AC_DEFINE(HAVE_PULSE, 1, [Define if PULSE sound server should be used])], + AC_DEFINE(HAVE_PULSE, 1, [Define if PulseAudio support is available])], [have_pulse=false]) fi AM_CONDITIONAL(HAVE_PULSE, test "x$have_pulse" = "xtrue") @@ -286,49 +277,45 @@ AM_CONDITIONAL(HAVE_PULSE, test "x$have_pulse" = "xtrue") AC_SUBST(PULSE_CFLAGS) AC_SUBST(PULSE_LIBS) - -dnl ============================================== -dnl GStreamer section -dnl ============================================== -GST_MAJORMINOR=auto - -AC_ARG_ENABLE(gstreamer, -AC_HELP_STRING([--enable-gstreamer],[use gstreamer if available (and optionally specify a version)]), -[case "${enableval}" in - yes) ENABLE_GSTREAMER=yes ;; - 0.10) ENABLE_GSTREAMER=yes && GST_MAJORMINOR=0.10 ;; - no) ENABLE_GSTREAMER=no ;; - *) AC_MSG_ERROR([ - *** Bad value ${enableval} for --enable-gstreamer - *** Please use one of the following: - *** --enable-gstreamer=0.10 - ]) ;; -esac], -[ENABLE_GSTREAMER=yes]) dnl Default value - -have_gstreamer=no -if test "x$ENABLE_GSTREAMER" = "xyes"; then - GST_REQS=0.10.1.2 - PKGS="gstreamer-0.10 >= $GST_REQS gstreamer-plugins-base-0.10 >= $GST_REQS" - - PKG_CHECK_MODULES(GST, $PKGS, have_gstreamer=yes, - AC_MSG_RESULT([no])) - - if test "x$have_pulse" = "xtrue"; then - AC_MSG_ERROR([*** GStreamer & Pulseaudio both are selected ***]) - fi - - if test "x$have_gstreamer" = "xyes"; then - GST_LIBS="$GST_LIBS -lgstinterfaces-0.10 -lgstaudio-0.10" - AC_DEFINE(HAVE_GSTREAMER,1,[enable gstreamer]) - fi -else - AC_MSG_NOTICE([*** GStreamer support disabled ***]) +have_libcanberra=no +AC_ARG_WITH(libcanberra, + AC_HELP_STRING([--without-libcanberra], [Disable sound events (default: auto)]), + with_libcanberra=$withval, with_libcanberra=auto) + +if test "x$with_libcanberra" != "xno"; then + PKG_CHECK_MODULES(LIBCANBERRA, $LIBCANBERRA_PC, + [AC_DEFINE(HAVE_LIBCANBERRA, 1, [Define if $LIBCANBERRA_PC is available]) + have_libcanberra=yes], have_libcanberra=no) + if test "x$have_libcanberra" = xno -a "x$with_libcanberra" = xyes; then + AC_MSG_ERROR([libcanberra support requested but library not found]) + fi +fi +AC_SUBST(LIBCANBERRA_CFLAGS) +AC_SUBST(LIBCANBERRA_LIBS) + +have_libmatemixer=no +AC_ARG_WITH(libmatemixer, + AC_HELP_STRING([--without-libmatemixer], [Disable volume event handling (default: auto)]), + with_libmatemixer=$withval, with_libmatemixer=auto) + +if test "x$with_libmatemixer" != "xno"; then + PKG_CHECK_MODULES(LIBMATEMIXER, libmatemixer >= $LIBMATEMIXER_REQUIRED_VERSION, + [AC_DEFINE(HAVE_LIBMATEMIXER, 1, [Define if libmatemixer is available]) + have_libmatemixer=yes], have_libmatemixer=no) + if test "x$have_libmatemixer" = xno -a "x$with_libmatemixer" = xyes; then + AC_MSG_ERROR([libmatemixer support requested but library not found]) + fi fi -AM_CONDITIONAL(HAVE_GSTREAMER, test "x$have_gstreamer" = "xyes") -AC_SUBST(GST_LIBS) -AC_SUBST(GST_CFLAGS) +AC_SUBST(LIBMATEMIXER_CFLAGS) +AC_SUBST(LIBMATEMIXER_LIBS) +dnl --------------------------------------------------------------------------- +dnl - Housekeeping plugin stuff +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES(GIOUNIX, [gio-unix-2.0]) +AC_SUBST(GIOUNIX_CFLAGS) +AC_SUBST(GIOUNIX_LIBS) dnl ============================================== dnl smartcard section @@ -375,7 +362,6 @@ fi AC_SUBST(NSS_DATABASE) - # --------------------------------------------------------------------------- # PolicyKit # --------------------------------------------------------------------------- @@ -411,8 +397,6 @@ AM_CONDITIONAL(HAVE_POLKIT, test "x$HAVE_POLKIT" = "xyes") AC_SUBST(POLKIT_CFLAGS) AC_SUBST(POLKIT_LIBS) - - # --------------------------------------------------------------------------- # Enable Profiling # --------------------------------------------------------------------------- @@ -424,7 +408,6 @@ if test "x$enable_profiling" = "xyes"; then AC_DEFINE(ENABLE_PROFILING,1,[enable profiling]) fi - # --------------------------------------------------------------------------- # Plugins # --------------------------------------------------------------------------- @@ -510,7 +493,6 @@ plugins/housekeeping/Makefile plugins/keybindings/Makefile plugins/keyboard/Makefile plugins/media-keys/Makefile -plugins/media-keys/cut-n-paste/Makefile plugins/mpris/Makefile plugins/mouse/Makefile plugins/smartcard/Makefile @@ -554,9 +536,10 @@ echo " PolicyKit support: ${HAVE_POLKIT} Gtk+ version: ${GTK_API_VERSION} - Libnotify support: ${have_libnotify} - GStreamer support: ${have_gstreamer} PulseAudio support: ${have_pulse} + Libnotify support: ${have_libnotify} + Libcanberra support: ${have_libcanberra} + Libmatemixer support: ${have_libmatemixer} Smartcard support: ${have_smartcard_support} ${NSS_DATABASE:+\ System nssdb: ${NSS_DATABASE} diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am index d0a7b6a..8268b08 100644 --- a/plugins/media-keys/Makefile.am +++ b/plugins/media-keys/Makefile.am @@ -3,7 +3,6 @@ context = actions NULL = -SUBDIRS = cut-n-paste plugin_LTLIBRARIES = libmedia-keys.la BUILT_SOURCES = \ @@ -80,7 +79,6 @@ libmedia_keys_la_SOURCES = \ libmedia_keys_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ -I$(top_srcdir)/plugins/common \ - -I$(top_srcdir)/plugins/media-keys/cut-n-paste \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DMATE_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ @@ -88,6 +86,8 @@ libmedia_keys_la_CPPFLAGS = \ libmedia_keys_la_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ + $(LIBMATEMIXER_CFLAGS) \ + $(LIBCANBERRA_CFLAGS) \ $(AM_CFLAGS) libmedia_keys_la_LDFLAGS = \ @@ -95,8 +95,9 @@ libmedia_keys_la_LDFLAGS = \ libmedia_keys_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ - $(top_builddir)/plugins/media-keys/cut-n-paste/libgvc.la \ $(SETTINGS_PLUGIN_LIBS) \ + $(LIBMATEMIXER_LIBS) \ + $(LIBCANBERRA_LIBS) \ $(XF86MISC_LIBS) \ -lm @@ -150,7 +151,6 @@ test_media_keys_SOURCES = \ test_media_keys_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ -I$(top_srcdir)/plugins/common \ - -I$(top_srcdir)/plugins/media-keys/cut-n-paste \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DMATE_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ @@ -158,6 +158,8 @@ test_media_keys_CPPFLAGS = \ test_media_keys_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ + $(LIBMATEMIXER_CFLAGS) \ + $(LIBCANBERRA_CFLAGS) \ $(AM_CFLAGS) test_media_keys_LDADD = \ @@ -165,19 +167,16 @@ test_media_keys_LDADD = \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ + $(LIBMATEMIXER_LIBS) \ + $(LIBCANBERRA_LIBS) \ $(XF86MISC_LIBS) \ - $(GST_LIBS) \ -lm -test_media_keys_LDADD += $(top_builddir)/plugins/media-keys/cut-n-paste/libgvc.la - gtkbuilderdir = $(pkgdatadir) gtkbuilder_DATA = \ acme.ui \ $(NULL) -DIST_SUBDIRS = cut-n-paste - EXTRA_DIST = \ msd-media-keys-manager.xml \ msd-marshal.list \ diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c index cc819c5..1ff0291 100644 --- a/plugins/media-keys/msd-media-keys-manager.c +++ b/plugins/media-keys/msd-media-keys-manager.c @@ -2,6 +2,7 @@ * * Copyright (C) 2001-2003 Bastien Nocera <[email protected]> * Copyright (C) 2006-2007 William Jon McCann <[email protected]> + * Copyright (C) 2014 Michal Ratajsky <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,16 +22,6 @@ #include "config.h" -#include <sys/types.h> -#include <sys/wait.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> - -#include <locale.h> - #include <glib.h> #include <glib/gi18n.h> #include <gdk/gdk.h> @@ -41,6 +32,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 +49,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 +57,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)) @@ -75,27 +66,26 @@ typedef struct { guint32 time; } MediaPlayer; -struct MsdMediaKeysManagerPrivate +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; + MateMixerContext *context; + MateMixerStream *stream; + MateMixerStreamControl *control; +#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 { @@ -107,13 +97,11 @@ static guint signals[LAST_SIGNAL] = { 0 }; static void msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass); static void msd_media_keys_manager_init (MsdMediaKeysManager *media_keys_manager); -static void msd_media_keys_manager_finalize (GObject *object); G_DEFINE_TYPE (MsdMediaKeysManager, msd_media_keys_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; - static void init_screens (MsdMediaKeysManager *manager) { @@ -134,7 +122,6 @@ init_screens (MsdMediaKeysManager *manager) manager->priv->current_screen = manager->priv->screens->data; } - static void acme_error (char * msg) { @@ -612,219 +599,177 @@ 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; - -#ifdef HAVE_PULSE - if (manager->priv->stream == NULL) - return; -#elif defined(HAVE_GSTREAMER) - if (manager->priv->volume == NULL) + gboolean muted_last; + gboolean sound_changed = FALSE; + guint volume; + guint volume_min, volume_max; + guint volume_step; + guint volume_last; + + if (manager->priv->control == 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_control_get_min_volume (manager->priv->control); + volume_max = mate_mixer_stream_control_get_normal_volume (manager->priv->control); - 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 control */ + 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_control_get_volume (manager->priv->control); + muted = muted_last = + mate_mixer_stream_control_get_mute (manager->priv->control); 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 (volume <= (volume_min + volume_step)) { + volume = volume_min; + muted = TRUE; + } else { + volume -= volume_step; + muted = FALSE; } -#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_control_set_mute (manager->priv->control, muted)) + sound_changed = TRUE; + else + muted = muted_last; + } + if (volume != mate_mixer_stream_control_get_volume (manager->priv->control)) { + if (mate_mixer_stream_control_set_volume (manager->priv->control, 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; + MateMixerStreamControl *control = NULL; + + stream = mate_mixer_context_get_default_output_stream (manager->priv->context); + if (stream != NULL) + control = mate_mixer_stream_get_default_control (stream); - stream = gvc_mixer_control_get_default_sink (manager->priv->volume); 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); + g_clear_object (&manager->priv->control); - if (stream != NULL) { - manager->priv->stream = g_object_ref (stream); - } else { - g_warning ("Unable to get default sink"); - } + if (control != NULL) { + MateMixerStreamControlFlags flags = mate_mixer_stream_control_get_flags (control); + + /* Do not use the stream if it is not possible to mute it or + * change the volume */ + if (!(flags & MATE_MIXER_STREAM_CONTROL_MUTE_WRITABLE) && + !(flags & MATE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE)) + return; + + manager->priv->stream = g_object_ref (stream); + manager->priv->control = g_object_ref (control); + g_debug ("Default output stream updated to %s", + mate_mixer_stream_get_name (stream)); + } else + g_debug ("Default output stream unset"); } static void -on_control_ready (GvcMixerControl *control, - MsdMediaKeysManager *manager) +on_context_state_notify (MateMixerContext *context, + 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_context_default_output_notify (MateMixerContext *context, + GParamSpec *pspec, + MsdMediaKeysManager *manager) { - update_default_sink (manager); + update_default_output (manager); } static void -on_control_stream_removed (GvcMixerControl *control, - guint id, +on_context_stream_removed (MateMixerContext *context, + 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_context_get_stream (manager->priv->context, name); + + if (stream == manager->priv->stream) { + g_clear_object (&manager->priv->stream); + g_clear_object (&manager->priv->control); + } } } - -#endif /* HAVE_PULSE */ +#endif /* HAVE_LIBMATEMIXER */ static gint find_by_application (gconstpointer a, @@ -949,9 +894,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 +1072,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_context_new"); + + manager->priv->context = mate_mixer_context_new (); + + g_signal_connect (manager->priv->context, + "notify::state", + G_CALLBACK (on_context_state_notify), + manager); + g_signal_connect (manager->priv->context, + "notify::default-output-stream", + G_CALLBACK (on_context_default_output_notify), + manager); + g_signal_connect (manager->priv->context, + "stream-removed", + G_CALLBACK (on_context_stream_removed), + manager); + + mate_mixer_context_open (manager->priv->context); + + mate_settings_profile_end ("mate_mixer_context_new"); + } +#endif g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager); mate_settings_profile_end (NULL); @@ -1224,19 +1160,11 @@ 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); + g_clear_object (&priv->context); +#endif if (priv->dialog != NULL) { gtk_widget_destroy (priv->dialog); @@ -1253,89 +1181,20 @@ msd_media_keys_manager_stop (MsdMediaKeysManager *manager) } static void -msd_media_keys_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdMediaKeysManager *self; - - self = MSD_MEDIA_KEYS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_media_keys_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdMediaKeysManager *self; - - self = MSD_MEDIA_KEYS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_media_keys_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdMediaKeysManager *media_keys_manager; - MsdMediaKeysManagerClass *klass; - - klass = MSD_MEDIA_KEYS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MEDIA_KEYS_MANAGER)); - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (media_keys_manager); -} - -static void -msd_media_keys_manager_dispose (GObject *object) -{ - MsdMediaKeysManager *media_keys_manager; - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); - - G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->dispose (object); -} - -static void msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_media_keys_manager_get_property; - object_class->set_property = msd_media_keys_manager_set_property; - object_class->constructor = msd_media_keys_manager_constructor; - object_class->dispose = msd_media_keys_manager_dispose; - object_class->finalize = msd_media_keys_manager_finalize; - - signals[MEDIA_PLAYER_KEY_PRESSED] = - g_signal_new ("media-player-key-pressed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdMediaKeysManagerClass, media_player_key_pressed), - NULL, - NULL, - msd_marshal_VOID__STRING_STRING, - G_TYPE_NONE, - 2, - G_TYPE_STRING, - G_TYPE_STRING); + signals[MEDIA_PLAYER_KEY_PRESSED] = + g_signal_new ("media-player-key-pressed", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdMediaKeysManagerClass, media_player_key_pressed), + NULL, + NULL, + msd_marshal_VOID__STRING_STRING, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_STRING); dbus_g_object_type_install_info (MSD_TYPE_MEDIA_KEYS_MANAGER, &dbus_glib_msd_media_keys_manager_object_info); @@ -1346,22 +1205,6 @@ static void msd_media_keys_manager_init (MsdMediaKeysManager *manager) { manager->priv = MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_media_keys_manager_finalize (GObject *object) -{ - MsdMediaKeysManager *media_keys_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MEDIA_KEYS_MANAGER (object)); - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); - - g_return_if_fail (media_keys_manager->priv != NULL); - - G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->finalize (object); } static gboolean diff --git a/plugins/media-keys/msd-media-keys-manager.h b/plugins/media-keys/msd-media-keys-manager.h index 1bcabf2..2afb5bc 100644 --- a/plugins/media-keys/msd-media-keys-manager.h +++ b/plugins/media-keys/msd-media-keys-manager.h @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2014 Michal Ratajsky <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,11 +22,10 @@ #ifndef __MSD_MEDIA_KEYS_MANAGER_H #define __MSD_MEDIA_KEYS_MANAGER_H +#include <glib.h> #include <glib-object.h> -#ifdef __cplusplus -extern "C" { -#endif +G_BEGIN_DECLS #define MSD_TYPE_MEDIA_KEYS_MANAGER (msd_media_keys_manager_get_type ()) #define MSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManager)) @@ -34,21 +34,23 @@ extern "C" { #define MSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_MANAGER)) #define MSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) -typedef struct MsdMediaKeysManagerPrivate MsdMediaKeysManagerPrivate; +typedef struct _MsdMediaKeysManager MsdMediaKeysManager; +typedef struct _MsdMediaKeysManagerClass MsdMediaKeysManagerClass; +typedef struct _MsdMediaKeysManagerPrivate MsdMediaKeysManagerPrivate; -typedef struct +struct _MsdMediaKeysManager { GObject parent; MsdMediaKeysManagerPrivate *priv; -} MsdMediaKeysManager; +}; -typedef struct +struct _MsdMediaKeysManagerClass { GObjectClass parent_class; void (* media_player_key_pressed) (MsdMediaKeysManager *manager, const char *application, const char *key); -} MsdMediaKeysManagerClass; +}; GType msd_media_keys_manager_get_type (void); @@ -65,8 +67,6 @@ gboolean msd_media_keys_manager_release_media_player_keys (MsdMedia const char *application, GError **error); -#ifdef __cplusplus -} -#endif +G_END_DECLS #endif /* __MSD_MEDIA_KEYS_MANAGER_H */ diff --git a/plugins/media-keys/msd-media-keys-plugin.c b/plugins/media-keys/msd-media-keys-plugin.c index 93a805f..3cce9d2 100644 --- a/plugins/media-keys/msd-media-keys-plugin.c +++ b/plugins/media-keys/msd-media-keys-plugin.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2014 Michal Ratajsky <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,14 +21,20 @@ #include "config.h" +#include <glib.h> #include <glib/gi18n-lib.h> -#include <gmodule.h> +#include <glib-object.h> + +#ifdef HAVE_LIBMATEMIXER +#include <libmatemixer/matemixer.h> +#endif #include "mate-settings-plugin.h" #include "msd-media-keys-plugin.h" #include "msd-media-keys-manager.h" -struct MsdMediaKeysPluginPrivate { +struct _MsdMediaKeysPluginPrivate +{ MsdMediaKeysManager *manager; }; @@ -46,35 +53,30 @@ msd_media_keys_plugin_init (MsdMediaKeysPlugin *plugin) } static void -msd_media_keys_plugin_finalize (GObject *object) +msd_media_keys_plugin_dispose (GObject *object) { MsdMediaKeysPlugin *plugin; - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MEDIA_KEYS_PLUGIN (object)); - - g_debug ("MsdMediaKeysPlugin finalizing"); + g_debug ("MsdMediaKeysPlugin disposing"); plugin = MSD_MEDIA_KEYS_PLUGIN (object); - g_return_if_fail (plugin->priv != NULL); + g_clear_object (&plugin->priv->manager); - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_media_keys_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_media_keys_plugin_parent_class)->dispose (object); } static void impl_activate (MateSettingsPlugin *plugin) { gboolean res; - GError *error; + GError *error = NULL; g_debug ("Activating media_keys plugin"); - error = NULL; +#ifdef HAVE_LIBMATEMIXER + mate_mixer_init (); +#endif res = msd_media_keys_manager_start (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start media_keys manager: %s", error->message); @@ -92,10 +94,10 @@ impl_deactivate (MateSettingsPlugin *plugin) static void msd_media_keys_plugin_class_init (MsdMediaKeysPluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = msd_media_keys_plugin_finalize; + object_class->dispose = msd_media_keys_plugin_dispose; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; @@ -107,4 +109,3 @@ static void msd_media_keys_plugin_class_finalize (MsdMediaKeysPluginClass *klass) { } - diff --git a/plugins/media-keys/msd-media-keys-plugin.h b/plugins/media-keys/msd-media-keys-plugin.h index dee322f..0662009 100644 --- a/plugins/media-keys/msd-media-keys-plugin.h +++ b/plugins/media-keys/msd-media-keys-plugin.h @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2014 Michal Ratajsky <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,9 +28,7 @@ #include "mate-settings-plugin.h" -#ifdef __cplusplus -extern "C" { -#endif +G_BEGIN_DECLS #define MSD_TYPE_MEDIA_KEYS_PLUGIN (msd_media_keys_plugin_get_type ()) #define MSD_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPlugin)) @@ -38,26 +37,26 @@ extern "C" { #define MSD_IS_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_PLUGIN)) #define MSD_MEDIA_KEYS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) -typedef struct MsdMediaKeysPluginPrivate MsdMediaKeysPluginPrivate; +typedef struct _MsdMediaKeysPlugin MsdMediaKeysPlugin; +typedef struct _MsdMediaKeysPluginClass MsdMediaKeysPluginClass; +typedef struct _MsdMediaKeysPluginPrivate MsdMediaKeysPluginPrivate; -typedef struct +struct _MsdMediaKeysPlugin { - MateSettingsPlugin parent; - MsdMediaKeysPluginPrivate *priv; -} MsdMediaKeysPlugin; + MateSettingsPlugin parent; + MsdMediaKeysPluginPrivate *priv; +}; -typedef struct +struct _MsdMediaKeysPluginClass { - MateSettingsPluginClass parent_class; -} MsdMediaKeysPluginClass; + MateSettingsPluginClass parent_class; +}; -GType msd_media_keys_plugin_get_type (void) G_GNUC_CONST; +GType msd_media_keys_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); -#ifdef __cplusplus -} -#endif +G_END_DECLS #endif /* __MSD_MEDIA_KEYS_PLUGIN_H__ */ diff --git a/plugins/media-keys/msd-media-keys-window.c b/plugins/media-keys/msd-media-keys-window.c index 9281a9e..7dde696 100644 --- a/plugins/media-keys/msd-media-keys-window.c +++ b/plugins/media-keys/msd-media-keys-window.c @@ -683,12 +683,8 @@ msd_media_keys_window_class_init (MsdMediaKeysWindowClass *klass) static void msd_media_keys_window_init (MsdMediaKeysWindow *window) { - GdkScreen *screen; - window->priv = MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { GtkBuilder *builder; const gchar *objects[] = {"acme_box", NULL}; diff --git a/plugins/media-keys/test-media-keys.c b/plugins/media-keys/test-media-keys.c index ce1e18a..51ea1e3 100644 --- a/plugins/media-keys/test-media-keys.c +++ b/plugins/media-keys/test-media-keys.c @@ -35,8 +35,7 @@ int main (int argc, char **argv) { - GError *error; - gboolean res; + GError *error = NULL; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, MATE_SETTINGS_LOCALEDIR); @@ -46,7 +45,6 @@ main (int argc, textdomain (GETTEXT_PACKAGE); #endif - error = NULL; if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { fprintf (stderr, "%s", error->message); g_error_free (error); @@ -56,7 +54,7 @@ main (int argc, manager = msd_media_keys_manager_new (); error = NULL; - res = msd_media_keys_manager_start (manager, &error); + msd_media_keys_manager_start (manager, &error); gtk_main (); |