#!/bin/bash
set -euo pipefail

# Infinite terminal scrolling
sudo -H -u zoox gconftool-2 -t bool --set /apps/gnome-terminal/profiles/Default/scrollback_unlimited 1

function _gsettings {
    user="$1"; shift
    command='eval $(dbus-launch --sh-syntax); gsettings '"$@"'; kill "$DBUS_SESSION_BUS_PID"'
    sudo -H -u "$user" bash -c "$command"
}

function _dconf {
    command='eval $(dbus-launch --sh-syntax); dconf '"$@"'; export a=$?; kill "$DBUS_SESSION_BUS_PID"; exit $a'
    sudo -H -u "$user" bash -c "$command"
}


# Workspace switcher dimensions
_gsettings zoox set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize 2
_gsettings zoox set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize 2

# Background wallpaper settings (the actual wallpaper is set by the customization role `desktop_background`)
_gsettings zoox set org.gnome.desktop.background picture-options stretched

# Auto-hide dock
if [ "$1" = "operator" ] ; then
    _gsettings zoox set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ launcher-hide-mode 1
fi

_dconf write "/org/gnome/desktop/wm/keybindings/toggle-shaded" "[\'\']"
_dconf write "/org/gnome/desktop/wm/keybindings/minimize" "[\'\']"
_dconf write "/org/gnome/desktop/wm/keybindings/show-desktop" "[\'\']"

_dconf write "/org/gnome/settings-daemon/plugins/media-keys/magnifier" "\'\'"
_dconf write "/org/gnome/settings-daemon/plugins/media-keys/magnifier-zoom-in" "\'\'"
_dconf write "/org/gnome/settings-daemon/plugins/media-keys/magnifier-zoom-out" "\'\'"
_dconf write "/org/gnome/settings-daemon/plugins/media-keys/screenreader" "\'\'"
