forked from Shinonome/dots-hyprland
New feature: adjust music volume by scrolling the music widget up/down
This commit is contained in:
@@ -26,6 +26,22 @@ function trimTrackTitle(title) {
|
|||||||
return 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({
|
const BarGroup = ({ child }) => Box({
|
||||||
className: 'bar-group-margin bar-sides',
|
className: 'bar-group-margin bar-sides',
|
||||||
children: [
|
children: [
|
||||||
@@ -105,6 +121,8 @@ const switchToRelativeWorkspace = async (self, num) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
// TODO: use cairo to make button bounce smaller on click, if that's possible
|
// 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
|
const playingState = Box({ // Wrap a box cuz overlay can't have margins itself
|
||||||
@@ -208,8 +226,8 @@ export default () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return EventBox({
|
return EventBox({
|
||||||
onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
|
onScrollUp: () => adjustVolume('up'),
|
||||||
onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
|
onScrollDown: () => adjustVolume('down'),
|
||||||
child: Box({
|
child: Box({
|
||||||
className: 'spacing-h-4',
|
className: 'spacing-h-4',
|
||||||
children: [
|
children: [
|
||||||
@@ -228,3 +246,4 @@ export default () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user