[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 12/12: Added a hidden option "volume-step"
noreply at xfce.org
noreply at xfce.org
Tue Feb 17 00:12:51 CET 2015
This is an automated email from the git hooks/post-receive script.
andrzejr pushed a commit to branch master
in repository panel-plugins/xfce4-pulseaudio-plugin.
commit c1cee6948aec47ca32fe77ac1d290fe554a0fd7f
Author: Andrzej <ndrwrdck at gmail.com>
Date: Mon Feb 16 00:52:12 2015 +0000
Added a hidden option "volume-step"
---
panel-plugin/pulseaudio-button.c | 11 ++++++--
panel-plugin/pulseaudio-button.h | 3 ++-
panel-plugin/pulseaudio-config.c | 53 ++++++++++++++++++++++++++++++++++----
panel-plugin/pulseaudio-config.h | 1 +
panel-plugin/pulseaudio-plugin.c | 8 +++---
panel-plugin/pulseaudio-plugin.h | 2 --
6 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/panel-plugin/pulseaudio-button.c b/panel-plugin/pulseaudio-button.c
index b1cc40f..3a8d1c3 100644
--- a/panel-plugin/pulseaudio-button.c
+++ b/panel-plugin/pulseaudio-button.c
@@ -30,6 +30,7 @@
#include <libxfce4panel/libxfce4panel.h>
#include "pulseaudio-plugin.h"
+#include "pulseaudio-config.h"
#include "pulseaudio-button.h"
#define V_MUTED 0
@@ -67,6 +68,7 @@ struct _PulseaudioButton
{
GtkToggleButton __parent__;
+ PulseaudioConfig *config;
PulseaudioVolume *volume;
GtkWidget *image;
@@ -137,6 +139,7 @@ pulseaudio_button_init (PulseaudioButton *button)
/* Intercept scroll events */
gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK);
+ button->config = NULL;
button->volume = NULL;
button->menu = NULL;
@@ -223,9 +226,11 @@ pulseaudio_button_scroll_event (GtkWidget *widget, GdkEventScroll *event)
{
PulseaudioButton *button = PULSEAUDIO_BUTTON (widget);
gdouble volume = pulseaudio_volume_get_volume (button->volume);
+ gdouble volume_step = pulseaudio_config_get_volume_step (button->config) / 100.0;
gdouble new_volume;
- new_volume = MIN (MAX (volume + (1.0 - 2.0 * event->direction) * VOLUME_STEP, 0.0), 1.0);
+
+ new_volume = MIN (MAX (volume + (1.0 - 2.0 * event->direction) * volume_step, 0.0), 1.0);
pulseaudio_volume_set_volume (button->volume, new_volume);
//g_debug ("dir: %d %f -> %f", event->direction, volume, new_volume);
@@ -333,7 +338,8 @@ pulseaudio_button_volume_changed (PulseaudioButton *button,
GtkWidget *
-pulseaudio_button_new (PulseaudioVolume *volume)
+pulseaudio_button_new (PulseaudioConfig *config,
+ PulseaudioVolume *volume)
{
PulseaudioButton *button;
@@ -342,6 +348,7 @@ pulseaudio_button_new (PulseaudioVolume *volume)
button = g_object_new (TYPE_PULSEAUDIO_BUTTON, NULL);
button->volume = volume;
+ button->config = config;
button->volume_changed_id =
g_signal_connect_swapped (G_OBJECT (button->volume), "volume-changed",
G_CALLBACK (pulseaudio_button_volume_changed), button);
diff --git a/panel-plugin/pulseaudio-button.h b/panel-plugin/pulseaudio-button.h
index 2082d3c..d43268c 100644
--- a/panel-plugin/pulseaudio-button.h
+++ b/panel-plugin/pulseaudio-button.h
@@ -38,7 +38,8 @@ GType pulseaudio_button_get_type (void);
typedef struct _PulseaudioButton PulseaudioButton;
typedef struct _PulseaudioButtonClass PulseaudioButtonClass;
-GtkWidget *pulseaudio_button_new (PulseaudioVolume *volume);
+GtkWidget *pulseaudio_button_new (PulseaudioConfig *config,
+ PulseaudioVolume *volume);
void pulseaudio_button_set_size (PulseaudioButton *button,
gint size);
diff --git a/panel-plugin/pulseaudio-config.c b/panel-plugin/pulseaudio-config.c
index 19a2c72..a4cfaad 100644
--- a/panel-plugin/pulseaudio-config.c
+++ b/panel-plugin/pulseaudio-config.c
@@ -46,6 +46,7 @@
#define DEFAULT_ENABLE_KEYBOARD_SHORTCUTS TRUE
+#define DEFAULT_VOLUME_STEP 6
@@ -64,7 +65,7 @@ static void pulseaudio_config_set_property (GObject *
struct _PulseaudioConfigClass
{
- GObjectClass __parent__;
+ GObjectClass __parent__;
};
struct _PulseaudioConfig
@@ -72,6 +73,7 @@ struct _PulseaudioConfig
GObject __parent__;
gboolean enable_keyboard_shortcuts;
+ guint volume_step;
};
@@ -80,6 +82,7 @@ enum
{
PROP_0,
PROP_ENABLE_KEYBOARD_SHORTCUTS,
+ PROP_VOLUME_STEP,
N_PROPERTIES,
};
@@ -115,6 +118,15 @@ pulseaudio_config_class_init (PulseaudioConfigClass *klass)
+ g_object_class_install_property (gobject_class,
+ PROP_VOLUME_STEP,
+ g_param_spec_uint ("volume-step", NULL, NULL,
+ 1, 50, DEFAULT_VOLUME_STEP,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+
+
pulseaudio_config_signals[CONFIGURATION_CHANGED] =
g_signal_new (g_intern_static_string ("configuration-changed"),
G_TYPE_FROM_CLASS (gobject_class),
@@ -130,6 +142,7 @@ static void
pulseaudio_config_init (PulseaudioConfig *config)
{
config->enable_keyboard_shortcuts = DEFAULT_ENABLE_KEYBOARD_SHORTCUTS;
+ config->volume_step = DEFAULT_VOLUME_STEP;
}
@@ -160,6 +173,10 @@ pulseaudio_config_get_property (GObject *object,
g_value_set_boolean (value, config->enable_keyboard_shortcuts);
break;
+ case PROP_VOLUME_STEP:
+ g_value_set_uint (value, config->volume_step);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -175,20 +192,31 @@ pulseaudio_config_set_property (GObject *object,
GParamSpec *pspec)
{
PulseaudioConfig *config = PULSEAUDIO_CONFIG (object);
- gint val;
+ guint val_uint;
+ gboolean val_bool;
switch (prop_id)
{
case PROP_ENABLE_KEYBOARD_SHORTCUTS:
- val = g_value_get_boolean (value);
- if (config->enable_keyboard_shortcuts != val)
+ val_bool = g_value_get_boolean (value);
+ if (config->enable_keyboard_shortcuts != val_bool)
{
- config->enable_keyboard_shortcuts = val;
+ config->enable_keyboard_shortcuts = val_bool;
g_object_notify (G_OBJECT (config), "enable-keyboard-shortcuts");
g_signal_emit (G_OBJECT (config), pulseaudio_config_signals [CONFIGURATION_CHANGED], 0);
}
break;
+ case PROP_VOLUME_STEP:
+ val_uint = g_value_get_uint (value);
+ if (config->volume_step != val_uint)
+ {
+ config->volume_step = val_uint;
+ g_object_notify (G_OBJECT (config), "volume-step");
+ g_signal_emit (G_OBJECT (config), pulseaudio_config_signals [CONFIGURATION_CHANGED], 0);
+ }
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -209,6 +237,17 @@ pulseaudio_config_get_enable_keyboard_shortcuts (PulseaudioConfig *config)
+guint
+pulseaudio_config_get_volume_step (PulseaudioConfig *config)
+{
+ g_return_val_if_fail (IS_PULSEAUDIO_CONFIG (config), DEFAULT_ENABLE_KEYBOARD_SHORTCUTS);
+
+ return config->volume_step;
+}
+
+
+
+
PulseaudioConfig *
pulseaudio_config_new (const gchar *property_base)
{
@@ -226,6 +265,10 @@ pulseaudio_config_new (const gchar *property_base)
xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "enable-keyboard-shortcuts");
g_free (property);
+ property = g_strconcat (property_base, "/volume-step", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_UINT, config, "volume-step");
+ g_free (property);
+
g_object_notify (G_OBJECT (config), "enable-keyboard-shortcuts");
g_signal_emit (G_OBJECT (config), pulseaudio_config_signals [CONFIGURATION_CHANGED], 0);
}
diff --git a/panel-plugin/pulseaudio-config.h b/panel-plugin/pulseaudio-config.h
index c8b534d..26c7603 100644
--- a/panel-plugin/pulseaudio-config.h
+++ b/panel-plugin/pulseaudio-config.h
@@ -39,6 +39,7 @@ GType pulseaudio_config_get_type (void)
PulseaudioConfig *pulseaudio_config_new (const gchar *property_base);
gboolean pulseaudio_config_get_enable_keyboard_shortcuts (PulseaudioConfig *config);
+guint pulseaudio_config_get_volume_step (PulseaudioConfig *config);
G_END_DECLS
diff --git a/panel-plugin/pulseaudio-plugin.c b/panel-plugin/pulseaudio-plugin.c
index b0a896b..ce026e2 100644
--- a/panel-plugin/pulseaudio-plugin.c
+++ b/panel-plugin/pulseaudio-plugin.c
@@ -294,14 +294,15 @@ pulseaudio_plugin_volume_key_pressed (const char *keystring,
{
PulseaudioPlugin *pulseaudio_plugin = PULSEAUDIO_PLUGIN (user_data);
gdouble volume = pulseaudio_volume_get_volume (pulseaudio_plugin->volume);
+ gdouble volume_step = pulseaudio_config_get_volume_step (pulseaudio_plugin->config) / 100.0;
gdouble new_volume;
g_debug ("%s pressed", keystring);
if (strcmp (keystring, PULSEAUDIO_PLUGIN_RAISE_VOLUME_KEY) == 0)
- pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (MAX (volume + VOLUME_STEP, 0.0), 1.0));
+ pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (MAX (volume + volume_step, 0.0), 1.0));
else if (strcmp (keystring, PULSEAUDIO_PLUGIN_LOWER_VOLUME_KEY) == 0)
- pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (MAX (volume - VOLUME_STEP, 0.0), 1.0));
+ pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (MAX (volume - volume_step, 0.0), 1.0));
}
@@ -359,7 +360,8 @@ pulseaudio_plugin_construct (XfcePanelPlugin *plugin)
pulseaudio_plugin->volume = pulseaudio_volume_new ();
/* instantiate a button box */
- pulseaudio_plugin->button = pulseaudio_button_new (pulseaudio_plugin->volume);
+ pulseaudio_plugin->button = pulseaudio_button_new (pulseaudio_plugin->config,
+ pulseaudio_plugin->volume);
gtk_container_add (GTK_CONTAINER (plugin), GTK_WIDGET (pulseaudio_plugin->button));
gtk_widget_show (GTK_WIDGET (pulseaudio_plugin->button));
diff --git a/panel-plugin/pulseaudio-plugin.h b/panel-plugin/pulseaudio-plugin.h
index 3cbfd2e..082b8ce 100644
--- a/panel-plugin/pulseaudio-plugin.h
+++ b/panel-plugin/pulseaudio-plugin.h
@@ -22,8 +22,6 @@
#include <gtk/gtk.h>
#include <libxfce4panel/libxfce4panel.h>
-#define VOLUME_STEP 0.06
-
G_BEGIN_DECLS
typedef struct _PulseaudioPluginClass PulseaudioPluginClass;
typedef struct _PulseaudioPlugin PulseaudioPlugin;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list