enlightenment/src/bin/e_theme.c

246 lines
6.1 KiB
C
Raw Normal View History

#include "e.h"
static void e_theme_handler_set(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *path);
static int e_theme_handler_test(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *path);
static E_Fm2_Mime_Handler *theme_hdl = NULL;
/* externally accessible functions */
EINTERN int
e_theme_init(void)
{
/* Register mime handler */
theme_hdl = e_fm2_mime_handler_new(_("Set As Theme"), "preferences-desktop-theme",
2012-07-02 01:15:02 -07:00
e_theme_handler_set, NULL,
e_theme_handler_test, NULL);
if (theme_hdl) e_fm2_mime_handler_glob_add(theme_hdl, "*.edj");
return 1;
}
EINTERN int
e_theme_shutdown(void)
{
if (theme_hdl)
{
2012-07-02 01:15:02 -07:00
e_fm2_mime_handler_glob_del(theme_hdl, "*.edj");
e_fm2_mime_handler_free(theme_hdl);
}
return 1;
}
E_API Eina_List *
e_theme_collection_items_find(const char *base EINA_UNUSED, const char *collname)
{
Eina_List *list, *list2 = NULL, *l;
const char *s, *s2;
int len = strlen(collname);
list = elm_theme_group_base_list(NULL, collname);
if (!list) return NULL;
EINA_LIST_FREE(list, s)
{
char *trans, *p, *p2;
size_t slen;
2012-07-02 01:15:02 -07:00
slen = strlen(s);
trans = memcpy(alloca(slen + 1), s, slen + 1);
p = trans + len + 1;
if (*p)
2012-07-02 01:15:02 -07:00
{
p2 = strchr(p, '/');
if (p2) *p2 = 0;
EINA_LIST_FOREACH(list2, l, s2)
2012-07-02 01:15:02 -07:00
{
if (!strcmp(s2, p)) break;
2012-07-02 01:15:02 -07:00
}
if (!l) list2 = eina_list_append(list2, eina_stringshare_add(p));
2012-07-02 01:15:02 -07:00
}
}
return list2;
}
E_API int
e_theme_edje_object_set(Evas_Object *o, const char *category EINA_UNUSED, const char *group)
{
const char *file;
2012-07-02 01:15:02 -07:00
file = elm_theme_group_path_find(NULL, group);
if (!file) return 0;
edje_object_file_set(o, file, group);
return 1;
}
E_API const char *
e_theme_edje_file_get(const char *category EINA_UNUSED, const char *group)
{
const char *file = elm_theme_group_path_find(NULL, group);
if (!file) return "";
return file;
}
E_API const char *
e_theme_edje_icon_fallback_file_get(const char *group)
{
const char *file;
if ((e_config->icon_theme) && (!strncmp(group, "e/icons", 7))) return "";
file = elm_theme_group_path_find(NULL, group);
if (!file) return "";
return file;
}
E_API int
e_theme_transition_find(const char *transition)
{
Eina_List *trans = NULL;
int found = 0;
const char *str;
trans = e_theme_collection_items_find(NULL, "e/transitions");
if (eina_list_search_sorted(trans, EINA_COMPARE_CB(strcmp), transition))
found = 1;
EINA_LIST_FREE(trans, str) eina_stringshare_del(str);
return found;
}
E_API Eina_List *
e_theme_transition_list(void)
{
return e_theme_collection_items_find(NULL, "e/transitions");
}
E_API int
e_theme_border_find(const char *border)
{
Eina_List *bds = NULL;
int found = 0;
const char *str;
bds = e_theme_collection_items_find(NULL, "e/widgets/border");
if (eina_list_search_sorted(bds, EINA_COMPARE_CB(strcmp), border))
found = 1;
EINA_LIST_FREE(bds, str) eina_stringshare_del(str);
return found;
}
E_API Eina_List *
e_theme_border_list(void)
{
return e_theme_collection_items_find(NULL, "e/widgets/border");
}
E_API int
e_theme_shelf_find(const char *shelf)
{
Eina_List *shelfs = NULL;
int found = 0;
const char *str;
shelfs = e_theme_collection_items_find(NULL, "e/shelf");
if (eina_list_search_sorted(shelfs, EINA_COMPARE_CB(strcmp), shelf))
found = 1;
EINA_LIST_FREE(shelfs, str) eina_stringshare_del(str);
return found;
}
E_API Eina_List *
e_theme_shelf_list(void)
{
return e_theme_collection_items_find(NULL, "e/shelf");
}
E_API int
e_theme_comp_frame_find(const char *comp)
{
Eina_List *comps = NULL;
int found = 0;
const char *str;
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
comps = e_theme_collection_items_find(NULL, "e/comp/frame");
if (eina_list_search_sorted(comps, EINA_COMPARE_CB(strcmp), comp))
found = 1;
EINA_LIST_FREE(comps, str) eina_stringshare_del(str);
return found;
}
E_API Eina_List *
e_theme_comp_frame_list(void)
{
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
return e_theme_collection_items_find(NULL, "e/comp/frame");
}
/* local subsystem functions */
static void
e_theme_handler_set(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *path)
{
E_Action *a;
char buf[PATH_MAX];
int copy = 1;
if (!path) return;
/* if not in system dir or user dir, copy to user dir */
snprintf(buf, sizeof(buf), "%s", elm_theme_system_dir_get());
if (!strncmp(buf, path, strlen(buf))) copy = 0;
if (copy)
{
snprintf(buf, sizeof(buf), "%s", elm_theme_user_dir_get());
if (!strncmp(buf, path, strlen(buf))) copy = 0;
}
if (copy)
{
const char *file;
char *name;
file = ecore_file_file_get(path);
name = ecore_file_strip_ext(file);
if (name)
{
double tim = ecore_time_unix_get();
snprintf(buf, sizeof(buf), "%s/%s-%f.edj",
elm_theme_user_dir_get(), name, tim);
if (!ecore_file_exists(buf))
{
ecore_file_cp(path, buf);
snprintf(buf, sizeof(buf), "%s-%f", name, tim);
elm_theme_set(NULL, buf);
}
else
elm_theme_set(NULL, path);
elm_config_all_flush();
elm_config_save();
free(name);
}
}
else
{
const char *file;
char *name;
file = ecore_file_file_get(path);
name = ecore_file_strip_ext(file);
if (name)
{
elm_theme_set(NULL, name);
elm_config_all_flush();
elm_config_save();
free(name);
}
}
e_config_save_queue();
a = e_action_find("restart");
if ((a) && (a->func.go)) a->func.go(NULL, NULL);
}
static int
e_theme_handler_test(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *path)
{
if (!path) return 0;
if (!edje_file_group_exists(path, "e/widgets/border/default/border"))
return 0;
return 1;
}