fix assign-workspace-monitors script
This commit is contained in:
@@ -3,11 +3,11 @@
|
|||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = [
|
||||||
'Samsung Electric Company LS27A800U HCJW301093': 1,
|
{'make': 'Samsung Electric Company', 'model': 'LS27A800U', 'position': 'left', 'workspace': 1},
|
||||||
'Seanix Technology Inc NX-EDG27X C6F0K3CN07UL': 2,
|
{'make': 'Seanix Technology Inc', 'model': 'NX-EDG27X', 'position': 'center', 'workspace': 2},
|
||||||
'BOE 0x0BCA': 3
|
{'make': 'BOE', 'model': '0x0BCA', 'position': 'right', 'workspace': 3},
|
||||||
}
|
]
|
||||||
|
|
||||||
|
|
||||||
p = subprocess.run(
|
p = subprocess.run(
|
||||||
@@ -17,15 +17,23 @@ p = subprocess.run(
|
|||||||
encoding='utf-8'
|
encoding='utf-8'
|
||||||
)
|
)
|
||||||
monitors = json.loads(p.stdout)
|
monitors = json.loads(p.stdout)
|
||||||
print('monitors:', monitors)
|
# print('monitors:', monitors)
|
||||||
|
|
||||||
if set(m['description'] for m in monitors) == CONFIG.keys():
|
monitor_ids = {}
|
||||||
|
for mon in monitors:
|
||||||
|
for conf in CONFIG:
|
||||||
|
if conf['make'] == mon['make'] and conf['model'] == mon['model']:
|
||||||
|
monitor_ids[ conf['position'] ] = mon['id']
|
||||||
|
|
||||||
|
|
||||||
|
if len(monitor_ids) == len(CONFIG):
|
||||||
print('config matched, assigning:')
|
print('config matched, assigning:')
|
||||||
dispatches = []
|
dispatches = []
|
||||||
for m in monitors:
|
for conf in CONFIG:
|
||||||
workspace = CONFIG[m['description']]
|
workspace = conf['workspace']
|
||||||
|
monitor_id = monitor_ids[ conf['position'] ]
|
||||||
# move workspace to desired monitor
|
# move workspace to desired monitor
|
||||||
dispatches.append(f"dispatch moveworkspacetomonitor {workspace} {m['name']}")
|
dispatches.append(f"dispatch moveworkspacetomonitor {workspace} {monitor_id}")
|
||||||
# focus the workspace so that it's visible after moving
|
# focus the workspace so that it's visible after moving
|
||||||
dispatches.append(f"workspace {workspace}")
|
dispatches.append(f"workspace {workspace}")
|
||||||
cmd = ['hyprctl', '--batch', ' ; '.join(dispatches)]
|
cmd = ['hyprctl', '--batch', ' ; '.join(dispatches)]
|
||||||
|
|||||||
Reference in New Issue
Block a user