e_client_volume: add E_EVENT_CLIENT_VOLUME_SINK handler

This commit introduce 3 new handlers to e_client_volume API. These allow to
catch event about sink add, del and update
This commit is contained in:
Michael Bouchaud 2017-02-20 00:45:41 +01:00 committed by Michaël Bouchaud (yoz)
parent 939ac0b93d
commit 0a73905895
3 changed files with 49 additions and 13 deletions

View File

@ -3,6 +3,9 @@
E_API int E_EVENT_CLIENT_VOLUME = -1; E_API int E_EVENT_CLIENT_VOLUME = -1;
E_API int E_EVENT_CLIENT_MUTE = -1; E_API int E_EVENT_CLIENT_MUTE = -1;
E_API int E_EVENT_CLIENT_UNMUTE = -1; E_API int E_EVENT_CLIENT_UNMUTE = -1;
E_API int E_EVENT_CLIENT_VOLUME_SINK_ADD = -1;
E_API int E_EVENT_CLIENT_VOLUME_SINK_DEL = -1;
E_API int E_EVENT_CLIENT_VOLUME_SINK_CHANGED = -1;
static void _e_client_volume_event_simple_free(void *d, E_Event_Client *ev); static void _e_client_volume_event_simple_free(void *d, E_Event_Client *ev);
static void _e_client_volume_event_simple(E_Client *ec, int type); static void _e_client_volume_event_simple(E_Client *ec, int type);
@ -32,6 +35,28 @@ _e_client_volume_event_simple(E_Client *ec, int type)
(Ecore_End_Cb)_e_client_volume_event_simple_free, NULL); (Ecore_End_Cb)_e_client_volume_event_simple_free, NULL);
} }
static void
_e_client_volume_sink_event_simple_free(void *d EINA_UNUSED, E_Event_Client_Volume_Sink *ev)
{
UNREFD(ev->ec, 3);
e_object_unref(E_OBJECT(ev->ec));
free(ev);
}
static void
_e_client_volume_sink_event_simple(E_Client *ec, E_Client_Volume_Sink *sink, int type)
{
E_Event_Client_Volume_Sink *ev;
ev = E_NEW(E_Event_Client_Volume_Sink, 1);
ev->ec = ec;
ev->sink = sink;
REFD(ec, 3);
e_object_ref(E_OBJECT(ec));
ecore_event_add(type, ev,
(Ecore_End_Cb)_e_client_volume_sink_event_simple_free, NULL);
}
static void static void
_e_client_volume_object_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) _e_client_volume_object_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{ {
@ -107,6 +132,9 @@ e_client_volume_init(void)
E_EVENT_CLIENT_VOLUME = ecore_event_type_new(); E_EVENT_CLIENT_VOLUME = ecore_event_type_new();
E_EVENT_CLIENT_MUTE = ecore_event_type_new(); E_EVENT_CLIENT_MUTE = ecore_event_type_new();
E_EVENT_CLIENT_UNMUTE = ecore_event_type_new(); E_EVENT_CLIENT_UNMUTE = ecore_event_type_new();
E_EVENT_CLIENT_VOLUME_SINK_ADD = ecore_event_type_new();
E_EVENT_CLIENT_VOLUME_SINK_DEL = ecore_event_type_new();
E_EVENT_CLIENT_VOLUME_SINK_CHANGED = ecore_event_type_new();
return EINA_TRUE; return EINA_TRUE;
} }
@ -141,6 +169,8 @@ e_client_volume_sink_del(E_Client_Volume_Sink *sink)
{ {
ec->sinks = eina_list_remove(ec->sinks, sink); ec->sinks = eina_list_remove(ec->sinks, sink);
e_comp_object_frame_volume_update(ec->frame); e_comp_object_frame_volume_update(ec->frame);
_e_client_volume_sink_event_simple(ec, sink,
E_EVENT_CLIENT_VOLUME_SINK_DEL);
} }
free(sink); free(sink);
} }
@ -222,6 +252,8 @@ e_client_volume_sink_append(E_Client *ec, E_Client_Volume_Sink *sink)
ec->volume_control_enabled = EINA_TRUE; ec->volume_control_enabled = EINA_TRUE;
} }
e_comp_object_frame_volume_update(ec->frame); e_comp_object_frame_volume_update(ec->frame);
_e_client_volume_sink_event_simple(ec, sink,
E_EVENT_CLIENT_VOLUME_SINK_ADD);
} }
E_API void E_API void
@ -231,6 +263,8 @@ e_client_volume_sink_remove(E_Client *ec, E_Client_Volume_Sink *sink)
ec->sinks = eina_list_remove(ec->sinks, sink); ec->sinks = eina_list_remove(ec->sinks, sink);
sink->clients = eina_list_remove(sink->clients, ec); sink->clients = eina_list_remove(sink->clients, ec);
e_comp_object_frame_volume_update(ec->frame); e_comp_object_frame_volume_update(ec->frame);
_e_client_volume_sink_event_simple(ec, sink,
E_EVENT_CLIENT_VOLUME_SINK_DEL);
} }
E_API void E_API void
@ -246,7 +280,10 @@ e_client_volume_sink_update(E_Client_Volume_Sink *sink)
e_client_volume_sink_get(sink, &volume, &mute); e_client_volume_sink_get(sink, &volume, &mute);
EINA_LIST_FOREACH(sink->clients, l, ec) EINA_LIST_FOREACH(sink->clients, l, ec)
{ {
e_client_volume_display_set(ec, volume, mute); if (eina_list_count(ec->sinks) == 1)
e_client_volume_display_set(ec, volume, mute);
_e_client_volume_sink_event_simple(ec, sink,
E_EVENT_CLIENT_VOLUME_SINK_CHANGED);
} }
} }

View File

@ -2,6 +2,7 @@
#define E_CLIENT_VOLUME_H_ #define E_CLIENT_VOLUME_H_
typedef struct _E_Client_Volume_Sink E_Client_Volume_Sink; typedef struct _E_Client_Volume_Sink E_Client_Volume_Sink;
typedef struct _E_Event_Client_Volume_Sink E_Event_Client_Volume_Sink;
typedef void (*E_Client_Volume_Sink_Get)(int *volume, Eina_Bool *mute, void *data); typedef void (*E_Client_Volume_Sink_Get)(int *volume, Eina_Bool *mute, void *data);
typedef void (*E_Client_Volume_Sink_Set)(int volume, Eina_Bool mute, void *data); typedef void (*E_Client_Volume_Sink_Set)(int volume, Eina_Bool mute, void *data);
@ -12,6 +13,9 @@ typedef const char *(*E_Client_Volume_Sink_Name_Get)(void *data);
E_API extern int E_EVENT_CLIENT_VOLUME; E_API extern int E_EVENT_CLIENT_VOLUME;
E_API extern int E_EVENT_CLIENT_MUTE; E_API extern int E_EVENT_CLIENT_MUTE;
E_API extern int E_EVENT_CLIENT_UNMUTE; E_API extern int E_EVENT_CLIENT_UNMUTE;
E_API extern int E_EVENT_CLIENT_VOLUME_SINK_ADD;
E_API extern int E_EVENT_CLIENT_VOLUME_SINK_DEL;
E_API extern int E_EVENT_CLIENT_VOLUME_SINK_CHANGED;
struct _E_Client_Volume_Sink struct _E_Client_Volume_Sink
{ {
@ -24,6 +28,12 @@ struct _E_Client_Volume_Sink
Eina_List *clients; Eina_List *clients;
}; };
struct _E_Event_Client_Volume_Sink
{
E_Client *ec;
E_Client_Volume_Sink *sink;
};
EINTERN int e_client_volume_init(void); EINTERN int e_client_volume_init(void);
EINTERN void e_client_volume_shutdown(void); EINTERN void e_client_volume_shutdown(void);

View File

@ -964,18 +964,7 @@ _sink_input_event(int type, Emix_Sink_Input *input)
{ {
if (sink->data == input) if (sink->data == input)
{ {
Eina_Bool update = EINA_TRUE; e_client_volume_sink_update(sink);
EINA_LIST_FOREACH(sink->clients, l, ec)
{
if (eina_list_count(ec->sinks) > 1)
{
update = EINA_FALSE;
break;
}
}
if (update)
e_client_volume_sink_update(sink);
} }
} }
break; break;