From 31af183981b773658154c09088adfa63d333569a Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Mon, 14 Apr 2025 13:49:49 -0400 Subject: [PATCH] Adds hyprland steam maps through script and Ryujinx rules - Integrates new steam mapping script for dynamic monitor control - Updates key bindings to toggle steam mapping via exec commands - Introduces Ryujinx window rules for improved session handling - Refactors submap binding output in scripts for consistency --- home/toph/common/optional/gaming/default.nix | 3 +- home/toph/common/optional/hyprland/binds.nix | 9 ++- home/toph/common/optional/hyprland/rules.nix | 7 ++- .../optional/hyprland/scripts/steam-map.nix | 55 +++++++++++++++++++ .../optional/hyprland/scripts/submaps.nix | 44 +++++++-------- 5 files changed, 92 insertions(+), 26 deletions(-) create mode 100644 home/toph/common/optional/hyprland/scripts/steam-map.nix diff --git a/home/toph/common/optional/gaming/default.nix b/home/toph/common/optional/gaming/default.nix index e9ceaa9..7c63440 100644 --- a/home/toph/common/optional/gaming/default.nix +++ b/home/toph/common/optional/gaming/default.nix @@ -48,8 +48,9 @@ let in { home.packages = with pkgs; [ - steam-session prismlauncher + ryubing + steam-session # modrinth-app (lutris.override { extraLibraries = pkgs: [ diff --git a/home/toph/common/optional/hyprland/binds.nix b/home/toph/common/optional/hyprland/binds.nix index b94cf3e..5279ec1 100644 --- a/home/toph/common/optional/hyprland/binds.nix +++ b/home/toph/common/optional/hyprland/binds.nix @@ -97,11 +97,11 @@ let ", Home, overview:toggle" "ALT, Tab, cyclenext," "ALT, Tab, bringactivetotop," - "SUPER_ALT, G, submap, steam" "SUPER, 1, workspace, 1" "SUPER, 2, workspace, 2" "SUPER, 3, workspace, 3" "SUPER, 4, workspace, 4" + "SUPER_ALT, G, exec, ${steam-map} on ${monitors-json}" ## Scroller ## "SUPER, P, scroller:pin" @@ -149,7 +149,9 @@ let steam = { binds = { "" = [ - "SUPER, Escape, submap, reset" + "SUPER, Escape, exec, ${steam-map} off ${monitors-json}" + ]; + n = [ "SUPER, SUPER_L, pass" ", mouse:275, pass" ", mouse:276, pass" @@ -158,6 +160,9 @@ let }; }; + steam-map = import ./scripts/steam-map.nix { inherit pkgs; }; + monitors-json = pkgs.writeText "monitors.json" (builtins.toJSON config.monitors); + submaps-script = import ./scripts/submaps.nix { inherit pkgs; }; submaps-json = pkgs.writeText "submaps.json" (builtins.toJSON submaps); submaps-run = pkgs.runCommand "submaps-run" { inherit submaps-json submaps-script; } '' diff --git a/home/toph/common/optional/hyprland/rules.nix b/home/toph/common/optional/hyprland/rules.nix index 522eef2..47e5c75 100644 --- a/home/toph/common/optional/hyprland/rules.nix +++ b/home/toph/common/optional/hyprland/rules.nix @@ -96,13 +96,18 @@ in #"size 80% 85%, workspace:^(special:special)$" #"center, workspace:^(special:special)$" + #Ryujinx + "opaque, initialClass:^(Ryujinx)$" + "immediate, initialClass:^(Ryujinx)$" + "workspace 3, initialClass:^(Ryujinx)$" + ## Steam rules ## "opaque, initialClass:^([Gg]amescope)$" + # "stayfocused, initialClass:^([Gg]amescope)$" "fullscreen, initialClass:^([Gg]amescope)$" "minsize 1 1, initialClass:^([Gg]amescope)$" "immediate, initialClass:^([Gg]amescope)$" "workspace 3, initialClass:^([Gg]amescope)$" - "monitor 0, initialClass:^([Gg]amescope)$" # # ========== Fameshot rules ========== diff --git a/home/toph/common/optional/hyprland/scripts/steam-map.nix b/home/toph/common/optional/hyprland/scripts/steam-map.nix new file mode 100644 index 0000000..cd6f97b --- /dev/null +++ b/home/toph/common/optional/hyprland/scripts/steam-map.nix @@ -0,0 +1,55 @@ +{ + pkgs, + ... +}: +pkgs.writeScript "steam-map" '' + #!/usr/bin/env fish + # Usage: ./steam-map-toggle.fish on|off + + if test (count $argv) -lt 2 + echo "Usage: $0 on|off " + exit 1 + end + + set mode $argv[1] + set json_file $argv[2] + + if not test -e $json_file + echo "Error: File $json_file does not exist" + exit 1 + end + + # Parse the JSON and generate instructions for NON-primary monitors. + # When 'off', build the monitor string; when 'on', disable the monitor. + set instructions (${pkgs.jq}/bin/jq -r --arg mode "$mode" ' + .[] | + if .primary then empty else + if $mode == "off" then + .name + "," + + (.width|tostring) + "x" + (.height|tostring) + "@" + (.refreshRate|tostring) + "," + + (.x|tostring) + "x" + (.y|tostring) + "," + + (.scale|tostring) + + (if has("transform") then ",transform," + (.transform|tostring) else "" end) + + ",vrr," + (if has("vrr") then (.vrr|tostring) else "0" end) + else + .name + ", disable" + end + end + ' $json_file) + + # Execute hyprctl keyword monitor for each instruction. + for instruction in $instructions + echo "Running: hyprctl keyword monitor $instruction" + hyprctl keyword monitor "$instruction" + end + + # Dispatch the appropriate submap. + if [ "$mode" = "on" ] + hyprctl --batch "dispatch submap steam; dispatch workspace 3" + else if [ "$mode" = "off" ] + hyprctl dispatch submap reset + else + echo "Invalid mode: $mode" + exit 1 + end +'' diff --git a/home/toph/common/optional/hyprland/scripts/submaps.nix b/home/toph/common/optional/hyprland/scripts/submaps.nix index 60ef94a..8739d71 100644 --- a/home/toph/common/optional/hyprland/scripts/submaps.nix +++ b/home/toph/common/optional/hyprland/scripts/submaps.nix @@ -7,38 +7,38 @@ pkgs.writeScript "submap-script" '' # Usage: ./parse_submaps.fish path/to/file.json if test (count $argv) -lt 1 - echo "Usage: $argv[0] path/to/file.json" - exit 1 + echo "Usage: $argv[0] path/to/file.json" + exit 1 end set json_file $argv[1] # Iterate over submaps preserving order for entry in (${pkgs.jq}/bin/jq -c '.| to_entries[]' $json_file) - set submap_name (echo $entry | ${pkgs.jq}/bin/jq -r '.key') - echo "submap=$submap_name" + set submap_name (echo $entry | ${pkgs.jq}/bin/jq -r '.key') + echo "submap=$submap_name" - # Process each binds entry within the submap - for bind_entry in (echo $entry | ${pkgs.jq}/bin/jq -c '.value.binds | to_entries[]') - set bind_key (echo $bind_entry | ${pkgs.jq}/bin/jq -r '.key') + # Process each binds entry within the submap + for bind_entry in (echo $entry | ${pkgs.jq}/bin/jq -c '.value.binds | to_entries[]') + set bind_key (echo $bind_entry | ${pkgs.jq}/bin/jq -r '.key') - if test "$bind_key" = "" - set prefix "bind=" - else if test "$bind_key" = "unbind" - set prefix "unbind=" - else - set prefix "bind$bind_key=" - end - - # Process each binding's value in the array - for binding in (echo $bind_entry | ${pkgs.jq}/bin/jq -r '.value[]') - echo "$prefix$binding" - end + if test "$bind_key" = "" + set prefix "bind=" + else if test "$bind_key" = "unbind" + set prefix "unbind=" + else + set prefix "bind$bind_key=" end - # Append submap reset except for default "" submap - if not test "$submap_name" = "" - echo "submap=reset" + # Process each binding's value in the array + for binding in (echo $bind_entry | ${pkgs.jq}/bin/jq -r '.value[]') + echo "$prefix$binding" end + end + + # Append submap reset except for default "" submap + if not test "$submap_name" = "" + echo "submap=reset" + end end ''