summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-07-04 20:54:49 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:18 -0300
commit32168ca4c9196169f69eaa7188d1f7f27ad741dd (patch)
treeee878c24d506d9d50ca1505fca463fa6fc0e2f99
parent27a6f45901e6853e1b3445f4b612f7c5a62671bd (diff)
module: Porting to use emix
For now the backend is hardcoded to use pulseaudio.
-rw-r--r--Makefile.am1
-rw-r--r--src/module/e_mod_main.c389
2 files changed, 154 insertions, 236 deletions
diff --git a/Makefile.am b/Makefile.am
index 569c6ff..0645600 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -113,6 +113,7 @@ src_module_module_la_SOURCES = \
113 113
114src_module_module_la_LIBADD = \ 114src_module_module_la_LIBADD = \
115 $(top_builddir)/src/lib/libepulse.la \ 115 $(top_builddir)/src/lib/libepulse.la \
116 $(top_builddir)/src/lib/libemix.la \
116 @EFL_LIBS@ \ 117 @EFL_LIBS@ \
117 @PULSE_LIBS@ 118 @PULSE_LIBS@
118 119
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 00d4fca..d526750 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -2,10 +2,10 @@
2 2
3#include <e.h> 3#include <e.h>
4#include <Eina.h> 4#include <Eina.h>
5#include <epulse.h> 5#include <emix.h>
6#include "e_mod_main.h" 6#include "e_mod_main.h"
7 7
8#define VOLUME_STEP (PA_VOLUME_NORM / BASE_VOLUME_STEP) 8#define VOLUME_STEP BASE_VOLUME_STEP
9 9
10/* module requirements */ 10/* module requirements */
11EAPI E_Module_Api e_modapi = 11EAPI E_Module_Api e_modapi =
@@ -28,7 +28,7 @@ static const char *_gc_id_new(const E_Gadcon_Client_Class *client_class);
28static const E_Gadcon_Client_Class _gadcon_class = 28static const E_Gadcon_Client_Class _gadcon_class =
29 { 29 {
30 GADCON_CLIENT_CLASS_VERSION, 30 GADCON_CLIENT_CLASS_VERSION,
31 "pulse_mixer", 31 "emix",
32 { 32 {
33 _gc_init, _gc_shutdown, 33 _gc_init, _gc_shutdown,
34 _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, 34 _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL,
@@ -37,29 +37,20 @@ static const E_Gadcon_Client_Class _gadcon_class =
37 E_GADCON_CLIENT_STYLE_PLAIN 37 E_GADCON_CLIENT_STYLE_PLAIN
38 }; 38 };
39 39
40typedef struct _Sink Sink;
41struct _Sink {
42 int index;
43 pa_cvolume volume;
44 int mute;
45 char *name;
46};
47
48typedef struct _Context Context; 40typedef struct _Context Context;
49struct _Context 41struct _Context
50{ 42{
51 char *theme; 43 char *theme;
52 Ecore_Exe *epulse; 44 Ecore_Exe *epulse;
53 Ecore_Event_Handler *disconnected_handler; 45 Ecore_Event_Handler *disconnected_handler;
54 Ecore_Event_Handler *epulse_event_handler; 46 Ecore_Event_Handler *ready_handler;
55 Ecore_Event_Handler *sink_default_handler; 47 Ecore_Event_Handler *emix_event_handler;
56 Ecore_Event_Handler *sink_changed_handler;
57 Ecore_Event_Handler *sink_added_handler; 48 Ecore_Event_Handler *sink_added_handler;
49 Ecore_Event_Handler *sink_changed_handler;
58 Ecore_Event_Handler *sink_removed_handler; 50 Ecore_Event_Handler *sink_removed_handler;
59 Sink *sink_default; 51 const Emix_Sink *sink_default;
60 E_Module *module; 52 E_Module *module;
61 Eina_List *instances; 53 Eina_List *instances;
62 Eina_List *sinks;
63 E_Menu *menu; 54 E_Menu *menu;
64 unsigned int notification_id; 55 unsigned int notification_id;
65 56
@@ -117,7 +108,7 @@ _notify(const int val)
117 else 108 else
118 icon = "audio-volume-high"; 109 icon = "audio-volume-high";
119 110
120 n.app_name = _("EPulse"); 111 n.app_name = _("Emix");
121 n.replaces_id = mixer_context->notification_id; 112 n.replaces_id = mixer_context->notification_id;
122 n.icon.icon = icon; 113 n.icon.icon = icon;
123 n.summary = _("Volume changed"); 114 n.summary = _("Volume changed");
@@ -140,7 +131,7 @@ _mixer_gadget_update(void)
140{ 131{
141 Edje_Message_Int_Set *msg; 132 Edje_Message_Int_Set *msg;
142 Instance *inst; 133 Instance *inst;
143 Eina_List*l; 134 Eina_List *l;
144 135
145 EINA_LIST_FOREACH(mixer_context->instances, l, inst) 136 EINA_LIST_FOREACH(mixer_context->instances, l, inst)
146 { 137 {
@@ -157,10 +148,14 @@ _mixer_gadget_update(void)
157 } 148 }
158 else 149 else
159 { 150 {
160 pa_volume_t vol = 151 int vol = 0;
161 pa_cvolume_avg(&mixer_context->sink_default->volume); 152 unsigned int i = 0;
153 for (i = 0; i <
154 mixer_context->sink_default->volume.channel_count; i++)
155 vol += mixer_context->sink_default->volume.volumes[i];
156 vol /= mixer_context->sink_default->volume.channel_count;
162 msg->val[0] = mixer_context->sink_default->mute; 157 msg->val[0] = mixer_context->sink_default->mute;
163 msg->val[1] = PA_VOLUME_TO_INT(vol); 158 msg->val[1] = vol;
164 msg->val[2] = msg->val[1]; 159 msg->val[2] = msg->val[1];
165 if (inst->popup) 160 if (inst->popup)
166 _mixer_popup_update(inst, mixer_context->sink_default->mute, 161 _mixer_popup_update(inst, mixer_context->sink_default->mute,
@@ -174,25 +169,35 @@ _mixer_gadget_update(void)
174static void 169static void
175_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 170_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
176{ 171{
172 unsigned int i;
177 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default); 173 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
174 Emix_Volume volume;
178 175
179 Sink *s = mixer_context->sink_default; 176 Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
180 pa_cvolume v = s->volume; 177 volume.channel_count = s->volume.channel_count;
181 pa_cvolume_inc(&v, VOLUME_STEP); 178 volume.volumes = calloc(s->volume.channel_count, sizeof(int));
179 for (i = 0; i < volume.channel_count; i++)
180 volume.volumes[i] = s->volume.volumes[i] + VOLUME_STEP;
182 181
183 epulse_sink_volume_set(s->index, v); 182 emix_sink_volume_set(s, volume);
183 free(volume.volumes);
184} 184}
185 185
186static void 186static void
187_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 187_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
188{ 188{
189 unsigned int i;
189 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default); 190 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
191 Emix_Volume volume;
190 192
191 Sink *s = mixer_context->sink_default; 193 Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
192 pa_cvolume v = s->volume; 194 volume.channel_count = s->volume.channel_count;
193 pa_cvolume_dec(&v, VOLUME_STEP); 195 volume.volumes = calloc(s->volume.channel_count, sizeof(int));
196 for (i = 0; i < volume.channel_count; i++)
197 volume.volumes[i] = s->volume.volumes[i] - VOLUME_STEP;
194 198
195 epulse_sink_volume_set(s->index, v); 199 emix_sink_volume_set(s, volume);
200 free(volume.volumes);
196} 201}
197 202
198static void 203static void
@@ -200,13 +205,9 @@ _volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
200{ 205{
201 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default); 206 EINA_SAFETY_ON_NULL_RETURN(mixer_context->sink_default);
202 207
203 Sink *s = mixer_context->sink_default; 208 Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
204 int mute = !s->mute; 209 Eina_Bool mute = !s->mute;
205 if (!epulse_sink_mute_set(s->index, mute)) 210 emix_sink_mute_set(s, mute);
206 {
207 WRN("Could not mute the sink: %d", s->index);
208 return;
209 }
210} 211}
211 212
212static void 213static void
@@ -245,21 +246,21 @@ _actions_unregister(void)
245{ 246{
246 if (mixer_context->actions.incr) 247 if (mixer_context->actions.incr)
247 { 248 {
248 e_action_predef_name_del("Pulse Mixer", _("Volume Increase")); 249 e_action_predef_name_del("Enlightnment Mixer", _("Volume Increase"));
249 e_action_del("volume_increase"); 250 e_action_del("volume_increase");
250 mixer_context->actions.incr = NULL; 251 mixer_context->actions.incr = NULL;
251 } 252 }
252 253
253 if (mixer_context->actions.decr) 254 if (mixer_context->actions.decr)
254 { 255 {
255 e_action_predef_name_del("Pulse Mixer", _("Volume Mute")); 256 e_action_predef_name_del("Enlightnment Mixer", _("Volume Mute"));
256 e_action_del("volume_decrease"); 257 e_action_del("volume_decrease");
257 mixer_context->actions.decr = NULL; 258 mixer_context->actions.decr = NULL;
258 } 259 }
259 260
260 if (mixer_context->actions.mute) 261 if (mixer_context->actions.mute)
261 { 262 {
262 e_action_predef_name_del("Pulse Mixer", _("Volume Mute")); 263 e_action_predef_name_del("Enlightnment Mixer", _("Volume Mute"));
263 e_action_del("volume_mute"); 264 e_action_del("volume_mute");
264 mixer_context->actions.mute = NULL; 265 mixer_context->actions.mute = NULL;
265 } 266 }
@@ -295,8 +296,8 @@ _epulse_del_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
295 void *info EINA_UNUSED) 296 void *info EINA_UNUSED)
296{ 297{
297 mixer_context->epulse = NULL; 298 mixer_context->epulse = NULL;
298 if (mixer_context->epulse_event_handler) 299 if (mixer_context->emix_event_handler)
299 ecore_event_handler_del(mixer_context->epulse_event_handler); 300 ecore_event_handler_del(mixer_context->emix_event_handler);
300 301
301 return EINA_TRUE; 302 return EINA_TRUE;
302} 303}
@@ -311,9 +312,9 @@ _epulse_exec_cb(void *data, void *data2 EINA_UNUSED)
311 return; 312 return;
312 313
313 mixer_context->epulse = ecore_exe_run("epulse", NULL); 314 mixer_context->epulse = ecore_exe_run("epulse", NULL);
314 if (mixer_context->epulse_event_handler) 315 if (mixer_context->emix_event_handler)
315 ecore_event_handler_del(mixer_context->epulse_event_handler); 316 ecore_event_handler_del(mixer_context->emix_event_handler);
316 mixer_context->epulse_event_handler = 317 mixer_context->emix_event_handler =
317 ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _epulse_del_cb, NULL); 318 ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _epulse_del_cb, NULL);
318} 319}
319 320
@@ -321,15 +322,12 @@ static void
321_check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 322_check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
322 void *event EINA_UNUSED) 323 void *event EINA_UNUSED)
323{ 324{
324 Sink *s = mixer_context->sink_default; 325 Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
325 s->mute = !s->mute; 326 emix_sink_mute_set(s, !s->mute);
326 if (!epulse_sink_mute_set(s->index, s->mute)) 327 /*
327 { 328 *TODO: is it really necessary ? or it will be update
328 WRN("Could not mute the sink: %d", s->index); 329 * with the sink changed hanlder
329 s->mute = !s->mute; 330 */
330 return;
331 }
332
333 _mixer_gadget_update(); 331 _mixer_gadget_update();
334} 332}
335 333
@@ -338,23 +336,31 @@ _slider_changed_cb(void *data EINA_UNUSED, Evas_Object *obj,
338 void *event EINA_UNUSED) 336 void *event EINA_UNUSED)
339{ 337{
340 int val; 338 int val;
341 pa_volume_t v; 339 Emix_Volume v;
342 Sink *s = mixer_context->sink_default; 340 unsigned int i;
341 Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
343 342
344 val = (int)e_slider_value_get(obj); 343 val = (int)e_slider_value_get(obj);
345 v = INT_TO_PA_VOLUME(val); 344 v.volumes = calloc(s->volume.channel_count, sizeof(int));
345 v.channel_count = s->volume.channel_count;
346 for (i = 0; i < s->volume.channel_count; i++)
347 v.volumes[i] = val;
346 348
347 pa_cvolume_set(&s->volume, s->volume.channels, v); 349 emix_sink_volume_set(s, v);
348 epulse_sink_volume_set(s->index, s->volume);
349} 350}
350 351
351static Evas_Object * 352static Evas_Object *
352_popup_add_slider(Instance *inst) 353_popup_add_slider(Instance *inst)
353{ 354{
354 pa_volume_t vol = pa_cvolume_avg(&mixer_context->sink_default->volume); 355 unsigned int volume, i;
355 int value = PA_VOLUME_TO_INT(vol);
356 Evas_Object *slider = e_slider_add(e_comp_get(inst->popup)->evas); 356 Evas_Object *slider = e_slider_add(e_comp_get(inst->popup)->evas);
357 357
358 for (volume = 0, i = 0; i <
359 mixer_context->sink_default->volume.channel_count; i++)
360 volume += mixer_context->sink_default->volume.volumes[i];
361
362 volume = volume / i;
363
358 evas_object_show(slider); 364 evas_object_show(slider);
359 e_slider_orientation_set(slider, 1); 365 e_slider_orientation_set(slider, 1);
360 e_slider_value_range_set(slider, 0.0, 100.0); 366 e_slider_value_range_set(slider, 0.0, 100.0);
@@ -362,14 +368,14 @@ _popup_add_slider(Instance *inst)
362 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb, 368 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb,
363 NULL); 369 NULL);
364 370
365 e_slider_value_set(slider, value); 371 e_slider_value_set(slider, volume);
366 return slider; 372 return slider;
367} 373}
368 374
369static void 375static void
370_sink_selected_cb(void *data) 376_sink_selected_cb(void *data)
371{ 377{
372 Sink *s = data; 378 Emix_Sink *s = data;
373 379
374 mixer_context->sink_default = s; 380 mixer_context->sink_default = s;
375 _mixer_gadget_update(); 381 _mixer_gadget_update();
@@ -381,7 +387,7 @@ _popup_new(Instance *inst)
381 Evas_Object *button, *list; 387 Evas_Object *button, *list;
382 Evas *evas; 388 Evas *evas;
383 Evas_Coord mw, mh; 389 Evas_Coord mw, mh;
384 Sink *s; 390 Emix_Sink *s;
385 Eina_List *l; 391 Eina_List *l;
386 int pos = 0; 392 int pos = 0;
387 393
@@ -396,7 +402,7 @@ _popup_new(Instance *inst)
396 e_widget_size_min_set(inst->list, 120, 100); 402 e_widget_size_min_set(inst->list, 120, 100);
397 e_widget_list_object_append(list, inst->list, 1, 1, 0.5); 403 e_widget_list_object_append(list, inst->list, 1, 1, 0.5);
398 404
399 EINA_LIST_FOREACH(mixer_context->sinks, l, s) 405 EINA_LIST_FOREACH((Eina_List *)emix_sinks_get(), l, s)
400 { 406 {
401 e_widget_ilist_append_full(inst->list, NULL, NULL, s->name, 407 e_widget_ilist_append_full(inst->list, NULL, NULL, s->name,
402 _sink_selected_cb, 408 _sink_selected_cb,
@@ -410,7 +416,7 @@ _popup_new(Instance *inst)
410 inst->slider = _popup_add_slider(inst); 416 inst->slider = _popup_add_slider(inst);
411 e_widget_list_object_append(list, inst->slider, 1, 1, 0.5); 417 e_widget_list_object_append(list, inst->slider, 1, 1, 0.5);
412 418
413 inst->mute = mixer_context->sink_default->mute; 419 inst->mute = (int) mixer_context->sink_default->mute;
414 inst->check = e_widget_check_add(evas, _("Mute"), 420 inst->check = e_widget_check_add(evas, _("Mute"),
415 &inst->mute); 421 &inst->mute);
416 e_widget_list_object_append(list, inst->check, 1, 9, 0.5); 422 e_widget_list_object_append(list, inst->check, 1, 9, 0.5);
@@ -596,204 +602,115 @@ _gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
596} 602}
597 603
598static Eina_Bool 604static Eina_Bool
599_sink_default_cb(void *data EINA_UNUSED, int type EINA_UNUSED, 605_sink_event_cb(void *data EINA_UNUSED, int type, void *info)
600 void *info)
601{ 606{
602 Epulse_Event *ev = info; 607 Emix_Sink *sink = info;
603 Eina_List *l; 608 const Eina_List *l;
604 Sink *s;
605 609
606 EINA_LIST_FOREACH(mixer_context->sinks, l, s) 610 if (type == EMIX_SINK_REMOVED_EVENT)
607 { 611 {
608 if (s->index == ev->index) 612 if (sink == mixer_context->sink_default)
609 { 613 {
610 mixer_context->sink_default = s; 614 l = emix_sinks_get();
611 goto end; 615 mixer_context->sink_default = l->data;
616 _mixer_gadget_update();
612 } 617 }
618 return ECORE_CALLBACK_DONE;
619 }
620 else if (type == EMIX_SINK_CHANGED_EVENT)
621 {
622 if (mixer_context->sink_default == sink)
623 {
624 _mixer_gadget_update();
625 _notify(sink->mute ? 0 : sink->volume.volumes[0]);
626 }
627 }
628 else
629 {
630 ERR("Sink added");
613 } 631 }
614 632
615 s = malloc(sizeof(*s)); 633 return ECORE_CALLBACK_DONE;
616 s->index = ev->index; 634}
617 s->volume = ev->volume;
618 s->name = strdup(ev->name);
619 s->mute = ev->mute;
620
621 mixer_context->sinks = eina_list_append(mixer_context->sinks, s);
622 mixer_context->sink_default = s;
623 635
624 end: 636static Eina_Bool
637_disconnected_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
638 void *info EINA_UNUSED)
639{
640 mixer_context->sink_default = NULL;
625 _mixer_gadget_update(); 641 _mixer_gadget_update();
642
626 return ECORE_CALLBACK_DONE; 643 return ECORE_CALLBACK_DONE;
627} 644}
628 645
629static Eina_Bool 646static Eina_Bool
630_sink_changed_cb(void *data EINA_UNUSED, int type EINA_UNUSED, 647_ready_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
631 void *info) 648 void *info EINA_UNUSED)
632{ 649{
633 Epulse_Event *ev = info; 650 mixer_context->sink_default = emix_sink_default_get();
634 Eina_List *l; 651 _mixer_gadget_update();
635 Sink *s; 652
636 Eina_Bool volume_changed; 653 return ECORE_CALLBACK_DONE;
654}
637 655
638 EINA_LIST_FOREACH(mixer_context->sinks, l, s) 656EAPI void *
657e_modapi_init(E_Module *m)
658{
659 char buf[4096];
660
661 emix_init();
662 emix_backend_set("PULSEAUDIO");
663 if (!mixer_context)
639 { 664 {
640 if (ev->index == s->index) 665 mixer_context = E_NEW(Context, 1);
641 { 666
642 volume_changed = (s->mute != ev->mute || 667 mixer_context->sink_added_handler =
643 !pa_cvolume_equal(&s->volume, &ev->volume)) 668 ecore_event_handler_add(EMIX_SINK_ADDED_EVENT, _sink_event_cb,
644 ? EINA_TRUE : EINA_FALSE; 669 NULL);
645 s->mute = ev->mute; 670 mixer_context->sink_changed_handler =
646 s->volume = ev->volume; 671 ecore_event_handler_add(EMIX_SINK_CHANGED_EVENT, _sink_event_cb,
647 if (ev->index == mixer_context->sink_default->index) 672 NULL);
648 { 673 mixer_context->sink_removed_handler =
649 _mixer_gadget_update(); 674 ecore_event_handler_add(EMIX_SINK_REMOVED_EVENT, _sink_event_cb,
650 if (volume_changed) 675 NULL);
651 _notify(s->mute ? 0 : PA_VOLUME_TO_INT( 676 mixer_context->disconnected_handler =
652 pa_cvolume_avg(&mixer_context->sink_default->volume))); 677 ecore_event_handler_add(EMIX_DISCONNECTED_EVENT, _disconnected_cb,
653 } 678 NULL);
654 } 679 mixer_context->ready_handler =
680 ecore_event_handler_add(EMIX_READY_EVENT, _ready_cb, NULL);
681 mixer_context->module = m;
682 snprintf(buf, sizeof(buf), "%s/mixer.edj",
683 e_module_dir_get(mixer_context->module));
684 mixer_context->theme = strdup(buf);
655 } 685 }
656 686
657 return ECORE_CALLBACK_DONE; 687 e_gadcon_provider_register(&_gadcon_class);
658 } 688 _actions_register();
659 689
660 static Eina_Bool 690 return m;
661 _disconnected_cb(void *data EINA_UNUSED, int type EINA_UNUSED, 691}
662 void *info EINA_UNUSED)
663 {
664 Sink *s;
665 692
666 EINA_LIST_FREE(mixer_context->sinks, s) 693EAPI int
667 { 694e_modapi_shutdown(E_Module *m EINA_UNUSED)
668 free(s->name); 695{
669 free(s); 696 _actions_unregister();
670 } 697 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class);
671 698
672 mixer_context->sinks = NULL; 699 if (!mixer_context)
673 mixer_context->sink_default = NULL; 700 {
674 _mixer_gadget_update(); 701 if (mixer_context->theme)
675 702 free(mixer_context->theme);
676 return ECORE_CALLBACK_DONE;
677 }
678
679 static Eina_Bool
680 _sink_added_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
681 void *info)
682 {
683 Epulse_Event *ev = info;
684 Eina_List *l;
685 Sink *s;
686
687 EINA_LIST_FOREACH(mixer_context->sinks, l, s)
688 if (s->index == ev->index)
689 return ECORE_CALLBACK_DONE;
690
691 s = malloc(sizeof(*s));
692 s->index = ev->index;
693 s->volume = ev->volume;
694 s->name = strdup(ev->name);
695 s->mute = ev->mute;
696
697 mixer_context->sinks = eina_list_append(mixer_context->sinks, s);
698 return ECORE_CALLBACK_DONE;
699 }
700
701 static Eina_Bool
702 _sink_removed_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
703 void *info)
704 {
705 Epulse_Event *ev = info;
706 Eina_List *l, *ll;
707 Sink *s;
708 Eina_Bool need_change_sink;
709
710 need_change_sink = (ev->index == mixer_context->sink_default->index)
711 ? EINA_TRUE : EINA_FALSE;
712
713 EINA_LIST_FOREACH_SAFE(mixer_context->sinks, l, ll, s)
714 {
715 if (ev->index == s->index)
716 {
717 free(s->name);
718 free(s);
719 mixer_context->sinks =
720 eina_list_remove_list(mixer_context->sinks, l);
721 }
722 }
723
724 if (need_change_sink)
725 {
726 s = mixer_context->sinks->data;
727 mixer_context->sink_default = s;
728 _mixer_gadget_update();
729 }
730
731 return ECORE_CALLBACK_DONE;
732 }
733
734 EAPI void *
735 e_modapi_init(E_Module *m)
736 {
737 char buf[4096];
738
739 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_common_init("epulse_mod"),
740 NULL);
741 EINA_SAFETY_ON_FALSE_RETURN_VAL(epulse_init() > 0, NULL);
742 if (!mixer_context)
743 {
744 mixer_context = E_NEW(Context, 1);
745
746 mixer_context->sink_default_handler =
747 ecore_event_handler_add(SINK_DEFAULT, _sink_default_cb, NULL);
748 mixer_context->sink_changed_handler =
749 ecore_event_handler_add(SINK_CHANGED, _sink_changed_cb, NULL);
750 mixer_context->sink_added_handler =
751 ecore_event_handler_add(SINK_ADDED, _sink_added_cb, NULL);
752 mixer_context->sink_removed_handler =
753 ecore_event_handler_add(SINK_REMOVED, _sink_removed_cb, NULL);
754 mixer_context->disconnected_handler =
755 ecore_event_handler_add(DISCONNECTED, _disconnected_cb, NULL);
756 mixer_context->module = m;
757 snprintf(buf, sizeof(buf), "%s/mixer.edj",
758 e_module_dir_get(mixer_context->module));
759 mixer_context->theme = strdup(buf);
760 }
761
762 e_gadcon_provider_register(&_gadcon_class);
763 _actions_register();
764
765 return m;
766 }
767
768 EAPI int
769 e_modapi_shutdown(E_Module *m EINA_UNUSED)
770 {
771 Sink *s;
772
773 _actions_unregister();
774 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class);
775
776 if (!mixer_context)
777 {
778 if (mixer_context->theme)
779 free(mixer_context->theme);
780 703
781 ecore_event_handler_del(mixer_context->sink_default_handler);
782 ecore_event_handler_del(mixer_context->sink_changed_handler);
783 ecore_event_handler_del(mixer_context->sink_added_handler); 704 ecore_event_handler_del(mixer_context->sink_added_handler);
705 ecore_event_handler_del(mixer_context->sink_changed_handler);
784 ecore_event_handler_del(mixer_context->sink_removed_handler); 706 ecore_event_handler_del(mixer_context->sink_removed_handler);
785 707 ecore_event_handler_del(mixer_context->disconnected_handler);
786 EINA_LIST_FREE(mixer_context->sinks, s) 708 ecore_event_handler_del(mixer_context->ready_handler);
787 {
788 free(s->name);
789 free(s);
790 }
791 709
792 E_FREE(mixer_context); 710 E_FREE(mixer_context);
793 } 711 }
794 712
795 epulse_common_shutdown(); 713 emix_shutdown();
796 epulse_shutdown();
797 return 1; 714 return 1;
798} 715}
799 716