Updating branch refs/heads/gber/improvements to 55c863fed1600579a886104029e86dfd25964b1e (commit) from e2656dab9c66887b491acb14d0d96b53c2f46c3d (commit)
commit 55c863fed1600579a886104029e86dfd25964b1e Author: Guido Berhoerster <guido+x...@berhoerster.name> Date: Fri Sep 21 12:00:36 2012 +0200 Add global keyboard shortcuts (bug #5314) Add global keyboard shortcuts for raising and lowering the volume as well as muting. Make the plugin single-instance. NEWS | 2 + configure.in.in | 1 + panel-plugin/Makefile.am | 6 +- panel-plugin/mixer.desktop.in | 2 +- panel-plugin/xfce-mixer-plugin.c | 139 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 853354f..400ccdd 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ - Add an item to the panel plugin context menu for muting (bug #7944). - Make name and description more meaningful (bug #5817). - Do not use deprecated APIs and adjust requirements to Xfce 4.10. +- Add global keyboard shortcuts for raising and lowering the volume as well as + muting (bug #5314). 4.8.0 diff --git a/configure.in.in b/configure.in.in index 91250d8..d0175e3 100644 --- a/configure.in.in +++ b/configure.in.in @@ -97,6 +97,7 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.10.0]) XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.10.0]) XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.10.0]) XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.10.0]) +XDT_CHECK_PACKAGE([KEYBINDER], [keybinder], [0.2.2]) dnl *********************************** dnl *** Check for debugging support *** diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am index 2170005..fa27e29 100644 --- a/panel-plugin/Makefile.am +++ b/panel-plugin/Makefile.am @@ -25,7 +25,8 @@ libmixer_la_CFLAGS = \ $(LIBXFCE4UI_CFLAGS) \ $(LIBXFCE4PANEL_CFLAGS) \ $(XFCONF_CFLAGS) \ - $(GST_PLUGINS_BASE_CFLAGS) + $(GST_PLUGINS_BASE_CFLAGS) \ + $(KEYBINDER_CFLAGS) libmixer_la_DEPENDENCIES = \ $(top_builddir)/libxfce4mixer/libxfce4mixer.la @@ -47,7 +48,8 @@ libmixer_la_LIBADD = \ $(XFCONF_LIBS) \ $(GST_PLUGINS_BASE_LIBS) \ -lgstaudio-0.10 \ - -lgstinterfaces-0.10 + -lgstinterfaces-0.10 \ + $(KEYBINDER_LIBS) desktopdir = $(datadir)/xfce4/panel/plugins diff --git a/panel-plugin/mixer.desktop.in b/panel-plugin/mixer.desktop.in index fb45c14..f4e7637 100644 --- a/panel-plugin/mixer.desktop.in +++ b/panel-plugin/mixer.desktop.in @@ -5,4 +5,4 @@ _Comment=Adjust volume levels Icon=multimedia-volume-control X-XFCE-Internal=false X-XFCE-Module=mixer -X-XFCE-Unique=false +X-XFCE-Unique=true diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c index 7e7a8cc..aa5ed41 100644 --- a/panel-plugin/xfce-mixer-plugin.c +++ b/panel-plugin/xfce-mixer-plugin.c @@ -36,6 +36,8 @@ #include <libxfce4panel/libxfce4panel.h> #include <xfconf/xfconf.h> +#include <keybinder.h> + #include "xfce-mixer-plugin.h" #include "libxfce4mixer/libxfce4mixer.h" @@ -56,6 +58,12 @@ enum +#define XFCE_MIXER_PLUGIN_RAISE_VOLUME_KEY "XF86AudioRaiseVolume" +#define XFCE_MIXER_PLUGIN_LOWER_VOLUME_KEY "XF86AudioLowerVolume" +#define XFCE_MIXER_PLUGIN_MUTE_KEY "XF86AudioMute" + + + static void xfce_mixer_plugin_construct (XfcePanelPlugin *plugin); static void xfce_mixer_plugin_set_property (GObject *object, guint prop_id, @@ -83,6 +91,10 @@ static void xfce_mixer_plugin_update_track (XfceMixerPlugin static void xfce_mixer_plugin_bus_message (GstBus *bus, GstMessage *message, XfceMixerPlugin *mixer_plugin); +static void xfce_mixer_plugin_volume_key_pressed (const char *keystring, + void *user_data); +static void xfce_mixer_plugin_mute_pressed (const char *keystring, + void *user_data); @@ -202,6 +214,9 @@ xfce_mixer_plugin_init (XfceMixerPlugin *mixer_plugin) /* Initialize the mixer library */ xfce_mixer_init (); + /* Initialize libkeybinder */ + keybinder_init (); + /* Create container for the plugin */ mixer_plugin->hvbox = GTK_WIDGET (xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0)); xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (mixer_plugin), mixer_plugin->hvbox); @@ -253,6 +268,11 @@ xfce_mixer_plugin_construct (XfcePanelPlugin *plugin) g_object_notify (G_OBJECT (mixer_plugin), "sound-card"); g_object_notify (G_OBJECT (mixer_plugin), "track"); g_object_notify (G_OBJECT (mixer_plugin), "command"); + + /* Set up global keyboard shortcuts */ + keybinder_bind(XFCE_MIXER_PLUGIN_LOWER_VOLUME_KEY, xfce_mixer_plugin_volume_key_pressed, mixer_plugin); + keybinder_bind(XFCE_MIXER_PLUGIN_RAISE_VOLUME_KEY, xfce_mixer_plugin_volume_key_pressed, mixer_plugin); + keybinder_bind(XFCE_MIXER_PLUGIN_MUTE_KEY, xfce_mixer_plugin_mute_pressed, mixer_plugin); } @@ -392,6 +412,11 @@ xfce_mixer_plugin_free_data (XfcePanelPlugin *plugin) { XfceMixerPlugin *mixer_plugin = XFCE_MIXER_PLUGIN (plugin); + /* Remove global keyboard shortcuts */ + keybinder_unbind(XFCE_MIXER_PLUGIN_LOWER_VOLUME_KEY, xfce_mixer_plugin_volume_key_pressed); + keybinder_unbind(XFCE_MIXER_PLUGIN_RAISE_VOLUME_KEY, xfce_mixer_plugin_volume_key_pressed); + keybinder_unbind(XFCE_MIXER_PLUGIN_MUTE_KEY, xfce_mixer_plugin_mute_pressed); + /* Shutdown xfconf */ g_object_unref (mixer_plugin->plugin_channel); xfconf_shutdown (); @@ -733,3 +758,117 @@ xfce_mixer_plugin_bus_message (GstBus *bus, break; } } + + + +static void +xfce_mixer_plugin_volume_key_pressed (const char *keystring, + void *user_data) +{ + XfceMixerPlugin *mixer_plugin = XFCE_MIXER_PLUGIN (user_data); + gint volume_range; + gint interval; + gint i; + gint *old_volumes; + gint *new_volumes; + gint old_volume; + gint new_volume; + gdouble button_volume; + + if (G_UNLIKELY (!GST_IS_MIXER (mixer_plugin->card) || !GST_IS_MIXER_TRACK (mixer_plugin->track) || mixer_plugin->track_label == NULL)) + return; + + /* Get volumes of the mixer track */ + old_volumes = g_new (gint, mixer_plugin->track->num_channels); + gst_mixer_get_volume (GST_MIXER (mixer_plugin->card), mixer_plugin->track, old_volumes); + old_volume = xfce_mixer_get_max_volume (old_volumes, mixer_plugin->track->num_channels); + g_free (old_volumes); + + volume_range = mixer_plugin->track->max_volume - mixer_plugin->track->min_volume; + + /* Increase/Decrease in intervals of 5% of the volume range but at least 1 */ + interval = round (volume_range * 0.05); + if (interval == 0) + interval = 1; + + if (strcmp (keystring, XFCE_MIXER_PLUGIN_RAISE_VOLUME_KEY) == 0) + { + /* Determine new volume */ + new_volume = old_volume + interval; + if (new_volume > mixer_plugin->track->max_volume) + new_volume = mixer_plugin->track->max_volume; + } + else if (strcmp (keystring, XFCE_MIXER_PLUGIN_LOWER_VOLUME_KEY) == 0) + { + /* Determine new volume */ + new_volume = old_volume - interval; + if (new_volume < mixer_plugin->track->min_volume) + new_volume = mixer_plugin->track->min_volume; + } + else + return; + + if (new_volume != old_volume) + { + /* Mute when volume reaches 0%, unmute if volume is raised from 0% */ + if (old_volume > 0 && new_volume == 0) + xfce_mixer_plugin_mute_changed (mixer_plugin, TRUE); + else if (old_volume == 0 && new_volume > 0) + xfce_mixer_plugin_mute_changed (mixer_plugin, FALSE); + + /* Set the new mute state */ + + mixer_plugin->ignore_bus_messages = TRUE; + + /* Calculate volume as double between 0.0 and 1.0 for the button */ + button_volume = ((gdouble) new_volume - mixer_plugin->track->min_volume) / volume_range; + + new_volumes = g_new (gint, mixer_plugin->track->num_channels); + for (i = 0; i < mixer_plugin->track->num_channels; ++i) + new_volumes[i] = new_volume; + + /* Apply volume change to the sound card */ + gst_mixer_set_volume (GST_MIXER (mixer_plugin->card), mixer_plugin->track, new_volumes); + + g_free (new_volumes); + + mixer_plugin->ignore_bus_messages = FALSE; + + /* Update the volume button */ + xfce_volume_button_set_volume (XFCE_VOLUME_BUTTON (mixer_plugin->button), button_volume); + if (old_volume > 0 && new_volume == 0) + xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), TRUE); + else if (old_volume == 0 && new_volume > 0) + xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), FALSE); + } +} + + + +static void +xfce_mixer_plugin_mute_pressed (const char *keystring, + void *user_data) +{ + XfceMixerPlugin *mixer_plugin = XFCE_MIXER_PLUGIN (user_data); + XfceMixerTrackType track_type; + gboolean muted = TRUE; + + if (G_UNLIKELY (!GST_IS_MIXER (mixer_plugin->card) || !GST_IS_MIXER_TRACK (mixer_plugin->track) || mixer_plugin->track_label == NULL)) + return; + + /* Determine track type */ + track_type = xfce_mixer_track_type_new (mixer_plugin->track); + + /* Determine current mute state */ + if (G_LIKELY (track_type == XFCE_MIXER_TRACK_TYPE_PLAYBACK)) + muted = GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_MUTE); + else if (track_type == XFCE_MIXER_TRACK_TYPE_CAPTURE) + muted = !GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_RECORD); + + /* Set the new mute state */ + xfce_mixer_plugin_mute_changed (mixer_plugin, !muted); + + /* Update the volume button */ + xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), !muted); +} + _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits