mirror of
https://github.com/starr-dusT/dotfiles.git
synced 2025-02-19 19:27:31 -08:00
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
#!/usr/bin/python
|
|
#
|
|
import subprocess
|
|
import json
|
|
import pathlib
|
|
import os
|
|
|
|
# save needed information in a dictionary
|
|
i3_dict = {}
|
|
|
|
cmd = str(subprocess.check_output("xrandr", shell=True))
|
|
outputs = []
|
|
|
|
for row in cmd.split('\\n'):
|
|
if " connected" in row:
|
|
outputs.append(row.split(" ")[0])
|
|
|
|
print("Available monitors:")
|
|
for output in outputs:
|
|
print(output)
|
|
|
|
if len(outputs) == 1:
|
|
print("skipping input only one monitor...")
|
|
os.system("xrandr --output %s --mode 2560x1440 --rate 144 --primary"%(outputs[0]))
|
|
elif len(outputs) == 2:
|
|
left = input('which monitor is on the left? ')
|
|
if left not in outputs:
|
|
# crash
|
|
0/0
|
|
outputs.remove(left)
|
|
right = outputs[0]
|
|
left_primary = input('is left primary? (y or n) ')
|
|
|
|
left_pri_str = "--primary" if left_primary == 'y' else ""
|
|
right_pri_str = "--primary" if left_primary == 'n' else ""
|
|
|
|
cmd_str = "xrandr --output %s --mode 2560x1440 --pos 0x0 --rate 144 %s --output %s --mode 2560x1440 --pos 2561x0 --rate 144 %s --right-of %s"%(left, left_pri_str, right, right_pri_str, left)
|
|
print(cmd_str)
|
|
os.system(cmd_str)
|
|
|
|
else:
|
|
#crash
|
|
0/0
|
|
|
|
|
|
os.system("autorandr --save current --force")
|
|
|
|
# ask user to define primary and secondary monitor
|
|
i3_dict["disp_pri"] = left if left_primary == 'y' else right
|
|
i3_dict["disp_sec"] = left if left_primary == 'n' else right
|
|
|
|
print(i3_dict["disp_pri"], i3_dict["disp_sec"])
|
|
|
|
# write result to json
|
|
p = pathlib.Path('{{ .chezmoi.sourceDir }}/.gen/i3.json')
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(p, 'w') as f:
|
|
json.dump(i3_dict, f, indent=4, sort_keys=True)
|