mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-05 14:59:27 -05:00
[FEATURE] Adjust volume via music widget (#953)
This commit is contained in:
@@ -26,6 +26,22 @@ function trimTrackTitle(title) {
|
||||
return title;
|
||||
}
|
||||
|
||||
function adjustVolume(direction) {
|
||||
const step = 0.03;
|
||||
execAsync(['playerctl', 'volume'])
|
||||
.then((output) => {
|
||||
let currentVolume = parseFloat(output.trim());
|
||||
let newVolume = direction === 'up' ? currentVolume + step : currentVolume - step;
|
||||
|
||||
if (newVolume > 1.0) newVolume = 1.0;
|
||||
if (newVolume < 0.0) newVolume = 0.0;
|
||||
|
||||
execAsync(['playerctl', 'volume', newVolume.toFixed(2)]).catch(print);
|
||||
})
|
||||
.catch(print);
|
||||
}
|
||||
|
||||
|
||||
const BarGroup = ({ child }) => Box({
|
||||
className: 'bar-group-margin bar-sides',
|
||||
children: [
|
||||
@@ -105,6 +121,8 @@ const switchToRelativeWorkspace = async (self, num) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default () => {
|
||||
// TODO: use cairo to make button bounce smaller on click, if that's possible
|
||||
const playingState = Box({ // Wrap a box cuz overlay can't have margins itself
|
||||
@@ -208,8 +226,8 @@ export default () => {
|
||||
});
|
||||
}
|
||||
return EventBox({
|
||||
onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
|
||||
onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
|
||||
onScrollUp: () => adjustVolume('up'),
|
||||
onScrollDown: () => adjustVolume('down'),
|
||||
child: Box({
|
||||
className: 'spacing-h-4',
|
||||
children: [
|
||||
@@ -228,3 +246,4 @@ export default () => {
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
change=$1
|
||||
|
||||
current_volume=$(playerctl volume)
|
||||
|
||||
new_volume=$(echo "$current_volume + $change" | bc)
|
||||
|
||||
if (( $(echo "$new_volume > 1.0" | bc -l) )); then
|
||||
new_volume=1.0
|
||||
elif (( $(echo "$new_volume < 0.0" | bc -l) )); then
|
||||
new_volume=0.0
|
||||
fi
|
||||
|
||||
playerctl volume "$new_volume"
|
||||
@@ -180,6 +180,8 @@ bind = Super+Alt, Equal, exec, notify-send "Urgent notification" "Ah hell no" -u
|
||||
bindl= Super+Shift, N, exec, playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` # Next track
|
||||
bindl= ,XF86AudioNext, exec, playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` # [hidden]
|
||||
bindl= ,XF86AudioPrev, exec, playerctl previous # [hidden]
|
||||
bindel = Super+Shift, Comma, exec, ~/.config/ags/scripts/music/adjust-volume.sh -0.03 # Raise music volume
|
||||
bindel = Super+Shift, Period, exec, ~/.config/ags/scripts/music/adjust-volume.sh 0.03 # Lower music volume
|
||||
bind = Super+Shift+Alt, mouse:275, exec, playerctl previous # [hidden]
|
||||
bind = Super+Shift+Alt, mouse:276, exec, playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` # [hidden]
|
||||
bindl= Super+Shift, B, exec, playerctl previous # Previous track
|
||||
|
||||
Reference in New Issue
Block a user