Put i3bar systray on specific display

I use i3 with i3bar and sometimes I use external displays. When I do, I want to the systray to be on my primary monitor. I use the script below to reconfigure i3 on the fly.

Raw
#!/bin/bash

# This helper function is defined in a different file that I re-use in many scripts
# It looks kind of overengineered for this one
__yesno () {
        default=${2:-n}
        if [ "$default" = "y" ]; then
                choices="Yn"
        else
                choices="yN"
        fi
        echo -n "${1:-Yes or no} [$choices]"
        read -rn1 answer
        if [ "$default" = "y" ] && [ "$answer" = 'n' ]; then
                echo
                return 1
        elif [ "$default" = "n" ] && [ "$answer" != 'y' ]; then
                echo
                return 1
        else
                echo
                return 0
        fi
}

__seti3tray () {
  sed -i "s#^\t.*tray_output.*#\ttray_output $1#" "${HOME}/.config/i3/config"
  i3-msg reload
}

lines=($(xrandr | grep " connected " | awk '{ print$1 }'))
for idx in ${!lines[*]}; do
  __yesno "Use display ${lines[$idx]} for systray?" y && __seti3tray "${lines[$idx]}" && exit 0
done

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityFontGnuPGThunderbirdJenkins