#! /usr/bin/env fish

set direction $argv[1]
set delta 30
set active (hyprctl activewindow -j | jq -r '.address + "\n" + (.floating | tostring)')
set address $active[1]
set floating $active[2]

function handleMoveLeft
    set curr (hyprctl activewindow -j | jq -r '(.at[0] | tostring) + "\n" + (.at[1] | tostring)')
    set y $curr[2]
    set x (math $curr[1] - $delta)
    hyprctl dispatch movewindowpixel "exact $x $y,address:$address"
    exit 0
end

if test "$floating" = "true"
    switch $direction
        case l left
            handleMoveLeft
        case r right
            set resizeparams "$delta 0"
        case u up
            set resizeparams "0 -$delta"
        case d down
            set resizeparams "0 $delta"
    end
    hyprctl dispatch movewindowpixel "$resizeparams,address:$address"
else
    hyprctl dispatch hy3:movewindow $direction,once
end