upload tizen1.0 source
[framework/uifw/e17.git] / src / modules / conf_randr / e_int_config_randr_orientation.c
1 #include "e_int_config_randr.h"
2 #include "e_randr.h"
3
4 #ifndef  Ecore_X_Randr_Unset
5 #define Ecore_X_Randr_Unset          -1
6 #endif
7
8 #define RANDR_DIALOG_ORIENTATION_ALL (ECORE_X_RANDR_ORIENTATION_ROT_0 | ECORE_X_RANDR_ORIENTATION_ROT_90 | ECORE_X_RANDR_ORIENTATION_ROT_180 | ECORE_X_RANDR_ORIENTATION_ROT_270 | ECORE_X_RANDR_ORIENTATION_ROT_270 | ECORE_X_RANDR_ORIENTATION_FLIP_X | ECORE_X_RANDR_ORIENTATION_FLIP_Y)
9
10 Eina_Bool    orientation_widget_create_data(E_Config_Dialog_Data *cfdata);
11 Evas_Object *orientation_widget_basic_create_widgets(Evas *canvas);
12 Eina_Bool    orientation_widget_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
13 Eina_Bool    orientation_widget_basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
14 Eina_Bool    orientation_widget_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
15 void         orientation_widget_update_radio_buttons(Evas_Object *crtc);
16 void         orientation_widget_update_edje(Evas_Object *crtc);
17
18 //static void _orientation_widget_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
19 extern E_Config_Dialog_Data *e_config_runtime_info;
20 extern char _theme_file_path[];
21
22 /*
23    static void
24    _orientation_widget_radio_add_callbacks(void)
25    {
26    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
27    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
28    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_rot270, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
29    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_rot180, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
30    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_rot90, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
31    evas_object_event_callback_add (e_config_runtime_info->gui.widgets.orientation.radio_normal, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
32    }
33  */
34
35 Eina_Bool
36 orientation_widget_create_data(E_Config_Dialog_Data *cfdata)
37 {
38    E_Config_Randr_Dialog_Output_Dialog_Data *odd;
39    E_Randr_Crtc_Info *ci;
40    Eina_List *iter;
41
42    if (!cfdata || !cfdata->output_dialog_data_list) return EINA_FALSE;
43
44    EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
45      {
46         ci = odd->crtc;
47         if (!ci || !ci->current_mode) continue;
48         odd->new_orientation = Ecore_X_Randr_Unset;
49         odd->previous_orientation = ci->current_orientation;
50      }
51
52    return EINA_TRUE;
53 }
54
55 Evas_Object *
56 orientation_widget_basic_create_widgets(Evas *canvas)
57 {
58    Evas_Object *widget;
59    E_Radio_Group *rg;
60    //char signal[29];
61
62    if (!canvas || !e_config_runtime_info) return NULL;
63    if (e_config_runtime_info->gui.widgets.orientation.widget) return e_config_runtime_info->gui.widgets.orientation.widget;
64
65    if (!(widget = e_widget_framelist_add(canvas, _("Display Orientation"), EINA_FALSE))) return NULL;
66
67    // Add radio buttons
68    if (!(rg = e_widget_radio_group_new(&e_config_runtime_info->gui.widgets.orientation.radio_val))) goto _orientation_widget_radio_add_fail;
69
70    //IMPROVABLE: use enum to determine objects via 'switch'-statement
71    e_config_runtime_info->gui.widgets.orientation.radio_normal = e_widget_radio_add(canvas, _("Normal"), ECORE_X_RANDR_OUTPUT_POLICY_ABOVE, rg);
72    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_normal);
73
74    e_config_runtime_info->gui.widgets.orientation.radio_rot90 = e_widget_radio_add(canvas, _("Rotated, 90°"), ECORE_X_RANDR_OUTPUT_POLICY_RIGHT, rg);
75    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot90);
76
77    e_config_runtime_info->gui.widgets.orientation.radio_rot180 = e_widget_radio_add(canvas, _("Rotated, 180°"), ECORE_X_RANDR_OUTPUT_POLICY_BELOW, rg);
78    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot180);
79
80    e_config_runtime_info->gui.widgets.orientation.radio_rot270 = e_widget_radio_add(canvas, _("Rotated, 270°"), ECORE_X_RANDR_OUTPUT_POLICY_LEFT, rg);
81    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot270);
82
83    e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal = e_widget_radio_add(canvas, _("Flipped, horizontally"), ECORE_X_RANDR_OUTPUT_POLICY_CLONE, rg);
84    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal);
85
86    e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical = e_widget_radio_add(canvas, _("Flipped, vertically"), ECORE_X_RANDR_OUTPUT_POLICY_NONE, rg);
87    e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical);
88
89    //_orientation_widget_radio_add_callbacks();
90
91    /*
92       // Add orientation demonstration edje
93       if (!(e_config_runtime_info->gui.widgets.orientation.swallowing_edje = edje_object_add(canvas)))
94       goto _orientation_widget_edje_add_fail;
95       if (!edje_object_file_set(e_config_runtime_info->gui.widgets.orientation.swallowing_edje, _theme_file_path, "e/conf/randr/dialog/widget/orientation"))
96       goto _orientation_widget_edje_set_fail;
97
98       e_widget_table_object_align_append(widget, e_config_runtime_info->gui.widgets.orientation.swallowing_edje, 1, 0, 1, 1, 1, 1, 1, 1, 1.0, 1.0);
99     */
100
101    //disable widgets, if no CRTC is selected
102    orientation_widget_update_radio_buttons(e_config_runtime_info->gui.selected_eo);
103
104    //evas_object_show(e_config_runtime_info->gui.widgets.orientation.swallowing_edje);
105
106    return widget;
107
108    /*
109       _orientation_widget_edje_set_fail:
110       evas_object_del(ol);
111       evas_object_del(e_config_runtime_info->gui.widgets.orientation.swallowing_edje);
112       _orientation_widget_edje_add_fail:
113       fprintf(stderr, "CONF_RANDR: Couldn't set edj for orientation widget!\n");
114       evas_object_del(widget);
115       return NULL;
116     */
117 _orientation_widget_radio_add_fail:
118    evas_object_del(widget);
119    fprintf(stderr, "CONF_RANDR: Could not add radio group!\n");
120    return NULL;
121 }
122
123 #if 0
124 static void
125 _orientation_widget_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
126 {
127    char signal[40];
128    int orientation = ECORE_X_RANDR_ORIENTATION_ROT_0;
129
130    /*
131     * IMPROVABLE:
132     * "sadly" the evas callbacks are called before radio_val is set to its new
133     * value. If that is ever changed, remove the used code below and just use the
134     * 1-liner below.
135     * snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,%d", e_config_runtime_info->gui.widgets.orientation.radio_val);
136     */
137    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_normal) orientation = ECORE_X_RANDR_ORIENTATION_ROT_0;
138    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot90) orientation = ECORE_X_RANDR_ORIENTATION_ROT_90;
139    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot180) orientation = ECORE_X_RANDR_ORIENTATION_ROT_180;
140    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot270) orientation = ECORE_X_RANDR_ORIENTATION_ROT_270;
141    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal) orientation = ECORE_X_RANDR_ORIENTATION_FLIP_X;
142    if (obj == e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical) orientation = ECORE_X_RANDR_ORIENTATION_FLIP_Y;
143
144    snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,%d", orientation);
145
146    edje_object_signal_emit(e_config_runtime_info->gui.widgets.orientation.swallowing_edje, signal, "e");
147
148    fprintf(stderr, "CONF_RANDR: mouse button released. Emitted signal to orientation: %s\n", signal);
149 }
150
151 #endif
152
153 void
154 orientation_widget_update_radio_buttons(Evas_Object *crtc)
155 {
156    E_Config_Randr_Dialog_Output_Dialog_Data *output_dialog_data;
157    Ecore_X_Randr_Orientation supported_oris, ori;
158
159    //disable widgets, if no crtc is selected
160    if (!crtc)
161      {
162         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
163         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
164         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
165         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
166         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
167         e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
168         return;
169      }
170
171    if (!(output_dialog_data = evas_object_data_get(crtc, "rep_info"))) return;
172
173    if (output_dialog_data->crtc)
174      {
175         //enabled monitor
176         supported_oris = output_dialog_data->crtc->orientations;
177         ori = output_dialog_data->crtc->current_orientation;
178      }
179    else
180      {
181         //disabled monitor
182         //assume all orientations are supported
183         supported_oris = RANDR_DIALOG_ORIENTATION_ALL;
184         ori = ECORE_X_RANDR_ORIENTATION_ROT_0;
185      }
186
187    if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_0)
188      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_FALSE);
189    else
190      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
191
192    if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_90)
193      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_FALSE);
194    else
195      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
196
197    if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_180)
198      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_FALSE);
199    else
200      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
201
202    if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_270)
203      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_FALSE);
204    else
205      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
206
207    if (supported_oris & ECORE_X_RANDR_ORIENTATION_FLIP_X)
208      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_FALSE);
209    else
210      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
211
212    if (supported_oris & ECORE_X_RANDR_ORIENTATION_FLIP_Y)
213      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_FALSE);
214    else
215      e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
216
217    //toggle the switch of the currently used orientation
218    switch (ori)
219      {
220       case ECORE_X_RANDR_ORIENTATION_ROT_90:
221         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
222         break;
223
224       case ECORE_X_RANDR_ORIENTATION_ROT_180:
225         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
226         break;
227
228       case ECORE_X_RANDR_ORIENTATION_ROT_270:
229         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
230         break;
231
232       case ECORE_X_RANDR_ORIENTATION_FLIP_X:
233         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
234         break;
235
236       case ECORE_X_RANDR_ORIENTATION_FLIP_Y:
237         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
238         break;
239
240       default: //== ECORE_X_RANDR_ORIENTATION_ROT_0:
241         e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
242      }
243 }
244
245 void
246 orientation_widget_update_edje(Evas_Object *crtc)
247 {
248    E_Config_Randr_Dialog_Output_Dialog_Data *output_dialog_data;
249    Ecore_X_Randr_Orientation supported_oris, ori;
250    char signal[40];
251
252    if (!e_config_runtime_info->gui.selected_eo || !(output_dialog_data = evas_object_data_get(crtc, "rep_info"))) return;
253
254    if (output_dialog_data->crtc)
255      {
256         //enabled monitor
257         supported_oris = output_dialog_data->crtc->orientations;
258         ori = output_dialog_data->crtc->current_orientation;
259      }
260    else
261      {
262         //disabled monitor
263         //assume all orientations are supported
264         supported_oris = RANDR_DIALOG_ORIENTATION_ALL;
265         ori = ECORE_X_RANDR_ORIENTATION_ROT_0;
266      }
267    //Send signal to the edje, to represent the supported and current set orientation
268    snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,supported,%d", supported_oris);
269    edje_object_signal_emit(crtc, signal, "e");
270    snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,current,%d", ori);
271    edje_object_signal_emit(crtc, signal, "e");
272 }
273
274 Eina_Bool
275 orientation_widget_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata __UNUSED__)
276 {
277    Ecore_X_Randr_Orientation orientation;
278    E_Config_Randr_Dialog_Output_Dialog_Data *output_dialog_data;
279
280    if (!e_config_runtime_info->gui.widgets.orientation.widget || !e_config_runtime_info->gui.selected_eo || !(output_dialog_data = evas_object_data_get(e_config_runtime_info->gui.selected_eo, "rep_info")) || !output_dialog_data->crtc) return EINA_FALSE;
281
282    orientation = e_config_runtime_info->gui.widgets.orientation.radio_val;
283
284    fprintf(stderr, "CONF_RANDR: Change orientation of crtc %d to %d.\n", output_dialog_data->crtc->xid, orientation);
285
286    if (ecore_x_randr_crtc_orientation_set(cfd->con->manager->root, output_dialog_data->crtc->xid, orientation))
287      {
288         ecore_x_randr_screen_reset(cfd->con->manager->root);
289         output_dialog_data->previous_orientation = output_dialog_data->new_orientation;
290         output_dialog_data->new_orientation = orientation;
291         return EINA_TRUE;
292      }
293    else
294      return EINA_FALSE;
295 }
296
297 Eina_Bool
298 orientation_widget_basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata __UNUSED__)
299 {
300    E_Config_Randr_Dialog_Output_Dialog_Data *output_dialog_data;
301
302    if (!e_config_runtime_info->gui.widgets.orientation.widget || !e_config_runtime_info->gui.selected_eo || !(output_dialog_data = evas_object_data_get(e_config_runtime_info->gui.selected_eo, "rep_info"))) return EINA_FALSE;
303
304    return (int)output_dialog_data->previous_orientation != (int)e_config_runtime_info->gui.widgets.orientation.radio_val;
305 }
306
307 void
308 orientation_widget_keep_changes(E_Config_Dialog_Data *cfdata)
309 {
310    E_Config_Randr_Dialog_Output_Dialog_Data *odd;
311    Eina_List *iter;
312
313    if (!cfdata) return;
314
315    EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
316      {
317         if (!odd || ((int)odd->previous_orientation == Ecore_X_Randr_Unset)) continue;
318         odd->previous_orientation = odd->new_orientation;
319         odd->new_orientation = Ecore_X_Randr_Unset;
320      }
321 }
322
323 void
324 orientation_widget_discard_changes(E_Config_Dialog_Data *cfdata)
325 {
326    E_Config_Randr_Dialog_Output_Dialog_Data *odd;
327    Eina_List *iter;
328
329    if (!cfdata) return;
330
331    EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
332      {
333         if (!odd->crtc || ((int)odd->previous_orientation == Ecore_X_Randr_Unset)) continue;
334         if (ecore_x_randr_crtc_orientation_set(cfdata->manager->root, odd->crtc->xid, odd->previous_orientation))
335           {
336              odd->new_orientation = odd->previous_orientation;
337              odd->previous_orientation = Ecore_X_Randr_Unset;
338              ecore_x_randr_screen_reset(cfdata->manager->root);
339           }
340      }
341 }
342