[gnome-settings-daemon] shell-helper: Use doubles for shell OSD dbus calls
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] shell-helper: Use doubles for shell OSD dbus calls
- Date: Sun, 28 Jul 2019 15:29:16 +0000 (UTC)
commit 65f6de3b127e28dc8d2d66145f721ba757afeca1
Author: Jonas Dreßler <verdre v0yd nl>
Date: Sat Feb 2 16:33:23 2019 +0100
shell-helper: Use doubles for shell OSD dbus calls
Allow for more precise values to be sent to the shell to fix a bug
where the volume icon in the shells OSD is not the "muted" icon while
the volume bar shows a value of 0.
This happened because casting the volume to an integer value might
return 0 while the value actually is near 0. Since we also generate the
icon name inside media-keys and use the non-casted value for that, the
icon and the volume we show in the shell would be different.
plugins/common/gsd-shell-helper.c | 14 ++++++------
plugins/common/gsd-shell-helper.h | 6 +++---
plugins/media-keys/gsd-media-keys-manager.c | 33 ++++++++++++++---------------
3 files changed, 26 insertions(+), 27 deletions(-)
---
diff --git a/plugins/common/gsd-shell-helper.c b/plugins/common/gsd-shell-helper.c
index 11499e30..e4a2f232 100644
--- a/plugins/common/gsd-shell-helper.c
+++ b/plugins/common/gsd-shell-helper.c
@@ -24,7 +24,7 @@ void
shell_show_osd (GsdShell *shell,
const gchar *icon_name,
const gchar *label,
- gint level,
+ double level,
const gchar *connector)
{
shell_show_osd_with_max_level (shell, icon_name, label, level, -1, connector);
@@ -34,8 +34,8 @@ void
shell_show_osd_with_max_level (GsdShell *shell,
const gchar *icon_name,
const gchar *label,
- gint level,
- gint max_level,
+ double level,
+ double max_level,
const gchar *connector)
{
GVariantBuilder builder;
@@ -50,12 +50,12 @@ shell_show_osd_with_max_level (GsdShell *shell,
if (label)
g_variant_builder_add (&builder, "{sv}",
"label", g_variant_new_string (label));
- if (level >= 0)
+ if (level >= 0.0)
g_variant_builder_add (&builder, "{sv}",
- "level", g_variant_new_int32 (level));
- if (max_level > 100)
+ "level", g_variant_new_double (level));
+ if (max_level > 1.0)
g_variant_builder_add (&builder, "{sv}",
- "max_level", g_variant_new_int32 (max_level));
+ "max_level", g_variant_new_double (max_level));
if (connector)
g_variant_builder_add (&builder, "{sv}",
"connector", g_variant_new_string (connector));
diff --git a/plugins/common/gsd-shell-helper.h b/plugins/common/gsd-shell-helper.h
index 1de75d49..16a694b4 100644
--- a/plugins/common/gsd-shell-helper.h
+++ b/plugins/common/gsd-shell-helper.h
@@ -27,14 +27,14 @@ G_BEGIN_DECLS
void shell_show_osd (GsdShell *shell,
const gchar *icon_name,
const gchar *label,
- gint level,
+ double level,
const gchar *connector);
void shell_show_osd_with_max_level (GsdShell *shell,
const gchar *icon_name,
const gchar *label,
- gint level,
- gint max_level,
+ double level,
+ double max_level,
const gchar *connector);
G_END_DECLS
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index e5f34789..e6a304a1 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -429,8 +429,8 @@ static void
show_osd_with_max_level (GsdMediaKeysManager *manager,
const char *icon,
const char *label,
- int level,
- int max_level,
+ double level,
+ double max_level,
const gchar *connector)
{
GsdMediaKeysManagerPrivate *priv = GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager);
@@ -446,7 +446,7 @@ static void
show_osd (GsdMediaKeysManager *manager,
const char *icon,
const char *label,
- int level,
+ double level,
const char *connector)
{
show_osd_with_max_level(manager,
@@ -456,7 +456,7 @@ show_osd (GsdMediaKeysManager *manager,
static const char *
get_icon_name_for_volume (gboolean is_mic,
gboolean muted,
- int volume)
+ double volume)
{
static const char *icon_names[] = {
"audio-volume-muted-symbolic",
@@ -479,7 +479,7 @@ get_icon_name_for_volume (gboolean is_mic,
n = 0;
} else {
/* select image */
- n = ceill (3.0 * (double) volume / 100);
+ n = ceill (3.0 * volume);
if (n < 1)
n = 1;
/* output volume above 100% */
@@ -1359,18 +1359,17 @@ update_dialog (GsdMediaKeysManager *manager,
GvcMixerUIDevice *device;
const GvcMixerStreamPort *port;
const char *icon;
- int max_volume_pct;
-
- max_volume_pct = (int) (100 * (double) priv->max_volume / PA_VOLUME_NORM);
+ double new_vol;
+ double max_volume;
+ max_volume = (double) priv->max_volume / PA_VOLUME_NORM;
if (!muted) {
- vol = (int) (100 * (double) vol / PA_VOLUME_NORM);
- vol = CLAMP (vol, 0, max_volume_pct);
+ new_vol = (double) vol / PA_VOLUME_NORM;
+ new_vol = CLAMP (new_vol, 0, max_volume);
} else {
- vol = 0.0;
+ new_vol = 0.0;
}
-
- icon = get_icon_name_for_volume (!GVC_IS_MIXER_SINK (stream), muted, vol);
+ icon = get_icon_name_for_volume (!GVC_IS_MIXER_SINK (stream), muted, new_vol);
port = gvc_mixer_stream_get_port (stream);
if (g_strcmp0 (gvc_mixer_stream_get_form_factor (stream), "internal") != 0 ||
(port != NULL &&
@@ -1379,9 +1378,9 @@ update_dialog (GsdMediaKeysManager *manager,
device = gvc_mixer_control_lookup_device_from_stream (priv->volume, stream);
show_osd_with_max_level (manager, icon,
gvc_mixer_ui_device_get_description (device),
- vol, max_volume_pct, NULL);
+ new_vol, max_volume, NULL);
} else {
- show_osd_with_max_level (manager, icon, NULL, vol, max_volume_pct, NULL);
+ show_osd_with_max_level (manager, icon, NULL, new_vol, max_volume, NULL);
}
if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) {
@@ -2297,7 +2296,7 @@ update_brightness_cb (GObject *source_object,
g_variant_get (variant, "(i&s)", &percentage, &connector);
}
- show_osd (manager, icon, NULL, percentage, connector);
+ show_osd (manager, icon, NULL, (double) percentage / 100.0, connector);
g_variant_unref (variant);
}
@@ -2378,7 +2377,7 @@ do_battery_action (GsdMediaKeysManager *manager)
if (kind == UP_DEVICE_KIND_UPS || kind == UP_DEVICE_KIND_BATTERY) {
g_debug ("showing battery level OSD");
- show_osd (manager, icon_name, NULL, percentage, NULL);
+ show_osd (manager, icon_name, NULL, (double) percentage / 100.0, NULL);
}
g_free (icon_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]