From 5f664bc63bcf2567bdb39be377c6c0341a9aa217 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Wed, 12 Dec 2018 11:41:16 +0200 Subject: [PATCH] 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 --- src/channelwidget.cc | 19 ++++++++++++++++++- src/pavucontrol.glade | 1 - 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/channelwidget.cc b/src/channelwidget.cc index d58bf96..f141009 100644 --- a/src/channelwidget.cc +++ b/src/channelwidget.cc @@ -67,10 +67,27 @@ ChannelWidget* ChannelWidget::createOne(MinimalStreamWidget *owner, int channelI } void ChannelWidget::create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel, ChannelWidget *widgets[PA_CHANNELS_MAX]) { - for (int i = 0; i < m.channels; i++) + 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) { diff --git a/src/pavucontrol.glade b/src/pavucontrol.glade index a08ffca..96c35be 100644 --- a/src/pavucontrol.glade +++ b/src/pavucontrol.glade @@ -24,7 +24,6 @@ False <b>left-front</b> True - 15 1 0