Files
nixos/apps/hyprland/scripts/workspace-toggle.nix
CLAUDE AI 40b7db2c00 fix(hypr): reliable gaming workspace focus across monitors
- Add game-focus-watcher: listens on hyprland socket, auto-focuses
  gaming workspace when a game opens, closing any special workspace
  on DP-1 first via --batch to avoid async dispatch races
- Add gaming-focus script: SUPER+G now handles special workspaces on
  DP-1 regardless of focused monitor, with toggle-back behavior
- Fix steam windowrule to send all class:steam windows to special:steam,
  not just title:Steam, preventing dialogs leaking to normal workspaces
- Fix monitor 0 -> monitor DP-1 in mkGameRules and steam_app rules
  so games always launch at correct resolution on the gaming monitor
- Extract gamingMonitor variable as single source of truth
2026-05-28 07:57:33 -05:00

28 lines
1.2 KiB
Nix

{pkgs, ...}: let
workspace-toggle = pkgs.writeShellScriptBin "workspace-toggle" ''
#!/usr/bin/env bash
target_workspace="$1"
# activeworkspace always returns the underlying workspace, even when a special
# workspace is open. Check the monitor's specialWorkspace field instead.
special=$(${pkgs.hyprland}/bin/hyprctl monitors -j | ${pkgs.jq}/bin/jq -r '.[] | select(.focused) | .specialWorkspace.name')
if [[ -n "$special" ]]; then
${pkgs.hyprland}/bin/hyprctl dispatch togglespecialworkspace "''${special#special:}"
current=$(${pkgs.hyprland}/bin/hyprctl activeworkspace -j | ${pkgs.jq}/bin/jq -r '.id')
if [[ $current -ne $target_workspace ]]; then
${pkgs.hyprland}/bin/hyprctl dispatch focusworkspaceoncurrentmonitor "$target_workspace"
fi
else
current=$(${pkgs.hyprland}/bin/hyprctl activeworkspace -j | ${pkgs.jq}/bin/jq -r '.id')
if [[ $current -eq $target_workspace ]]; then
${pkgs.hyprland}/bin/hyprctl dispatch workspace previous
else
${pkgs.hyprland}/bin/hyprctl dispatch split:workspace "$target_workspace"
fi
fi
'';
in {
home.packages = [workspace-toggle];
}