#!/bin/bash

# set background color (doesnt work with compositor)
#xsetroot -solid "#222222"
hsetroot -solid "#222222"
#feh --bg-scale /home/jon/Pictures/christmas_tree_minimal.jpg

## fix trackball left and middle click
#ELECOM_ID=$(xinput list | grep -E -i "elecom.*pointer" | sed -r 's/.*id=([0-9]+).*/\1/')
#xinput set-button-map 9 1 2 3 4 5 6 7 8 1 10 11 2

# launch ime for typing in japanese
#ibus-daemon --xim &

## triple monitor setup
#xrandr --output DP-2 --primary --auto \
#    --output DP-3 --auto --right-of DP-2 \
#    --output DP-1 --auto --left-of DP-2

# set default pulseaudio "sink" (output device) to index 21
#pacmd set-default-sink 21

## this worked prior to Fedora 35 (and PipeWire)
#pacmd set-default-sink alsa_output.usb-Audioengine_Audioengine_2_-00.iec958-stereo

## this worked on Fedora 35, not pretty but I cobbled it together.
## it will find the first sink that contains audioengine and pipewire and set
## as default.  also fixed my vol up/down keybinds in dwm
#pactl set-default-sink $(pactl list short | grep -i audioengine | grep -i pipewire | head -n 1 | awk '{print $1}')

### 2021-12-13 
#pactl list sinks short
pactl set-default-sink 46

### apply monitor calibration
#xcalib /s/misc/monitor_calibration/dell.icc


#############################################
# Launch scripts
# Check if running first for idempotency
# 20220604 - dramatically simplified using a loop+array
#############################################

HOME_DIR=$HOME
echo $HOME

apps=( "picom" "jstat" "keepassxc" "nextcloud" "playerctld" "fcitx5" )

for i in "${apps[@]}"
do
    if pgrep -x "$i" >/dev/null
    then
        # check for binary 
        if [ -f "/usr/bin/$i" ] || [ -f "$HOME/bin/$i" ] || [ -f "/usr/local/bin/$i" ]
        then
            echo "$i - Already Running ..."
        else
            echo "$i - Error - $i binary not found!"
        fi
    else
        echo "$i stopped - starting now"
        command $i &
    fi
done

