Use script to bind workspaces to primary/nonprimary displays

This was a bit janky (and so never made it off my desktop), but
necessary until 4.22, which added `output nonprimary`
This commit is contained in:
Adam Goldsmith 2023-01-02 12:55:59 -05:00
parent 306548b39d
commit fdfd0c045f
2 changed files with 74 additions and 25 deletions

View File

@ -4,12 +4,13 @@
# variables for use later
set $mod Mod4
set $mon1 DP-0
set $mon2 LVDS-0
set $config_dir ~/.config/i3
include include/`hostname`.conf
exec_always $config_dir/monitor_workspaces.py
include include/dynamic.conf
## Startup Applications ##
exec --no-startup-id ~/.fehbg
exec --no-startup-id xfce4-panel -d
@ -210,29 +211,6 @@ bindsym --whole-window $mod+Shift+button1 mark --add quickswap; mode "swap-dest"
bindsym $mod+Mod1+comma mark --add quickswap
bindsym $mod+comma swap container with mark quickswap; [con_mark="quickswap"] focus; unmark quickswap
# bind workspaces 1-10 to monitor 1, 11-20 to monitor 2
workspace 1 output $mon1
workspace 2 output $mon1
workspace 3 output $mon1
workspace 4 output $mon1
workspace 5 output $mon1
workspace 6 output $mon1
workspace 7 output $mon1
workspace 8 output $mon1
workspace 9 output $mon1
workspace 10 output $mon1
workspace 11 output $mon2
workspace 12 output $mon2
workspace 13 output $mon2
workspace 14 output $mon2
workspace 15 output $mon2
workspace 16 output $mon2
workspace 17 output $mon2
workspace 18 output $mon2
workspace 19 output $mon2
workspace 20 output $mon2
# switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2

View File

@ -0,0 +1,71 @@
#!/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")