diff --git a/PKGBUILD b/PKGBUILD index 87efffb..8c2e3b8 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,11 +1,11 @@ # Maintainer: 0xDEADCADE <$(base64 -d<< pkgname=headsetcontrol-chatmixd-git _pkgname=${pkgname%-git} -pkgver=r1.2cab32f +pkgver=r1.d79fb51 pkgrel=1 pkgdesc="A bash daemon to control volume of different applications through the Chatmix wheel." arch=('any') -url="https://github.com/0xDEADCADE/${_pkgname}" +url="https://g.deadca.de/deadcade/${_pkgname}" license=('GPLv3') provides=("$_pkgname") conflicts=("$_pkgname") @@ -24,5 +24,5 @@ package() { cd $pkgname install -D -m755 "$_pkgname" "$pkgdir/usr/bin/$_pkgname" install -D -m644 LICENSE "$pkgdir/usr/share/licenses/$_pkgname/LICENSE" - install -D -m644 "${_pkgname}.service" "$pkgdir/usr/lib/systemd/user/" + install -D -m644 "${_pkgname}.service" "$pkgdir/usr/lib/systemd/user/${_pkgname}.service" } diff --git a/headsetcontrol-chatmixd b/headsetcontrol-chatmixd index a3e01f3..6f5ff64 100755 --- a/headsetcontrol-chatmixd +++ b/headsetcontrol-chatmixd @@ -1,7 +1,7 @@ #!/bin/bash # Config -_pollingInterval=1 +_pollingInterval=0 _chatmixCenter=64 _chatmixCenterSize=5 _debug=1 @@ -9,10 +9,12 @@ _voicechatSink="Voicechat_chatmixd" _gameSink="Game_chatmixd" # Internal vars -_running=0 +_running=false _centerMin=$((_chatmixCenter - _chatmixCenterSize)) _centerMax=$((_chatmixCenter + _chatmixCenterSize)) declare -A _known_devices +_voicechatSinkModule="" +_gameSinkModule="" # Main loop update() { @@ -20,7 +22,7 @@ update() { local _chatmix=$2 local _old_chatmix=${_known_devices["${_model}"]} _known_devices["${_model}"]=${_chatmix} - [[ ${_running} -eq 0 ]] && return + [[ ! ${_running} ]] && return [[ ${_debug} -eq 1 ]] && printf "Model: %s Chatmix: %s -> %s\n" "${_model}" "${_old_chatmix}" "${_chatmix}" [[ "${_chatmix}" == "${_old_chatmix}" ]] && return @@ -61,22 +63,28 @@ main() { fi # Link up sinks to default sink, try to avoid looping - if [[ "$DEFAULT_SINK" != *"${_voicechatSink}"* ]] && [[ "$DEFAULT_SINK" != *"${_gameSink}"* ]]; then - pw-link "${_voicechatSink}:monitor_FL" "$DEFAULT_SINK:playback_FL" - pw-link "${_voicechatSink}:monitor_FR" "$DEFAULT_SINK:playback_FR" - pw-link "${_gameSink}:monitor_FL" "$DEFAULT_SINK:playback_FL" - pw-link "${_gameSink}:monitor_FR" "$DEFAULT_SINK:playback_FR" + if [[ "$DEFAULT_SINK" != *"${_voicechatSink}"* ]] && [[ "${_defaultSink}" != *"${_gameSink}"* ]]; then + pw-link "${_voicechatSink}:monitor_FL" "${_defaultSink}:playback_FL" + pw-link "${_voicechatSink}:monitor_FR" "${_defaultSink}:playback_FR" + pw-link "${_gameSink}:monitor_FL" "${_defaultSink}:playback_FL" + pw-link "${_gameSink}:monitor_FR" "${_defaultSink}:playback_FR" fi - while true; do + _running=true + while ${_running}; do # shellcheck disable=SC1090 source <(headsetcontrol -o ENV) update "${DEVICE_0}" "${DEVICE_0_CHATMIX}" sleep ${_pollingInterval} - _running=1 done +} + +trap close INT TERM + +function close() { pactl unload-module "${_voicechatSinkModule}" pactl unload-module "${_gameSinkModule}" + _running=false } main