1 #include "e_int_config_randr.h"
4 #ifndef Ecore_X_Randr_Unset
5 #define Ecore_X_Randr_Unset -1
8 static void _orientation_widget_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
9 static void _orientation_widget_radio_add_callbacks(void);
10 extern E_Config_Dialog_Data *e_config_runtime_info;
11 extern char _theme_file_path[];
14 static const char *_ORIENTATION_STRINGS[] = {
19 "Flipped, Horizontally",
20 "Flipped, Vertically" };
24 orientation_widget_create_data(E_Config_Dialog_Data *cfdata)
26 E_Config_Randr_Dialog_Output_Dialog_Data *odd;
29 if (!cfdata || !cfdata->output_dialog_data_list) return EINA_FALSE;
31 EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
33 odd->new_orientation = Ecore_X_Randr_Unset;
34 odd->previous_orientation = odd->crtc ? odd->crtc->current_orientation : (Ecore_X_Randr_Orientation) Ecore_X_Randr_Unset;
41 orientation_widget_free_cfdata(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
43 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_reflect_vertical, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
44 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_reflect_horizontal, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
45 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_rot270, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
46 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_rot180, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
47 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_rot90, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
48 evas_object_event_callback_del(cfdata->gui.widgets.orientation.radio_normal, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb);
52 orientation_widget_basic_create_widgets(Evas *canvas)
58 if (!canvas || !e_config_runtime_info) return NULL;
59 if (e_config_runtime_info->gui.widgets.orientation.widget) return e_config_runtime_info->gui.widgets.orientation.widget;
61 if (!(widget = e_widget_framelist_add(canvas, _("Display Orientation"), EINA_FALSE))) return NULL;
64 if (!(rg = e_widget_radio_group_new(&e_config_runtime_info->gui.widgets.orientation.radio_val))) goto _orientation_widget_radio_add_fail;
66 //IMPROVABLE: use enum to determine objects via 'switch'-statement
67 e_config_runtime_info->gui.widgets.orientation.radio_normal = e_widget_radio_add(canvas, _("Normal"), ECORE_X_RANDR_OUTPUT_POLICY_ABOVE, rg);
68 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_normal);
70 e_config_runtime_info->gui.widgets.orientation.radio_rot90 = e_widget_radio_add(canvas, _("Rotated, 90°"), ECORE_X_RANDR_OUTPUT_POLICY_RIGHT, rg);
71 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot90);
73 e_config_runtime_info->gui.widgets.orientation.radio_rot180 = e_widget_radio_add(canvas, _("Rotated, 180°"), ECORE_X_RANDR_OUTPUT_POLICY_BELOW, rg);
74 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot180);
76 e_config_runtime_info->gui.widgets.orientation.radio_rot270 = e_widget_radio_add(canvas, _("Rotated, 270°"), ECORE_X_RANDR_OUTPUT_POLICY_LEFT, rg);
77 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_rot270);
79 e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal = e_widget_radio_add(canvas, _("Flipped, horizontally"), ECORE_X_RANDR_OUTPUT_POLICY_CLONE, rg);
80 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal);
82 e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical = e_widget_radio_add(canvas, _("Flipped, vertically"), ECORE_X_RANDR_OUTPUT_POLICY_NONE, rg);
83 e_widget_framelist_object_append(widget, e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical);
85 _orientation_widget_radio_add_callbacks();
88 // Add orientation demonstration edje
89 if (!(e_config_runtime_info->gui.widgets.orientation.swallowing_edje = edje_object_add(canvas)))
90 goto _orientation_widget_edje_add_fail;
91 if (!edje_object_file_set(e_config_runtime_info->gui.widgets.orientation.swallowing_edje, _theme_file_path, "e/conf/randr/dialog/widget/orientation"))
92 goto _orientation_widget_edje_set_fail;
94 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);
97 //disable widgets, if no CRTC is selected
98 orientation_widget_update_radio_buttons(e_config_runtime_info->gui.selected_output_dd);
100 //evas_object_show(e_config_runtime_info->gui.widgets.orientation.swallowing_edje);
105 _orientation_widget_edje_set_fail:
107 evas_object_del(e_config_runtime_info->gui.widgets.orientation.swallowing_edje);
108 _orientation_widget_edje_add_fail:
109 fprintf(stderr, "CONF_RANDR: Couldn't set edj for orientation widget!\n");
110 evas_object_del(widget);
113 _orientation_widget_radio_add_fail:
114 evas_object_del(widget);
115 fprintf(stderr, "CONF_RANDR: Could not add radio group!\n");
120 _orientation_widget_mouse_up_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
123 int orientation = Ecore_X_Randr_Unset;
125 if (!e_config_runtime_info->gui.selected_output_dd)
130 * "sadly" the evas callbacks are called before radio_val is set to its new
131 * value. If that is ever changed, remove the used code below and just use the
133 * snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,%d", e_config_runtime_info->gui.widgets.orientation.radio_val);
135 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_normal) orientation = ECORE_X_RANDR_ORIENTATION_ROT_0;
136 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot90) orientation = ECORE_X_RANDR_ORIENTATION_ROT_90;
137 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot180) orientation = ECORE_X_RANDR_ORIENTATION_ROT_180;
138 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_rot270) orientation = ECORE_X_RANDR_ORIENTATION_ROT_270;
139 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal) orientation = ECORE_X_RANDR_ORIENTATION_FLIP_X;
140 if (obj == e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical) orientation = ECORE_X_RANDR_ORIENTATION_FLIP_Y;
142 e_config_runtime_info->gui.selected_output_dd->new_orientation = orientation;
144 arrangement_widget_rep_update(e_config_runtime_info->gui.selected_output_dd);
146 //edje_object_signal_emit(e_config_runtime_info->gui.widgets.orientation.swallowing_edje, signal, "e");
148 //fprintf(stderr, "CONF_RANDR: mouse button released. Emitted signal to orientation: %s\n", signal);
152 orientation_widget_update_radio_buttons(E_Config_Randr_Dialog_Output_Dialog_Data *odd)
154 Ecore_X_Randr_Orientation supported_oris, ori;
156 //disable widgets, if no crtc is selected
159 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
160 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
161 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
162 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
163 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
164 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
171 supported_oris = odd->crtc->orientations;
172 ori = (odd->new_orientation != (Ecore_X_Randr_Orientation) Ecore_X_Randr_Unset) ? odd->new_orientation : odd->crtc->current_orientation;
177 //assume all orientations are supported
178 supported_oris = Ecore_X_Randr_Unset;
179 ori = Ecore_X_Randr_Unset;
182 if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_0)
183 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_FALSE);
185 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
187 if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_90)
188 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_FALSE);
190 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
192 if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_180)
193 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_FALSE);
195 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
197 if (supported_oris & ECORE_X_RANDR_ORIENTATION_ROT_270)
198 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_FALSE);
200 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
202 if (supported_oris & ECORE_X_RANDR_ORIENTATION_FLIP_X)
203 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_FALSE);
205 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
207 if (supported_oris & ECORE_X_RANDR_ORIENTATION_FLIP_Y)
208 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_FALSE);
210 e_widget_disabled_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
212 //toggle the switch of the currently used orientation
215 case ECORE_X_RANDR_ORIENTATION_ROT_0:
216 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_normal, EINA_TRUE);
219 case ECORE_X_RANDR_ORIENTATION_ROT_90:
220 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EINA_TRUE);
223 case ECORE_X_RANDR_ORIENTATION_ROT_180:
224 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EINA_TRUE);
227 case ECORE_X_RANDR_ORIENTATION_ROT_270:
228 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EINA_TRUE);
231 case ECORE_X_RANDR_ORIENTATION_FLIP_X:
232 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_horizontal, EINA_TRUE);
235 case ECORE_X_RANDR_ORIENTATION_FLIP_Y:
236 e_widget_radio_toggle_set(e_config_runtime_info->gui.widgets.orientation.radio_reflect_vertical, EINA_TRUE);
246 orientation_widget_update_edje(E_Config_Randr_Dialog_Output_Dialog_Data *odd)
248 Ecore_X_Randr_Orientation supported_oris, ori;
257 supported_oris = odd->crtc->orientations;
258 ori = odd->crtc->current_orientation;
263 //assume all orientations are supported
264 //#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)
265 supported_oris = RANDR_DIALOG_ORIENTATION_ALL;
266 ori = ECORE_X_RANDR_ORIENTATION_ROT_0;
268 //Send signal to the edje, to represent the supported and current set orientation
269 snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,supported,%d", supported_oris);
270 edje_object_signal_emit(crtc, signal, "e");
271 snprintf(signal, sizeof(signal), "conf,randr,dialog,orientation,current,%d", ori);
272 edje_object_signal_emit(crtc, signal, "e");
277 orientation_widget_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
279 E_Config_Randr_Dialog_Output_Dialog_Data *odd;
281 Eina_Bool success = EINA_TRUE;
283 if (!cfdata) return EINA_FALSE;
285 EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
287 if (!odd || !odd->crtc || ((int)odd->new_orientation == Ecore_X_Randr_Unset))
289 fprintf(stderr, "CONF_RANDR: Change orientation of crtc %d to %d.\n", odd->crtc->xid, odd->new_orientation);
290 if (!ecore_x_randr_crtc_orientation_set(cfd->con->manager->root, odd->crtc->xid, odd->new_orientation))
291 success = EINA_FALSE;
298 orientation_widget_basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
300 E_Config_Randr_Dialog_Output_Dialog_Data *odd;
303 if (!cfdata) return EINA_FALSE;
305 EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
307 if (!odd || !odd->crtc || ((int)odd->previous_orientation == Ecore_X_Randr_Unset) || ((int)odd->new_orientation == Ecore_X_Randr_Unset))
309 if (odd->previous_orientation != odd->new_orientation)
317 orientation_widget_keep_changes(E_Config_Dialog_Data *cfdata)
319 E_Config_Randr_Dialog_Output_Dialog_Data *odd;
324 EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
326 if (!odd || ((int)odd->previous_orientation == Ecore_X_Randr_Unset))
328 odd->previous_orientation = odd->new_orientation;
329 odd->new_orientation = Ecore_X_Randr_Unset;
334 orientation_widget_discard_changes(E_Config_Dialog_Data *cfdata)
336 E_Config_Randr_Dialog_Output_Dialog_Data *odd;
341 EINA_LIST_FOREACH(cfdata->output_dialog_data_list, iter, odd)
343 if (!odd->crtc || ((int)odd->previous_orientation == Ecore_X_Randr_Unset))
345 ecore_x_randr_crtc_orientation_set(cfdata->manager->root, odd->crtc->xid, odd->previous_orientation);
346 odd->new_orientation = Ecore_X_Randr_Unset;
351 _orientation_widget_radio_add_callbacks(void)
353 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);
354 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);
355 evas_object_event_callback_add(e_config_runtime_info->gui.widgets.orientation.radio_rot270, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
356 evas_object_event_callback_add(e_config_runtime_info->gui.widgets.orientation.radio_rot180, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
357 evas_object_event_callback_add(e_config_runtime_info->gui.widgets.orientation.radio_rot90, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);
358 evas_object_event_callback_add(e_config_runtime_info->gui.widgets.orientation.radio_normal, EVAS_CALLBACK_MOUSE_UP, _orientation_widget_mouse_up_cb, NULL);