#!/bin/sh

gamedir="$HOME/Games"

games=$(find "$gamedir" -maxdepth 5 -type f -name '*.exe' -executable | sed "s|$gamedir/||g;/[U|u]nin.*/d")

[ -z "$games" ] && notify-send -e -u critical "No games installed" && exit 1
game=$(printf '%s\n' "$games" | bemenu --fn 'IBM Plex Sans 15' -i -c -W 0.5 -B 3 -R 20 -p "PLAY GAME: " -l 15 -P ">> " --bdr="#$GLOBAL_ACCENT" --tf="#$GLOBAL_ACCENT" --hf="#$GLOBAL_ACCENT" --accept-single)

[ -z "$game" ] && notify-send -e -h "string:x-canonical-private-synchronous:${0##*/}" -u critical "No game selected" && exit 1

cd "$(dirname "$gamedir"/"$game")" || (notify-send -e -h "string:x-canonical-private-synchronous:${0##*/}" -u critical "Directory Not found" && exit 1)

gamename=$(basename "$game")

notify-send -e -h "string:x-canonical-private-synchronous:${0##*/}" -i "wine" "Launching $gamename"

trap 'wineserver -k' INT HUP

#DXVK_CONFIG=dxgi.hideAmdGpu=True WINEFSYNC=1 WINEESYNC=1 gamescope --mangoapp -W 1280 -H 800 -r 60 -- gamemoderun wine "$gamename"

hyprctl keyword monitor "eDP-1",'1440x900@60','auto','1'
#WINEFSYNC=1 WINEESYNC=1 MANGOHUD=1 env -u DISPLAY gamemoderun wine "$gamename"
#WINEFSYNC=1 WINEESYNC=1 env -u DISPLAY gamescope --mangoapp -W 1440 -H 900 -r 60 -- gamemoderun wine "$gamename"
WINEFSYNC=1 WINEESYNC=1 MANGOHUD=1 env -u DISPLAY gamemoderun wine "$gamename"
hyprctl keyword monitor "eDP-1",highrr,'auto','1'
