6e1027a5dc9c78567c69532c8bfb1119272b4ef5
[framework/uifw/e17.git] / src / modules / comp / e_mod_main.c
1 #include "e.h"
2 #include "e_mod_main.h"
3 #include "e_mod_config.h"
4 #include "e_mod_comp.h"
5
6 //static Ecore_Event_Handler *init_done_handler = NULL;
7
8 //static int
9 //_e_init_done(void *data, int type, void *event)
10 //{
11 //   ecore_event_handler_del(init_done_handler);
12 //   init_done_handler = NULL;
13 //   if (!e_mod_comp_init())
14 //     {
15 //        // FIXME: handle if comp init fails
16 //     }
17 //   return 1;
18 //}
19
20 /* module private routines */
21 Mod *_comp_mod = NULL;
22
23 /* public module routines. all modules must have these */
24 EAPI E_Module_Api e_modapi =
25 {
26    E_MODULE_API_VERSION,
27    "Composite"
28 };
29
30 EAPI void *
31 e_modapi_init(E_Module *m)
32 {
33    Mod *mod;
34    char buf[4096];
35
36    mod = calloc(1, sizeof(Mod));
37    m->data = mod;
38
39    mod->module = m;
40    snprintf(buf, sizeof(buf), "%s/e-module-comp.edj", e_module_dir_get(m));
41    e_configure_registry_category_add("appearance", 10, _("Look"), NULL,
42                                      "preferences-look");
43    e_configure_registry_item_add("appearance/comp", 120, _("Composite"), NULL,
44                                  buf, e_int_config_comp_module);
45
46    mod->conf_match_edd = E_CONFIG_DD_NEW("Comp_Match", Match);
47 #undef T
48 #undef D
49 #define T Match
50 #define D mod->conf_match_edd
51    E_CONFIG_VAL(D, T, title, STR);
52    E_CONFIG_VAL(D, T, name, STR);
53    E_CONFIG_VAL(D, T, clas, STR);
54    E_CONFIG_VAL(D, T, role, STR);
55    E_CONFIG_VAL(D, T, primary_type, INT);
56    E_CONFIG_VAL(D, T, borderless, CHAR);
57    E_CONFIG_VAL(D, T, dialog, CHAR);
58    E_CONFIG_VAL(D, T, accepts_focus, CHAR);
59    E_CONFIG_VAL(D, T, vkbd, CHAR);
60    E_CONFIG_VAL(D, T, quickpanel, CHAR);
61    E_CONFIG_VAL(D, T, argb, CHAR);
62    E_CONFIG_VAL(D, T, fullscreen, CHAR);
63    E_CONFIG_VAL(D, T, modal, CHAR);
64    E_CONFIG_VAL(D, T, shadow_style, STR);
65
66    mod->conf_edd = E_CONFIG_DD_NEW("Comp_Config", Config);
67 #undef T
68 #undef D
69 #define T Config
70 #define D mod->conf_edd
71    E_CONFIG_VAL(D, T, shadow_file, STR);
72    E_CONFIG_VAL(D, T, shadow_style, STR);
73    E_CONFIG_VAL(D, T, engine, INT);
74    E_CONFIG_VAL(D, T, max_unmapped_pixels, INT);
75    E_CONFIG_VAL(D, T, max_unmapped_time, INT);
76    E_CONFIG_VAL(D, T, min_unmapped_time, INT);
77    E_CONFIG_VAL(D, T, fps_average_range, INT);
78    E_CONFIG_VAL(D, T, fps_corner, UCHAR);
79    E_CONFIG_VAL(D, T, fps_show, UCHAR);
80    E_CONFIG_VAL(D, T, use_shadow, UCHAR);
81    E_CONFIG_VAL(D, T, indirect, UCHAR);
82    E_CONFIG_VAL(D, T, texture_from_pixmap, UCHAR);
83    E_CONFIG_VAL(D, T, lock_fps, UCHAR);
84    E_CONFIG_VAL(D, T, efl_sync, UCHAR);
85    E_CONFIG_VAL(D, T, loose_sync, UCHAR);
86    E_CONFIG_VAL(D, T, grab, UCHAR);
87    E_CONFIG_VAL(D, T, vsync, UCHAR);
88    E_CONFIG_VAL(D, T, keep_unmapped, UCHAR);
89    E_CONFIG_VAL(D, T, send_flush, UCHAR);
90    E_CONFIG_VAL(D, T, send_dump, UCHAR);
91    E_CONFIG_VAL(D, T, nocomp_fs, UCHAR);
92    E_CONFIG_VAL(D, T, smooth_windows, UCHAR);
93    E_CONFIG_VAL(D, T, first_draw_delay, DOUBLE);
94    E_CONFIG_LIST(D, T, match.popups, mod->conf_match_edd);
95    E_CONFIG_LIST(D, T, match.borders, mod->conf_match_edd);
96    E_CONFIG_LIST(D, T, match.overrides, mod->conf_match_edd);
97    E_CONFIG_LIST(D, T, match.menus, mod->conf_match_edd);
98
99    mod->conf = e_config_domain_load("module.comp", mod->conf_edd);
100    if (!mod->conf) _e_mod_config_new(m);
101
102    if (!e_config->use_composite)
103      {
104         e_config->use_composite = 1;
105         e_config_save_queue();
106      }
107
108    /* XXX: disabled dropshadow module when comp is running */
109    {
110       Eina_List *l;
111       E_Module *m2;
112       EINA_LIST_FOREACH(e_module_list(), l, m2)
113         {
114            if (m2->enabled && (!strcmp(m2->name, "dropshadow")))
115              e_module_disable(m2);
116         }
117    }
118
119    /* XXX: update old configs. add config versioning */
120    if (mod->conf->first_draw_delay == 0)
121      mod->conf->first_draw_delay = 0.05;
122
123    _comp_mod = mod;
124
125    if (!e_mod_comp_init())
126      {
127         // FIXME: handle if comp init fails
128      }
129
130    e_module_delayed_set(m, 0);
131    e_module_priority_set(m, -1000);
132    return mod;
133 }
134
135 void
136 _e_mod_config_new(E_Module *m)
137 {
138    Mod *mod = m->data;
139    Match *mat;
140
141    mod->conf = E_NEW(Config, 1);
142    mod->conf->shadow_file = NULL;
143    mod->conf->shadow_style = eina_stringshare_add("default");
144    mod->conf->engine = E_EVAS_ENGINE_SOFTWARE_X11;
145    mod->conf->max_unmapped_pixels = 32 * 1024;  // implement
146    mod->conf->max_unmapped_time = 10 * 3600; // implement
147    mod->conf->min_unmapped_time = 5 * 60; // implement
148    mod->conf->fps_average_range = 30;
149    mod->conf->fps_corner = 0;
150    mod->conf->fps_show = 0;
151    mod->conf->use_shadow = 1;
152    mod->conf->indirect = 0;
153    mod->conf->texture_from_pixmap = 0;
154    mod->conf->lock_fps = 0;
155    mod->conf->efl_sync = 1;
156    mod->conf->loose_sync = 1;
157    mod->conf->grab = 0;
158    mod->conf->vsync = 1;
159    mod->conf->keep_unmapped = 1;
160    mod->conf->send_flush = 1; // implement
161    mod->conf->send_dump = 0; // implement
162    mod->conf->nocomp_fs = 0; // buggy
163    mod->conf->smooth_windows = 0;
164    mod->conf->first_draw_delay = 0.05;
165
166    mod->conf->match.popups = NULL;
167    mat = E_NEW(Match, 1);
168    mod->conf->match.popups = eina_list_append(mod->conf->match.popups, mat);
169    mat->name = eina_stringshare_add("shelf");
170    mat->shadow_style = eina_stringshare_add("still");
171    mat = E_NEW(Match, 1);
172    mod->conf->match.popups = eina_list_append(mod->conf->match.popups, mat);
173    mat->shadow_style = eina_stringshare_add("popup");
174
175    mod->conf->match.borders = NULL;
176
177    mod->conf->match.overrides = NULL;
178    mat = E_NEW(Match, 1);
179    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
180    mat->name = eina_stringshare_add("E");
181    mat->clas = eina_stringshare_add("Background_Window");
182    mat->shadow_style = eina_stringshare_add("none");
183    mat = E_NEW(Match, 1);
184    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
185    mat->name = eina_stringshare_add("E");
186    mat->clas = eina_stringshare_add("everything");
187    mat->shadow_style = eina_stringshare_add("everything");
188    mat = E_NEW(Match, 1);
189    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
190    mat->primary_type = ECORE_X_WINDOW_TYPE_DROPDOWN_MENU;
191    mat->shadow_style = eina_stringshare_add("menu");
192    mat = E_NEW(Match, 1);
193    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
194    mat->primary_type = ECORE_X_WINDOW_TYPE_POPUP_MENU;
195    mat->shadow_style = eina_stringshare_add("menu");
196    mat = E_NEW(Match, 1);
197    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
198    mat->primary_type = ECORE_X_WINDOW_TYPE_COMBO;
199    mat->shadow_style = eina_stringshare_add("menu");
200    mat = E_NEW(Match, 1);
201    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
202    mat->primary_type = ECORE_X_WINDOW_TYPE_TOOLTIP;
203    mat->shadow_style = eina_stringshare_add("menu");
204    mat = E_NEW(Match, 1);
205    mod->conf->match.overrides = eina_list_append(mod->conf->match.overrides, mat);
206    mat->shadow_style = eina_stringshare_add("popup");
207
208    mod->conf->match.menus = NULL;
209    mat = E_NEW(Match, 1);
210    mod->conf->match.menus = eina_list_append(mod->conf->match.menus, mat);
211    mat->shadow_style = eina_stringshare_add("menu");
212 }
213
214 static void
215 _match_list_free(Eina_List *list)
216 {
217    Match *m;
218
219    EINA_LIST_FREE(list, m)
220      {
221         if (m->title) eina_stringshare_del(m->title);
222         if (m->name) eina_stringshare_del(m->name);
223         if (m->clas) eina_stringshare_del(m->clas);
224         if (m->role) eina_stringshare_del(m->role);
225         if (m->shadow_style) eina_stringshare_del(m->shadow_style);
226         free(m);
227      }
228 }
229
230 void
231 _e_mod_config_free(E_Module *m)
232 {
233    Mod *mod = m->data;
234
235    if (mod->conf->shadow_file) eina_stringshare_del(mod->conf->shadow_file);
236    if (mod->conf->shadow_style) eina_stringshare_del(mod->conf->shadow_style);
237
238    _match_list_free(mod->conf->match.popups);
239    _match_list_free(mod->conf->match.borders);
240    _match_list_free(mod->conf->match.overrides);
241    _match_list_free(mod->conf->match.menus);
242
243    free(mod->conf);
244    mod->conf = NULL;
245 }
246
247 EAPI int
248 e_modapi_shutdown(E_Module *m)
249 {
250    Mod *mod = m->data;
251
252    e_mod_comp_shutdown();
253
254    e_configure_registry_item_del("appearance/comp");
255    e_configure_registry_category_del("appearance");
256
257    if (mod->config_dialog)
258      {
259         e_object_del(E_OBJECT(mod->config_dialog));
260         mod->config_dialog = NULL;
261      }
262    _e_mod_config_free(m);
263
264    E_CONFIG_DD_FREE(mod->conf_match_edd);
265    E_CONFIG_DD_FREE(mod->conf_edd);
266    free(mod);
267
268    if (mod == _comp_mod) _comp_mod = NULL;
269
270    return 1;
271 }
272
273 EAPI int
274 e_modapi_save(E_Module *m)
275 {
276    Mod *mod = m->data;
277    e_config_domain_save("module.comp", mod->conf_edd, mod->conf);
278    return 1;
279 }
280