[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Improve the calculation of the preferred mode
Jérôme Guelfucci
noreply at xfce.org
Fri Jun 25 23:58:02 CEST 2010
Updating branch refs/heads/xrandr-display-settings
to 62bb60c1257463faee602e3ef7ebca5eda3756fe (commit)
from 576a0241156e2063406aacb0ea85e5d82f26b57c (commit)
commit 62bb60c1257463faee602e3ef7ebca5eda3756fe
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date: Fri Jun 25 21:16:40 2010 +0200
Improve the calculation of the preferred mode
Instead of taking the first one from the list, use the same algorithm as xrandr
(more consistent).
dialogs/display-settings/main.c | 8 ++----
dialogs/display-settings/xfce-randr.c | 38 +++++++++++++++++++++++++++++++++
dialogs/display-settings/xfce-randr.h | 5 +++-
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index b390b71..a1262ff 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -518,7 +518,7 @@ display_setting_output_toggled (GtkToggleButton *togglebutton,
if (is_active && XFCE_RANDR_MODE (xfce_randr) == None)
XFCE_RANDR_MODE (xfce_randr) =
- XFCE_RANDR_OUTPUT_INFO (xfce_randr)->modes[XFCE_RANDR_OUTPUT_INFO (xfce_randr)->npreferred];
+ xfce_randr_preferred_mode (xfce_randr, xfce_randr->active_output);
else if (!is_active && XFCE_RANDR_MODE (xfce_randr) != None)
XFCE_RANDR_MODE (xfce_randr) = None;
@@ -900,14 +900,12 @@ display_settings_minimal_dialog_response (GtkDialog *dialog,
if (use_first_screen)
{
- xfce_randr->mode[first] =
- xfce_randr->output_info[first]->modes[xfce_randr->output_info[first]->npreferred];
+ xfce_randr->mode[first] = xfce_randr_preferred_mode (xfce_randr, first);
xfce_randr->mode[second] = None;
}
else if (use_second_screen)
{
- xfce_randr->mode[second] =
- xfce_randr->output_info[second]->modes[xfce_randr->output_info[second]->npreferred];
+ xfce_randr->mode[second] = xfce_randr_preferred_mode (xfce_randr, second);
xfce_randr->mode[first] = None;
}
else
diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index ae87c30..69d137a 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -615,4 +615,42 @@ xfce_randr_find_mode_by_id (XfceRandr *randr,
return NULL;
}
+
+
+RRMode
+xfce_randr_preferred_mode (XfceRandr *randr,
+ guint output)
+{
+ RRMode best_mode;
+ gint best_dist, dist, n;
+
+ g_return_val_if_fail (randr != NULL, None);
+ g_return_val_if_fail (output < randr->noutput, None);
+
+ /* mimic xrandr's preferred_mode () */
+
+ best_mode = None;
+ best_dist = 0;
+ for (n = 0; n < randr->output_info[output]->nmode; ++n)
+ {
+ if (n < randr->output_info[output]->npreferred)
+ dist = 0;
+ else if (randr->output_info[output]->mm_height != 0)
+ dist = (1000 * gdk_screen_height () / gdk_screen_height_mm () -
+ 1000 * randr->modes[output][n].height /
+ randr->output_info[output]->mm_height);
+ else
+ dist = gdk_screen_height () - randr->modes[output][n].height;
+
+ dist = ABS (dist);
+
+ if (best_mode == None || dist < best_dist)
+ {
+ best_mode = randr->modes[output][n].id;
+ best_dist = dist;
+ }
+ }
+ return best_mode;
+}
+
#endif /* !HAS_RANDR_ONE_POINT_TWO */
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 28c3732..400192d 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -110,7 +110,7 @@ struct _XfceRandr
-XfceRandr *xfce_randr_new (GdkDisplay *display,
+XfceRandr *xfce_randr_new (GdkDisplay *display,
GError **error);
void xfce_randr_free (XfceRandr *randr);
@@ -133,6 +133,9 @@ XfceRRMode *xfce_randr_find_mode_by_id (XfceRandr *randr,
guint output,
RRMode id);
+RRMode xfce_randr_preferred_mode (XfceRandr *randr,
+ guint output);
+
#endif /* !HAS_RANDR_ONE_POINT_TWO */
#endif /* !__XFCE_RANDR_H__ */
More information about the Xfce4-commits
mailing list