72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
from pathlib import Path
|
||
|
|
||
|
import i3ipc
|
||
|
|
||
|
import Xlib.display
|
||
|
from Xlib.ext import randr
|
||
|
|
||
|
i3 = i3ipc.Connection()
|
||
|
|
||
|
|
||
|
def iter_outputs():
|
||
|
display = Xlib.display.Display()
|
||
|
screen_root = display.screen().root
|
||
|
res = randr.get_screen_resources(screen_root)
|
||
|
primary_display_id = screen_root.xrandr_get_output_primary().output
|
||
|
|
||
|
for output in sorted(res.outputs, key=lambda o: o != primary_display_id):
|
||
|
params = display.xrandr_get_output_info(output, res.config_timestamp)
|
||
|
if not params.crtc: # skip inactive
|
||
|
continue
|
||
|
yield params.name, output == primary_display_id
|
||
|
|
||
|
|
||
|
def workspaces_for_output(name, primary):
|
||
|
if primary:
|
||
|
yield "# Primary Monitor"
|
||
|
workspaces = range(1, 11)
|
||
|
else:
|
||
|
yield "# Secondary Monitor"
|
||
|
workspaces = range(11, 21)
|
||
|
|
||
|
for workspace in workspaces:
|
||
|
yield f"workspace {workspace} output {name}"
|
||
|
|
||
|
|
||
|
with open(Path(__file__).parent / "include/dynamic.conf", "w") as f:
|
||
|
f.write(
|
||
|
"\n\n".join(
|
||
|
"\n".join(workspaces_for_output(output, primary))
|
||
|
for output, primary in iter_outputs()
|
||
|
)
|
||
|
)
|
||
|
f.write("\n")
|
||
|
|
||
|
|
||
|
# outputs = i3.get_outputs()
|
||
|
|
||
|
|
||
|
# def workspaces_for_output(output: i3ipc.OutputReply):
|
||
|
# if output.primary:
|
||
|
# yield "# Primary Monitor"
|
||
|
# workspaces = range(1, 11)
|
||
|
# else:
|
||
|
# yield "# Secondary Monitor"
|
||
|
# workspaces = range(11, 21)
|
||
|
|
||
|
# for workspace in workspaces:
|
||
|
# yield f"workspace {workspace} output {output.name}"
|
||
|
|
||
|
|
||
|
# with open(Path(__file__).parent / "include/dynamic.conf", "w") as f:
|
||
|
# f.write(
|
||
|
# "\n\n".join(
|
||
|
# "\n".join(workspaces_for_output(output))
|
||
|
# for output in sorted(outputs, key=lambda o: o.primary, reverse=True)
|
||
|
# if output.active
|
||
|
# )
|
||
|
# )
|
||
|
# f.write("\n")
|