refactor
This commit is contained in:
parent
a31e08bd5f
commit
388924ed6e
16 changed files with 951 additions and 294 deletions
332
buttons.sh
332
buttons.sh
|
@ -1,302 +1,52 @@
|
|||
#!/bin/bash
|
||||
shopt -s nocasematch #sets case insensitive option for the shell
|
||||
websites=("youtube" "pbs")
|
||||
|
||||
export ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
button=$1
|
||||
|
||||
### if no specific commands found run these
|
||||
all(){
|
||||
case $1 in
|
||||
### navigation etc.
|
||||
"play")
|
||||
#sleep .5
|
||||
xdotool_helper "key space"
|
||||
;;
|
||||
"fast_forward")
|
||||
xdotool_helper "key Right"
|
||||
;;
|
||||
"rewind")
|
||||
xdotool_helper "key Left"
|
||||
;;
|
||||
"forward" | "back" | "split_up" | "split_down")
|
||||
sleep .1
|
||||
echo "no default action assigned to $1"
|
||||
;;
|
||||
"split_right")
|
||||
bluetoothctl disconnect 4C:B9:9B:11:4B:31
|
||||
;;
|
||||
"split_left")
|
||||
sh /home/htpc/scripts/xrandr.sh
|
||||
;;
|
||||
|
||||
### top buttons
|
||||
"main" | "notification" | "settings" | "task_manager" | "search")
|
||||
echo "no default action assigned to $1"
|
||||
;;
|
||||
"browser")
|
||||
helper_find_or_open firefox
|
||||
;;
|
||||
"file_explorer")
|
||||
helper_find_or_open kodi
|
||||
;;
|
||||
"action_center")
|
||||
helper_find_or_open steam
|
||||
;;
|
||||
|
||||
### arrow buttons
|
||||
"desktop")
|
||||
;;
|
||||
"tasks")
|
||||
;;
|
||||
|
||||
"sleep")
|
||||
sh ~/scripts/PJ/cec.sh
|
||||
;;
|
||||
### test
|
||||
"test")
|
||||
#test code here, run with buttons.sh test
|
||||
echo "sucessful test"
|
||||
;;
|
||||
*)
|
||||
echo "unexpected action: ${1-}"
|
||||
;;
|
||||
esac
|
||||
|
||||
debug(){
|
||||
debug=$ROOT/debug
|
||||
echo $1
|
||||
echo $1>>$debug
|
||||
}
|
||||
# debugging
|
||||
#tail -n 30 "$debug" > tmp && cp tmp "$debug"
|
||||
active=$(bash $ROOT/get_active_window.sh)
|
||||
debug ""
|
||||
debug "$(date +%s)"
|
||||
debug "active: $active"
|
||||
debug "button: $button"
|
||||
|
||||
|
||||
|
||||
|
||||
firefox_youtube(){
|
||||
firefox_init
|
||||
|
||||
split_up(){
|
||||
|
||||
xdotool_helper "key f"
|
||||
}
|
||||
search(){
|
||||
ff_search
|
||||
}
|
||||
play(){
|
||||
echo "ffyt play"
|
||||
xdotool_helper "key k"
|
||||
}
|
||||
desktop(){
|
||||
ff_home "https://www.youtube.com"
|
||||
}
|
||||
split_right(){
|
||||
xdotool_helper "key F11"
|
||||
}
|
||||
# move_up(){
|
||||
# ff_home 'ext+container:name=hh&url=https://youtube.com'
|
||||
# }
|
||||
forward(){
|
||||
ff_home 'ext+container:name=fr&url=https://youtube.com'
|
||||
}
|
||||
}
|
||||
|
||||
firefox_pbs(){
|
||||
firefox_init
|
||||
|
||||
split_up(){
|
||||
xdotool_helper "mousemove 500 300"
|
||||
xdotool_helper "click 1 click 1"
|
||||
}
|
||||
play(){
|
||||
xdotool_helper "mousemove 500 300"
|
||||
xdotool_helper "click 1"
|
||||
}
|
||||
desktop(){
|
||||
ff_home "https://www.pbs.org"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Kodi(){
|
||||
|
||||
play(){
|
||||
kodi-send --action="PlayPause"
|
||||
}
|
||||
forward(){
|
||||
kodi-send --action="SkipNext"
|
||||
}
|
||||
back(){
|
||||
kodi-send --action="SkipPrevious"
|
||||
}
|
||||
split_up(){
|
||||
xdotool_helper "key p"
|
||||
}
|
||||
move_up(){
|
||||
xdotool_helper "key o"
|
||||
}
|
||||
search(){
|
||||
kodi-send --action="VideoLibrary.Search"
|
||||
}
|
||||
desktop(){
|
||||
kodi-send --action="PreviousMenu"
|
||||
}
|
||||
refresh(){
|
||||
kodi-send --action="UpdateLibrary(video)"
|
||||
}
|
||||
notification(){
|
||||
kodi-send --action="ShowSubtitles"
|
||||
}
|
||||
settings(){
|
||||
kodi-send --action="ActivateWindow(10123)"
|
||||
for i in {0..3}
|
||||
do
|
||||
kodi-send --action="Down"
|
||||
done
|
||||
kodi-send --action="Select"
|
||||
}
|
||||
fast_forward(){
|
||||
kodi-send --action="NextPreset"
|
||||
}
|
||||
rewind(){
|
||||
kodi-send --action="PreviousPreset"
|
||||
}
|
||||
split_right(){
|
||||
kodi-send --action="LockPreset"
|
||||
}
|
||||
file_explorer(){
|
||||
kodi-send --action="ActivateWindow(12901)"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
steam_bp(){
|
||||
|
||||
desktop(){
|
||||
xdotool_helper "key alt+Enter"
|
||||
}
|
||||
}
|
||||
|
||||
steam_lp(){
|
||||
|
||||
desktop(){
|
||||
xdotool_helper "mousemove 1872 13"
|
||||
xdotool_helper "click 1"
|
||||
}
|
||||
}
|
||||
|
||||
Xfdesktop(){
|
||||
|
||||
search(){
|
||||
rofi -modi drun,run -show drun
|
||||
}
|
||||
next(){
|
||||
xfdesktop -N
|
||||
}
|
||||
}
|
||||
|
||||
Spotify(){
|
||||
play(){
|
||||
xdotool_helper "key space"
|
||||
}
|
||||
forward(){
|
||||
xdotool_helper "key XF86AudioNext"
|
||||
}
|
||||
back(){
|
||||
xdotool_helper "key XF86AudioPrev"
|
||||
}
|
||||
}
|
||||
|
||||
#firefox(){
|
||||
|
||||
# echo "return and run all()"
|
||||
#}
|
||||
|
||||
discord(){
|
||||
|
||||
play(){
|
||||
xdotool_helper "key F12"
|
||||
}
|
||||
}
|
||||
|
||||
Vncviewer() {
|
||||
split_up(){
|
||||
xdotool_helper "key F8"
|
||||
sleep .1
|
||||
xdotool_helper "key F"
|
||||
}
|
||||
}
|
||||
|
||||
mousepad(){
|
||||
echo "return and run all()"
|
||||
}
|
||||
|
||||
other(){
|
||||
echo "return and run all()"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
### helpers
|
||||
firefox_init(){
|
||||
|
||||
ff_home(){
|
||||
#xdg-open $1
|
||||
firefox $1
|
||||
sleep .1
|
||||
xdotool_helper "key ctrl+shift+Tab"
|
||||
sleep .1
|
||||
xdotool_helper "key ctrl+w"
|
||||
|
||||
}
|
||||
ff_search(){
|
||||
sleep .2
|
||||
xdotool_helper "key slash"
|
||||
sleep .2
|
||||
xdotool_helper "key ctrl+a"
|
||||
sleep .2
|
||||
xdotool_helper "key BackSpace"
|
||||
}
|
||||
}
|
||||
|
||||
helper_find_or_open() {
|
||||
windows=$(wmctrl -l)
|
||||
if [[ "$windows" == *"$1"* ]]; then
|
||||
xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)"
|
||||
else
|
||||
nohup "$1" >/dev/null 2>&1 &
|
||||
fi
|
||||
}
|
||||
|
||||
xdotool_helper(){
|
||||
sleep .2
|
||||
xdotool $1
|
||||
}
|
||||
|
||||
### get active window
|
||||
target="$(xdotool getactivewindow getwindowclassname)"
|
||||
|
||||
if [[ "$target" == *"firefox"* ]]; then
|
||||
name="$(xdotool getactivewindow getwindowname)"
|
||||
for ws in "${websites[@]}"; do
|
||||
if [[ "$name" == *"$ws"* ]]; then
|
||||
target+="_$ws"
|
||||
fi
|
||||
done
|
||||
elif [[ "$target" == *"steam"* ]]; then
|
||||
name="$(xdotool getactivewindow getwindowname)"
|
||||
if [[ "$name" == *"picture"* ]]; then
|
||||
target+="_bp"
|
||||
else
|
||||
tagret+="_lp"
|
||||
fi
|
||||
# source the app folder
|
||||
#APPS="$(pwd)/apps"
|
||||
#if [ -d "$APPS" ]; then
|
||||
# for file in "$APPS"/*; do
|
||||
# if [ -f "$file" ]; then
|
||||
# . "$file"
|
||||
# fi
|
||||
# done
|
||||
#fi
|
||||
. $ROOT/find_or_open.sh
|
||||
. $ROOT/apps/default_commands.sh
|
||||
if [ -f "$ROOT/apps/${active%%_*}.sh" ]; then
|
||||
. "$ROOT/apps/${active%%_*}.sh"
|
||||
debug "$active sourced"
|
||||
else
|
||||
debug "no $active source found"
|
||||
fi
|
||||
|
||||
printf "action: %s\ntarget: %s\n" "$1" "$target"
|
||||
|
||||
### init target functions
|
||||
$target
|
||||
|
||||
### find and run $1
|
||||
if [[ $(type -t $1) == function ]]; then
|
||||
$1
|
||||
if [[ $(type -t $active) == function ]]; then
|
||||
debug "found $active methods"
|
||||
$active
|
||||
else
|
||||
echo "program specific method not found calling all_$1"
|
||||
all $1
|
||||
#echo "unexpected action: ${1-}"
|
||||
debug "no $button method found in $active"
|
||||
fi
|
||||
|
||||
if [[ $(type -t $button) == function ]]; then
|
||||
debug "found $button"
|
||||
$1
|
||||
else
|
||||
debug "program specific method not found calling all $button"
|
||||
all $1
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue