Refactor Hyprland Scripts:

- the script files are now actual scripts
- move the configs in them to their usual place
- Added some window rules sorta kinda not really related
This commit is contained in:
Chris Toph 2025-04-02 01:48:57 -04:00
parent 9d6dec5f80
commit 1f6c90fa85
9 changed files with 158 additions and 127 deletions

View file

@ -26,7 +26,7 @@ let
editor = "code";
launcher = "${pkgs.walker}/bin/walker --modules applications,ssh";
pactl = lib.getExe' pkgs.pulseaudio "pactl";
terminal = exec ./scripts/terminal.fish;
terminal = exec (import ./scripts/terminal.nix { inherit pkgs; });
## Long ass keys ##
lowerVol = "XF86AudioLowerVolume";
@ -148,47 +148,8 @@ let
};
};
submaps-script = import ./scripts/submaps.nix { inherit pkgs; };
submaps-json = pkgs.writeText "submaps.json" (builtins.toJSON submaps);
submaps-script = pkgs.writeScript "submap-script" ''
#!/usr/bin/env fish
# Usage: ./parse_submaps.fish path/to/file.json
if test (count $argv) -lt 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"
# 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
end
# Append submap reset except for default "" submap
if not test "$submap_name" = ""
echo "submap=reset"
end
end
'';
submaps-run = pkgs.runCommand "submaps-run" { inherit submaps-json submaps-script; } ''
mkdir -p $out
${pkgs.fish}/bin/fish ${submaps-script} ${submaps-json} > $out/submaps-out

View file

@ -33,6 +33,7 @@
showSpecialWorkspaces = true;
};
scroller = {
mode = "row";
center_active_column = true;
center_active_window = false;
focus_wrap = true;
@ -59,7 +60,7 @@
# window_heights = seveneighths onehalf onethird twothirds
# ),
# )'';
monitor_options = "(DP-3 = (mode = row;column_default_width = onehalf;column_widths = threequarters twothirds onehalf onethird;window_default_height = one;window_heights = one seveneighths twothirds onehalf onethird),HDMI-A-2 = (mode = col; column_default_width = one;column_widths = one onehalf;window_default_height = twothirds;window_heights = seveneighths twothirds onehalf onethird),)";
monitor_options = "(DP-3 = (mode = row;column_default_width = onehalf;column_widths = seveneighths threequarters twothirds onehalf onethird;window_default_height = one;window_heights = one seveneighths twothirds onehalf onethird),HDMI-A-2 = (mode = col; column_default_width = one;column_widths = one onehalf;window_default_height = twothirds;window_heights = seveneighths twothirds onehalf onethird),)";
};
};
};

View file

@ -1,7 +1,29 @@
{ pkgs, ... }:
let
# Zen extensions to float
zen-script = import ./scripts/zen-float.nix { inherit pkgs; };
zen-json = pkgs.writeText "zen-extensions.json" (builtins.toJSON zen-extensions);
zen-extensions = {
bitwarden = {
regex = "'*(Bitwarden Password Manager) - Bitwarden*'";
x = 500;
y = 900;
};
authenticator = {
regex = "'*(Authenticator) - Authenticator*'";
x = 335;
y = 525;
};
};
in
{
wayland.windowManager.hyprland.settings = {
# Floats zen extensions
exec-once = [
"${pkgs.fish}/bin/fish ${zen-script} ${zen-json}"
];
## Layers Rules ##
layer = [
@ -23,7 +45,7 @@
"float, title:^(Accounts)(.*)$"
"float, title:^(Media viewer)$"
## Zen ##
# Zen
"suppressevent maximize, class:^(zen)$"
"float, title:^(Picture-in-Picture)$"
"pin, title:^(Picture-in-Picture)$"
@ -31,6 +53,22 @@
"workspace special silent, title:^(Zen Sharing Indicator)$"
"workspace special silent, title:^(.*is sharing (your screen|a window)\.)$"
# Foot
"plugin:scroller:modemodifier col after focus, class:^(foot)$"
"plugin:scroller:windowheight onethird, class:^(foot)$"
# Vesktop
"workspace 1, class:^(vesktop)$"
"plugin:scroller:group vesktop, class:^(vesktop)$"
"opaque, initialTitle:^(Discord Popout)$"
"plugin:scroller:modemodifier row before focus, initialTitle:^(Discord Popout)$"
"plugin:scroller:windowheight onethird, initialTitle:^(Discord Popout)$"
# VsCode
"plugin:scroller:group code, class:^(code)$"
"plugin:scroller:alignwindow center, class:^(code)$"
"plugin:scroller:windowheight seveneighths, class:^(code)$"
# Float Apps
"float, class:^(galculator)$"
"float, class:^(waypaper)$"
@ -44,7 +82,6 @@
# Always opaque
"opaque, class:^([Gg]imp)$"
"opaque, class:^([Ff]lameshot)$"
"opaque, class:^([Ii]nkscape)$"
"opaque, class:^([Bb]lender)$"
"opaque, class:^([Oo][Bb][Ss])$"
@ -78,7 +115,6 @@
# "monitor:DP-1, ${flameshot}"
## Workspace Assignments ##
"workspace 1, initialClass:^(vesktop)$"
"workspace 1, initialClass:^(spotify)$"
"workspace 1, initialClass:^(org.telegram.desktop)$"
# "workspace name:4, initialClass:^(virt-manager)$"

View file

@ -1,4 +1,3 @@
{ lib, ... }:
{
imports = lib.custom.scanPaths ./.;
# :D
}

View file

@ -0,0 +1,44 @@
{
pkgs,
...
}:
pkgs.writeScript "submap-script" ''
#!/usr/bin/env fish
# Usage: ./parse_submaps.fish path/to/file.json
if test (count $argv) -lt 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"
# 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
end
# Append submap reset except for default "" submap
if not test "$submap_name" = ""
echo "submap=reset"
end
end
''

View file

@ -1,3 +0,0 @@
#!/usr/bin/env fish
foot

View file

@ -0,0 +1,10 @@
{
pkgs,
...
}:
# TODO: obviously lol
# Handle float terminal and grim select terminal
pkgs.writeScript "terminal-launch" ''
#!/usr/bin/env fish
foot
''

View file

@ -1,24 +1,20 @@
{ pkgs, lib, ... }:
let
zen-extensions = {
bitwarden = {
regex = "'*(Bitwarden Password Manager) - Bitwarden*'";
x = 500;
y = 900;
};
authenticator = {
regex = "'*(Authenticator) - Authenticator*'";
x = 335;
y = 525;
};
};
zen-json = pkgs.writeText "zen-extensions.json" (builtins.toJSON zen-extensions);
zen-script = pkgs.writeScript "zen-script" ''
{
pkgs,
...
}:
pkgs.writeScript "zen-script" ''
#!/usr/bin/env fish
if test (count $argv) -lt 1
echo "Usage: $argv[0] path/to/your.json"
exit 1
end
set json_file $argv[1]
function handle
set -l line $argv[1]
set -l file_path $argv[2]
switch $line
case "windowtitlev2*"
# Expected format: windowtitlev2>><id>,<title>
@ -32,12 +28,12 @@ let
echo "Extracted title: [$title]"
# Loop over the extensions defined in the JSON file.
for ext in ( ${pkgs.jq}/bin/jq -r 'keys[]' ${zen-json} )
for ext in ( ${pkgs.jq}/bin/jq -r 'keys[]' $file_path )
echo "Processing extension: [$ext]"
# Get regex, x and y for the current extension.
set -l reg ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].regex' ${zen-json} )
set -l ext_x ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].x' ${zen-json} )
set -l ext_y ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].y' ${zen-json} )
set -l reg ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].regex' $file_path )
set -l ext_x ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].x' $file_path )
set -l ext_y ( ${pkgs.jq}/bin/jq -r --arg k $ext '.[$k].y' $file_path )
# Remove any extra surrounding single quotes.
set -l reg (string trim -c "'" $reg)
@ -48,31 +44,17 @@ let
# If the title matches the regex, dispatch floating commands.
if string match -q -- "*$reg*" "$title"
echo "$ext window id: $window_id -- setting float mode with size $ext_x x $ext_y"
hyprctl --batch "dispatch togglefloating address:0x$window_id; dispatch resizewindowpixel exact $ext_x $ext_y,address:0x$window_id; dispatch movewindowpixel exact 64% 3%,address:0x$window_id"
hyprctl --batch "dispatch togglefloating address:0x$window_id; dispatch resizewindowpixel exact $ext_x $ext_y,address:0x$window_id;"
return
end
end
;;
case "*"
# Do nothing for other events.
;;
end
end
${pkgs.socat}/bin/socat -U - UNIX-CONNECT:/run/user/1000/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -l line
handle "$line"
handle "$line" "$json_file"
end
'';
in
{
wayland.windowManager.hyprland.settings = {
exec-once = [
"${pkgs.fish}/bin/fish ${zen-script}"
];
windowrulev2 = [
# Zen Extensions
"suppressevent maximize, class:^(zen)$"
];
};
}
''

View file

@ -15,5 +15,6 @@
environment.systemPackages = [
inputs.rose-pine-hyprcursor.packages.${pkgs.system}.default
inputs.better-control.packages.${pkgs.system}.better-control
];
}