#!/usr/bin/env bash
export MOZ_ENABLE_WAYLAND=1
echo $MOZ_ENABLE_WAYLAND

# Check to see if firefox is running
if [ $(pgrep -c firefox) -gt 0 ]; then
    echo "ff running"

    if [ "$XDG_SESSION_TYPE" = "x11" ]; then
        #X11
        ffrg=$(wmctrl -lx | rg firefox | awk '{print $1}')
        # echo $emacsrg

        if [ -z $ffrg ]; then
            exec firefox
            exit
        else
            exec wmctrl -ia $ffrg
            exit
        fi
    else
        if [ "$KDE_FULL_SESSION" = "true" ]; then
            echo "KDE"
            exec /home/chris/bin/ww -fa firefox -c firefox
            exit
        else
            # WAYLAND
            ffrg=$(wlrctl window list | rg firefox)

            ffwin=$(echo $ffrg | sed 's/.*\: //')
            # echo $ffwin

            exec wlrctl toplevel focus firefox
            exit
        fi
    fi
else
    exec firefox
fi