[PATCH 2/2] xrandr: generalize output property printing
Andy Ritger
aritger at nvidia.com
Fri Sep 7 17:58:46 PDT 2012
Signed-off-by: Andy Ritger <aritger at nvidia.com>
Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
---
xrandr.c | 182 ++++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 125 insertions(+), 57 deletions(-)
diff --git a/xrandr.c b/xrandr.c
index d5f0d5a..548015c 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -36,6 +36,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <math.h>
@@ -2293,6 +2294,81 @@ property_values_from_string(const char *str, const Atom type, const int format,
}
+static void
+print_output_property_value(Bool is_edid,
+ int value_format, /* 8, 16, 32 */
+ Atom value_type, /* XA_{ATOM,INTEGER,CARDINAL} */
+ const void *value_bytes)
+{
+ /* special-case the EDID */
+ if (is_edid && value_format == 8)
+ {
+ const uint8_t *val = value_bytes;
+ printf ("%02" PRIx8, *val);
+ return;
+ }
+
+ if (value_type == XA_ATOM && value_format == 32)
+ {
+ const Atom *val = value_bytes;
+ char *str = XGetAtomName (dpy, *val);
+ if (str != NULL)
+ {
+ printf ("%s", str);
+ XFree (str);
+ return;
+ }
+ }
+
+ if (value_type == XA_INTEGER)
+ {
+ if (value_format == 8)
+ {
+ const int8_t *val = value_bytes;
+ printf ("%" PRId8, *val);
+ return;
+ }
+ if (value_format == 16)
+ {
+ const int16_t *val = value_bytes;
+ printf ("%" PRId16, *val);
+ return;
+ }
+ if (value_format == 32)
+ {
+ const int32_t *val = value_bytes;
+ printf ("%" PRId32, *val);
+ return;
+ }
+ }
+
+ if (value_type == XA_CARDINAL)
+ {
+ if (value_format == 8)
+ {
+ const uint8_t *val = value_bytes;
+ printf ("%" PRIu8, *val);
+ return;
+ }
+ if (value_format == 16)
+ {
+ const uint16_t *val = value_bytes;
+ printf ("%" PRIu16, *val);
+ return;
+ }
+ if (value_format == 32)
+ {
+ const uint32_t *val = value_bytes;
+ printf ("%" PRIu32, *val);
+ return;
+ }
+ }
+
+ printf ("?");
+}
+
+
+
int
main (int argc, char **argv)
{
@@ -3311,7 +3387,10 @@ main (int argc, char **argv)
unsigned long nitems, bytes_after;
Atom actual_type;
XRRPropertyInfo *propinfo;
-
+ char *atom_name = XGetAtomName (dpy, props[j]);
+ Bool is_edid = strcmp (atom_name, "EDID") == 0;
+ int bytes_per_item;
+
XRRGetOutputProperty (dpy, output->output.xid, props[j],
0, 100, False, False,
AnyPropertyType,
@@ -3321,70 +3400,59 @@ main (int argc, char **argv)
propinfo = XRRQueryOutputProperty(dpy, output->output.xid,
props[j]);
- if (actual_type == XA_INTEGER && actual_format == 8) {
- int k;
-
- printf("\t%s:\n", XGetAtomName (dpy, props[j]));
- for (k = 0; k < nitems; k++) {
- if (k % 16 == 0)
- printf ("\t\t");
- printf("%02x", (unsigned char)prop[k]);
- if (k % 16 == 15)
- printf("\n");
- }
- } else if (actual_type == XA_INTEGER &&
- actual_format == 32)
- {
- printf("\t%s: ", XGetAtomName (dpy, props[j]));
- for (k = 0; k < nitems; k++) {
- if (k > 0)
- printf ("\n\t\t\t");
- printf("%d (0x%08x)",
- (int)((INT32 *)prop)[k], (int)((INT32 *)prop)[k]);
- }
+ bytes_per_item = actual_format / 8;
- if (propinfo->range && propinfo->num_values > 0) {
- if (nitems > 1)
- printf ("\n\t\t");
- printf("\trange%s: ",
- (propinfo->num_values == 2) ? "" : "s");
+ printf ("\t%s: ", atom_name);
- for (k = 0; k < propinfo->num_values / 2; k++)
- printf(" (%d,%d)", (int)propinfo->values[k * 2],
- (int)propinfo->values[k * 2 + 1]);
- }
+ if (is_edid)
+ {
+ printf ("\n\t\t");
+ }
- printf("\n");
- } else if (actual_type == XA_ATOM &&
- actual_format == 32)
+ for (k = 0; k < nitems; k++)
{
- printf("\t%s:", XGetAtomName (dpy, props[j]));
- for (k = 0; k < nitems; k++) {
- if (k > 0 && (k & 1) == 0)
+ if (k != 0)
+ {
+ if ((k % 16) == 0)
+ {
printf ("\n\t\t");
- printf("\t%s", XGetAtomName (dpy, ((Atom *)prop)[k]));
+ }
}
+ print_output_property_value (is_edid, actual_format,
+ actual_type,
+ prop + (k * bytes_per_item));
+ if (!is_edid)
+ {
+ printf (" ");
+ }
+ }
+ printf ("\n");
- if (!propinfo->range && propinfo->num_values > 0) {
- printf("\n\t\tsupported:");
-
- for (k = 0; k < propinfo->num_values; k++)
- {
- printf(" %-12.12s", XGetAtomName (dpy,
- propinfo->values[k]));
- if (k % 4 == 3 && k < propinfo->num_values - 1)
- printf ("\n\t\t ");
- }
+ if (propinfo->range && propinfo->num_values > 0)
+ {
+ printf ("\t\trange%s: ",
+ (propinfo->num_values == 2) ? "" : "s");
+ for (k = 0; k < propinfo->num_values / 2; k++)
+ {
+ printf ("(");
+ print_output_property_value (False, 32, actual_type,
+ (unsigned char *) &(propinfo->values[k * 2]));
+ printf (", ");
+ print_output_property_value (False, 32, actual_type,
+ (unsigned char *) &(propinfo->values[k * 2 + 1]));
+ printf (")");
+ }
+ printf ("\n");
+ }
+ if (!propinfo->range && propinfo->num_values > 0)
+ {
+ printf ("\t\tsupported: ");
+ for (k = 0; k < propinfo->num_values; k++)
+ {
+ print_output_property_value (False, 32, actual_type,
+ (unsigned char *) &(propinfo->values[k]));
}
- printf("\n");
- } else if (actual_format == 8) {
- printf ("\t%s: %s%s\n", XGetAtomName (dpy, props[j]),
- prop, bytes_after ? "..." : "");
- } else {
- const char *type = actual_type ? XGetAtomName (dpy, actual_type) : "none";
- printf ("\t%s: %s(%d) (format %d items %d) ????\n",
- XGetAtomName (dpy, props[j]),
- type, (int)actual_type, actual_format, (int)nitems);
+ printf ("\n");
}
free(propinfo);
--
1.7.2.5
More information about the xorg-devel
mailing list