tools/get-state: Add --short

Often, most of the output consists of a long list of exposed modes for
each monitor. If --short is passed, only pass modes that has properties.
In practice, this means "preferred" modes, "current" modes, and
similarly special cases, which significantly reduces noise.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2448>
This commit is contained in:
Jonas Ådahl 2022-06-02 17:44:25 +02:00 committed by Marge Bot
parent e883046c5f
commit 8d8694fd08

View File

@ -16,6 +16,7 @@ class Source(enum.Enum):
parser = argparse.ArgumentParser(description='Get display state') parser = argparse.ArgumentParser(description='Get display state')
parser.add_argument('file', metavar='FILE', type=str, nargs='?', parser.add_argument('file', metavar='FILE', type=str, nargs='?',
help='Read the output from gdbus call instead of calling D-Bus') help='Read the output from gdbus call instead of calling D-Bus')
parser.add_argument('--short', action='store_true')
args = parser.parse_args() args = parser.parse_args()
@ -25,6 +26,8 @@ if args.file:
else: else:
source = Source.DBUS source = Source.DBUS
short = args.short
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})' type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
variant_type = GLib.VariantType.new(type_signature) variant_type = GLib.VariantType.new(type_signature)
@ -106,7 +109,15 @@ for monitor in monitors:
properties = monitor[2] properties = monitor[2]
print_data(0, is_last, lines, 'Monitor {}'.format(spec[0])) print_data(0, is_last, lines, 'Monitor {}'.format(spec[0]))
print_data(1, False, lines, f'EDID: vendor: {spec[1]}, product: {spec[2]}, serial: {spec[3]}') print_data(1, False, lines, f'EDID: vendor: {spec[1]}, product: {spec[2]}, serial: {spec[3]}')
print_data(1, False, lines, f'Modes ({len(modes)})')
mode_count = len(modes)
if short:
modes = [mode for mode in modes if len(mode[6]) > 0]
print_data(1, False, lines,
f'Modes ({len(modes)}, {mode_count - len(modes)} omitted)')
else:
print_data(1, False, lines,
f'Modes ({len(modes)})')
for mode in modes: for mode in modes:
is_last = mode == modes[-1] is_last = mode == modes[-1]