[pulseaudio-commits] [Git][pulseaudio/pavucontrol][master] 3 commits: pavucontrol.glade: right-align channel labels
Tanu Kaskinen
gitlab at gitlab.freedesktop.org
Tue Feb 26 15:43:45 UTC 2019
Tanu Kaskinen pushed to branch master at PulseAudio / pavucontrol
Commits:
46ce3e41 by Tanu Kaskinen at 2019-02-26T15:42:57Z
pavucontrol.glade: right-align channel labels
The channel labels ("Front Left" etc.) that are adjacent to volume
sliders used to be left-aligned, which meant that there was some empty
space (depending on the text width) between the label text and the
volume slider. Right-aligning the labels looks nicer.
- - - - -
f200a10d by Tanu Kaskinen at 2019-02-26T15:42:57Z
channelwidget: refactor to reduce repetition
DeviceWidget and StreamWidget had some duplicate code to initialize
ChannelWidgets. This patch moves some of the duplicated initialization
code into ChannelWidgets to reduce repetition and to improve
encapsulation.
- - - - -
5f664bc6 by Tanu Kaskinen at 2019-02-26T15:42:57Z
channelwidget: ensure that all channel labels have the same width
pavucontrol.glade previously set the channel label width to 15
characters, with the goal of making all channel labels have the same
width. However, with some translations and font settings the configured
width wasn't enough, so sometimes a label was wider than others, and
that made the volume slider widths different too. If the volume sliders
have different widths, it's very hard to visually compare the volumes of
the channels.
This patch removes the fixed width in pavucontrol.glade and solves the
problem by finding the widest label and using that label's width with
all labels.
Fixes: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/issues/51
- - - - -
5 changed files:
- src/channelwidget.cc
- src/channelwidget.h
- src/devicewidget.cc
- src/pavucontrol.glade
- src/streamwidget.cc
Changes:
=====================================
src/channelwidget.cc
=====================================
@@ -47,16 +47,49 @@ ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Bu
volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged));
}
-ChannelWidget* ChannelWidget::create() {
+ChannelWidget* ChannelWidget::createOne(MinimalStreamWidget *owner, int channelIndex, pa_channel_position channelPosition, bool can_decibel) {
ChannelWidget* w;
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
x->add_from_file(GLADE_FILE, "adjustment1");
x->add_from_file(GLADE_FILE, "channelWidget");
x->get_widget_derived("channelWidget", w);
w->reference();
+
+ w->channel = channelIndex;
+ w->can_decibel = can_decibel;
+ w->minimalStreamWidget = owner;
+
+ char text[64];
+ snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(channelPosition));
+ w->channelLabel->set_markup(text);
+
return w;
}
+void ChannelWidget::create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel, ChannelWidget *widgets[PA_CHANNELS_MAX]) {
+ int maxLabelWidth = 0;
+
+ for (int i = 0; i < m.channels; i++) {
+ widgets[i] = ChannelWidget::createOne(owner, i, m.map[i], can_decibel);
+
+ Gtk::Requisition minimumSize;
+ Gtk::Requisition naturalSize;
+ widgets[i]->channelLabel->get_preferred_size(minimumSize, naturalSize);
+ if (naturalSize.width > maxLabelWidth)
+ maxLabelWidth = naturalSize.width;
+ }
+
+ widgets[m.channels - 1]->last = true;
+
+ /* The channel labels have different widths by default, which makes the
+ * volume slider widths different too. The volume sliders must have the
+ * same width, otherwise it's very hard to see how the volumes of different
+ * channels relate to each other, so we have to change all channel labels
+ * to have the same width. */
+ for (int i = 0; i < m.channels; i++)
+ widgets[i]->channelLabel->set_size_request(maxLabelWidth, -1);
+}
+
void ChannelWidget::setVolume(pa_volume_t volume) {
double v;
char txt[64];
=====================================
src/channelwidget.h
=====================================
@@ -28,7 +28,11 @@ class MinimalStreamWidget;
class ChannelWidget : public Gtk::EventBox {
public:
ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x);
- static ChannelWidget* create();
+
+ /* This creates multiple ChannelWidgets based on the given channel map. The
+ * widgets are stored in the caller-provided array. */
+ static void create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel,
+ ChannelWidget *widgets[PA_CHANNELS_MAX]);
void setVolume(pa_volume_t volume);
@@ -47,7 +51,10 @@ public:
virtual void set_sensitive(bool enabled);
virtual void setBaseVolume(pa_volume_t);
-};
+private:
+ static ChannelWidget *createOne(MinimalStreamWidget *owner, int channelIndex, pa_channel_position channelPosition,
+ bool can_decibel);
+};
#endif
=====================================
src/devicewidget.cc
=====================================
@@ -83,19 +83,13 @@ void DeviceWidget::init(MainWindow* mainWindow, Glib::ustring deviceType) {
void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
channelMap = m;
+ ChannelWidget::create(this, m, can_decibel, channelWidgets);
for (int i = 0; i < m.channels; i++) {
- ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
- cw->channel = i;
- cw->can_decibel = can_decibel;
- cw->minimalStreamWidget = this;
- char text[64];
- snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
- cw->channelLabel->set_markup(text);
+ ChannelWidget *cw = channelWidgets[i];
channelsVBox->pack_start(*cw, false, false, 0);
cw->unreference();
}
- channelWidgets[m.channels-1]->last = true;
lockToggleButton->set_sensitive(m.channels > 1);
hideLockedChannels(lockToggleButton->get_active());
=====================================
src/pavucontrol.glade
=====================================
@@ -24,8 +24,7 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes"><b>left-front</b></property>
<property name="use_markup">True</property>
- <property name="width_chars">15</property>
- <property name="xalign">0</property>
+ <property name="xalign">1</property>
<property name="yalign">0</property>
</object>
<packing>
=====================================
src/streamwidget.cc
=====================================
@@ -76,18 +76,14 @@ bool StreamWidget::onContextTriggerEvent(GdkEventButton* event) {
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
channelMap = m;
+ ChannelWidget::create(this, m, can_decibel, channelWidgets);
+
for (int i = 0; i < m.channels; i++) {
- ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
- cw->channel = i;
- cw->can_decibel = can_decibel;
- cw->minimalStreamWidget = this;
- char text[64];
- snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
- cw->channelLabel->set_markup(text);
+ ChannelWidget *cw = channelWidgets[i];
channelsVBox->pack_start(*cw, false, false, 0);
cw->unreference();
}
- channelWidgets[m.channels-1]->last = true;
+
channelWidgets[m.channels-1]->setBaseVolume(PA_VOLUME_NORM);
lockToggleButton->set_sensitive(m.channels > 1);
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/compare/7ce421a80d9c6831ba74fe209f8c1577e95296c9...5f664bc63bcf2567bdb39be377c6c0341a9aa217
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/compare/7ce421a80d9c6831ba74fe209f8c1577e95296c9...5f664bc63bcf2567bdb39be377c6c0341a9aa217
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20190226/89c1c9a1/attachment-0001.html>
More information about the pulseaudio-commits
mailing list