all repos — quickshell @ c697d17aa981dceb9b93e2b66735b1f784e6bbca

A desert-witch desktop shell

bar/modules/Volume.qml (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
// Volume.qml
import QtQuick
import Quickshell
import QtQuick.Controls.Basic
import QtQuick.Layouts
import Quickshell.Services.Pipewire
import "../classes" as Class
import "../../"

Button {
  PwObjectTracker {
    objects: [ Pipewire.defaultAudioSink ]
  }
  property var muted: Pipewire.defaultAudioSink?.audio.muted
  padding: 0
  MouseArea{
    id: vol_button
    anchors.fill: parent
    hoverEnabled: true
    cursorShape: Qt.PointingHandCursor
    onClicked: muted = !muted
  }
  background: Rectangle {
    color:
      (vol_button.containsMouse)
      ? Resources.palette.altbg
      : Resources.palette.bg
  }
contentItem: Class.RightRowLayout {
  id: volume_module
  Layout.alignment: Qt.AlignVCenter
    Class.TopbarText {
      id: volume_indicator
      property var vol: Math.round((Pipewire.defaultAudioSink?.audio.volume ?? 0) * 100)
      text:
        (muted)
        ? ""
        : vol + "%"
      color: Resources.palette.fg
    }
    Class.TopbarIcon {
      text: if (muted) {
        Icons.volume.mute
      } else if (volume_indicator.vol == 0) {
        Icons.volume.off
      } else if (volume_indicator.vol <= 50) {
        Icons.volume.low
      } else if (volume_indicator.vol > 50) {
        Icons.volume.high
      } else {
        Icons.volume.low
      }
      color:
        (muted)
        ? Resources.palette.scarlet
        : Resources.palette.orange
    }
  }
}