From b4c8a87fc44cab9a1e3379e2f923a47805ccbf0b Mon Sep 17 00:00:00 2001 From: reionwong Date: Sun, 21 Nov 2021 23:31:57 +0800 Subject: [PATCH] Use libcutefish audio --- CMakeLists.txt | 1 - qml/ControlCenter.qml | 51 ++++++++++++++++++++++++++++++++++--------- qml/main.qml | 8 ++----- src/main.cpp | 2 -- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 402a376..eb3b62e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ set(SRCS src/brightness.cpp src/battery.cpp src/appearance.cpp - src/volume.cpp src/processprovider.cpp src/activity.cpp src/capplications.cpp diff --git a/qml/ControlCenter.qml b/qml/ControlCenter.qml index 8e1be87..e596c5b 100644 --- a/qml/ControlCenter.qml +++ b/qml/ControlCenter.qml @@ -26,6 +26,7 @@ import QtGraphicalEffects 1.0 import Cutefish.Accounts 1.0 as Accounts import Cutefish.Bluez 1.0 as Bluez import Cutefish.StatusBar 1.0 +import Cutefish.Audio 1.0 import FishUI 1.0 as FishUI ControlCenterDialog { @@ -39,6 +40,19 @@ ControlCenterDialog { property bool bluetoothDisConnected: Bluez.Manager.bluetoothBlocked + property var defaultSinkValue: defaultSink ? defaultSink.volume / PulseAudio.NormalVolume * 100.0: -1 + + property var volumeIconName: { + if (defaultSinkValue <= 0) + return "audio-volume-muted-symbolic" + else if (defaultSinkValue <= 25) + return "audio-volume-low-symbolic" + else if (defaultSinkValue <= 75) + return "audio-volume-medium-symbolic" + else + return "audio-volume-high-symbolic" + } + onBluetoothDisConnectedChanged: { bluetoothItem.checked = !bluetoothDisConnected } @@ -56,6 +70,18 @@ ControlCenterDialog { id: appearance } + property var defaultSink: paSinkModel.defaultSink + + SinkModel { + id: paSinkModel + + onDefaultSinkChanged: { + if (!defaultSink) { + return + } + } + } + function toggleBluetooth() { const enable = !control.bluetoothDisConnected Bluez.Manager.bluetoothBlocked = enable @@ -321,7 +347,7 @@ ControlCenterDialog { id: volumeItem Layout.fillWidth: true height: 40 - visible: volume.isValid + visible: defaultSink Rectangle { id: volumeItemBg @@ -344,25 +370,30 @@ ControlCenterDialog { height: 16 width: height sourceSize: Qt.size(width, height) - source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/" + volume.iconName + ".svg" + source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/" + control.volumeIconName + ".svg" smooth: false antialiasing: true } Slider { - id: slider - from: 0 - to: 100 - stepSize: 1 - value: volume.volume + id: volumeSlider + Layout.fillWidth: true Layout.fillHeight: true + from: PulseAudio.MinimalVolume + to: PulseAudio.NormalVolume + + stepSize: to / (to / PulseAudio.NormalVolume * 100.0) + + value: defaultSink ? defaultSink.volume : 0 + onValueChanged: { - volume.setVolume(value) + if (!defaultSink) + return - if (volume.isMute && value > 0) - volume.setMute(false) + defaultSink.volume = value + defaultSink.muted = (value === 0) } } } diff --git a/qml/main.qml b/qml/main.qml index 6a75e75..f4c2a8b 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -356,8 +356,8 @@ Item { Image { id: volumeIcon - visible: volume.isValid && status === Image.Ready - source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + volume.iconName + ".svg" + visible: controlCenter.defaultSink + source: "qrc:/images/" + (rootItem.darkMode ? "dark/" : "light/") + controlCenter.volumeIconName + ".svg" width: rootItem.iconSize height: width sourceSize: Qt.size(width, height) @@ -520,10 +520,6 @@ Item { id: controlCenter } - Volume { - id: volume - } - NM.ActiveConnection { id: activeConnection } diff --git a/src/main.cpp b/src/main.cpp index 6426017..9fefde0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,6 @@ #include "appearance.h" #include "brightness.h" #include "battery.h" -#include "volume.h" int main(int argc, char *argv[]) { @@ -43,7 +42,6 @@ int main(int argc, char *argv[]) qmlRegisterType(uri, 1, 0, "Appearance"); qmlRegisterType(uri, 1, 0, "Brightness"); qmlRegisterType(uri, 1, 0, "Battery"); - qmlRegisterType(uri, 1, 0, "Volume"); qmlRegisterType(uri, 1, 0, "AppMenuModel"); qmlRegisterType(uri, 1, 0, "AppMenuApplet");