mirror of
https://github.com/brl/mutter.git
synced 2024-12-26 04:42:14 +00:00
get-state: Move code into __main__ functions
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2448>
This commit is contained in:
parent
8d8694fd08
commit
40509154fb
@ -13,41 +13,6 @@ class Source(enum.Enum):
|
||||
FILE = 2
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Get display state')
|
||||
parser.add_argument('file', metavar='FILE', type=str, nargs='?',
|
||||
help='Read the output from gdbus call instead of calling D-Bus')
|
||||
parser.add_argument('--short', action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.file:
|
||||
source = Source.FILE
|
||||
path = args.file
|
||||
else:
|
||||
source = Source.DBUS
|
||||
|
||||
short = args.short
|
||||
|
||||
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
|
||||
variant_type = GLib.VariantType.new(type_signature)
|
||||
|
||||
if source == Source.DBUS:
|
||||
command = 'gdbus call -e '\
|
||||
'-d org.gnome.Mutter.DisplayConfig '\
|
||||
'-o /org/gnome/Mutter/DisplayConfig '\
|
||||
'-m org.gnome.Mutter.DisplayConfig.GetCurrentState'
|
||||
result = subprocess.run(command,
|
||||
shell=True, check=True, capture_output=True, text=True)
|
||||
data = result.stdout
|
||||
else:
|
||||
if path == '-':
|
||||
data = sys.stdin.read()
|
||||
else:
|
||||
with open(path) as file:
|
||||
data = file.read()
|
||||
|
||||
variant = GLib.variant_parse(variant_type, data)
|
||||
|
||||
def transform_to_string(transform):
|
||||
match transform:
|
||||
case 0: return 'normal'
|
||||
@ -97,6 +62,35 @@ def print_properties(level, lines, properties):
|
||||
print_data(level + 1, is_last, lines,
|
||||
f'{property} ⇒ {properties[property]}')
|
||||
|
||||
def print_current_state(args):
|
||||
if args.file:
|
||||
source = Source.FILE
|
||||
path = args.file
|
||||
else:
|
||||
source = Source.DBUS
|
||||
|
||||
short = args.short
|
||||
|
||||
type_signature = '(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})'
|
||||
variant_type = GLib.VariantType.new(type_signature)
|
||||
|
||||
if source == Source.DBUS:
|
||||
command = 'gdbus call -e '\
|
||||
'-d org.gnome.Mutter.DisplayConfig '\
|
||||
'-o /org/gnome/Mutter/DisplayConfig '\
|
||||
'-m org.gnome.Mutter.DisplayConfig.GetCurrentState'
|
||||
result = subprocess.run(command,
|
||||
shell=True, check=True, capture_output=True, text=True)
|
||||
data = result.stdout
|
||||
else:
|
||||
if path == '-':
|
||||
data = sys.stdin.read()
|
||||
else:
|
||||
with open(path) as file:
|
||||
data = file.read()
|
||||
|
||||
variant = GLib.variant_parse(variant_type, data)
|
||||
|
||||
print('Serial: {}'.format(variant[0]))
|
||||
print()
|
||||
print('Monitors:')
|
||||
@ -108,7 +102,8 @@ for monitor in monitors:
|
||||
modes = monitor[1]
|
||||
properties = monitor[2]
|
||||
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]}')
|
||||
|
||||
mode_count = len(modes)
|
||||
if short:
|
||||
@ -164,3 +159,14 @@ for logical_monitor in logical_monitors:
|
||||
properties = variant[3]
|
||||
print()
|
||||
print_properties(-1, lines, properties)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Get display state')
|
||||
parser.add_argument('file', metavar='FILE', type=str, nargs='?',
|
||||
help='Read the output from gdbus call instead of calling D-Bus')
|
||||
parser.add_argument('--short', action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print_current_state(args)
|
||||
|
Loading…
Reference in New Issue
Block a user