update for beta release
[framework/uifw/e17.git] / src / modules / wizard / page_150.c
1 /* Ask about compositing */
2 #include "e.h"
3 #include "e_mod_main.h"
4 #include "e_mod_comp_cfdata.h"
5
6 static int do_comp = 1;
7 static int do_gl = 0;
8 static int do_vsync = 0;
9
10 static int
11 match_file_glob(FILE *f, const char *glob)
12 {
13    char buf[32768];
14    int found = 0;
15    
16    while (fgets(buf, sizeof(buf), f))
17      {
18         if (e_util_glob_match(buf, glob))
19           {
20              found = 1;
21              break;
22           }
23      }
24    fclose(f);
25    return found;
26 }
27
28 static int
29 match_xorg_log(const char *glob)
30 {
31    FILE *f;
32    int i;
33    char buf[PATH_MAX];
34    
35    for (i = 0; i < 5; i++)
36      {
37         snprintf(buf, sizeof(buf), "/var/log/Xorg.%i.log", i);
38         f = fopen(buf, "rb");
39         if (f)
40           {
41              if (match_file_glob(f, glob)) return 1;
42           }
43      }
44    return 0;
45 }
46
47 EAPI int
48 wizard_page_init(E_Wizard_Page *pg __UNUSED__)
49 {
50    return 1;
51 }
52
53 EAPI int
54 wizard_page_shutdown(E_Wizard_Page *pg __UNUSED__)
55 {
56    return 1;
57 }
58
59 EAPI int
60 wizard_page_show(E_Wizard_Page *pg)
61 {
62    Evas_Object *o, *of, *ob;
63    Ecore_Evas *ee;
64    Ecore_X_Window_Attributes att;
65    
66    if (!ecore_x_composite_query()) return 0;
67    if (!ecore_x_damage_query()) return 0;
68    
69    memset((&att), 0, sizeof(Ecore_X_Window_Attributes));
70    ecore_x_window_attributes_get(ecore_x_window_root_first_get(), &att);
71    if ((att.depth != 24) && (att.depth != 32)) return 0;
72    
73    ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 320, 240);
74    if (ee)
75      {
76         ecore_evas_free(ee);
77         if (
78             (match_xorg_log("*(II)*NVIDIA*: Creating default Display*")) ||
79             (match_xorg_log("*(II)*intel*: Creating default Display*")) ||
80             (match_xorg_log("*(II)*NOUVEAU*: Creating default Display*")) ||
81             (match_xorg_log("*(II)*RADEON*: Creating default Display*"))
82            )
83           {
84              do_gl = 1;
85              do_vsync = 1;
86           }
87      }
88    
89    o = e_widget_list_add(pg->evas, 1, 0);
90    e_wizard_title_set(_("Compositing"));
91    
92    of = e_widget_framelist_add(pg->evas, _("Transparent windows and effects"), 0);
93    
94    ob = e_widget_textblock_add(pg->evas);
95    e_widget_size_min_set(ob, 200 * e_scale, 180 * e_scale);
96    e_widget_textblock_markup_set
97       (ob, 
98           _("Compositing provides translucency<br>"
99             "for windows, window effects like<br>"
100             "fading in and out and zooming<br>"
101             "when they appear and dissapear.<br>"
102             "It is highly recommended to<br>"
103             "enable this for a better<br>"
104             "experience, but it comes at a<br>"
105             "cost. It requires extra CPU<br>"
106             "or a GLSL Shader capable GPU<br>"
107             "with well written drivers.<br>"
108             "It also will add between 10 to<br>"
109             "100 MB to the memory needed<br>"
110             "for Enlightenment."
111               )
112       );
113    e_widget_framelist_object_append(of, ob);
114    
115    ob = e_widget_check_add(pg->evas, _("Enable Compositing"), &(do_comp));
116    e_widget_framelist_object_append(of, ob);
117    
118    if (ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_OPENGL_X11))
119      {
120         ob = e_widget_check_add(pg->evas, _("Hardware Accelerated (OpenGL)"), &(do_gl));
121         e_widget_framelist_object_append(of, ob);
122         
123         ob = e_widget_check_add(pg->evas, _("Tear-free Rendering (OpenGL only)"), &(do_vsync));
124         e_widget_framelist_object_append(of, ob);
125      }
126    
127    e_widget_list_object_append(o, of, 0, 0, 0.5);
128
129    evas_object_show(of);
130
131    e_wizard_page_show(o);
132 //   pg->data = o;
133    return 1; /* 1 == show ui, and wait for user, 0 == just continue */
134 }
135
136 EAPI int
137 wizard_page_hide(E_Wizard_Page *pg __UNUSED__)
138 {
139    if (!do_comp)
140      {
141         E_Config_Module *em;
142         Eina_List *l;
143         
144         EINA_LIST_FOREACH(e_config->modules, l, em)
145           {
146              if (!em->name) continue;
147              if (!strcmp(em->name, "comp"))
148                {
149                   e_config->modules = eina_list_remove_list
150                      (e_config->modules, l);
151                   if (em->name) eina_stringshare_del(em->name);
152                   free(em);
153                   break;
154                }
155           }
156         e_config->use_composite = 0;
157      }
158    else
159      {
160         E_Config_Module *em;
161         Eina_List *l;
162         E_Config_DD *conf_edd = NULL;
163         E_Config_DD *conf_match_edd = NULL;
164         Config *cfg = NULL;
165         
166         EINA_LIST_FOREACH(e_config->modules, l, em)
167           {
168              if (!em->name) continue;
169              if (!strcmp(em->name, "dropshadow"))
170                {
171                   e_config->modules = eina_list_remove_list
172                      (e_config->modules, l);
173                   if (em->name) eina_stringshare_del(em->name);
174                   free(em);
175                   break;
176                }
177           }
178         
179         e_config->use_composite = 1;
180         
181         e_mod_comp_cfdata_edd_init(&(conf_edd), &(conf_match_edd));
182         cfg = e_mod_comp_cfdata_config_new();
183         
184         if (do_gl)
185           {
186              cfg->engine = E_EVAS_ENGINE_GL_X11;
187              cfg->smooth_windows = 1;
188              cfg->vsync = do_vsync;
189           }
190         else
191           {
192              cfg->engine = E_EVAS_ENGINE_SOFTWARE_X11;
193              cfg->smooth_windows = 0;
194              cfg->vsync = 0;
195           }
196         
197         e_config_domain_save("module.comp", conf_edd, cfg);
198         E_CONFIG_DD_FREE(conf_match_edd);
199         E_CONFIG_DD_FREE(conf_edd);
200      }
201    e_config_save_queue();
202 //   if (pg->data) evas_object_del(pg->data);
203    return 1;
204 }
205
206 EAPI int
207 wizard_page_apply(E_Wizard_Page *pg __UNUSED__)
208 {
209    return 1;
210 }