enlightenment/src/modules/music-control/ui.c

305 lines
9.4 KiB
C
Raw Normal View History

#include "private.h"
extern Player music_player_players[];
static void
_play_state_update(E_Music_Control_Instance *inst, Eina_Bool without_delay)
{
if (!inst->popup) return;
2013-02-22 05:25:41 -08:00
if (inst->ctxt->playing)
{
edje_object_signal_emit(inst->content_popup, "btn,state,image,pause", "play");
return;
}
if (without_delay)
edje_object_signal_emit(inst->content_popup, "btn,state,image,play,no_delay", "play");
else
edje_object_signal_emit(inst->content_popup, "btn,state,image,play", "play");
}
void
music_control_state_update_all(E_Music_Control_Module_Context *ctxt)
{
E_Music_Control_Instance *inst;
Eina_List *list;
EINA_LIST_FOREACH(ctxt->instances, list, inst)
_play_state_update(inst, EINA_FALSE);
}
static void
_metadata_update(E_Music_Control_Instance *inst)
{
Eina_Strbuf *str;
Evas_Object *img;
if (!inst->popup) return;
str = eina_strbuf_new();
if (inst->ctxt->meta_title)
2017-08-21 07:16:30 -07:00
eina_strbuf_append_printf(str, "<title>%s</><ps/>", inst->ctxt->meta_title);
if (inst->ctxt->meta_artist)
2017-08-21 07:16:30 -07:00
eina_strbuf_append_printf(str, "<tag>by</> %s<ps/>", inst->ctxt->meta_artist);
if (inst->ctxt->meta_album)
2017-08-21 07:16:30 -07:00
eina_strbuf_append_printf(str, "<tag>from</> %s<ps/>", inst->ctxt->meta_album);
edje_object_part_text_set(inst->content_popup, "metadata", eina_strbuf_string_get(str));
eina_strbuf_free(str);
img = edje_object_part_swallow_get(inst->content_popup, "cover_swallow");
if (img)
{
if (inst->ctxt->meta_cover_prev != inst->ctxt->meta_cover)
{
e_comp_object_util_del_list_remove(inst->popup->comp_object, img);
evas_object_del(img);
img = NULL;
if (inst->ctxt->meta_cover_prev)
{
eina_stringshare_del(inst->ctxt->meta_cover_prev);
inst->ctxt->meta_cover_prev = NULL;
}
}
}
if ((!img) && (inst->ctxt->meta_cover))
{
if (inst->ctxt->meta_cover)
inst->ctxt->meta_cover_prev = eina_stringshare_add(inst->ctxt->meta_cover);
img = e_icon_add(evas_object_evas_get(inst->content_popup));
e_icon_scale_size_set(img, 512);
e_icon_scale_up_set(img, EINA_TRUE);
e_icon_fill_inside_set(img, EINA_FALSE);
e_icon_file_set(img, inst->ctxt->meta_cover);
edje_object_part_swallow(inst->content_popup, "cover_swallow", img);
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
e_comp_object_util_del_list_append(inst->popup->comp_object, img);
}
}
void
music_control_metadata_update_all(E_Music_Control_Module_Context *ctxt)
{
E_Music_Control_Instance *inst;
Eina_List *list;
EINA_LIST_FOREACH(ctxt->instances, list, inst)
_metadata_update(inst);
}
static void
_btn_clicked(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source)
{
E_Music_Control_Instance *inst = data;
if (!strcmp(source, "play"))
media_player2_player_play_pause_call(inst->ctxt->mpris2_player);
else if (!strcmp(source, "next"))
media_player2_player_next_call(inst->ctxt->mpris2_player);
else if (!strcmp(source, "previous"))
media_player2_player_previous_call(inst->ctxt->mpris2_player);
}
static void
_label_clicked(void *data, Evas_Object *obj EINA_UNUSED, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
{
E_Music_Control_Instance *inst = data;
music_control_popup_del(inst);
music_control_launch(inst);
mpris_media_player2_raise_call(inst->ctxt->mrpis2);
}
static void
_player_name_update(E_Music_Control_Instance *inst)
{
Edje_Message_String msg;
msg.str = (char *)music_player_players[inst->ctxt->config->player_selected].name;
edje_object_message_send(inst->content_popup, EDJE_MESSAGE_STRING, 0, &msg);
}
static void
_popup_del_cb(void *obj)
{
music_control_popup_del(e_object_data_get(obj));
}
2014-01-19 06:03:31 -08:00
static void
_popup_autoclose_cb(void *data, Evas_Object *obj EINA_UNUSED)
{
music_control_popup_del((E_Music_Control_Instance *)data);
}
static void
_popup_new(E_Music_Control_Instance *inst)
{
Evas_Object *o;
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
inst->popup = e_gadcon_popup_new(inst->gcc, 0);
o = edje_object_add(e_comp->evas);
e_theme_edje_object_set(o, "base/theme/modules/music-control",
2014-05-11 11:05:12 -07:00
"e/modules/music-control/popup");
edje_object_signal_callback_add(o, "btn,clicked", "*", _btn_clicked, inst);
edje_object_signal_callback_add(o, "label,clicked", "player_name", _label_clicked, inst);
e_gadcon_popup_content_set(inst->popup, o);
inst->content_popup = o;
_player_name_update(inst);
_play_state_update(inst, EINA_TRUE);
_metadata_update(inst);
2014-01-19 06:03:31 -08:00
e_comp_object_util_autoclose(inst->popup->comp_object,
_popup_autoclose_cb, NULL, inst);
e_gadcon_popup_show(inst->popup);
e_object_data_set(E_OBJECT(inst->popup), inst);
E_OBJECT_DEL_SET(inst->popup, _popup_del_cb);
}
void
music_control_popup_del(E_Music_Control_Instance *inst)
{
E_FREE_FUNC(inst->popup, e_object_del);
}
struct _E_Config_Dialog_Data
{
int index;
int pause_on_desklock;
};
static Evas_Object *
_cfg_widgets_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
{
Evas_Object *o, *of, *ob, *oc;
E_Radio_Group *rg;
int i;
E_Music_Control_Instance *inst = cfd->data;
int player_selected = inst->ctxt->config->player_selected;
o = e_widget_list_add(evas, 0, 0);
of = e_widget_framelist_add(evas, _("Music Player"), 0);
e_widget_framelist_content_align_set(of, 0.0, 0.0);
rg = e_widget_radio_group_new(&(cfdata->index));
for (i = 0; music_player_players[i].dbus_name; i++)
{
ob = e_widget_radio_add(evas, music_player_players[i].name, i, rg);
e_widget_framelist_object_append(of, ob);
if (i == player_selected)
e_widget_radio_toggle_set(ob, EINA_TRUE);
}
ob = e_widget_label_add(evas, _("* Your player must be configured to export the DBus interface MPRIS2."));
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);
return o;
}
static void *
_cfg_data_create(E_Config_Dialog *cfd)
{
E_Music_Control_Instance *inst = cfd->data;
E_Config_Dialog_Data *cfdata = calloc(1, sizeof(E_Config_Dialog_Data));
cfdata->index = inst->ctxt->config->player_selected;
cfdata->pause_on_desklock = inst->ctxt->config->pause_on_desklock;
return cfdata;
}
static void
_cfg_data_free(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
free(cfdata);
}
static int
_cfg_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
E_Music_Control_Instance *inst = cfd->data;
return ((inst->ctxt->config->pause_on_desklock != cfdata->pause_on_desklock) ||
(inst->ctxt->config->player_selected != cfdata->index));
}
static int
_cfg_data_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
E_Music_Control_Instance *inst = cfd->data;
if ((inst->ctxt->config->player_selected == cfdata->index) &&
(inst->ctxt->config->pause_on_desklock == cfdata->pause_on_desklock))
return 1;
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);
2013-02-22 05:25:41 -08:00
inst->ctxt->playing = EINA_FALSE;
music_control_dbus_init(inst->ctxt,
music_player_players[inst->ctxt->config->player_selected].dbus_name);
return 1;
}
static void
_cb_menu_cfg(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
{
E_Config_Dialog_View *v;
v = calloc(1, sizeof(E_Config_Dialog_View));
v->create_cfdata = _cfg_data_create;
v->free_cfdata = _cfg_data_free;
v->basic.create_widgets = _cfg_widgets_create;
v->basic.apply_cfdata = _cfg_data_apply;
v->basic.check_changed = _cfg_check_changed;
e_config_dialog_new(NULL, _("Music control Settings"), "E",
"_e_mod_music_config_dialog",
NULL, 0, v, data);
}
void
music_control_mouse_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
E_Music_Control_Instance *inst = data;
Evas_Event_Mouse_Down *ev = event;
if (ev->button == 1)
{
music_control_launch(inst);
if (!inst->popup)
_popup_new(inst);
else
music_control_popup_del(inst);
}
else if (ev->button == 3)
{
E_Menu *m;
E_Menu_Item *mi;
2015-03-13 14:47:36 -07:00
E_Zone *zone = e_zone_current_get();
int x, y;
if (inst->popup)
music_control_popup_del(inst);
m = e_menu_new();
mi = e_menu_item_new(m);
e_menu_item_label_set(mi, _("Settings"));
e_util_menu_item_theme_icon_set(mi, "configure");
e_menu_item_callback_set(mi, _cb_menu_cfg, inst);
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
e_menu_activate_mouse(m, zone, (x + ev->output.x),(y + ev->output.y),
1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
EVAS_BUTTON_NONE, ev->timestamp, NULL);
}
}