# Adapted from strychnine (setup.sh) http://gitlab.com/stormdragon2976/strychnine

# Miscellaneous
startup_message off
set winname name
set bgcolor #000000
set fgcolor #FFFFFF
set font -*-terminus-medium-r-normal-*-24-*-*-*-*-*-*-*
set waitcursor 1
banish


# Hook section
addhook key announce_top_level_key
addhook newwindow announce_new_window
addhook switchwin set_fenrir

# Unbind section
unbind C-A
unbind A
unbind C-a
unbind a
unbind c
unbind C-c
unbind C-f
unbind F
unbind r
unbind C-r
unbind S
unbind C-S
unbind s
unbind C-s
unbind C-t
unbind C-v
unbind v
unbind C-w
unbind C-Down
unbind Down
unbind C-exclam
unbind exclam
unbind C-Left
unbind Left
unbind question
unbind C-Right
unbind Right
unbind C-Up
unbind Up
unbind C-apostrophe
unbind apostrophe
unbind colon
unbind t

# Key binding section
escape M-Escape
# Alt+f2 executes the run dialog
definekey top M-F2 run_dialog
# Alt+f4 closes the current window.
definekey top M-F4 close_window
# Alt+tab switches through open windows
definekey top M-Tab next
definekey top M-ISO_Left_Tab prev
definekey top Print exec /usr/bin/ocrdesktop -d
definekey top C-F12 exec if pgrep -c barnard ; then echo "talk" > ~/.config/barnard/cmd;fi
definekey top C-M-f exec pcmanfm
definekey top C-M-m exec thunderbird
definekey top C-M-t exec pluma
definekey top C-M-w exec firefox
definekey top Super_L exec mygtkmenu /etc/mygtkmenu/${LANG::2}
definekey top Super_R exec mygtkmenu /etc/mygtkmenu/${LANG::2}
definekey top C-Escape exec mygtkmenu /etc/mygtkmenu/${LANG::2}
definekey top M-F1 exec mygtkmenu /etc/mygtkmenu/${LANG::2}
bind c exec /usr/bin/urxvt -name terminal -C -e fenrir -s /etc/fenrirscreenreader/settings/xterm.conf -o "remote#socketFile=/tmp/fenrirscreenreader-terminal.sock"
bind exclam run_dialog
bind question ratpoison_keybindings
bind p exec /usr/bin/pidgin
bind C-c exec /usr/bin/lxterminal
bind C-exclam run_in_terminal_dialog
bind C-A set_window_name
bind A set_window_name
bind C-a show_date
bind a show_date
bind C-t show_date
bind o exec /usr/bin/orca &> ~/orca.txt # start Orca
bind O exec /usr/bin/orca -r # Restart Orca
bind C-v ratpoison_version
bind v ratpoison_version
bind C-apostrophe window_menu
bind apostrophe window_menu
bind colon run_ratpoison_command
bind C-colon reload_ratpoison_configuration
bind C-M-r restart
bind C-M-q quit

# Autostart section
exec /usr/bin/xbrlapi -q
exec /usr/bin/glipper
exec if [ "$(gsettings get org.gnome.desktop.a11y.applications screen-reader-enabled)" != "true" ]; then gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true&& notify-send "QT5 accessibility enabled. You need to restart ratpoison for the changes to take affect.";fi
#exec /usr/bin/urxvt -name terminal -e fenrir -s /etc/fenrirscreenreader/settings/xterm.conf -o "remote#socketFile=/tmp/fenrirscreenreader-terminal.sock"
exec [[ -e ~/.firstboot ]] && /usr/bin/urxvt -name terminal -e fenrir -s /etc/fenrirscreenreader/settings/xterm.conf -o "remote#socketFile=/tmp/fenrirscreenreader-terminal.sock"
exec [[ -e ~/.firstboot ]] || /usr/bin/pcmanfm --desktop
exec [[ -e ~/.firstboot ]] || if [[ -f /usr/share/doc/F123/${LANG}/desktop.md ]]; then cp /usr/share/doc/F123/${LANG}/desktop.md /tmp/orca-speak;else cp /usr/share/doc/F123/en_US.UTF-8/desktop.md /tmp/orca-speak;fi;/usr/bin/orca

# Alias Section
alias close_window exec ratpoison -c 'delete'
alias ratpoison_keybindings exec ratpoison -c "help root" | yad --text-info --show-cursor --title "Ratpoison Keybindings" --button "Close:0"
alias run_dialog exec historyPath="${XDG_CONFIG_HOME:-$HOME/.config}/strychnine";if ! [ -d "$historyPath" ]; then mkdir -p "$historyPath";fi;write_history(){ oldHistory="$(grep -v "$txt" "$historyPath/history" | head -n 49)";echo -e "$txt\n$oldHistory" | sed 's/^$//g' > "$historyPath/history"; };if [ -f "$historyPath/history" ]; then txt=$(yad --entry --editable --title "Ratpoison" --text "Execute program or enter file" --button "Open:0" --separator "\n" --rest "$historyPath/history");else txt=$(yad --entry --title "Ratpoison" --text "Execute program or enter file" --button "Open:0");fi;if [ -z "$txt" ]; then exit 0;fi;if [[ "$txt" =~ ^ftp://|http://|https://|www.* ]]; then /usr/bin/firefox $txt;write_history;exit 0;fi;if [[ "$txt" =~ ^mailto://.* ]]; then xdg-email $txt;write_history;exit 0;fi;if [[ "$txt" =~ ^man://.* ]]; then eval "${txt/:\/\// }" | yad --text-info --show-cursor --button "Close:0" --title "Ratpoison" -;write_history;exit 0;fi;if command -v "$(echo "$txt" | cut -d " " -f1)" &> /dev/null ; then eval $txt& else (xdg-open $txt || /usr/bin/pcmanfm)&fi;write_history;exit 0
alias run_in_terminal_dialog exec c="$(yad --entry --title "Ratpoison" --text "Enter command:")" && /usr/bin/gnome-terminal -e $c
alias set_window_name exec t="$(yad --entry --title "Ratpoison" --text "Enter window name") && ratpoison -c "title $t"
alias show_date exec notify-send "$(date +"%A, %B %d, %Y%n%I:%M%p")"
alias ratpoison_version exec notify-send "$(ratpoison -c "version")"
alias window_menu exec ifs="$IFS";IFS=$'\n';w="$(yad --list --title "Ratpoison" --text "Select Window" --column "Select" $(ratpoison -c "windows"))";IFS="$ifs";ratpoison -c "select ${w:0:1}"
alias run_ratpoison_command exec c="$(yad --entry --title "Ratpoison" --text="Enter Ratpoison command:")" && ratpoison -c "$c"
alias reload_ratpoison_configuration exec ratpoison -c "source $HOME/.ratpoisonrc"&&notify-send "Ratpoison configuration reloaded"
alias announce_new_window exec play -n synth .25 sin 440:880 sin 480:920 remix - norm -3 pitch -500
alias announce_top_level_key exec play -qV0 "|sox -np synth .07 sq 400" "|sox -np synth .5 sq 800" fade h 0 .5 .5 norm -20
alias set_fenrir exec bash -c 'winName="$(ratpoison -c "info %t")";for i in /tmp/fenrirscreenreader-*.sock ; do if [[ -S "$i" ]]; then if [[ "$i" = "/tmp/fenrirscreenreader-${winName}.sock" ]] ; then echo -n "setting set screen#suspendingScreen=" | socat - UNIX-CLIENT:$i;else echo -n "setting set screen#suspendingScreen=pty" | socat - UNIX-CLIENT:$i;fi;fi;done;spd-say "$winName"'
