1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-26 22:42:50 -05:00

Add percentage to the volume control slider

This commit is contained in:
purian23
2025-07-24 22:46:11 -04:00
parent 1197b9385c
commit 8e7bcabcf7
4 changed files with 180 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Services.Pipewire
Singleton {
@@ -10,6 +11,8 @@ Singleton {
readonly property PwNode sink: Pipewire.defaultAudioSink
readonly property PwNode source: Pipewire.defaultAudioSource
signal volumeChanged()
function displayName(node) {
if (!node) return ""
@@ -63,4 +66,109 @@ Singleton {
PwObjectTracker {
objects: [Pipewire.defaultAudioSink, Pipewire.defaultAudioSource]
}
// Volume control functions
function setVolume(percentage) {
if (root.sink && root.sink.audio) {
const clampedVolume = Math.max(0, Math.min(100, percentage));
root.sink.audio.volume = clampedVolume / 100;
return "Volume set to " + clampedVolume + "%";
}
return "No audio sink available";
}
function incrementVolume(step) {
if (root.sink && root.sink.audio) {
const currentVolume = Math.round(root.sink.audio.volume * 100);
const newVolume = Math.max(0, Math.min(100, currentVolume + step));
root.sink.audio.volume = newVolume / 100;
return "Volume increased to " + newVolume + "%";
}
return "No audio sink available";
}
function decrementVolume(step) {
if (root.sink && root.sink.audio) {
const currentVolume = Math.round(root.sink.audio.volume * 100);
const newVolume = Math.max(0, Math.min(100, currentVolume - step));
root.sink.audio.volume = newVolume / 100;
return "Volume decreased to " + newVolume + "%";
}
return "No audio sink available";
}
function toggleMute() {
if (root.sink && root.sink.audio) {
root.sink.audio.muted = !root.sink.audio.muted;
return root.sink.audio.muted ? "Audio muted" : "Audio unmuted";
}
return "No audio sink available";
}
function setMicVolume(percentage) {
if (root.source && root.source.audio) {
const clampedVolume = Math.max(0, Math.min(100, percentage));
root.source.audio.volume = clampedVolume / 100;
return "Microphone volume set to " + clampedVolume + "%";
}
return "No audio source available";
}
function toggleMicMute() {
if (root.source && root.source.audio) {
root.source.audio.muted = !root.source.audio.muted;
return root.source.audio.muted ? "Microphone muted" : "Microphone unmuted";
}
return "No audio source available";
}
// IPC Handler for external control
IpcHandler {
target: "audio"
function setvolume(percentage: string): string {
return root.setVolume(parseInt(percentage));
}
function increment(step: string): string {
return root.incrementVolume(parseInt(step || "5"));
}
function decrement(step: string): string {
return root.decrementVolume(parseInt(step || "5"));
}
function mute(): string {
return root.toggleMute();
}
function setmic(percentage: string): string {
return root.setMicVolume(parseInt(percentage));
}
function micmute(): string {
return root.toggleMicMute();
}
function status(): string {
let result = "Audio Status:\n";
if (root.sink && root.sink.audio) {
const volume = Math.round(root.sink.audio.volume * 100);
result += "Output: " + volume + "%" + (root.sink.audio.muted ? " (muted)" : "") + "\n";
} else {
result += "Output: No sink available\n";
}
if (root.source && root.source.audio) {
const micVolume = Math.round(root.source.audio.volume * 100);
result += "Input: " + micVolume + "%" + (root.source.audio.muted ? " (muted)" : "");
} else {
result += "Input: No source available";
}
return result;
}
}
}