[PATCH xrandr] xrandr: dump configuration in parsable format
Stefan Tomanek
stefan.tomanek at wertarbyte.de
Mon Feb 13 12:40:53 PST 2012
This patch adds the command line switch "--dump" to the xrandr program.
When specified, xrandr outputs the current display configuration in an
easily parsable format similar to the command line options accepted by
xrandr itself. That way, an existing configuration can easily be saved
and restored later.
Signed-off-by: Stefan Tomanek <stefan.tomanek at wertarbyte.de>
---
man/xrandr.man | 3 +++
xrandr.c | 55 ++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 43 insertions(+), 15 deletions(-)
diff --git a/man/xrandr.man b/man/xrandr.man
index ba36ae3..41f4332 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -26,6 +26,7 @@ xrandr \- primitive command line interface to RandR extension
.B "xrandr"
[\-help] [\-display \fIdisplay\fP]
[\-q] [\-v]
+[\-\-dump]
[\-\-verbose]
[\-\-dryrun]
[\-\-screen \fIsnum\fP]
@@ -110,6 +111,8 @@ reported while executing the configuration changes.
.IP "\-q, \-\-query"
When this option is present, or when no configuration changes are requested,
xrandr will display the current state of the system.
+.IP "\-\-dump"
+Dump the current display configuration in an easily parsable format.
.IP "\-\-dryrun"
Performs all the actions specified except that no changes are made.
.IP "\-\-nograb"
diff --git a/xrandr.c b/xrandr.c
index 35dff3e..78818b9 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -144,6 +144,7 @@ usage(void)
fprintf(stderr, " --rmmode <name>\n");
fprintf(stderr, " --addmode <output> <name>\n");
fprintf(stderr, " --delmode <output> <name>\n");
+ fprintf(stderr, " --dump\n");
exit(1);
/*NOTREACHED*/
@@ -2169,6 +2170,7 @@ main (int argc, char **argv)
Bool modeit = False;
Bool propit = False;
Bool query_1 = False;
+ Bool dump = False;
int major, minor;
Bool current = False;
@@ -2260,6 +2262,10 @@ main (int argc, char **argv)
query = True;
continue;
}
+ if (!strcmp ("--dump", argv[i])) {
+ dump = True;
+ continue;
+ }
if (!strcmp ("-o", argv[i]) || !strcmp ("--orientation", argv[i])) {
char *endptr;
if (++i>=argc) usage ();
@@ -2925,11 +2931,13 @@ main (int argc, char **argv)
get_screen (current);
get_crtcs ();
get_outputs ();
-
- printf ("Screen %d: minimum %d x %d, current %d x %d, maximum %d x %d\n",
+ if (!dump)
+ {
+ printf ("Screen %d: minimum %d x %d, current %d x %d, maximum %d x %d\n",
screen, minWidth, minHeight,
DisplayWidth (dpy, screen), DisplayHeight(dpy, screen),
maxWidth, maxHeight);
+ }
for (output = outputs; output; output = output->next)
{
@@ -2942,28 +2950,38 @@ main (int argc, char **argv)
Bool *mode_shown;
Rotation rotations = output_rotations (output);
- printf ("%s %s", output_info->name, connection[output_info->connection]);
+ printf ( dump ? "output %s\n" : "%s %s", output_info->name, connection[output_info->connection]);
+ if (dump && output_is_primary(output))
+ {
+ printf( "primary\n" );
+ }
+
if (mode)
{
if (crtc_info) {
- printf (" %dx%d+%d+%d",
+ printf ( dump ? "mode %dx%d\npos %dx%d\n" : " %dx%d+%d+%d",
crtc_info->width, crtc_info->height,
crtc_info->x, crtc_info->y);
} else {
- printf (" %dx%d+%d+%d",
- mode->width, mode->height, output->x, output->y);
+ printf ( dump ? "mode %dx%d\npos %dx%d\n" : " %dx%d+%d+%d",
+ mode->width, mode->height, output->x, output->y);
}
- if (verbose)
+ if (verbose && !dump)
printf (" (0x%x)", (int)mode->id);
- if (output->rotation != RR_Rotate_0 || verbose)
+ if (output->rotation != RR_Rotate_0 || verbose || dump)
{
- printf (" %s",
+ printf ( dump ? "rotate %s\n" : " %s",
rotation_name (output->rotation));
if (output->rotation & (RR_Reflect_X|RR_Reflect_Y))
- printf (" %s", reflection_name (output->rotation));
+ printf ( dump ? "reflect %s\n" : " %s", reflection_name (output->rotation));
+ }
+ } else {
+ if (dump)
+ {
+ printf( "off\n" );
}
}
- if (rotations != RR_Rotate_0 || verbose)
+ if (!dump && (rotations != RR_Rotate_0 || verbose))
{
Bool first = True;
printf (" (");
@@ -2986,7 +3004,7 @@ main (int argc, char **argv)
printf (")");
}
- if (mode)
+ if (!dump && mode)
{
printf (" %dmm x %dmm",
(int)output_info->mm_width, (int)output_info->mm_height);
@@ -2995,7 +3013,7 @@ main (int argc, char **argv)
if (crtc && crtc->panning_info && crtc->panning_info->width > 0)
{
XRRPanning *pan = crtc->panning_info;
- printf (" panning %dx%d+%d+%d",
+ printf ( dump ? "panning %dx%d+%d+%d" : " panning %dx%d+%d+%d",
pan->width, pan->height, pan->left, pan->top);
if ((pan->track_width != 0 &&
(pan->track_left != pan->left ||
@@ -3007,12 +3025,19 @@ main (int argc, char **argv)
pan->track_height != pan->height ||
pan->border_top != 0 ||
pan->border_bottom != 0)))
- printf (" tracking %dx%d+%d+%d border %d/%d/%d/%d",
+ printf ( dump ? "/%dx%d+%d+%d/%d/%d/%d/%d\n" : "tracking %dx%d+%d+%d border %d/%d/%d/%d",
pan->track_width, pan->track_height,
pan->track_left, pan->track_top,
pan->border_left, pan->border_top,
pan->border_right, pan->border_bottom);
}
+
+ /* If we are dumping our configuration, we end the loop here */
+ if (dump)
+ {
+ continue;
+ }
+
printf ("\n");
if (verbose)
@@ -3227,7 +3252,7 @@ main (int argc, char **argv)
{
XRRModeInfo *mode = &res->modes[m];
- if (!(mode->modeFlags & ModeShown))
+ if (!(mode->modeFlags & ModeShown) && !dump)
{
printf (" %s (0x%x) %6.1fMHz\n",
mode->name, (int)mode->id,
--
1.7.9
More information about the xorg-devel
mailing list