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