Hypr, move from xonsh to python3
This commit is contained in:
parent
b57482b98b
commit
7e81e09ca4
4 changed files with 97 additions and 54 deletions
61
hmModules/apps/hypr/scripts/changeprimary.py
Executable file
61
hmModules/apps/hypr/scripts/changeprimary.py
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
import shelve
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
# Usage:
|
||||
# ./changeprimary.xsh workspace
|
||||
# changes to that workspace
|
||||
# if workspace is "etc" then changes to etcN where N is a number
|
||||
|
||||
def changeprimary(workspace, pmonitor, smonitor, dbpath):
|
||||
current_primary = ""
|
||||
current_secondary = ""
|
||||
|
||||
with shelve.open(dbpath) as db:
|
||||
current_primary = db.get("primary")
|
||||
current_secondary = db.get("secondary")
|
||||
|
||||
old_primary = current_primary
|
||||
current_primary = workspace
|
||||
|
||||
if current_primary == current_secondary:
|
||||
workspaces = db.get("secondaries").copy()
|
||||
if old_primary in workspaces:
|
||||
current_secondary = old_primary
|
||||
else:
|
||||
current_secondary = workspaces[
|
||||
(workspaces.index(current_secondary)+1) % len(workspaces)
|
||||
]
|
||||
|
||||
db["primary"] = current_primary
|
||||
db["secondary"] = current_secondary
|
||||
|
||||
subprocess.run([
|
||||
"hyprctl", "dispatch", "moveworkspacetomonitor",
|
||||
"name:" + current_secondary, smonitor
|
||||
])
|
||||
subprocess.run([
|
||||
"hyprctl", "dispatch", "workspace",
|
||||
"name:" + current_secondary
|
||||
])
|
||||
subprocess.run([
|
||||
"hyprctl", "dispatch", "moveworkspacetomonitor",
|
||||
"name:" + current_primary, pmonitor
|
||||
])
|
||||
subprocess.run([
|
||||
"hyprctl", "dispatch", "workspace",
|
||||
"name:" + current_primary
|
||||
])
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
workspace=sys.argv[1]
|
||||
primary_monitor=os.environ["HYPR_MON_PRIMARY"]
|
||||
secondary_monitor=os.environ["HYPR_MON_SECONDARY"]
|
||||
db=os.environ["HYPR_WORK_DB"]
|
||||
changeprimary(workspace, primary_monitor, secondary_monitor, db)
|
||||
except KeyError:
|
||||
print("Please set HYPR_MON_PRIMARY and HYPR_WORK_DB")
|
||||
sys.exit(1)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env xonsh
|
||||
import shelve
|
||||
|
||||
# Usage:
|
||||
# ./changeprimary.xsh workspace
|
||||
# changes to that workspace
|
||||
# if workspace is "etc" then changes to etcN where N is a number
|
||||
|
||||
workspace=$ARG1
|
||||
monitor=$HYPR_MON_PRIMARY
|
||||
|
||||
current_workspace = "home"
|
||||
|
||||
with shelve.open($HYPR_WORK_DB) as db:
|
||||
current_workspace = db.get("primary")
|
||||
if workspace == "etc":
|
||||
if current_workspace.startswith("etc"):
|
||||
current = current_workspace[3:] % db.get("primary_extras")
|
||||
current_workspace = "etc" + str(current)
|
||||
else:
|
||||
current_workspace = "etc0"
|
||||
else:
|
||||
current_workspace = workspace
|
||||
db["primary"] = current_workspace
|
||||
|
||||
hyprctl dispatch moveworkspacetomonitor name:@(current_workspace) $HYPR_MON_PRIMARY >> /dev/null
|
||||
hyprctl dispatch workspace name:@(current_workspace) >> /dev/null
|
||||
36
hmModules/apps/hypr/scripts/changesecondary.py
Executable file
36
hmModules/apps/hypr/scripts/changesecondary.py
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3
|
||||
import shelve
|
||||
import copy
|
||||
|
||||
# Usage:
|
||||
# ./changesecondary.xsh
|
||||
# cycles through the secondary workspaces
|
||||
|
||||
def cyclesecondary(monitor, dbpath):
|
||||
current_secondary = ""
|
||||
|
||||
with shelve.open(dbpath) as db:
|
||||
workspaces = db.get("secondaries").copy()
|
||||
current_primary = db.get("primary")
|
||||
current_secondary = db.get("secondary")
|
||||
|
||||
if current_primary in workspaces:
|
||||
workspaces.remove(current_primary)
|
||||
|
||||
current_secondary = workspaces[
|
||||
(workspaces.index(current_secondary)+1) % len(workspaces)
|
||||
]
|
||||
db["secondary"] = current_secondary
|
||||
|
||||
# Change primary to bind
|
||||
hyprctl dispatch moveworkspacetomonitor name:@(current_secondary) $HYPR_MON_SECONDARY
|
||||
hyprctl dispatch workspace name:@(current_secondary)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
monitor=os.environ["HYPR_MON_SECONDARY"]
|
||||
db=os.environ["HYPR_WORK_DB"]
|
||||
cyclesecondary(monitor, db)
|
||||
except KeyError:
|
||||
print("Please set HYPR_MON_PRIMARY and HYPR_WORK_DB")
|
||||
sys.exit(1)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env xonsh
|
||||
import shelve
|
||||
import copy
|
||||
|
||||
# Usage:
|
||||
# ./changesecondary.xsh
|
||||
# cycles through the secondary workspaces
|
||||
|
||||
current_secondary = "chat"
|
||||
|
||||
with shelve.open($HYPR_WORK_DB) as db:
|
||||
workspaces = db.get("secondaries").copy()
|
||||
current_primary = db.get("primary")
|
||||
current_secondary = db.get("secondary")
|
||||
#extras = db.get("secondary_extras")
|
||||
|
||||
if current_primary in workspaces:
|
||||
workspaces.remove(current_primary)
|
||||
|
||||
current_secondary = workspaces[
|
||||
(workspaces.index(current_secondary)+1) % len(workspaces)
|
||||
]
|
||||
db["secondary"] = current_secondary
|
||||
|
||||
# Change primary to bind
|
||||
hyprctl dispatch moveworkspacetomonitor name:@(current_secondary) $HYPR_MON_SECONDARY
|
||||
hyprctl dispatch workspace name:@(current_secondary)
|
||||
Loading…
Add table
Add a link
Reference in a new issue