e/music_control: Add option to pause music on desklock.

Locking your screen pauses the music unlocking starts playing again.
Option is off by default.
This commit is contained in:
Stefan Schmidt 2013-02-22 13:28:09 +00:00
parent d032d0e52f
commit b81777bfde
3 changed files with 63 additions and 3 deletions

View File

@ -4,6 +4,8 @@
static E_Module *music_control_mod = NULL; static E_Module *music_control_mod = NULL;
static Eina_Bool was_playing_before_lock = EINA_FALSE;
static const char _e_music_control_Name[] = "Music controller"; static const char _e_music_control_Name[] = "Music controller";
const Player music_player_players[] = const Player music_player_players[] =
@ -17,6 +19,37 @@ const Player music_player_players[] =
{NULL, NULL} {NULL, NULL}
}; };
Eina_Bool
_desklock_cb(void *data, int type, void *ev)
{
E_Music_Control_Module_Context *ctxt;
E_Event_Desklock *event;
ctxt = data;
event = ev;
/* Lock with music on. Pause it */
if (event->on && ctxt->playing)
{
media_player2_player_play_pause_call(ctxt->mpris2_player);
was_playing_before_lock = EINA_TRUE;
return ECORE_CALLBACK_DONE;
}
/* Lock without music. Keep music off as state */
if (event->on && (!ctxt->playing))
{
was_playing_before_lock = EINA_FALSE;
return ECORE_CALLBACK_DONE;
}
/* Unlock with music pause and playing before lock. Turn it back on */
if ((!event->on) && (!ctxt->playing) && was_playing_before_lock)
media_player2_player_play_pause_call(ctxt->mpris2_player);
return ECORE_CALLBACK_DONE;
}
static void static void
_music_control(E_Object *obj, const char *params) _music_control(E_Object *obj, const char *params)
{ {
@ -242,6 +275,7 @@ e_modapi_init(E_Module *m)
#define T Music_Control_Config #define T Music_Control_Config
#define D ctxt->conf_edd #define D ctxt->conf_edd
E_CONFIG_VAL(D, T, player_selected, INT); E_CONFIG_VAL(D, T, player_selected, INT);
E_CONFIG_VAL(D, T, pause_on_desklock, INT);
ctxt->config = e_config_domain_load(MUSIC_CONTROL_DOMAIN, ctxt->conf_edd); ctxt->config = e_config_domain_load(MUSIC_CONTROL_DOMAIN, ctxt->conf_edd);
if (!ctxt->config) if (!ctxt->config)
ctxt->config = calloc(1, sizeof(Music_Control_Config)); ctxt->config = calloc(1, sizeof(Music_Control_Config));
@ -252,6 +286,9 @@ e_modapi_init(E_Module *m)
e_gadcon_provider_register(&_gc_class); e_gadcon_provider_register(&_gc_class);
if (ctxt->config->pause_on_desklock)
desklock_handler = ecore_event_handler_add(E_EVENT_DESKLOCK, _desklock_cb, ctxt);
return ctxt; return ctxt;
error_dbus_bus_get: error_dbus_bus_get:
@ -269,6 +306,8 @@ e_modapi_shutdown(E_Module *m)
free(ctxt->config); free(ctxt->config);
E_CONFIG_DD_FREE(ctxt->conf_edd); E_CONFIG_DD_FREE(ctxt->conf_edd);
E_FREE_FUNC(desklock_handler, ecore_event_handler_del);
media_player2_player_proxy_unref(ctxt->mpris2_player); media_player2_player_proxy_unref(ctxt->mpris2_player);
mpris_media_player2_proxy_unref(ctxt->mrpis2); mpris_media_player2_proxy_unref(ctxt->mrpis2);
edbus_connection_unref(ctxt->conn); edbus_connection_unref(ctxt->conn);

View File

@ -5,9 +5,12 @@
#include "gen/edbus_media_player2_player.h" #include "gen/edbus_media_player2_player.h"
#include "gen/edbus_mpris_media_player2.h" #include "gen/edbus_mpris_media_player2.h"
static Ecore_Event_Handler *desklock_handler = NULL;
typedef struct _Music_Control_Config typedef struct _Music_Control_Config
{ {
int player_selected; int player_selected;
int pause_on_desklock;
} Music_Control_Config; } Music_Control_Config;
typedef struct _E_Music_Control_Module_Context typedef struct _E_Music_Control_Module_Context
@ -36,6 +39,7 @@ const char *music_control_edj_path_get(void);
void music_control_popup_del(E_Music_Control_Instance *inst); void music_control_popup_del(E_Music_Control_Instance *inst);
void music_control_state_update_all(E_Music_Control_Module_Context *ctxt); void music_control_state_update_all(E_Music_Control_Module_Context *ctxt);
Eina_Bool music_control_dbus_init(E_Music_Control_Module_Context *ctxt, const char *bus); Eina_Bool music_control_dbus_init(E_Music_Control_Module_Context *ctxt, const char *bus);
Eina_Bool _desklock_cb(void *data, int type, void *ev);
typedef struct _Player { typedef struct _Player {
const char *name; const char *name;

View File

@ -94,12 +94,13 @@ music_control_popup_del(E_Music_Control_Instance *inst)
struct _E_Config_Dialog_Data struct _E_Config_Dialog_Data
{ {
int index; int index;
int pause_on_desklock;
}; };
static Evas_Object * static Evas_Object *
_cfg_widgets_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) _cfg_widgets_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
{ {
Evas_Object *o, *of, *ob; Evas_Object *o, *of, *ob, *oc;
E_Radio_Group *rg; E_Radio_Group *rg;
int i; int i;
E_Music_Control_Instance *inst = cfd->data; E_Music_Control_Instance *inst = cfd->data;
@ -119,6 +120,10 @@ _cfg_widgets_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfda
} }
ob = e_widget_label_add(evas, "* Your player must be configured to export the DBus interface MPRIS2."); ob = e_widget_label_add(evas, "* Your player must be configured to export the DBus interface MPRIS2.");
e_widget_framelist_object_append(of, ob); e_widget_framelist_object_append(of, ob);
oc = e_widget_check_add(evas, _("Pause music when screen is locked"), &(cfdata->pause_on_desklock));
e_widget_framelist_object_append(of, oc);
e_widget_list_object_append(o, of, 1, 1, 0.5); e_widget_list_object_append(o, of, 1, 1, 0.5);
return o; return o;
@ -130,6 +135,8 @@ _cfg_data_create(E_Config_Dialog *cfd)
E_Music_Control_Instance *inst = cfd->data; E_Music_Control_Instance *inst = cfd->data;
E_Config_Dialog_Data *cfdata = calloc(1, sizeof(E_Config_Dialog_Data)); E_Config_Dialog_Data *cfdata = calloc(1, sizeof(E_Config_Dialog_Data));
cfdata->index = inst->ctxt->config->player_selected; cfdata->index = inst->ctxt->config->player_selected;
cfdata->pause_on_desklock = inst->ctxt->config->pause_on_desklock;
return cfdata; return cfdata;
} }
@ -144,17 +151,27 @@ _cfg_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{ {
E_Music_Control_Instance *inst = cfd->data; E_Music_Control_Instance *inst = cfd->data;
return inst->ctxt->config->player_selected != cfdata->index; return ((inst->ctxt->config->pause_on_desklock != cfdata->pause_on_desklock) ||
(inst->ctxt->config->player_selected != cfdata->index));
} }
static int static int
_cfg_data_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) _cfg_data_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{ {
E_Music_Control_Instance *inst = cfd->data; E_Music_Control_Instance *inst = cfd->data;
if (inst->ctxt->config->player_selected == cfdata->index)
if ((inst->ctxt->config->player_selected == cfdata->index) &&
(inst->ctxt->config->pause_on_desklock == cfdata->pause_on_desklock))
return 1; return 1;
inst->ctxt->config->player_selected = cfdata->index; inst->ctxt->config->player_selected = cfdata->index;
inst->ctxt->config->pause_on_desklock = cfdata->pause_on_desklock;
if (inst->ctxt->config->pause_on_desklock)
desklock_handler = ecore_event_handler_add(E_EVENT_DESKLOCK, _desklock_cb, inst->ctxt);
else
E_FREE_FUNC(desklock_handler, ecore_event_handler_del);
inst->ctxt->playing = EINA_FALSE; inst->ctxt->playing = EINA_FALSE;
mpris_media_player2_proxy_unref(inst->ctxt->mpris2_player); mpris_media_player2_proxy_unref(inst->ctxt->mpris2_player);
media_player2_player_proxy_unref(inst->ctxt->mrpis2); media_player2_player_proxy_unref(inst->ctxt->mrpis2);