13a77bba6b88acf29cc2a013eb67d6e7e9ae160b
[platform/upstream/enlightenment.git] / src / modules / conf_comp / e_mod_main.c
1 #include "e.h"
2 #include "e_mod_main.h"
3 #include "e_mod_config.h"
4 #include "e_comp.h"
5 #include "e_comp_cfdata.h"
6
7 static Eina_Inlist *cfg_opts = NULL;
8
9 /* module private routines */
10 EINTERN Mod *_comp_mod = NULL;
11
12 /* public module routines. all modules must have these */
13 EAPI E_Module_Api e_modapi =
14 {
15    E_MODULE_API_VERSION,
16    "Composite Settings"
17 };
18
19 static Eina_List *
20 _e_mod_engine_info_cb(E_Configure_Option *co)
21 {
22    Eina_List *ret = NULL;
23    E_Configure_Option_Info *oi;
24    int x;
25    const char *name[] =
26    {
27     "Software",
28     NULL
29    };
30
31    if (!getenv("ECORE_X_NO_XLIB"))
32      {
33         if (ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_OPENGL_X11))
34           {
35              name[1] = "OpenGL";
36           }
37      }
38
39    for (x = ENGINE_SW; x <= ENGINE_GL; x++)
40      {
41         if (!name[x - 1]) continue;
42         oi = e_configure_option_info_new(co, _(name[x - 1]), (intptr_t*)(long)x);
43         oi->current = (*(int*)co->valptr == x);
44         ret = eina_list_append(ret, oi);
45      }
46    return ret;
47 }
48
49 EAPI void *
50 e_modapi_init(E_Module *m)
51 {
52    Mod *mod;
53    char buf[4096];
54
55    mod = calloc(1, sizeof(Mod));
56    m->data = mod;
57
58    mod->module = m;
59    snprintf(buf, sizeof(buf), "%s/e-module-comp.edj", e_module_dir_get(m));
60    e_configure_registry_category_add("appearance", 10, _("Look"), NULL,
61                                      "preferences-look");
62    e_configure_registry_item_add("appearance/comp", 120, _("Composite"), NULL,
63                                  buf, e_int_config_comp_module);
64
65    e_comp_cfdata_edd_init(&(mod->conf_edd),
66                           &(mod->conf_match_edd));
67
68    mod->conf = e_config_domain_load("module.comp", mod->conf_edd);
69    if (mod->conf)
70      {
71         mod->conf->max_unmapped_pixels = 32 * 1024;
72         mod->conf->keep_unmapped = 1;
73      }
74    else _e_mod_config_new(m);
75
76    /* force some config vals off */
77    mod->conf->lock_fps = 0;
78    mod->conf->indirect = 0;
79
80    /* XXX: update old configs. add config versioning */
81    if (mod->conf->first_draw_delay == 0)
82      mod->conf->first_draw_delay = 0.20;
83
84    _comp_mod = mod;
85
86    e_module_delayed_set(m, 0);
87    e_module_priority_set(m, -1000);
88
89    {
90       E_Configure_Option *co;
91
92       E_CONFIGURE_OPTION_ADD(co, CUSTOM, engine, mod->conf, _("Composite settings panel"), _("composite"), _("border"));
93       co->info = eina_stringshare_add("appearance/comp");
94       E_CONFIGURE_OPTION_ICON(co, buf);
95       cfg_opts = eina_inlist_append(cfg_opts, EINA_INLIST_GET(co));
96       E_CONFIGURE_OPTION_ADD(co, BOOL, vsync, mod->conf, _("Tear-free compositing (VSYNC)"), _("composite"), _("border"));
97       co->requires_restart = 1;
98       cfg_opts = eina_inlist_append(cfg_opts, EINA_INLIST_GET(co));
99       E_CONFIGURE_OPTION_ADD(co, BOOL, smooth_windows, mod->conf, _("Smooth scaling of composited window content"), _("composite"), _("border"));
100       co->funcs[1].none = co->funcs[0].none = e_comp_shadow_set;
101       cfg_opts = eina_inlist_append(cfg_opts, EINA_INLIST_GET(co));
102       E_CONFIGURE_OPTION_ADD(co, BOOL, nocomp_fs, mod->conf, _("Don't composite fullscreen windows"), _("composite"), _("border"));
103       co->funcs[1].none = co->funcs[0].none = e_comp_shadow_set;
104       cfg_opts = eina_inlist_append(cfg_opts, EINA_INLIST_GET(co));
105       E_CONFIGURE_OPTION_ADD(co, ENUM, engine, mod->conf, _("Compositing engine"), _("composite"), _("border"));
106       co->info_cb = _e_mod_engine_info_cb;
107       co->requires_restart = 1;
108       cfg_opts = eina_inlist_append(cfg_opts, EINA_INLIST_GET(co));
109
110       e_configure_option_category_tag_add(_("windows"), _("composite"));
111       e_configure_option_category_tag_add(_("composite"), _("composite"));
112       e_configure_option_category_icon_set(_("composite"), buf);
113    }
114
115    return mod;
116 }
117
118 void
119 _e_mod_config_new(E_Module *m)
120 {
121    Mod *mod = m->data;
122
123    mod->conf = e_comp_cfdata_config_new();
124 }
125
126 void
127 _e_mod_config_free(E_Module *m)
128 {
129    Mod *mod = m->data;
130
131    e_comp_cfdata_config_free(mod->conf);
132    mod->conf = NULL;
133 }
134
135 EAPI int
136 e_modapi_shutdown(E_Module *m)
137 {
138    Mod *mod = m->data;
139
140    e_configure_registry_item_del("appearance/comp");
141    e_configure_registry_category_del("appearance");
142
143    if (mod->config_dialog)
144      {
145         e_object_del(E_OBJECT(mod->config_dialog));
146         mod->config_dialog = NULL;
147      }
148
149    E_CONFIGURE_OPTION_LIST_CLEAR(cfg_opts);
150    e_configure_option_category_tag_del(_("composite"), _("composite"));
151    e_configure_option_category_tag_del(_("windows"), _("composite"));
152
153    _e_mod_config_free(m);
154
155    E_CONFIG_DD_FREE(mod->conf_match_edd);
156    E_CONFIG_DD_FREE(mod->conf_edd);
157    free(mod);
158
159    if (mod == _comp_mod) _comp_mod = NULL;
160
161    return 1;
162 }
163
164 EAPI int
165 e_modapi_save(E_Module *m)
166 {
167    Mod *mod = m->data;
168    e_config_domain_save("module.comp", mod->conf_edd, mod->conf);
169    return 1;
170 }
171