diff --git a/home/programs/graphical/wms/hyprland/config/keybinds.nix b/home/programs/graphical/wms/hyprland/config/keybinds.nix index 880a730..cd9fc84 100644 --- a/home/programs/graphical/wms/hyprland/config/keybinds.nix +++ b/home/programs/graphical/wms/hyprland/config/keybinds.nix @@ -102,7 +102,15 @@ # # Switch workspace (swapping to current monitor) # - # TODO: requires script (swap-workspace) + "SUPER, 1, exec, hyprland-swap-workspace 1" + "SUPER, 2, exec, hyprland-swap-workspace 2" + "SUPER, 3, exec, hyprland-swap-workspace 3" + "SUPER, 4, exec, hyprland-swap-workspace 4" + "SUPER, 5, exec, hyprland-swap-workspace 5" + "SUPER, 6, exec, hyprland-swap-workspace 6" + "SUPER, 7, exec, hyprland-swap-workspace 7" + "SUPER, 8, exec, hyprland-swap-workspace 8" + "SUPER, 9, exec, hyprland-swap-workspace 9" # # Move window to workspace diff --git a/home/programs/graphical/wms/hyprland/default.nix b/home/programs/graphical/wms/hyprland/default.nix index 43c1e4d..ba062f0 100644 --- a/home/programs/graphical/wms/hyprland/default.nix +++ b/home/programs/graphical/wms/hyprland/default.nix @@ -6,7 +6,7 @@ }: let inherit (lib) mkIf; - inherit (import ./packages {inherit pkgs;}) dbus-hyprland-env; + inherit (import ./packages {inherit pkgs;}) hyprland-swap-workspace; cfg = osConfig.myOptions.home-manager.wms.hyprland; in { @@ -16,7 +16,7 @@ in { config = mkIf cfg.enable { home.packages = with pkgs; [ - dbus-hyprland-env + hyprland-swap-workspace ]; wayland.windowManager.hyprland = { diff --git a/home/programs/graphical/wms/hyprland/packages/dbus-hyprland-env.nix b/home/programs/graphical/wms/hyprland/packages/dbus-hyprland-env.nix deleted file mode 100644 index 8fef3e5..0000000 --- a/home/programs/graphical/wms/hyprland/packages/dbus-hyprland-env.nix +++ /dev/null @@ -1,11 +0,0 @@ -{pkgs, ...}: -pkgs.writeTextFile { - name = "dbus-hyprland-env"; - destination = "/bin/dbus-hyprland-environment"; - executable = true; - text = '' - dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=hyprland - systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr - systemctl --user start pipewire wireplumber pipewire-media-session xdg-desktop-portal xdg-desktop-portal-hyprland - ''; -} diff --git a/home/programs/graphical/wms/hyprland/packages/default.nix b/home/programs/graphical/wms/hyprland/packages/default.nix index 36e2305..2679e8c 100644 --- a/home/programs/graphical/wms/hyprland/packages/default.nix +++ b/home/programs/graphical/wms/hyprland/packages/default.nix @@ -3,7 +3,7 @@ ... }: let packages = { - dbus-hyprland-env = pkgs.callPackage ./dbus-hyprland-env.nix {}; + hyprland-swap-workspace = pkgs.callPackage ./hyprland-swap-workspace.nix {}; }; in packages diff --git a/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.nix b/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.nix new file mode 100644 index 0000000..25433db --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.nix @@ -0,0 +1,4 @@ +{pkgs, ...}: + pkgs.writeShellScriptBin "hyprland-swap-workspace" '' + ${builtins.readFile ./hyprland-swap-workspace.sh} + '' diff --git a/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.sh b/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.sh new file mode 100644 index 0000000..64030b4 --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +WORKSPACE="$1" + +monitors_out="$(hyprctl monitors -j)" +focused_mon="$(echo "$monitors_out" | jq '.[] | select(.focused==true) | .id')" +focused_wks="$(echo "$monitors_out" | jq '.[].activeWorkspace.id')" + +# Workspace is already focused, check on which monitor +if echo "$focused_wks" | grep "$WORKSPACE" >/dev/null; then + mon_id="$(echo "$monitors_out" | jq ".[] | select(.activeWorkspace.id==$WORKSPACE) | .id")" + + # If the workspace is focused on the active monitor, don't do anything (we're here). + # Otherwise, swap the workspaces. + if [ "$mon_id" -ne "$focused_mon" ]; then + hyprctl dispatch swapactiveworkspaces "$focused_mon" "$mon_id" + fi +# Switching to an unfocused workspace, always move it to focused monitor +else + hyprctl dispatch moveworkspacetomonitor "$WORKSPACE" "$focused_mon" + hyprctl dispatch workspace "$WORKSPACE" +fi