[pulseaudio-discuss] [PATCH] pavucontrol: Show only one volume slider when channels are locked

Ivan Ivanov ivanradanov at yahoo.co.uk
Sat Nov 8 14:55:51 PST 2014


---
I find that having volume sliders for all the channels that are
present clutters the window, and rarely does one need to control the
channels seperately, so this patch hides the unneeded volume sliders
when channels are locked.

 src/devicewidget.cc       | 13 +++++++++++++
 src/devicewidget.h        |  3 +++
 src/minimalstreamwidget.h |  1 +
 src/streamwidget.cc       | 13 +++++++++++++
 src/streamwidget.h        |  3 +++
 5 files changed, 33 insertions(+)

diff --git a/src/devicewidget.cc b/src/devicewidget.cc
index 813780f..5831f21 100644
--- a/src/devicewidget.cc
+++ b/src/devicewidget.cc
@@ -46,6 +46,7 @@ DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Buil
 
     this->signal_button_press_event().connect(sigc::mem_fun(*this, &DeviceWidget::onContextTriggerEvent));
     muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &DeviceWidget::onMuteToggleButton));
+    lockToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &DeviceWidget::onLockToggleButton));
     defaultToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &DeviceWidget::onDefaultToggleButton));
 
     rename.set_label(_("Rename Device..."));
@@ -94,6 +95,7 @@ void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
     channelWidgets[m.channels-1]->last = true;
 
     lockToggleButton->set_sensitive(m.channels > 1);
+    hideLockedChannels(lockToggleButton->get_active());
 }
 
 void DeviceWidget::setVolume(const pa_cvolume &v, bool force) {
@@ -123,6 +125,13 @@ void DeviceWidget::updateChannelVolume(int channel, pa_volume_t v) {
         timeoutConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &DeviceWidget::timeoutEvent), 100);
 }
 
+void DeviceWidget::hideLockedChannels(bool hide) {
+    for (int i = 0; i < channelMap.channels - 1; i++)
+        channelWidgets[i]->set_visible(!hide);
+
+    channelWidgets[channelMap.channels - 1]->channelLabel->set_visible(!hide);
+}
+
 void DeviceWidget::onMuteToggleButton() {
 
     lockToggleButton->set_sensitive(!muteToggleButton->get_active());
@@ -131,6 +140,10 @@ void DeviceWidget::onMuteToggleButton() {
         channelWidgets[i]->set_sensitive(!muteToggleButton->get_active());
 }
 
+void DeviceWidget::onLockToggleButton() {
+    hideLockedChannels(lockToggleButton->get_active());
+}
+
 void DeviceWidget::onDefaultToggleButton() {
 }
 
diff --git a/src/devicewidget.h b/src/devicewidget.h
index 586c2cf..3bff264 100644
--- a/src/devicewidget.h
+++ b/src/devicewidget.h
@@ -37,6 +37,8 @@ public:
     void setVolume(const pa_cvolume &volume, bool force = false);
     virtual void updateChannelVolume(int channel, pa_volume_t v);
 
+    void hideLockedChannels(bool hide = true);
+
     Glib::ustring name;
     Glib::ustring description;
     uint32_t index, card_index;
@@ -52,6 +54,7 @@ public:
     ChannelWidget *channelWidgets[PA_CHANNELS_MAX];
 
     virtual void onMuteToggleButton();
+    virtual void onLockToggleButton();
     virtual void onDefaultToggleButton();
     virtual void setDefault(bool isDefault);
     virtual bool onContextTriggerEvent(GdkEventButton*);
diff --git a/src/minimalstreamwidget.h b/src/minimalstreamwidget.h
index 7d5ee24..c020667 100644
--- a/src/minimalstreamwidget.h
+++ b/src/minimalstreamwidget.h
@@ -36,6 +36,7 @@ public:
     bool updating;
 
     virtual void onMuteToggleButton() = 0;
+    virtual void onLockToggleButton() = 0;
     virtual void updateChannelVolume(int channel, pa_volume_t v) = 0;
 
     bool volumeMeterEnabled;
diff --git a/src/streamwidget.cc b/src/streamwidget.cc
index e602cce..1f21afc 100644
--- a/src/streamwidget.cc
+++ b/src/streamwidget.cc
@@ -41,6 +41,7 @@ StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Buil
 
     this->signal_button_press_event().connect(sigc::mem_fun(*this, &StreamWidget::onContextTriggerEvent));
     muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onMuteToggleButton));
+    lockToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onLockToggleButton));
     deviceButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onDeviceChangePopup));
 
     terminate.set_label(_("Terminate"));
@@ -83,6 +84,7 @@ void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
     channelWidgets[m.channels-1]->setBaseVolume(PA_VOLUME_NORM);
 
     lockToggleButton->set_sensitive(m.channels > 1);
+    hideLockedChannels(lockToggleButton->get_active());
 }
 
 void StreamWidget::setVolume(const pa_cvolume &v, bool force) {
@@ -113,6 +115,13 @@ void StreamWidget::updateChannelVolume(int channel, pa_volume_t v) {
         timeoutConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &StreamWidget::timeoutEvent), 100);
 }
 
+void StreamWidget::hideLockedChannels(bool hide) {
+    for (int i = 0; i < channelMap.channels - 1; i++)
+        channelWidgets[i]->set_visible(!hide);
+
+    channelWidgets[channelMap.channels - 1]->channelLabel->set_visible(!hide);
+}
+
 void StreamWidget::onMuteToggleButton() {
 
     lockToggleButton->set_sensitive(!muteToggleButton->get_active());
@@ -121,6 +130,10 @@ void StreamWidget::onMuteToggleButton() {
         channelWidgets[i]->set_sensitive(!muteToggleButton->get_active());
 }
 
+void StreamWidget::onLockToggleButton() {
+    hideLockedChannels(lockToggleButton->get_active());
+}
+
 bool StreamWidget::timeoutEvent() {
     executeVolumeUpdate();
     return false;
diff --git a/src/streamwidget.h b/src/streamwidget.h
index b797ec5..c769920 100644
--- a/src/streamwidget.h
+++ b/src/streamwidget.h
@@ -37,6 +37,8 @@ public:
     void setVolume(const pa_cvolume &volume, bool force = false);
     virtual void updateChannelVolume(int channel, pa_volume_t v);
 
+    void hideLockedChannels(bool hide = true);
+
     Gtk::ToggleButton *lockToggleButton, *muteToggleButton;
     Gtk::Label *directionLabel;
     Gtk::Button *deviceButton;
@@ -48,6 +50,7 @@ public:
     ChannelWidget *channelWidgets[PA_CHANNELS_MAX];
 
     virtual void onMuteToggleButton();
+    virtual void onLockToggleButton();
     virtual void onDeviceChangePopup();
     virtual bool onContextTriggerEvent(GdkEventButton*);
 
-- 
2.1.1



More information about the pulseaudio-discuss mailing list