Some work on display settings:

- add check changed,
- don't display rotation and reflection settings if they are not supported,
- display a check icon next to the current resolution and rate,
- correct some segfault happening when surebox timeouts,
- change surebox yes/no to save/restore,
- other cosmetic changes.


SVN revision: 37565
This commit is contained in:
Chidambar Zinnoury 2008-11-09 18:08:12 +00:00
parent ac419db029
commit 7ed13851d0
1 changed files with 152 additions and 103 deletions

View File

@ -8,10 +8,13 @@
* Give list some icons.
*/
static void _fill_data (E_Config_Dialog_Data *cfdata);
static void *_create_data (E_Config_Dialog *cfd);
static void _free_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_check_changed (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_apply_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create_widgets (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static void _load_resolutions (E_Config_Dialog_Data *cfdata);
static void _load_rates (E_Config_Dialog_Data *cfdata);
static void _ilist_item_change (void *data);
static int _deferred_noxrandr_error (void *data);
@ -43,6 +46,8 @@ struct _E_Config_Dialog_Data
Eina_List *resolutions;
Ecore_X_Screen_Size orig_size;
Ecore_X_Screen_Refresh_Rate orig_rate;
int orig_rotation;
int orig_flip;
int restore;
int can_rotate;
int can_flip;
@ -91,8 +96,10 @@ _surebox_dialog_cb_yes(void *data, E_Dialog *dia)
e_config->display_res_height = c_size.height;
e_config->display_res_hz = c_rate.rate;
e_config_save_queue();
sb->cfdata->orig_size = c_size;
sb->cfdata->orig_rate = c_rate;
_fill_data(sb->cfdata);
_load_resolutions(sb->cfdata);
/* No need to load rates as the currently selected resolution has not been
* changed since last selection. */
if (dia) _surebox_dialog_cb_delete(dia->win);
}
@ -100,22 +107,11 @@ static void
_surebox_dialog_cb_no(void *data, E_Dialog *dia)
{
SureBox *sb;
Eina_List *l;
sb = data;
ecore_x_randr_screen_refresh_rate_set(sb->dia->win->container->manager->root,
sb->cfdata->orig_size, sb->cfdata->orig_rate);
for (l = sb->cfdata->resolutions; l; l = l->next)
{
Resolution *res = l->data;
if ((res->size.width == sb->cfdata->orig_size.width)
&& (res->size.height == sb->cfdata->orig_size.height))
{
e_widget_ilist_selected_set(sb->cfdata->res_list, res->id);
break;
}
}
_load_resolutions(sb->cfdata);
_load_rates(sb->cfdata);
_surebox_dialog_cb_delete(dia->win);
}
@ -130,14 +126,14 @@ _surebox_text_fill(SureBox *sb)
{
if (sb->cfdata->has_rates)
snprintf(buf, sizeof(buf),
_("Does this look OK? Press <hilight>Yes</hilight> if it does, or No if not.<br>"
_("Does this look OK? <hilight>Save</hilight> if it does, or restore if not.<br>"
"If you do not press a button, the old resolution of<br>"
"%dx%d at %d Hz will be restored in %d seconds."),
sb->cfdata->orig_size.width, sb->cfdata->orig_size.height,
sb->cfdata->orig_rate.rate, sb->iterations);
else
snprintf(buf, sizeof(buf),
_("Does this look OK? Press <hilight>Yes</hilight> if it does, or No if not.<br>"
_("Does this look OK? <hilight>Save</hilight> if it does, or restore if not.<br>"
"If you do not press a button, the old resolution of<br>"
"%dx%d will be restored in %d seconds."),
sb->cfdata->orig_size.width, sb->cfdata->orig_size.height,
@ -147,14 +143,14 @@ _surebox_text_fill(SureBox *sb)
{
if (sb->cfdata->has_rates)
snprintf(buf, sizeof(buf),
_("Does this look OK? Press <hilight>Yes</hilight> if it does, or No if not.<br>"
_("Does this look OK? <hilight>Save</hilight> if it does, or restore if not.<br>"
"If you do not press a button, the old resolution of<br>"
"%dx%d at %d Hz will be restored <hilight>IMMEDIATELY</hilight>."),
sb->cfdata->orig_size.width, sb->cfdata->orig_size.height,
sb->cfdata->orig_rate.rate);
else
snprintf(buf, sizeof(buf),
_("Does this look OK? Press <hilight>Yes</hilight> if it does, or No if not.<br>"
_("Does this look OK? <hilight>Save</hilight> if it does, or restore if not.<br>"
"If you do not press a button, the old resolution of<br>"
"%dx%d will be restored <hilight>IMMEDIATELY</hilight>."),
sb->cfdata->orig_size.width, sb->cfdata->orig_size.height);
@ -172,25 +168,7 @@ _surebox_timer_cb(void *data)
_surebox_text_fill(sb);
if (sb->iterations == 0)
{
Eina_List *l;
ecore_x_randr_screen_refresh_rate_set(sb->dia->win->container->manager->root,
sb->cfdata->orig_size, sb->cfdata->orig_rate);
for (l = sb->cfdata->resolutions; l; l = l->next)
{
Resolution *res = l->data;
if ((res->size.width == sb->cfdata->orig_size.width)
&& (res->size.height == sb->cfdata->orig_size.height))
{
e_widget_ilist_selected_set(sb->cfdata->res_list, res->id);
break;
}
}
_load_rates(sb->cfdata);
sb->timer = NULL;
e_object_del(E_OBJECT(sb->dia));
sb->dia = NULL;
_surebox_dialog_cb_no(sb, sb->dia);
return 0;
}
return 1;
@ -210,10 +188,11 @@ _surebox_new(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
cfdata->surebox = sb;
sb->dia->data = sb;
e_dialog_title_set(sb->dia, _("Resolution change"));
e_dialog_icon_set(sb->dia, "enlightenment/screen_resolution", 48);
_surebox_text_fill(sb);
e_win_delete_callback_set(sb->dia->win, _surebox_dialog_cb_delete);
e_dialog_button_add(sb->dia, _("Yes"), NULL, _surebox_dialog_cb_yes, sb);
e_dialog_button_add(sb->dia, _("No"), NULL, _surebox_dialog_cb_no, sb);
e_dialog_button_add(sb->dia, _("Save"), NULL, _surebox_dialog_cb_yes, sb);
e_dialog_button_add(sb->dia, _("Restore"), NULL, _surebox_dialog_cb_no, sb);
e_dialog_button_focus_num(sb->dia, 1);
e_win_centered_set(sb->dia->win, 1);
e_win_borderless_set(sb->dia->win, 1);
@ -234,7 +213,7 @@ e_int_config_display(E_Container *con, const char *params __UNUSED__)
if (!ecore_x_randr_query())
{
ecore_timer_add(0.5, _deferred_noxrandr_error, NULL);
fprintf(stderr, "XRandR not present on this display. \n");
fprintf(stderr, "XRandR not present on this display.\n");
return NULL;
}
@ -244,6 +223,7 @@ e_int_config_display(E_Container *con, const char *params __UNUSED__)
v->free_cfdata = _free_data;
v->basic.apply_cfdata = _basic_apply_data;
v->basic.create_widgets = _basic_create_widgets;
v->basic.check_changed = _basic_check_changed;
v->override_auto_apply = 1;
cfd = e_config_dialog_new(con,
@ -265,12 +245,13 @@ _fill_data(E_Config_Dialog_Data *cfdata)
cfdata->restore = e_config->display_res_restore;
rots = ecore_x_randr_screen_rotations_get(man->root);
if (rots)
if (rots && rots != ECORE_X_RANDR_ROT_0)
{
cfdata->rotation = ecore_x_randr_screen_rotation_get(man->root);
cfdata->can_flip = rots & (ECORE_X_RANDR_FLIP_X | ECORE_X_RANDR_FLIP_Y);
cfdata->flip = cfdata->rotation &
(ECORE_X_RANDR_FLIP_X | ECORE_X_RANDR_FLIP_Y);
cfdata->orig_flip = cfdata->flip;
if (cfdata->rotation & (ECORE_X_RANDR_FLIP_X))
cfdata->flip_x = 1;
@ -284,6 +265,7 @@ _fill_data(E_Config_Dialog_Data *cfdata)
cfdata->rotation &
(ECORE_X_RANDR_ROT_0 | ECORE_X_RANDR_ROT_90 |
ECORE_X_RANDR_ROT_180 | ECORE_X_RANDR_ROT_270);
cfdata->orig_rotation = cfdata->rotation;
}
}
@ -299,7 +281,7 @@ _create_data(E_Config_Dialog *cfd)
}
static void
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
{
Eina_List *l, *ll;
@ -320,31 +302,54 @@ _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
E_FREE(cfdata);
}
static int
_basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
{
int r;
Resolution *res;
Ecore_X_Screen_Refresh_Rate *rt;
r = e_widget_ilist_selected_get(cfdata->res_list);
res = evas_list_nth(cfdata->resolutions, r);
r = e_widget_ilist_selected_get(cfdata->rate_list);
rt = evas_list_nth(res->rates, r);
return (e_config->display_res_restore != cfdata->restore) ||
(res->size.width != cfdata->orig_size.width) ||
(res->size.height != cfdata->orig_size.height) ||
(cfdata->has_rates && (rt->rate != cfdata->orig_rate.rate)) ||
(cfdata->can_rotate &&
(cfdata->orig_rotation != cfdata->rotation)) ||
(cfdata->can_flip &&
(((!(cfdata->orig_flip & ECORE_X_RANDR_FLIP_X)) !=
(!cfdata->flip_x)) ||
((!(cfdata->orig_flip & ECORE_X_RANDR_FLIP_Y)) !=
(!cfdata->flip_y))));
}
static int
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
const char *sel_res, *sel_rate;
Ecore_X_Screen_Size size;
Ecore_X_Screen_Refresh_Rate rate;
int r;
Resolution *res;
Ecore_X_Screen_Refresh_Rate *rate;
E_Manager *man;
sel_res = e_widget_ilist_selected_label_get(cfdata->res_list);
sel_rate = e_widget_ilist_selected_label_get(cfdata->rate_list);
if (!sel_res) return 0;
if (!sel_rate && cfdata->has_rates) return 0;
sscanf(sel_res, "%ix%i", &size.width, &size.height);
if (cfdata->has_rates) sscanf(sel_rate, "%i Hz", &rate.rate);
r = e_widget_ilist_selected_get(cfdata->res_list);
res = evas_list_nth(cfdata->resolutions, r);
r = e_widget_ilist_selected_get(cfdata->rate_list);
rate = evas_list_nth(res->rates, r);
man = e_manager_current_get();
if (!((cfdata->orig_size.width == size.width) && (cfdata->orig_size.height == size.height) &&
(cfdata->orig_rate.rate == rate.rate || !cfdata->has_rates)))
if (!((cfdata->orig_size.width == res->size.width) &&
(cfdata->orig_size.height == res->size.height) &&
(cfdata->orig_rate.rate == rate->rate || !cfdata->has_rates)))
{
if (cfdata->has_rates)
ecore_x_randr_screen_refresh_rate_set(man->root, size, rate);
ecore_x_randr_screen_refresh_rate_set(man->root, res->size, *rate);
else
ecore_x_randr_screen_size_set(man->root, size);
ecore_x_randr_screen_size_set(man->root, res->size);
if (e_config->cnfmdlg_disabled)
{
@ -372,6 +377,8 @@ _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
rot = ecore_x_randr_screen_rotation_get(man->root);
ecore_x_randr_screen_rotation_set(man->root,
cfdata->rotation | cfdata->flip);
cfdata->orig_rotation = cfdata->rotation;
cfdata->orig_flip = cfdata->flip;
e_config->display_res_rotation = cfdata->rotation | cfdata->flip;
}
else
@ -386,29 +393,27 @@ _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
static Evas_Object *
_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
{
Evas_Object *o, *of, *ob, *ot, *o2;
Evas_Object *o, *of, *ob, *ot;
E_Radio_Group *rg;
E_Manager *man;
Ecore_X_Screen_Size *sizes;
int i, s, sel = 0;
int i, s;
o = e_widget_list_add(evas, 0, 1);
o = e_widget_table_add(evas, 0);
o2 = e_widget_list_add(evas, 0, 0);
of = e_widget_framelist_add(evas, _("Resolution"), 0);
ob = e_widget_ilist_add(evas, 24, 24, NULL);
ob = e_widget_ilist_add(evas, 16, 16, NULL);
cfdata->res_list = ob;
e_widget_min_size_set(ob, 170, 215);
e_widget_framelist_object_append(of, ob);
e_widget_list_object_append(o2, of, 1, 1, 0.5);
e_widget_table_object_append(o, of, 0, 0, 1, 1, 1, 1, 1, 1);
ob = e_widget_check_add(evas, _("Restore on login"), &cfdata->restore);
e_widget_list_object_append(o2, ob, 1, 0, 0.0);
e_widget_list_object_append(o, o2, 1, 1, 0.5);
e_widget_table_object_append(o, ob, 0, 1, 2, 1, 1, 1, 0, 0);
ot = e_widget_table_add(evas, 0);
of = e_widget_framelist_add(evas, _("Refresh"), 0);
ob = e_widget_ilist_add(evas, 24, 24, NULL);
ob = e_widget_ilist_add(evas, 16, 16, NULL);
cfdata->rate_list = ob;
e_widget_min_size_set(ob, 100, 80);
e_widget_framelist_object_append(of, ob);
@ -422,8 +427,6 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
ecore_timer_add(0.5, _deferred_noxrandr_error, NULL);
else
{
Eina_List *l;
cfdata->orig_size = ecore_x_randr_current_screen_size_get(man->root);
cfdata->orig_rate = ecore_x_randr_current_screen_refresh_rate_get(man->root);
@ -457,36 +460,14 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
eina_list_count(cfdata->resolutions), _sort_resolutions);
cfdata->resolutions = eina_list_reverse(cfdata->resolutions);
evas_event_freeze(evas_object_evas_get(cfdata->res_list));
edje_freeze();
e_widget_ilist_freeze(cfdata->res_list);
i = 0;
for (l = cfdata->resolutions; l; l = l->next)
{
char buf[1024];
Resolution *res = l->data;
res->id = i++;
snprintf(buf, sizeof(buf), "%ix%i", res->size.width, res->size.height);
e_widget_ilist_append(cfdata->res_list, NULL, buf, _ilist_item_change, cfdata, NULL);
if ((res->size.width == cfdata->orig_size.width) &&
(res->size.height == cfdata->orig_size.height))
sel = res->id;
}
_load_resolutions(cfdata);
if (!cfdata->has_rates)
ecore_timer_add(0.5, _deferred_norates_error, NULL);
}
E_FREE(sizes);
e_widget_ilist_go(cfdata->res_list);
e_widget_ilist_selected_set(cfdata->res_list, sel);
_load_rates(cfdata);
e_widget_ilist_thaw(cfdata->res_list);
edje_thaw();
evas_event_thaw(evas_object_evas_get(cfdata->res_list));
if (cfdata->can_rotate)
{
@ -512,15 +493,15 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
of = e_widget_framelist_add(evas, _("Mirroring"), 0);
ob = e_widget_check_icon_add(evas, NULL, "enlightenment/screen_hflip", 24, 24, &(cfdata->flip_x));
e_widget_framelist_object_append(of, ob);
if (!(cfdata->can_rotate & ECORE_X_RANDR_FLIP_X)) e_widget_disabled_set(ob, 1);
if (!(cfdata->can_flip & ECORE_X_RANDR_FLIP_X)) e_widget_disabled_set(ob, 1);
ob = e_widget_check_icon_add(evas, NULL, "enlightenment/screen_vflip", 24, 24, &(cfdata->flip_y));
e_widget_framelist_object_append(of, ob);
if (!(cfdata->can_rotate & ECORE_X_RANDR_FLIP_Y))
if (!(cfdata->can_flip & ECORE_X_RANDR_FLIP_Y))
e_widget_disabled_set(ob, 1);
e_widget_table_object_append(ot, of, 0, 2, 1, 1, 1, 0, 1, 0);
}
e_widget_list_object_append(o, ot, 1, 1, 0.5);
e_widget_table_object_append(o, ot, 1, 0, 1, 1, 1, 1, 1, 1);
e_dialog_resizable_set(cfd->dia, 1);
return o;
}
@ -538,14 +519,76 @@ _sort_resolutions(const void *d1, const void *d2)
return -1;
}
static void
_load_resolutions(E_Config_Dialog_Data *cfdata)
{
int i, sel = 0;
Evas *evas;
Eina_List *l;
evas = evas_object_evas_get(cfdata->res_list);
if (e_widget_ilist_count(cfdata->res_list) !=
eina_list_count(cfdata->resolutions))
{
evas_event_freeze(evas);
edje_freeze();
e_widget_ilist_freeze(cfdata->res_list);
e_widget_ilist_clear(cfdata->res_list);
for (l = cfdata->resolutions, i = 0; l; l = l->next, i++)
{
char buf[1024];
Resolution *res = l->data;
Evas_Object *ob = NULL;
res->id = i;
snprintf(buf, sizeof(buf), "%ix%i", res->size.width, res->size.height);
if ((res->size.width == cfdata->orig_size.width) &&
(res->size.height == cfdata->orig_size.height))
{
ob = edje_object_add(evas);
e_util_edje_icon_set(ob, "enlightenment/check");
sel = res->id;
}
e_widget_ilist_append(cfdata->res_list, ob, buf, _ilist_item_change, cfdata, NULL);
}
e_widget_ilist_go(cfdata->res_list);
e_widget_ilist_selected_set(cfdata->res_list, sel);
e_widget_ilist_thaw(cfdata->res_list);
edje_thaw();
evas_event_thaw(evas);
}
else
{
for (l = cfdata->resolutions; l; l = l->next)
{
Resolution *res = l->data;
Evas_Object *ob = NULL;
if ((res->size.width == cfdata->orig_size.width) &&
(res->size.height == cfdata->orig_size.height))
{
ob = edje_object_add(evas);
e_util_edje_icon_set(ob, "enlightenment/check");
sel = res->id;
}
e_widget_ilist_nth_icon_set(cfdata->res_list, res->id, ob);
}
}
}
static void
_load_rates(E_Config_Dialog_Data *cfdata)
{
int r, k = 0, sel = 0;
char buf[16];
Evas *evas;
Eina_List *l;
evas_event_freeze(evas_object_evas_get(cfdata->rate_list));
evas = evas_object_evas_get(cfdata->rate_list);
evas_event_freeze(evas);
edje_freeze();
e_widget_ilist_freeze(cfdata->rate_list);
e_widget_ilist_clear(cfdata->rate_list);
@ -562,12 +605,18 @@ _load_rates(E_Config_Dialog_Data *cfdata)
for (ll = res->rates; ll; ll = ll->next)
{
Ecore_X_Screen_Refresh_Rate *rt;
Evas_Object *ob = NULL;
rt = ll->data;
snprintf(buf, sizeof(buf), "%i Hz", rt->rate);
e_widget_ilist_append(cfdata->rate_list, NULL, buf, NULL, NULL, NULL);
if (rt->rate == cfdata->orig_rate.rate) sel = k;
if (rt->rate == cfdata->orig_rate.rate)
{
ob = edje_object_add(evas);
e_util_edje_icon_set(ob, "enlightenment/check");
sel = k;
}
e_widget_ilist_append(cfdata->rate_list, ob, buf, NULL, NULL, NULL);
k++;
}
break;
@ -575,10 +624,10 @@ _load_rates(E_Config_Dialog_Data *cfdata)
}
e_widget_ilist_go(cfdata->rate_list);
e_widget_ilist_selected_set(cfdata->rate_list, k);
e_widget_ilist_selected_set(cfdata->rate_list, sel);
e_widget_ilist_thaw(cfdata->rate_list);
edje_thaw();
evas_event_thaw(evas_object_evas_get(cfdata->rate_list));
evas_event_thaw(evas);
}
static void
@ -588,20 +637,20 @@ _ilist_item_change(void *data)
}
static int
_deferred_noxrandr_error(void *data)
_deferred_noxrandr_error(void *data __UNUSED__)
{
e_util_dialog_show(_("Missing Features"),
_("Your X Display Server is missing support for<br>"
"the <hilight>XRandr</hilight> (X Resize and Rotate) extension.<br>"
"the <hilight>XRandR</hilight> (X Resize and Rotate) extension.<br>"
"You cannot change screen resolutions without<br>"
"the support of this extension. It could also be<br>"
"that at the time <hilight>ecore</hilight> was built, there<br>"
"was no XRandr support detected."));
"was no XRandR support detected."));
return 0;
}
static int
_deferred_norates_error(void *data)
_deferred_norates_error(void *data __UNUSED__)
{
e_util_dialog_show(_("No Refresh Rates Found"),
_("No refresh rates were reported by your X Display Server.<br>"