aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mute-menu-item.c72
-rw-r--r--src/mute-menu-item.h13
-rw-r--r--src/sound-service-dbus.c36
3 files changed, 66 insertions, 55 deletions
diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c
index 2c5af6d..344c17e 100644
--- a/src/mute-menu-item.c
+++ b/src/mute-menu-item.c
@@ -20,14 +20,16 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#endif
-#include "common-defs.h"
#include <glib/gi18n.h>
+
+#include "common-defs.h"
#include "mute-menu-item.h"
#include "pulse-manager.h"
typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate;
struct _MuteMenuItemPrivate {
+ DbusmenuMenuitem* button;
};
#define MUTE_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_MENU_ITEM_TYPE, MuteMenuItemPrivate))
@@ -39,8 +41,10 @@ static void mute_menu_item_dispose (GObject *object);
static void mute_menu_item_finalize (GObject *object);
static void handle_event (DbusmenuMenuitem * mi, const gchar * name,
GVariant * value, guint timestamp);
+static void
+mute_menu_item_set_global_mute_from_ui (gpointer user_data);
-G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, DBUSMENU_TYPE_MENUITEM);
+G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, G_TYPE_OBJECT);
static void mute_menu_item_class_init (MuteMenuItemClass *klass)
{
@@ -51,14 +55,19 @@ static void mute_menu_item_class_init (MuteMenuItemClass *klass)
object_class->dispose = mute_menu_item_dispose;
object_class->finalize = mute_menu_item_finalize;
- DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass);
- mclass->handle_event = handle_event;
return;
}
static void mute_menu_item_init (MuteMenuItem *self)
{
g_debug("Building new Mute Menu Item");
+ MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self);
+ priv->button = dbusmenu_menuitem_new();
+
+ g_signal_connect (G_OBJECT (priv->button),
+ DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
+ G_CALLBACK (mute_menu_item_set_global_mute_from_ui),
+ self);
return;
}
@@ -74,53 +83,50 @@ mute_menu_item_finalize (GObject *object)
G_OBJECT_CLASS (mute_menu_item_parent_class)->finalize (object);
}
-static void
-handle_event (DbusmenuMenuitem * mi,
- const gchar * name,
- GVariant * value,
- guint timestamp)
+static void
+mute_menu_item_set_global_mute_from_ui (gpointer user_data)
{
- /*g_debug ( "handle-event in the mute at the backend, input is of type %s",
- g_variant_get_type_string(value));*/
-
- GVariant* input = NULL;
- input = value;
- g_variant_ref (input);
-
- // Please note: Subject to change in future DBusmenu revisions
- if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT) == TRUE) {
- input = g_variant_get_variant(value);
- }
-
- gboolean mute_input = g_variant_get_boolean(input);
- toggle_global_mute (mute_input);
- g_variant_unref (input);
+ g_return_if_fail (DBUSMENU_IS_MENUITEM (user_data));
+ DbusmenuMenuitem* button = DBUSMENU_MENUITEM (user_data);
+ gboolean current_value = dbusmenu_menuitem_property_get_bool (button,
+ DBUSMENU_MUTE_MENUITEM_VALUE);
+
+ gboolean new_value = !current_value;
+ // pa manager api - to be refactored
+ toggle_global_mute (new_value);
}
+
void mute_menu_item_update(MuteMenuItem* item, gboolean value_update)
{
- dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(item),
+ MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item);
+
+ dbusmenu_menuitem_property_set_bool (priv->button,
DBUSMENU_MUTE_MENUITEM_VALUE,
value_update);
- dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(item),
+ dbusmenu_menuitem_property_set (priv->button,
DBUSMENU_MENUITEM_PROP_LABEL,
value_update == FALSE ? _("Mute") : _("Unmute"));
}
void mute_menu_item_enable(MuteMenuItem* item, gboolean active)
{
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(item),
- DBUSMENU_MENUITEM_PROP_ENABLED,
- active);
+ MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item);
+
+ dbusmenu_menuitem_property_set_bool (priv->button,
+ DBUSMENU_MENUITEM_PROP_ENABLED,
+ active);
}
+DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item)
+{
+ MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item);
+ return priv->button;
+}
MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled)
{
- MuteMenuItem *self = g_object_new(MUTE_MENU_ITEM_TYPE, NULL);
- dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(self),
- DBUSMENU_MENUITEM_PROP_TYPE,
- DBUSMENU_MUTE_MENUITEM_TYPE);
+ MuteMenuItem *self = g_object_new (MUTE_MENU_ITEM_TYPE, NULL);
mute_menu_item_update (self, initial_update);
mute_menu_item_enable (self, enabled);
return self;
diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h
index 1432de1..8240441 100644
--- a/src/mute-menu-item.h
+++ b/src/mute-menu-item.h
@@ -22,7 +22,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib.h>
#include <glib-object.h>
-
#include <libdbusmenu-glib/menuitem.h>
G_BEGIN_DECLS
@@ -38,19 +37,21 @@ typedef struct _MuteMenuItem MuteMenuItem;
typedef struct _MuteMenuItemClass MuteMenuItemClass;
struct _MuteMenuItemClass {
- DbusmenuMenuitemClass parent_class;
+ GObjectClass parent_class;
};
struct _MuteMenuItem {
- DbusmenuMenuitem parent;
+ GObject parent;
};
GType mute_menu_item_get_type (void);
-MuteMenuItem* mute_menu_item_new();
+MuteMenuItem* mute_menu_item_new ();
+
+void mute_menu_item_update (MuteMenuItem* item, gboolean update);
+void mute_menu_item_enable (MuteMenuItem* item, gboolean active);
-void mute_menu_item_update(MuteMenuItem* item, gboolean update);
-void mute_menu_item_enable(MuteMenuItem* item, gboolean active);
+DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item);
G_END_DECLS
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index ec802f7..1bdb2cf 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -173,7 +173,8 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self,
// Mute button
priv->mute_menuitem = mute_menu_item_new ( mute_update, availability);
- dbusmenu_menuitem_child_append (priv->root_menuitem, DBUSMENU_MENUITEM(priv->mute_menuitem));
+ dbusmenu_menuitem_child_append (priv->root_menuitem,
+ mute_menu_item_get_button (priv->mute_menuitem));
// Slider
priv->volume_slider_menuitem = slider_menu_item_new ( availability, volume );
@@ -240,12 +241,6 @@ void sound_service_dbus_update_pa_state ( SoundServiceDbus* self,
availability );
sound_service_dbus_determine_state (self, availability, mute_update, volume);
- // Emit the signals after the menus are setup/torn down
- // preserve ordering !
- /*sound_service_dbus_update_sink_availability(dbus_interface, sink_available);
- dbus_menu_manager_update_volume(percent);
- sound_service_dbus_update_sink_mute(dbus_interface, sink_muted);
- dbus_menu_manager_update_mute_ui(b_all_muted);*/
}
@@ -302,11 +297,16 @@ void sound_service_dbus_update_volume(SoundServiceDbus* self,
sound_service_dbus_get_state_from_volume (self));
}
-void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj,
+void sound_service_dbus_update_sink_mute(SoundServiceDbus* self,
gboolean mute_update)
{
- SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj);
+ SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
mute_menu_item_update (priv->mute_menuitem, mute_update);
+ SoundState state = sound_service_dbus_get_state_from_volume (self);
+ if (mute_update == TRUE){
+ state = MUTED;
+ }
+ sound_service_dbus_update_sound_state (self, state);
}
// TODO: this will be a bit messy until the pa_manager is sorted.
@@ -316,11 +316,14 @@ void sound_service_dbus_update_sound_state (SoundServiceDbus* self,
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
SoundState update = new_state;
+ // Ensure that after it has become available update the state with the current volume level
if (new_state == AVAILABLE &&
dbusmenu_menuitem_property_get_bool ( DBUSMENU_MENUITEM(priv->mute_menuitem),
DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE ){
update = sound_service_dbus_get_state_from_volume (self);
}
+
+ priv->current_sound_state = update;
GVariant* v_output = g_variant_new("(i)", (int)update);
@@ -370,19 +373,20 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self,
gboolean mute,
gdouble volume)
{
- SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
-
+ //SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self);
+ SoundState update;
if (availability == FALSE) {
- priv->current_sound_state = AVAILABLE;
+ update = UNAVAILABLE;
}
else if (mute == TRUE) {
- priv->current_sound_state = MUTED;
+ update = MUTED;
}
else{
- priv->current_sound_state = sound_service_dbus_get_state_from_volume (self);
+ update = sound_service_dbus_get_state_from_volume (self);
}
- GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state);
+ sound_service_dbus_update_sound_state (self, update);
+ /*GVariant* v_output = g_variant_new("(i)", (int)priv->current_sound_state);
GError * error = NULL;
@@ -398,7 +402,7 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self,
g_error("Unable to emit signal 'sinkinputwhilemuted' because : %s", error->message);
g_error_free(error);
return;
- }
+ }*/
}