diff --git a/hmModules/apps/hypr/scripts/changeprimary.py b/hmModules/apps/hypr/scripts/changeprimary.py new file mode 100755 index 0000000..9b88129 --- /dev/null +++ b/hmModules/apps/hypr/scripts/changeprimary.py @@ -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) diff --git a/hmModules/apps/hypr/scripts/changeprimary.xsh b/hmModules/apps/hypr/scripts/changeprimary.xsh deleted file mode 100755 index 9b7e0e7..0000000 --- a/hmModules/apps/hypr/scripts/changeprimary.xsh +++ /dev/null @@ -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 diff --git a/hmModules/apps/hypr/scripts/changesecondary.py b/hmModules/apps/hypr/scripts/changesecondary.py new file mode 100755 index 0000000..2eb2b46 --- /dev/null +++ b/hmModules/apps/hypr/scripts/changesecondary.py @@ -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) diff --git a/hmModules/apps/hypr/scripts/changesecondary.xsh b/hmModules/apps/hypr/scripts/changesecondary.xsh deleted file mode 100755 index b4cfdf9..0000000 --- a/hmModules/apps/hypr/scripts/changesecondary.xsh +++ /dev/null @@ -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)