100
100
static void prepare_state_machine();
101
101
static void determine_state_from_volume(gdouble volume_percent);
102
102
static void update_state(const gint state);
103
104
static const gint STATE_MUTED = 0;
104
105
static const gint STATE_ZERO = 1;
105
106
static const gint STATE_LOW = 2;
106
107
static const gint STATE_MEDIUM = 3;
107
108
static const gint STATE_HIGH = 4;
108
109
static const gint STATE_MUTED_WHILE_INPUT = 5;
109
static const gint STATE_SINKS_NONE = 5;
110
static const gint STATE_SINKS_NONE = 6;
110
112
static GHashTable *volume_states = NULL;
111
113
static GtkImage *speaker_image = NULL;
112
114
static GtkWidget* primary_image = NULL;
152
Prepare states Array.
154
static void prepare_state_machine()
156
// TODO we need three more images
157
volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
158
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted-panel"));
159
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero-panel"));
160
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low-panel"));
161
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium-panel"));
162
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high-panel"));
163
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking-panel"));
164
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel"));
154
indicator_sound_dispose (GObject *object)
156
IndicatorSound * self = INDICATOR_SOUND(object);
158
if (self->service != NULL) {
159
g_object_unref(G_OBJECT(self->service));
160
self->service = NULL;
162
g_hash_table_destroy(volume_states);
163
G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object);
168
indicator_sound_finalize (GObject *object)
170
G_OBJECT_CLASS (indicator_sound_parent_class)->finalize (object);
175
get_label (IndicatorObject * io)
181
get_icon (IndicatorObject * io)
183
gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
184
//g_debug("At start-up attempting to set the image to %s", current_name);
185
speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(current_name, GTK_ICON_SIZE_MENU));
186
gtk_widget_show(GTK_WIDGET(speaker_image));
187
return speaker_image;
190
/* Indicator based function to get the menu for the whole
191
applet. This starts up asking for the parts of the menu
192
from the various services. */
194
get_menu (IndicatorObject * io)
196
DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
197
DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu);
198
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item);
200
// register Key-press listening on the menu widget as the slider does not allow this.
201
g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL);
203
return GTK_MENU(menu);
208
Create a new dBusMenu Slider item.
210
static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
212
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
213
g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
215
volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5);
216
g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL);
218
GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider);
220
dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent);
221
g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider);
223
// register slider changes listening on the range
224
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
225
g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem);
226
// alternative callback mechanism which i could use again at some point.
227
/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */
229
// Set images on the ido
230
primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider);
231
gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU);
232
GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider);
233
gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU);
235
gtk_widget_show_all(volume_slider);
285
Prepare states Array.
287
static void prepare_state_machine()
289
// TODO we need three more images
290
volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
291
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted-panel"));
292
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-low-zero-panel"));
293
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low-panel"));
294
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium-panel"));
295
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high-panel"));
296
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking-panel"));
297
g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel"));
302
static void update_state(const gint state)
304
/* g_debug("update state beginning - previous_state = %i", previous_state);*/
306
previous_state = current_state;
308
/* g_debug("update state 3rd line - previous_state = %i", previous_state);*/
310
current_state = state;
311
gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
312
gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU);
316
static void determine_state_from_volume(gdouble volume_percent)
318
/* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/
320
gint state = previous_state;
321
if (volume_percent < 30.0 && volume_percent > 0){
324
else if(volume_percent < 70.0 && volume_percent >= 30.0){
325
state = STATE_MEDIUM;
327
else if(volume_percent >= 70.0){
330
else if(volume_percent == 0.0){
208
338
static void fetch_volume_percent_from_dbus()
210
340
GError * error = NULL;
270
400
g_debug("signal caught - sink mute update with mute value: %i", mute_value);
271
401
gtk_widget_set_sensitive(volume_slider, !mute_value);
276
indicator_sound_dispose (GObject *object)
278
IndicatorSound * self = INDICATOR_SOUND(object);
280
if (self->service != NULL) {
281
g_object_unref(G_OBJECT(self->service));
282
self->service = NULL;
284
g_hash_table_destroy(volume_states);
285
G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object);
290
indicator_sound_finalize (GObject *object)
292
G_OBJECT_CLASS (indicator_sound_parent_class)->finalize (object);
297
get_label (IndicatorObject * io)
303
get_icon (IndicatorObject * io)
305
gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
306
g_debug("At start-up attempting to set the image to %s", current_name);
307
speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(current_name, GTK_ICON_SIZE_MENU));
308
gtk_widget_show(GTK_WIDGET(speaker_image));
309
return speaker_image;
312
static void update_state(const gint state)
314
/* g_debug("update state beginning - previous_state = %i", previous_state);*/
316
previous_state = current_state;
318
/* g_debug("update state 3rd line - previous_state = %i", previous_state);*/
320
current_state = state;
321
gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
322
gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU);
326
static void determine_state_from_volume(gdouble volume_percent)
328
/* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/
330
gint state = previous_state;
331
if (volume_percent < 30.0 && volume_percent > 0){
334
else if(volume_percent < 70.0 && volume_percent > 30.0){
335
state = STATE_MEDIUM;
337
else if(volume_percent > 70.0){
340
else if(volume_percent == 0.0){
347
/* Indicator based function to get the menu for the whole
348
applet. This starts up asking for the parts of the menu
349
from the various services. */
351
get_menu (IndicatorObject * io)
353
DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
354
DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu);
355
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item);
357
// register Key-press listening on the menu widget as the slider does not allow this.
358
g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL);
360
return GTK_MENU(menu);
365
Create a new dBusMenu Slider item, register the
367
static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
369
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
370
g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
372
volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5);
373
g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL);
375
GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider);
377
dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent);
378
g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider);
380
// register slider changes listening on the range
381
GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);
382
g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem);
383
// alternative callback mechanism which i could use again at some point.
384
/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */
386
// Set images on the ido
387
primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider);
388
gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU);
389
GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider);
390
gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU);
392
gtk_widget_show_all(volume_slider);
398
404
slider_prop_change_cb:
399
405
Whenever we have a property change on a DbusmenuMenuitem this will be called.