From 8181ce359868bab08745d2748ee6b0319c724dfe Mon Sep 17 00:00:00 2001 From: Uyanide Date: Mon, 4 Aug 2025 22:26:59 +0200 Subject: [PATCH] my first hyprland plugin :D --- .scripts/workspace-org.py | 58 ------------------------------------- hypr/hyprland/keybinds.conf | 2 +- 2 files changed, 1 insertion(+), 59 deletions(-) delete mode 100755 .scripts/workspace-org.py diff --git a/.scripts/workspace-org.py b/.scripts/workspace-org.py deleted file mode 100755 index 58e2ea5..0000000 --- a/.scripts/workspace-org.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/env python3 -''' -Author: Uyanide pywang0608@foxmail.com -Date: 2025-08-02 20:56:46 -LastEditTime: 2025-08-03 00:33:13 -Description: Organize Hyprland workspaces from 1 to N, where N is the number of workspaces with windows, - e.g. 3 5 6 -> 1 2 3. - One must have xtra-dispatchers plugin installed and enabled to use this script. -''' - -import subprocess -import re - - -def get_active_workspace_ids() -> list[int]: - """Get workspace IDs that have windows > 0""" - try: - result = subprocess.run(['hyprctl', 'workspaces'], capture_output=True, text=True, check=True) - output = result.stdout - except subprocess.CalledProcessError: - return [] - - workspace_ids = [] - current_id : int | None = None - - for line in output.split('\n'): - # Match workspace ID line - workspace_match = re.match(r'^workspace ID (\d+)', line) - if workspace_match: - current_id = int(workspace_match.group(1)) - continue - - # Match windows count line - # Only consider workspaces with at least one window - windows_match = re.match(r'\s+windows: (\d+)', line) - if windows_match and current_id is not None: - windows_count = int(windows_match.group(1)) - if windows_count > 0: - workspace_ids.append(current_id) - current_id = None - - return sorted(workspace_ids) - - -def organize_workspaces(ids: list[int]) -> None: - """Reorganize workspaces to consecutive numbers starting from 1""" - if not ids: - return - moveto = 1 - for workspace_id in ids: - if moveto != workspace_id: - subprocess.run(['hyprctl', 'dispatch', 'workspace', str(moveto)], check=False) - subprocess.run(['hyprctl', 'dispatch', 'plugin:xtd:bringallfrom', str(workspace_id)], check=False) - moveto += 1 - - -if __name__ == '__main__': - organize_workspaces(get_active_workspace_ids()) diff --git a/hypr/hyprland/keybinds.conf b/hypr/hyprland/keybinds.conf index 68555d1..26869bf 100755 --- a/hypr/hyprland/keybinds.conf +++ b/hypr/hyprland/keybinds.conf @@ -103,7 +103,7 @@ bind = Super+Alt, F, fullscreenstate, 0 3 # Toggle fake fullscreen bind = Super, F, fullscreen, 0 bind = Super, D, fullscreen, 1 bind = Super, J, togglesplit -bind = Super, O, exec, workspace-org.py # Organize windows in workspace +bind = Super, O, plugin:uyani:organize # https://github.com/Uyanide/hyprplug #! ##! Workspace navigation