Compare commits
2 Commits
7cb7f10ff6
...
626c7dbcc1
| Author | SHA1 | Date | |
|---|---|---|---|
| 626c7dbcc1 | |||
| 35374800bf |
@@ -1,143 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# HyprFlux — https://github.com/ahmad9059/HyprFlux
|
# Volume controls for audio and mic via wpctl (PipeWire).
|
||||||
# Scripts for volume controls for audio and mic
|
# Quickshell's VolumeOsd watches PipeWire directly, so no notifications here.
|
||||||
|
|
||||||
iDIR="$HOME/.config/swaync/icons"
|
SINK="@DEFAULT_AUDIO_SINK@"
|
||||||
sDIR="$HOME/.config/hypr/scripts"
|
SOURCE="@DEFAULT_AUDIO_SOURCE@"
|
||||||
|
STEP="5%"
|
||||||
|
|
||||||
# Get Volume
|
# Print volume as an integer percent, or "Muted"
|
||||||
get_volume() {
|
get_volume() {
|
||||||
volume=$(pamixer --get-volume)
|
local out
|
||||||
if [[ "$volume" -eq "0" ]]; then
|
out=$(wpctl get-volume "$1")
|
||||||
|
if [[ "$out" == *MUTED* ]]; then
|
||||||
echo "Muted"
|
echo "Muted"
|
||||||
else
|
else
|
||||||
echo "$volume %"
|
awk '{ printf "%d %%\n", $2 * 100 + 0.5 }' <<< "$out"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get icons
|
is_muted() {
|
||||||
get_icon() {
|
[[ "$(wpctl get-volume "$1")" == *MUTED* ]]
|
||||||
current=$(get_volume)
|
|
||||||
if [[ "$current" == "Muted" ]]; then
|
|
||||||
echo "$iDIR/volume-mute.png"
|
|
||||||
elif [[ "${current%\%}" -le 30 ]]; then
|
|
||||||
echo "$iDIR/volume-low.png"
|
|
||||||
elif [[ "${current%\%}" -le 60 ]]; then
|
|
||||||
echo "$iDIR/volume-mid.png"
|
|
||||||
else
|
|
||||||
echo "$iDIR/volume-high.png"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Notify
|
# Raising/lowering while muted unmutes first, matching the old behaviour
|
||||||
notify_user() {
|
inc() { is_muted "$1" && wpctl set-mute "$1" 0 || wpctl set-volume -l 1.0 "$1" "$STEP+"; }
|
||||||
if [[ "$(get_volume)" == "Muted" ]]; then
|
dec() { is_muted "$1" && wpctl set-mute "$1" 0 || wpctl set-volume "$1" "$STEP-"; }
|
||||||
notify-send -e -h string:x-canonical-private-synchronous:volume_notif -h boolean:SWAYNC_BYPASS_DND:true -u low -i "$(get_icon)" " Volume:" " Muted"
|
|
||||||
else
|
|
||||||
notify-send -e -h int:value:"$(get_volume | sed 's/%//')" -h string:x-canonical-private-synchronous:volume_notif -h boolean:SWAYNC_BYPASS_DND:true -u low -i "$(get_icon)" " Volume Level:" " $(get_volume)" &&
|
|
||||||
"$sDIR/Sounds.sh" --volume
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Increase Volume
|
case "$1" in
|
||||||
inc_volume() {
|
--inc) inc "$SINK" ;;
|
||||||
if [ "$(pamixer --get-mute)" == "true" ]; then
|
--dec) dec "$SINK" ;;
|
||||||
toggle_mute
|
--toggle) wpctl set-mute "$SINK" toggle ;;
|
||||||
else
|
--toggle-mic) wpctl set-mute "$SOURCE" toggle ;;
|
||||||
pamixer -i 5 --allow-boost --set-limit 150 && notify_user
|
--mic-inc) inc "$SOURCE" ;;
|
||||||
fi
|
--mic-dec) dec "$SOURCE" ;;
|
||||||
}
|
--get-mic) get_volume "$SOURCE" ;;
|
||||||
|
*) get_volume "$SINK" ;;
|
||||||
# Decrease Volume
|
esac
|
||||||
dec_volume() {
|
|
||||||
if [ "$(pamixer --get-mute)" == "true" ]; then
|
|
||||||
toggle_mute
|
|
||||||
else
|
|
||||||
pamixer -d 5 && notify_user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Toggle Mute
|
|
||||||
toggle_mute() {
|
|
||||||
if [ "$(pamixer --get-mute)" == "false" ]; then
|
|
||||||
pamixer -m && notify-send -e -u low -h boolean:SWAYNC_BYPASS_DND:true -i "$iDIR/volume-mute.png" " Mute"
|
|
||||||
elif [ "$(pamixer --get-mute)" == "true" ]; then
|
|
||||||
pamixer -u && notify-send -e -u low -h boolean:SWAYNC_BYPASS_DND:true -i "$(get_icon)" " Volume:" " Switched ON"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Toggle Mic
|
|
||||||
toggle_mic() {
|
|
||||||
if [ "$(pamixer --default-source --get-mute)" == "false" ]; then
|
|
||||||
pamixer --default-source -m && notify-send -e -u low -h boolean:SWAYNC_BYPASS_DND:true -i "$iDIR/microphone-mute.png" " Microphone:" " Switched OFF"
|
|
||||||
elif [ "$(pamixer --default-source --get-mute)" == "true" ]; then
|
|
||||||
pamixer -u --default-source u && notify-send -e -u low -h boolean:SWAYNC_BYPASS_DND:true -i "$iDIR/microphone.png" " Microphone:" " Switched ON"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
# Get Mic Icon
|
|
||||||
get_mic_icon() {
|
|
||||||
current=$(pamixer --default-source --get-volume)
|
|
||||||
if [[ "$current" -eq "0" ]]; then
|
|
||||||
echo "$iDIR/microphone-mute.png"
|
|
||||||
else
|
|
||||||
echo "$iDIR/microphone.png"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get Microphone Volume
|
|
||||||
get_mic_volume() {
|
|
||||||
volume=$(pamixer --default-source --get-volume)
|
|
||||||
if [[ "$volume" -eq "0" ]]; then
|
|
||||||
echo "Muted"
|
|
||||||
else
|
|
||||||
echo "$volume %"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Notify for Microphone
|
|
||||||
notify_mic_user() {
|
|
||||||
volume=$(get_mic_volume)
|
|
||||||
icon=$(get_mic_icon)
|
|
||||||
notify-send -e -h int:value:"$volume" -h "string:x-canonical-private-synchronous:volume_notif" -h boolean:SWAYNC_BYPASS_DND:true -u low -i "$icon" " Mic Level:" " $volume"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Increase MIC Volume
|
|
||||||
inc_mic_volume() {
|
|
||||||
if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
|
|
||||||
toggle_mic
|
|
||||||
else
|
|
||||||
pamixer --default-source -i 5 && notify_mic_user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Decrease MIC Volume
|
|
||||||
dec_mic_volume() {
|
|
||||||
if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
|
|
||||||
toggle-mic
|
|
||||||
else
|
|
||||||
pamixer --default-source -d 5 && notify_mic_user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Execute accordingly
|
|
||||||
if [[ "$1" == "--get" ]]; then
|
|
||||||
get_volume
|
|
||||||
elif [[ "$1" == "--inc" ]]; then
|
|
||||||
inc_volume
|
|
||||||
elif [[ "$1" == "--dec" ]]; then
|
|
||||||
dec_volume
|
|
||||||
elif [[ "$1" == "--toggle" ]]; then
|
|
||||||
toggle_mute
|
|
||||||
elif [[ "$1" == "--toggle-mic" ]]; then
|
|
||||||
toggle_mic
|
|
||||||
elif [[ "$1" == "--get-icon" ]]; then
|
|
||||||
get_icon
|
|
||||||
elif [[ "$1" == "--get-mic-icon" ]]; then
|
|
||||||
get_mic_icon
|
|
||||||
elif [[ "$1" == "--mic-inc" ]]; then
|
|
||||||
inc_mic_volume
|
|
||||||
elif [[ "$1" == "--mic-dec" ]]; then
|
|
||||||
dec_mic_volume
|
|
||||||
else
|
|
||||||
get_volume
|
|
||||||
fi
|
|
||||||
|
|||||||
@@ -11,16 +11,13 @@ PanelWindow {
|
|||||||
color: "transparent"
|
color: "transparent"
|
||||||
exclusiveZone: 0
|
exclusiveZone: 0
|
||||||
|
|
||||||
// Top-right, just under the bar — same fixed distance from the bar and
|
// Bottom-center: anchoring only the bottom edge lets the layer shell
|
||||||
// screen edge (Appearance.spacing) that every popup opened from the bar
|
// center it horizontally.
|
||||||
// itself uses, so this lines up with them instead of floating
|
anchors { bottom: true }
|
||||||
// bottom-center.
|
margins.bottom: Appearance.spacing * 4
|
||||||
anchors { top: true; right: true }
|
|
||||||
margins.top: Appearance.spacing
|
|
||||||
margins.right: Appearance.spacing
|
|
||||||
|
|
||||||
implicitWidth: 272
|
implicitWidth: 300
|
||||||
implicitHeight: 54
|
implicitHeight: 60
|
||||||
|
|
||||||
WlrLayershell.layer: WlrLayer.Overlay
|
WlrLayershell.layer: WlrLayer.Overlay
|
||||||
WlrLayershell.namespace: "quickshell:osd"
|
WlrLayershell.namespace: "quickshell:osd"
|
||||||
@@ -49,13 +46,13 @@ PanelWindow {
|
|||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 14
|
anchors.margins: 15
|
||||||
spacing: 12
|
spacing: 13
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
font.family: Appearance.iconFontFamilyRounded
|
font.family: Appearance.iconFontFamilyRounded
|
||||||
font.variableAxes: Appearance.iconFontAxes
|
font.variableAxes: Appearance.iconFontAxes
|
||||||
font.pixelSize: 18
|
font.pixelSize: 21
|
||||||
color: Colors.foreground
|
color: Colors.foreground
|
||||||
text: {
|
text: {
|
||||||
const audio = osd.sink ? osd.sink.audio : null
|
const audio = osd.sink ? osd.sink.audio : null
|
||||||
@@ -67,7 +64,7 @@ PanelWindow {
|
|||||||
Item {
|
Item {
|
||||||
id: slider
|
id: slider
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: 16
|
implicitHeight: 18
|
||||||
|
|
||||||
readonly property real value: osd.sink && osd.sink.audio ? osd.sink.audio.volume : 0
|
readonly property real value: osd.sink && osd.sink.audio ? osd.sink.audio.volume : 0
|
||||||
readonly property bool enabled: !!osd.sink
|
readonly property bool enabled: !!osd.sink
|
||||||
@@ -76,7 +73,7 @@ PanelWindow {
|
|||||||
id: track
|
id: track
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 4
|
height: 5
|
||||||
radius: 0
|
radius: 0
|
||||||
color: Colors.muted
|
color: Colors.muted
|
||||||
opacity: 0.35
|
opacity: 0.35
|
||||||
@@ -85,15 +82,15 @@ PanelWindow {
|
|||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
width: track.width * Math.max(0, Math.min(1, slider.value))
|
width: track.width * Math.max(0, Math.min(1, slider.value))
|
||||||
height: 4
|
height: 5
|
||||||
radius: 0
|
radius: 0
|
||||||
color: Colors.primary
|
color: Colors.primary
|
||||||
opacity: slider.enabled ? 1 : 0.4
|
opacity: slider.enabled ? 1 : 0.4
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: 12
|
width: 14
|
||||||
height: 12
|
height: 14
|
||||||
radius: 6
|
radius: 7
|
||||||
color: Colors.primary
|
color: Colors.primary
|
||||||
opacity: slider.enabled ? 1 : 0.4
|
opacity: slider.enabled ? 1 : 0.4
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
@@ -113,10 +110,10 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
Layout.preferredWidth: 32
|
Layout.preferredWidth: 38
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
font.family: Appearance.fontFamily
|
font.family: Appearance.fontFamily
|
||||||
font.pixelSize: Appearance.fontSizeSmall
|
font.pixelSize: 13
|
||||||
color: Colors.muted
|
color: Colors.muted
|
||||||
text: Math.round(slider.value * 100) + "%"
|
text: Math.round(slider.value * 100) + "%"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user