aboutsummaryrefslogtreecommitdiff
path: root/src/volume-widget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/volume-widget.c')
-rw-r--r--src/volume-widget.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/volume-widget.c b/src/volume-widget.c
index 8b54a32..9b6e5f7 100644
--- a/src/volume-widget.c
+++ b/src/volume-widget.c
@@ -22,6 +22,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include <glib/gi18n.h>
+#include <math.h>
+#include <glib.h>
#include "volume-widget.h"
#include "common-defs.h"
#include <libido/idoscalemenuitem.h>
@@ -45,8 +47,7 @@ static void volume_widget_finalize (GObject *object);
static void volume_widget_set_twin_item( VolumeWidget* self,
DbusmenuMenuitem* twin_item);
static void volume_widget_set_ido_position(VolumeWidget* self,
- gint position,
- gint duration);
+ gdouble new_volume);
//callbacks
static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property,
GValue* value, gpointer userdata);
@@ -54,6 +55,9 @@ static gboolean volume_widget_change_value_cb (GtkRange *range,
GtkScrollType scroll,
gdouble value,
gpointer user_data);
+static gboolean volume_widget_value_changed_cb(GtkRange *range,
+ gpointer user_data);
+
static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data);
static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data);
static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data);
@@ -82,14 +86,14 @@ volume_widget_init (VolumeWidget *self)
ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE);
g_object_set(priv->ido_volume_slider, "reverse-scroll-events", TRUE, NULL);
- g_signal_connect (volume_slider,
- "notify::parent", G_CALLBACK (slider_parent_changed),
+ g_signal_connect (priv->ido_volume_slider,
+ "notify::parent", G_CALLBACK (volume_widget_parent_changed),
NULL);
GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider);
// register slider changes listening on the range
- g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self);
+ //g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self);
g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self);
g_signal_connect(priv->ido_volume_slider, "slider-grabbed", G_CALLBACK(volume_widget_slider_grabbed), self);
g_signal_connect(priv->ido_volume_slider, "slider-released", G_CALLBACK(volume_widget_slider_released), self);
@@ -107,8 +111,6 @@ volume_widget_init (VolumeWidget *self)
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (volume_widget));
gtk_adjustment_set_step_increment(adj, 3);
-
- gtk_widget_show_all(volume_widget);
}
static void
@@ -126,13 +128,18 @@ volume_widget_finalize (GObject *object)
static void
volume_widget_property_update(DbusmenuMenuitem* item, gchar* property,
GValue* value, gpointer userdata)
-{
- g_debug("scrub-widget::property_update");
-
+{
g_return_if_fail (IS_VOLUME_WIDGET (userdata));
VolumeWidget* mitem = VOLUME_WIDGET(userdata);
VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem);
-
+ g_debug("scrub-widget::property_update for prop %s", property);
+ if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){
+ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider);
+ GtkRange *range = (GtkRange*)slider;
+ gdouble update = g_value_get_double (value);
+ g_debug("volume-widget - update level with value %f", update);
+ gtk_range_set_value(range, update);
+ }
}
static void
@@ -174,20 +181,18 @@ volume_widget_change_value_cb (GtkRange *range,
}
static gboolean
-volume_widget_value_changed(GtkRange *range, gpointer user_data)
+volume_widget_value_changed_cb(GtkRange *range, gpointer user_data)
{
g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE);
VolumeWidget* mitem = VOLUME_WIDGET(user_data);
VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem);
-
- gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider), 0, 100);
- // Replace with dbus properties inspection
- /*if (current_value == exterior_vol_update) {
- g_debug("ignore the value changed event - its come from the outside");
- return FALSE;
- }*/
-
+ if(priv->grabbed == TRUE){
+ return TRUE;
+ }
+
+ gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider)), 0, 100);
+
GValue value = {0};
g_value_init(&value, G_TYPE_DOUBLE);
g_value_set_double(&value, current_value);
@@ -195,13 +200,13 @@ volume_widget_value_changed(GtkRange *range, gpointer user_data)
dbusmenu_menuitem_handle_event (priv->twin_item, "slider_change", &value, 0);
// This is not ideal in that the icon ui will update on ui actions and not on actual service feedback.
// but necessary for now as the server does not send volume update information if the source of change was this ui.
- determine_state_from_volume(current_value);
+ //determine_state_from_volume(current_value);
return FALSE;
}
GtkWidget*
-volume_widget_get_ido_bar(VolumeWidget* self)
+volume_widget_get_ido_slider(VolumeWidget* self)
{
VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self);
return priv->ido_volume_slider;
@@ -215,20 +220,16 @@ volume_widget_parent_changed (GtkWidget *widget,
g_debug("volume_widget_parent_changed");
}
-
+
+//TODO: are we using this as convenience function
static void
volume_widget_set_ido_position(VolumeWidget* self,
- gint position,
- gint duration)
+ gdouble new_volume)
{
VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self);
- gdouble ido_position = position/(gdouble)duration * 100.0;
- g_debug("volume_widget_set_ido_position - pos: %i, duration: %i, ido_pos: %f", position, duration, ido_position);
GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider);
GtkRange *range = (GtkRange*)slider;
- if(duration == 0)
- ido_position = 0.0;
- gtk_range_set_value(range, ido_position);
+ gtk_range_set_value(range, new_volume);
}
static void