From 388924ed6e276c6f15037867d196302e252f087b Mon Sep 17 00:00:00 2001 From: zerf58 Date: Fri, 13 Jun 2025 16:09:14 -0700 Subject: [PATCH] refactor --- apps/default_commands.sh | 79 +++ apps/discord.sh | 7 + apps/firefox.sh | 74 +++ apps/kodi.sh | 53 ++ apps/spotify.sh | 14 + apps/steam.sh | 17 + apps/vncviewer.sh | 8 + apps/xfdesktop.sh | 9 + buttons.sh | 332 ++-------- debug | 607 ++++++++++++++++++ find_or_open.sh | 11 + get_active_window.sh | 28 + init.sh | 6 +- .../advancedsettings.xml | 0 keyboard.xml => xml/keyboard.xml | 0 .../xfce4-keyboard-shortcuts.xml | 0 16 files changed, 951 insertions(+), 294 deletions(-) create mode 100644 apps/default_commands.sh create mode 100644 apps/discord.sh create mode 100644 apps/firefox.sh create mode 100644 apps/kodi.sh create mode 100644 apps/spotify.sh create mode 100644 apps/steam.sh create mode 100644 apps/vncviewer.sh create mode 100644 apps/xfdesktop.sh create mode 100644 debug create mode 100755 find_or_open.sh create mode 100755 get_active_window.sh rename advancedsettings.xml => xml/advancedsettings.xml (100%) rename keyboard.xml => xml/keyboard.xml (100%) rename xfce4-keyboard-shortcuts.xml => xml/xfce4-keyboard-shortcuts.xml (100%) diff --git a/apps/default_commands.sh b/apps/default_commands.sh new file mode 100644 index 0000000..8eabb61 --- /dev/null +++ b/apps/default_commands.sh @@ -0,0 +1,79 @@ +### if no specific commands found run these + +all(){ + case $1 in + ### navigation etc. + "play") + sleep .3 + xdotool key space + ;; + "fast_forward") + sleep .2 + xdotool key Right + ;; + "rewind") + sleep .2 + xdotool key Left + ;; + "forward" | "back" | "split_up" | "split_down") + debug "no op" + ;; + "split_right") + bluetoothctl disconnect 4C:B9:9B:11:4B:31 + ;; + "split_left") + toggle_res + ;; + + ### 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") + debug "no op" + ;; + "tasks") + debug "no op" + ;; + + "sleep") + sh ~/scripts/PJ/cec.sh + ;; + ### test + "test") + #test code here, run with buttons.sh test + echo "sucessful test" + ;; + *) + echo "unexpected action: ${1-}" + ;; + esac + +} + +toggle_res(){ + display=$(xrandr --listmonitors | grep -o '\S*$' | tail -n 1) + current_res=$(xrandr | grep "$display" | grep -o '[0-9]*x[0-9]*' | head -n 1) + res_1080p="1920x1080" + res_4k="3840x2160" + + if [ "$current_res" = "$res_1080p" ]; then + target_res="$res_4k" + elif [ "$current_res" = "$res_4k" ]; then + target_res="$res_1080p" + fi + + debug "Switching to: $target_res" + xrandr --output "$display" --mode "$target_res" +} diff --git a/apps/discord.sh b/apps/discord.sh new file mode 100644 index 0000000..313621d --- /dev/null +++ b/apps/discord.sh @@ -0,0 +1,7 @@ +discord(){ + + play(){ + sleep .2 + xdotool key F12 + } +} diff --git a/apps/firefox.sh b/apps/firefox.sh new file mode 100644 index 0000000..502f77e --- /dev/null +++ b/apps/firefox.sh @@ -0,0 +1,74 @@ +firefox(){ + debug "no op for ff on this website" +} +firefox_youtube(){ + # fullscreen + split_up(){ + xdotool key f + } + search(){ + helpers + search + } + play(){ + xdotool key k + } + # kiosk + split_right(){ + xdotool key F11 + } + # go to yt.com in shared container + desktop(){ + helpers + firefox 'ext+container:name=shared&url=https://youtube.com' + close_last_tab + } + # open hh container + back(){ + helpers + firefox 'ext+container:name=hh&url=https://youtube.com' + close_last_tab + } + # open fr container + forward(){ + helpers + firefox 'ext+container:name=fr&url=https://youtube.com' + close_last_tab + } +} + +firefox_pbs(){ + firefox_init + + split_up(){ + xdotool mousemove 500 300 + xdotool click 1 click 1 + } + play(){ + xdotool mousemove 500 300 + xdotool click 1 + } + desktop(){ + helpers + home "https://www.pbs.org" + } +} + +### helpers +helpers(){ + close_last_tab(){ + sleep .2 + xdotool key ctrl+shift+Tab + sleep .1 + xdotool key ctrl+w + + } + search(){ + sleep .2 + xdotool key slash + sleep .2 + xdotool key ctrl+a + sleep .2 + xdotool key BackSpace + } +} diff --git a/apps/kodi.sh b/apps/kodi.sh new file mode 100644 index 0000000..0951544 --- /dev/null +++ b/apps/kodi.sh @@ -0,0 +1,53 @@ +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)" + } + +} + + diff --git a/apps/spotify.sh b/apps/spotify.sh new file mode 100644 index 0000000..46e6689 --- /dev/null +++ b/apps/spotify.sh @@ -0,0 +1,14 @@ +spotify(){ + play(){ + sleep .2 + xdotool key space + } + forward(){ + sleep .2 + xdotool key XF86AudioNext + } + back(){ + sleep .2 + xdotool key XF86AudioPrev + } +} diff --git a/apps/steam.sh b/apps/steam.sh new file mode 100644 index 0000000..3e6b9ae --- /dev/null +++ b/apps/steam.sh @@ -0,0 +1,17 @@ +steam_bp(){ + + desktop(){ + sleep .2 + xdotool key alt+Enter + } +} + +steam_lp(){ + + desktop(){ + sleep .2 + xdotool mousemove 1872 13 + sleep .2 + xdotool click 1 + } +} diff --git a/apps/vncviewer.sh b/apps/vncviewer.sh new file mode 100644 index 0000000..01715f5 --- /dev/null +++ b/apps/vncviewer.sh @@ -0,0 +1,8 @@ +vncviewer() { + split_up(){ + sleep .5 + xdotool key F8 + sleep .2 + xdotool key F + } +} diff --git a/apps/xfdesktop.sh b/apps/xfdesktop.sh new file mode 100644 index 0000000..76335a5 --- /dev/null +++ b/apps/xfdesktop.sh @@ -0,0 +1,9 @@ +xfdesktop(){ + + search(){ + rofi -modi drun,run -show drun + } + forward(){ + xfdesktop -N + } +} diff --git a/buttons.sh b/buttons.sh index 227691e..bc4d6ed 100755 --- a/buttons.sh +++ b/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 diff --git a/debug b/debug new file mode 100644 index 0000000..92020d5 --- /dev/null +++ b/debug @@ -0,0 +1,607 @@ +/home/htpc/scripts/PJ +1749852338 +test firefox firefox_youtube +desktop +/home/htpc/scripts/PJ +1749852353 +test firefox firefox_youtube +desktop +/home/htpc/scripts/PJ +1749852354 +test firefox firefox_youtube +desktop +/home/htpc/scripts/PJ +1749852462 + +desktop +/home/htpc/scripts/PJ +1749852550 +test firefox firefox_youtube + +/home/htpc/scripts/PJ +1749852604 +test firefox firefox_youtube + +/home/htpc/scripts/PJ +1749852608 +test firefox firefox_youtube + +/home/htpc/scripts/PJ +1749852609 +test firefox firefox_youtube +desktop +/home/htpc/scripts/PJ +1749852611 +test firefox firefox_youtube +search +/home/htpc/scripts/PJ +1749852615 +test firefox firefox_youtube +desktop +/home/htpc/scripts/PJ +1749852624 +test firefox firefox_youtube +desktop +1749852696 +test firefox firefox_youtube +11111 + +1749852703 +test firefox firefox_youtube +11111 +home +1749852705 +test firefox firefox_youtube +11111 +desktop +1749852759 +firefox_youtube +11111 +desktop +1749852765 +firefox_youtube +11111 +search +1749852818 +firefox_youtube +home +1749852819 +firefox_youtube +home +1749852824 +firefox_youtube +home +1749852846 +firefox_youtube +desktop +1749852886 +firefox_youtube +desktop +1749852907 +firefox_youtube +desktop +1749852927 +firefox_youtube +desktop +1749852946 +firefox_youtube +desktop +1749853013 +firefox_youtube +desktop +1749853048 +firefox_youtube +desktop +1749853051 +firefox_youtube +desktop +1749853057 +firefox_youtube +back +1749853060 +firefox_youtube +forward +1749853064 +firefox_youtube +desktop +1749853085 +firefox +desktop +1749853087 +firefox +desktop +1749853090 +firefox +desktop +1749853097 +firefox +desktop +1749853117 +xfdesktop +browser +1749853119 +firefox +browser +1749853121 +firefox +browser +1749853122 +firefox +desktop +1749853149 +firefox_youtube +desktop +1749853154 +firefox +desktop +1749853182 +firefox +desktop +1749853198 +firefox +desktop +1749853200 +firefox +desktop +1749853254 +firefox +file_explorer +1749853482 +kodi +desktop +target: kodi +no desktop method found in kodi +program specific method not found calling all desktop +1749853484 +kodi +desktop +target: kodi +no desktop method found in kodi +program specific method not found calling all desktop +1749853552 +kodi +desktop +target: kodi +no desktop method found in kodi +program specific method not found calling all desktop +1749853600 +kodi +desktop +active: +no desktop method found in kodi +program specific method not found calling all desktop +1749853630 +kodi +desktop +kodi sourced +active: +no desktop method found in kodi +program specific method not found calling all desktop +1749853765 +active: kodi +button: desktop +kodi sourced +active: +no desktop method found in kodi +program specific method not found calling all desktop + +1749853786 +active: kodi +button: desktop +kodi sourced +active: +no desktop method found in kodi +program specific method not found calling all desktop + +1749853788 +active: kodi +button: desktop +kodi sourced +active: +no desktop method found in kodi +program specific method not found calling all desktop + +1749853791 +active: kodi +button: desktop +kodi sourced +active: +no desktop method found in kodi +program specific method not found calling all desktop + +1749853891 +active: kodi +button: desktop +kodi sourced +found kodi methods +found desktop + +1749853980 +active: xfdesktop +button: search +xfdesktop sourced +found xfdesktop methods +found search + +1749853994 +active: xfdesktop +button: forward +xfdesktop sourced +found xfdesktop methods +program specific method not found calling all forward + +1749854004 +active: xfdesktop +button: fast_forward +xfdesktop sourced +found xfdesktop methods +program specific method not found calling all fast_forward + +1749854038 +active: xfdesktop +button: forward +xfdesktop sourced +found xfdesktop methods +found forward + +1749854040 +active: xfdesktop +button: forward +xfdesktop sourced +found xfdesktop methods +found forward + +1749854196 +active: vncviewer +button: desktop +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktop + +1749854224 +active: vncviewer +button: desktop +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktop + +1749854233 +active: vncviewer +button: desktop +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktop +no op + +1749854234 +active: vncviewer +button: desktop +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktop +no op + +1749854261 +active: vncviewer +button: desktop +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktop +no op + +1749854293 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854295 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854297 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854299 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854301 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854302 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854306 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854309 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854311 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854312 +active: vncviewer +button: split_down +vncviewer sourced +found vncviewer methods +program specific method not found calling all split_down + +1749854320 +active: vncviewer +button: split_up +vncviewer sourced +found vncviewer methods +found split_up + +1749854461 +active: vncviewer +button: desktopp +vncviewer sourced +found vncviewer methods +program specific method not found calling all desktopp + +1749855450 +active: xfdesktop +button: browser +xfdesktop sourced +found xfdesktop methods +program specific method not found calling all browser + +1749855455 +active: firefox_youtube +button: desktop +firefox_youtube sourced +found firefox_youtube methods +found desktop + +1749855458 +active: firefox_youtube +button: desktop +firefox_youtube sourced +found firefox_youtube methods +found desktop + +1749855464 +active: firefox_youtube +button: desktop +firefox_youtube sourced +found firefox_youtube methods +found desktop + +1749855472 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855479 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855481 +active: firefox_youtube +button: forward +firefox_youtube sourced +found firefox_youtube methods +found forward + +1749855572 +active: firefox_youtube +button: file_explorer +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all file_explorer + +1749855576 +active: kodi +button: browser +kodi sourced +found kodi methods +program specific method not found calling all browser + +1749855578 +active: firefox_youtube +button: file_explorer +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all file_explorer + +1749855579 +active: kodi +button: file_explorer +kodi sourced +found kodi methods +found file_explorer + +1749855580 +active: kodi +button: file_explorer +kodi sourced +found kodi methods +found file_explorer + +1749855581 +active: kodi +button: browser +kodi sourced +found kodi methods +program specific method not found calling all browser + +1749855582 +active: firefox_youtube +button: browser +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all browser + +1749855583 +active: firefox_youtube +button: browser +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all browser + +1749855584 +active: firefox_youtube +button: browser +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all browser + +1749855584 +active: firefox_youtube +button: browser +firefox_youtube sourced +found firefox_youtube methods +program specific method not found calling all browser + +1749855587 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855588 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855589 +active: firefox_youtube +button: desktop +firefox_youtube sourced +found firefox_youtube methods +found desktop + +1749855717 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855720 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855728 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855737 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855755 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855764 +active: firefox_youtube +button: forward +firefox_youtube sourced +found firefox_youtube methods +found forward + +1749855775 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855779 +active: firefox_youtube +button: desktop +firefox_youtube sourced +found firefox_youtube methods +found desktop + +1749855783 +active: firefox_youtube +button: back +firefox_youtube sourced +found firefox_youtube methods +found back + +1749855786 +active: firefox_youtube +button: forward +firefox_youtube sourced +found firefox_youtube methods +found forward + +1749855804 +active: firefox_youtube +button: search +firefox_youtube sourced +found firefox_youtube methods +found search + +1749855811 +active: firefox_youtube +button: search +firefox_youtube sourced +found firefox_youtube methods +found search + +1749856037 +active: firefox +button: desktop +firefox sourced +found firefox methods +no op for ff on this website +program specific method not found calling all desktop +no op diff --git a/find_or_open.sh b/find_or_open.sh new file mode 100755 index 0000000..20851d4 --- /dev/null +++ b/find_or_open.sh @@ -0,0 +1,11 @@ +#!/bin/bash +helper_find_or_open(){ + windows=$(wmctrl -l) + if [[ "${windows,,}" == *"$1"* ]]; then + xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)" + echo "found $1" + else + nohup "$1" >/dev/null 2>&1 & + echo "opening $1" + fi +} diff --git a/get_active_window.sh b/get_active_window.sh new file mode 100755 index 0000000..08b1c68 --- /dev/null +++ b/get_active_window.sh @@ -0,0 +1,28 @@ +#!/bin/bash +shopt -s nocasematch # ignore case for website titles +websites=("youtube" "youtube" "pbs") + +### get active window +active="$(xdotool getactivewindow getwindowclassname)" +name="$(xdotool getactivewindow getwindowname)" +active="${active,,}" +case "$active" in + *"firefox" ) + for ws in "${websites[@]}"; do + if [[ "$name" == *"$ws"* ]]; then + active+="_$ws" + break + fi + done + ;; + *"steam") + if [[ "$name" == *"picture"* ]]; then + active+="_big" + else + active+="_little" + fi + ;; +esac + +echo "$active" + diff --git a/init.sh b/init.sh index 7810acb..5459682 100755 --- a/init.sh +++ b/init.sh @@ -1,13 +1,13 @@ #!/bin/bash rm /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml -ln /home/htpc/scripts/PJ/xfce4-keyboard-shortcuts.xml /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml +ln /home/htpc/scripts/PJ/xml/xfce4-keyboard-shortcuts.xml /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml rm /home/htpc/.kodi/userdata/keymaps/keyboard.xml -ln /home/htpc/scripts/PJ/keyboard.xml /home/htpc/.kodi/userdata/keymaps/keyboard.xml +ln /home/htpc/scripts/PJ/xml/keyboard.xml /home/htpc/.kodi/userdata/keymaps/keyboard.xml rm /home/htpc/.kodi/userdata/advancedsettings.xml -export $(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs) +export $(grep -v '^#' /home/htpc/scripts/PJ/xml/secrets.env | xargs) envsubst < /home/htpc/scripts/PJ/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml # disable the power button on PJ, ignore if already commented diff --git a/advancedsettings.xml b/xml/advancedsettings.xml similarity index 100% rename from advancedsettings.xml rename to xml/advancedsettings.xml diff --git a/keyboard.xml b/xml/keyboard.xml similarity index 100% rename from keyboard.xml rename to xml/keyboard.xml diff --git a/xfce4-keyboard-shortcuts.xml b/xml/xfce4-keyboard-shortcuts.xml similarity index 100% rename from xfce4-keyboard-shortcuts.xml rename to xml/xfce4-keyboard-shortcuts.xml