From 410575cc9a214cad430a0903bc4c757842983d31 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 10 Oct 2011 00:45:18 +0200 Subject: [PATCH 2/2] code refactoring: new function mode_show_verbose this reduces code duplication and discrepancies between outputs of assigned and unassigned modes (as discussed in bug 35149) --- xrandr.c | 56 ++++++++++++++++++++++++++------------------------------ 1 files changed, 26 insertions(+), 30 deletions(-) diff --git a/xrandr.c b/xrandr.c index 8bb737d..27ebdc1 100644 --- a/xrandr.c +++ b/xrandr.c @@ -2127,6 +2127,30 @@ check_strtod(char *s) return result; } +static void +mode_show_verbose(XRRModeInfo *mode, Bool is_preferred, Bool is_current) +{ + int f; + + printf (" %s (0x%x) %6.1fMHz", + mode->name, (int)mode->id, + (double)mode->dotClock / 1000000.0); + for (f = 0; mode_flags[f].flag; f++) + if (mode->modeFlags & mode_flags[f].flag) + printf (" %s", mode_flags[f].string); + if (is_current) + printf (" *current"); + if (is_preferred) + printf (" +preferred"); + printf ("\n"); + printf (" h: width %4d start %4d end %4d total %4d skew %4d clock %6.1fKHz\n", + mode->width, mode->hSyncStart, mode->hSyncEnd, + mode->hTotal, mode->hSkew, mode_hsync (mode) / 1000); + printf (" v: height %4d start %4d end %4d total %4d clock %6.1fHz\n", + mode->height, mode->vSyncStart, mode->vSyncEnd, mode->vTotal, + mode_refresh (mode)); +} + int main (int argc, char **argv) { @@ -3159,25 +3183,7 @@ main (int argc, char **argv) for (j = 0; j < output_info->nmode; j++) { XRRModeInfo *mode = find_mode_by_xid (output_info->modes[j]); - int f; - - printf (" %s (0x%x) %6.1fMHz", - mode->name, (int)mode->id, - (double)mode->dotClock / 1000000.0); - for (f = 0; mode_flags[f].flag; f++) - if (mode->modeFlags & mode_flags[f].flag) - printf (" %s", mode_flags[f].string); - if (mode == output->mode_info) - printf (" *current"); - if (j < output_info->npreferred) - printf (" +preferred"); - printf ("\n"); - printf (" h: width %4d start %4d end %4d total %4d skew %4d clock %6.1fKHz\n", - mode->width, mode->hSyncStart, mode->hSyncEnd, - mode->hTotal, mode->hSkew, mode_hsync (mode) / 1000); - printf (" v: height %4d start %4d end %4d total %4d clock %6.1fHz\n", - mode->height, mode->vSyncStart, mode->vSyncEnd, mode->vTotal, - mode_refresh (mode)); + mode_show_verbose(mode, j < output_info->npreferred, mode == output->mode_info); mode->modeFlags |= ModeShown; } } @@ -3223,17 +3229,7 @@ main (int argc, char **argv) XRRModeInfo *mode = &res->modes[m]; if (!(mode->modeFlags & ModeShown)) - { - printf (" %s (0x%x) %6.1fMHz\n", - mode->name, (int)mode->id, - (double)mode->dotClock / 1000000.0); - printf (" h: width %4d start %4d end %4d total %4d skew %4d clock %6.1fKHz\n", - mode->width, mode->hSyncStart, mode->hSyncEnd, - mode->hTotal, mode->hSkew, mode_hsync (mode) / 1000); - printf (" v: height %4d start %4d end %4d total %4d clock %6.1fHz\n", - mode->height, mode->vSyncStart, mode->vSyncEnd, mode->vTotal, - mode_refresh (mode)); - } + mode_show_verbose(mode, False, False); } exit (0); } -- 1.7.6.3