3 /* local subsystem functions */
4 static void _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source);
5 static void _e_bg_event_bg_update_free(void *data, void *event);
6 static void e_bg_handler_set(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *path);
7 static int e_bg_handler_test(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *path);
8 static void _e_bg_handler_image_imported(const char *image_path, void *data);
10 /* local subsystem globals */
11 EAPI int E_EVENT_BG_UPDATE = 0;
12 static E_Fm2_Mime_Handler *bg_hdl = NULL;
14 /* externally accessible functions */
19 E_Config_Desktop_Background *cfbg = NULL;
21 /* Register mime handler */
22 bg_hdl = e_fm2_mime_handler_new(_("Set As Background"),
23 "preferences-desktop-wallpaper",
24 e_bg_handler_set, NULL,
25 e_bg_handler_test, NULL);
28 e_fm2_mime_handler_glob_add(bg_hdl, "*.edj");
29 e_fm2_mime_handler_mime_add(bg_hdl, "image/png");
30 e_fm2_mime_handler_mime_add(bg_hdl, "image/jpeg");
33 /* Register files in use */
34 if (e_config->desktop_default_background)
35 e_filereg_register(e_config->desktop_default_background);
37 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
40 e_filereg_register(cfbg->file);
43 E_EVENT_BG_UPDATE = ecore_event_type_new();
51 E_Config_Desktop_Background *cfbg = NULL;
53 /* Deregister mime handler */
56 e_fm2_mime_handler_glob_del(bg_hdl, "*.edj");
57 e_fm2_mime_handler_free(bg_hdl);
60 /* Deregister files in use */
61 if (e_config->desktop_default_background)
62 e_filereg_deregister(e_config->desktop_default_background);
64 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
67 e_filereg_deregister(cfbg->file);
74 * Find the configuration for a given desktop background
75 * Use -1 as a wild card for each parameter.
76 * The most specific match will be returned
78 EAPI const E_Config_Desktop_Background *
79 e_bg_config_get(int container_num, int zone_num, int desk_x, int desk_y)
81 Eina_List *l, *ll, *entries;
82 E_Config_Desktop_Background *bg = NULL, *cfbg = NULL;
83 const char *bgfile = "";
85 int current_spec = 0; /* how specific the setting is - we want the least general one that applies */
87 /* look for desk specific background. */
88 if (container_num >= 0 || zone_num >= 0 || desk_x >= 0 || desk_y >= 0)
90 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
96 if (cfbg->container == container_num) spec++;
97 else if (cfbg->container >= 0)
99 if (cfbg->zone == zone_num) spec++;
100 else if (cfbg->zone >= 0)
102 if (cfbg->desk_x == desk_x) spec++;
103 else if (cfbg->desk_x >= 0)
105 if (cfbg->desk_y == desk_y) spec++;
106 else if (cfbg->desk_y >= 0)
109 if (spec <= current_spec) continue;
113 if (bgfile[0] != '/')
117 bf = e_path_find(path_backgrounds, bgfile);
121 if (eina_str_has_extension(bgfile, ".edj"))
123 entries = edje_file_collection_list(bgfile);
126 EINA_LIST_FOREACH(entries, ll, entry)
128 if (!strcmp(entry, "e/desktop/background"))
134 edje_file_collection_list_free(entries);
148 e_bg_file_get(int container_num, int zone_num, int desk_x, int desk_y)
150 const E_Config_Desktop_Background *cfbg;
151 Eina_List *l, *entries;
152 const char *bgfile = "";
156 cfbg = e_bg_config_get(container_num, zone_num, desk_x, desk_y);
158 /* fall back to default */
164 if (bgfile[0] != '/')
168 bf = e_path_find(path_backgrounds, bgfile);
175 bgfile = e_config->desktop_default_background;
178 if (bgfile[0] != '/')
182 bf = e_path_find(path_backgrounds, bgfile);
186 if (bgfile && eina_str_has_extension(bgfile, ".edj"))
188 entries = edje_file_collection_list(bgfile);
191 EINA_LIST_FOREACH(entries, l, entry)
193 if (!strcmp(entry, "e/desktop/background"))
199 edje_file_collection_list_free(entries);
202 else if ((bgfile) && (bgfile[0]))
205 bgfile = e_theme_edje_file_get("base/theme/background",
206 "e/desktop/background");
213 e_bg_zone_update(E_Zone *zone, E_Bg_Transition transition)
216 const char *bgfile = "";
217 const char *trans = "";
220 if (transition == E_BG_TRANSITION_START) trans = e_config->transition_start;
221 else if (transition == E_BG_TRANSITION_DESK)
222 trans = e_config->transition_desk;
223 else if (transition == E_BG_TRANSITION_CHANGE)
224 trans = e_config->transition_change;
225 if ((!trans) || (!trans[0])) transition = E_BG_TRANSITION_NONE;
227 desk = e_desk_current_get(zone);
229 bgfile = e_bg_file_get(zone->container->num, zone->num, desk->x, desk->y);
231 bgfile = e_bg_file_get(zone->container->num, zone->num, -1, -1);
235 const char *pfile = "";
237 edje_object_file_get(zone->bg_object, &pfile, NULL);
238 if (!e_util_strcmp(pfile, bgfile)) return;
241 if (transition == E_BG_TRANSITION_NONE)
245 evas_object_del(zone->bg_object);
246 zone->bg_object = NULL;
255 if (zone->prev_bg_object)
256 evas_object_del(zone->prev_bg_object);
257 zone->prev_bg_object = zone->bg_object;
258 if (zone->transition_object)
259 evas_object_del(zone->transition_object);
260 zone->transition_object = NULL;
261 zone->bg_object = NULL;
263 o = edje_object_add(zone->container->bg_evas);
264 zone->transition_object = o;
265 /* FIXME: segv if zone is deleted while up??? */
266 evas_object_data_set(o, "e_zone", zone);
267 snprintf(buf, sizeof(buf), "e/transitions/%s", trans);
268 e_theme_edje_object_set(o, "base/theme/transitions", buf);
269 edje_object_signal_callback_add(o, "e,state,done", "*", _e_bg_signal, zone);
270 evas_object_move(o, zone->x, zone->y);
271 evas_object_resize(o, zone->w, zone->h);
272 evas_object_layer_set(o, -1);
273 evas_object_clip_set(o, zone->bg_clip_object);
276 if (eina_str_has_extension(bgfile, ".edj"))
278 o = edje_object_add(zone->container->bg_evas);
279 evas_object_data_set(o, "e_zone", zone);
280 edje_object_file_set(o, bgfile, "e/desktop/background");
281 if (edje_object_data_get(o, "noanimation"))
282 edje_object_animation_set(o, EINA_FALSE);
286 o = e_icon_add(zone->container->bg_evas);
287 evas_object_data_set(o, "e_zone", zone);
288 e_icon_file_key_set(o, bgfile, NULL);
289 e_icon_fill_inside_set(o, 0);
292 if (transition == E_BG_TRANSITION_NONE)
294 evas_object_move(o, zone->x, zone->y);
295 evas_object_resize(o, zone->w, zone->h);
296 evas_object_layer_set(o, -1);
298 evas_object_clip_set(o, zone->bg_clip_object);
301 if (transition != E_BG_TRANSITION_NONE)
303 edje_extern_object_max_size_set(zone->prev_bg_object, 65536, 65536);
304 edje_extern_object_min_size_set(zone->prev_bg_object, 0, 0);
305 edje_object_part_swallow(zone->transition_object, "e.swallow.bg.old",
306 zone->prev_bg_object);
307 edje_extern_object_max_size_set(zone->bg_object, 65536, 65536);
308 edje_extern_object_min_size_set(zone->bg_object, 0, 0);
309 edje_object_part_swallow(zone->transition_object, "e.swallow.bg.new",
311 edje_object_signal_emit(zone->transition_object, "e,action,start", "e");
316 e_bg_default_set(const char *file)
318 E_Event_Bg_Update *ev;
321 file = eina_stringshare_add(file);
322 changed = file != e_config->desktop_default_background;
326 eina_stringshare_del(file);
330 if (e_config->desktop_default_background)
332 e_filereg_deregister(e_config->desktop_default_background);
333 eina_stringshare_del(e_config->desktop_default_background);
338 e_filereg_register(file);
339 e_config->desktop_default_background = file;
342 e_config->desktop_default_background = NULL;
344 ev = E_NEW(E_Event_Bg_Update, 1);
349 ecore_event_add(E_EVENT_BG_UPDATE, ev, _e_bg_event_bg_update_free, NULL);
353 e_bg_add(int container, int zone, int desk_x, int desk_y, const char *file)
356 E_Config_Desktop_Background *cfbg;
357 E_Event_Bg_Update *ev;
359 file = eina_stringshare_add(file);
361 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
364 (cfbg->container == container) &&
365 (cfbg->zone == zone) &&
366 (cfbg->desk_x == desk_x) &&
367 (cfbg->desk_y == desk_y) &&
368 (cfbg->file == file))
370 eina_stringshare_del(file);
375 e_bg_del(container, zone, desk_x, desk_y);
376 cfbg = E_NEW(E_Config_Desktop_Background, 1);
377 cfbg->container = container;
379 cfbg->desk_x = desk_x;
380 cfbg->desk_y = desk_y;
382 e_config->desktop_backgrounds = eina_list_append(e_config->desktop_backgrounds, cfbg);
384 e_filereg_register(cfbg->file);
386 ev = E_NEW(E_Event_Bg_Update, 1);
387 ev->container = container;
391 ecore_event_add(E_EVENT_BG_UPDATE, ev, _e_bg_event_bg_update_free, NULL);
395 e_bg_del(int container, int zone, int desk_x, int desk_y)
398 E_Config_Desktop_Background *cfbg;
399 E_Event_Bg_Update *ev;
401 EINA_LIST_FOREACH(e_config->desktop_backgrounds, l, cfbg)
404 if ((cfbg->container == container) && (cfbg->zone == zone) &&
405 (cfbg->desk_x == desk_x) && (cfbg->desk_y == desk_y))
407 e_config->desktop_backgrounds = eina_list_remove_list(e_config->desktop_backgrounds, l);
408 e_filereg_deregister(cfbg->file);
409 if (cfbg->file) eina_stringshare_del(cfbg->file);
415 ev = E_NEW(E_Event_Bg_Update, 1);
416 ev->container = container;
420 ecore_event_add(E_EVENT_BG_UPDATE, ev, _e_bg_event_bg_update_free, NULL);
426 Eina_List *l, *ll, *lll;
431 EINA_LIST_FOREACH(e_manager_list(), l, man)
433 EINA_LIST_FOREACH(man->containers, ll, con)
435 EINA_LIST_FOREACH(con->zones, lll, zone)
437 e_zone_bg_reconfigure(zone);
443 /* local subsystem functions */
446 * Set background to image, as required in e_fm2_mime_handler_new()
449 e_bg_handler_set(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *path)
459 con = e_container_current_get(e_manager_current_get());
460 if (!eina_str_has_extension(path, "edj"))
462 e_import_config_dialog_show(con, path, (Ecore_End_Cb)_e_bg_handler_image_imported, NULL);
465 zone = e_zone_current_get(con);
466 desk = e_desk_current_get(zone);
468 /* if not in system dir or user dir, copy to user dir */
469 e_prefix_data_concat_static(buf, "data/backgrounds");
470 if (!strncmp(buf, path, strlen(buf)))
474 e_user_dir_concat_static(buf, "backgrounds");
475 if (!strncmp(buf, path, strlen(buf)))
483 file = ecore_file_file_get(path);
484 name = ecore_file_strip_ext(file);
486 e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s-%f.edj", name, ecore_time_unix_get());
489 if (!ecore_file_exists(buf))
491 if (!ecore_file_cp(path, buf)) return;
492 e_bg_add(con->num, zone->num, desk->x, desk->y, buf);
495 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
498 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
501 e_config_save_queue();
505 * Test if possible to set background to file, as required in
506 * e_fm2_mime_handler_new()
508 * This handler tests for files that would be acceptable for setting
511 * You should just register it with "*.edj" (glob matching extension)
512 * or "image/" (mimetypes)that are acceptable with Evas loaders.
514 * Just edje files with "e/desktop/background" group are used.
517 e_bg_handler_test(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *path)
521 if (eina_str_has_extension(path, "edj"))
523 if (edje_file_group_exists(path, "e/desktop/background")) return 1;
527 /* it's image/png or image/jpeg, we'll import it. */
532 _e_bg_signal(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
536 if (zone->prev_bg_object)
538 evas_object_del(zone->prev_bg_object);
539 zone->prev_bg_object = NULL;
541 if (zone->transition_object)
543 evas_object_del(zone->transition_object);
544 zone->transition_object = NULL;
546 evas_object_move(zone->bg_object, zone->x, zone->y);
547 evas_object_resize(zone->bg_object, zone->w, zone->h);
548 evas_object_layer_set(zone->bg_object, -1);
549 evas_object_clip_set(zone->bg_object, zone->bg_clip_object);
550 evas_object_show(zone->bg_object);
554 _e_bg_event_bg_update_free(void *data __UNUSED__, void *event)
560 _e_bg_handler_image_imported(const char *image_path, void *data __UNUSED__)
562 E_Container *con = e_container_current_get(e_manager_current_get());
563 E_Zone *zone = e_zone_current_get(con);
564 E_Desk *desk = e_desk_current_get(zone);
566 e_bg_add(con->num, zone->num, desk->x, desk->y, image_path);
568 e_config_save_queue();