Do not show both volumes if unnecessary

Also, make it apparent which value comes from where.
This commit is contained in:
Přemysl Eric Janouch 2021-11-16 03:41:30 +01:00
parent e66e9f249a
commit 227b8e0fa2
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 33 additions and 19 deletions

View File

@ -1243,6 +1243,7 @@ static struct app_context
#ifdef WITH_PULSE #ifdef WITH_PULSE
struct pulse pulse; ///< PulseAudio control struct pulse pulse; ///< PulseAudio control
#endif // WITH_PULSE #endif // WITH_PULSE
bool pulse_control_requested; ///< PulseAudio control desired by user
struct line_editor editor; ///< Line editor struct line_editor editor; ///< Line editor
struct poller_idle refresh_event; ///< Refresh the screen struct poller_idle refresh_event; ///< Refresh the screen
@ -1304,6 +1305,13 @@ on_poll_elapsed_time_changed (struct config_item *item)
g.elapsed_poll = item->value.boolean; g.elapsed_poll = item->value.boolean;
} }
static void
on_pulseaudio_changed (struct config_item *item)
{
// This is only set once, on application startup
g.pulse_control_requested = item->value.boolean;
}
static struct config_schema g_config_settings[] = static struct config_schema g_config_settings[] =
{ {
{ .name = "address", { .name = "address",
@ -1340,6 +1348,7 @@ static struct config_schema g_config_settings[] =
{ .name = "pulseaudio", { .name = "pulseaudio",
.comment = "Look up MPD in PulseAudio for improved volume controls", .comment = "Look up MPD in PulseAudio for improved volume controls",
.type = CONFIG_ITEM_BOOLEAN, .type = CONFIG_ITEM_BOOLEAN,
.on_change = on_pulseaudio_changed,
.default_ = "off" }, .default_ = "off" },
#endif // WITH_PULSE #endif // WITH_PULSE
@ -1376,14 +1385,6 @@ get_config_string (struct config_item *root, const char *key)
return item->value.string.str; return item->value.string.str;
} }
static bool
get_config_boolean (struct config_item *root, const char *key)
{
struct config_item *item = config_item_get (root, key, NULL);
hard_assert (item && item->type == CONFIG_ITEM_BOOLEAN);
return item->value.boolean;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void static void
@ -1782,18 +1783,31 @@ app_draw_status (void)
// It gets a bit complicated due to the only right-aligned item on the row // It gets a bit complicated due to the only right-aligned item on the row
struct str volume = str_make (); struct str volume = str_make ();
int remaining = COLS - buf.total_width;
if (g.volume >= 0)
{
str_append (&volume, " ");
#ifdef WITH_PULSE #ifdef WITH_PULSE
if (pulse_volume_status (&g.pulse, &volume)) if (g.pulse_control_requested)
str_append (&volume, " @ "); {
#endif // WITH_PULSE struct str buf = str_make ();
str_append_printf (&volume, "%3d%%", g.volume); if (pulse_volume_status (&g.pulse, &buf))
remaining -= volume.len; {
} if (g.volume >= 0 && g.volume != 100)
str_append_printf (&buf, " (%d%%)", g.volume);
}
else
{
if (g.volume >= 0)
str_append_printf (&buf, "(%d%%)", g.volume);
}
if (buf.len)
str_append_printf (&volume, " %s", buf.str);
str_free (&buf);
}
else
#endif // WITH_PULSE
if (g.volume >= 0)
str_append_printf (&volume, " %3d%%", g.volume);
int remaining = COLS - buf.total_width - volume.len;
if (!stopped && g.song_elapsed >= 0 && g.song_duration >= 1 if (!stopped && g.song_elapsed >= 0 && g.song_duration >= 1
&& remaining > 0) && remaining > 0)
{ {
@ -4173,7 +4187,7 @@ static void
pulse_update (void) pulse_update (void)
{ {
struct mpd_client *c = &g.client; struct mpd_client *c = &g.client;
if (!get_config_boolean (g.config.root, "settings.pulseaudio")) if (!g.pulse_control_requested)
return; return;
// The read permission is sufficient for this command // The read permission is sufficient for this command