[PATCH] Add --output-index, to select an output with a numerical ID instead of a name or XID.

Arthur HUILLET arthur.huillet at free.fr
Thu Mar 10 10:14:51 PST 2011


This provides a way for distribution/user scripts to refer to "the first output" independantly of their names.
Additionally, given that the actual name of the output can change over the course of driver upgrades, this provides a
way of not having to change one's scripts after an upgrade.

Signed-off-by: Arthur HUILLET <arthur.huillet at free.fr>
---
 man/xrandr.man |    3 +++
 xrandr.c       |   23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/man/xrandr.man b/man/xrandr.man
index ba36ae3..152990b 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -241,6 +241,9 @@ Remove a mode from the set of valid modes for an output.
 .IP "\-\-output \fIoutput\fP"
 Selects an output to reconfigure. Use either the name of the output or the
 XID.
+.IP "\-\-output-index \fIoutput index\fP"
+Selects an output to reconfigure. Use either the numerical index of the input
+starting at 0.
 .IP \-\-auto
 For connected but disabled outputs, this will enable them using their
 preferred mode (or, something close to 96dpi if they have no preferred
diff --git a/xrandr.c b/xrandr.c
index 558fa45..a7dc428 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -678,6 +678,16 @@ find_output_by_name (char *name)
     return find_output (&output_name);
 }
 
+static output_t *
+find_output_by_index (int index)
+{
+    name_t  output_name;
+
+    init_name (&output_name);
+    set_name_index (&output_name, index);
+    return find_output (&output_name);
+}
+
 static crtc_t *
 find_crtc (name_t *name)
 {
@@ -2290,6 +2300,19 @@ main (int argc, char **argv)
 	    action_requested = True;
 	    continue;
 	}
+	if (!strcmp ("--output-index", argv[i])) {
+	    if (++i >= argc) usage();
+
+	    output = find_output_by_index (atoi(argv[i]));
+	    if (!output) {
+		output = add_output ();
+		set_name (&output->output, argv[i], name_index);
+	    }
+	    
+	    setit_1_2 = True;
+	    action_requested = True;
+	    continue;
+	}
 	if (!strcmp ("--crtc", argv[i])) {
 	    if (++i >= argc) usage();
 	    if (!output) usage();
-- 
1.7.4.1




More information about the xorg-devel mailing list