diff options
Diffstat (limited to 'mate-volume-control/gvc-level-bar.c')
-rw-r--r-- | mate-volume-control/gvc-level-bar.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/mate-volume-control/gvc-level-bar.c b/mate-volume-control/gvc-level-bar.c index e6c000d..13e7aeb 100644 --- a/mate-volume-control/gvc-level-bar.c +++ b/mate-volume-control/gvc-level-bar.c @@ -2,6 +2,7 @@ * * Copyright (C) 2008 William Jon McCann <[email protected]> * Copyright (C) 2014 Michal Ratajsky <[email protected]> + * Copyright (C) 2014-2021 MATE Developers * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -149,8 +150,8 @@ reset_max_peak (GvcLevelBar *bar) static void bar_calc_layout (GvcLevelBar *bar) { - int peak_level; - int max_peak_level; + gdouble peak_level; + gdouble max_peak_level; GtkAllocation allocation; GtkStyleContext *context; @@ -178,8 +179,8 @@ bar_calc_layout (GvcLevelBar *bar) bar->priv->layout.area.height = allocation.height - 2; if (bar->priv->orientation == GTK_ORIENTATION_VERTICAL) { - peak_level = bar->priv->peak_fraction * bar->priv->layout.area.height; - max_peak_level = bar->priv->max_peak * bar->priv->layout.area.height; + peak_level = bar->priv->peak_fraction * (gdouble) bar->priv->layout.area.height; + max_peak_level = bar->priv->max_peak * (gdouble) bar->priv->layout.area.height; bar->priv->layout.delta = bar->priv->layout.area.height / NUM_BOXES; bar->priv->layout.area.x = 0; @@ -188,8 +189,8 @@ bar_calc_layout (GvcLevelBar *bar) bar->priv->layout.box_width = bar->priv->layout.area.width; bar->priv->layout.box_radius = bar->priv->layout.box_width / 2; } else { - peak_level = bar->priv->peak_fraction * bar->priv->layout.area.width; - max_peak_level = bar->priv->max_peak * bar->priv->layout.area.width; + peak_level = bar->priv->peak_fraction * (gdouble) bar->priv->layout.area.width; + max_peak_level = bar->priv->max_peak * (gdouble) bar->priv->layout.area.width; bar->priv->layout.delta = bar->priv->layout.area.width / NUM_BOXES; bar->priv->layout.area.x = 0; @@ -199,8 +200,8 @@ bar_calc_layout (GvcLevelBar *bar) bar->priv->layout.box_radius = bar->priv->layout.box_height / 2; } - bar->priv->layout.peak_num = peak_level / bar->priv->layout.delta; - bar->priv->layout.max_peak_num = max_peak_level / bar->priv->layout.delta; + bar->priv->layout.peak_num = (int) (peak_level / (gdouble) bar->priv->layout.delta); + bar->priv->layout.max_peak_num = (int) (max_peak_level / (gdouble) bar->priv->layout.delta); } static void @@ -214,12 +215,23 @@ update_peak_value (GvcLevelBar *bar) bar->priv->peak_fraction = value; if (value > bar->priv->max_peak) { + AtkObject *acc_obj; + char *acc_string; + gdouble peak_percentage; + if (bar->priv->max_peak_id > 0) g_source_remove (bar->priv->max_peak_id); bar->priv->max_peak_id = g_timeout_add_seconds (1, (GSourceFunc) reset_max_peak, bar); bar->priv->max_peak = value; + /* Providing an accessible based on peaks, so that + * it doesn’t get updated too often. */ + acc_obj = gtk_widget_get_accessible (GTK_WIDGET (bar)); + peak_percentage = round (value * 100.0); + acc_string = g_strdup_printf (_("Peak: %.0lf"), peak_percentage); + atk_object_set_name (acc_obj, acc_string); + g_free (acc_string); } layout = bar->priv->layout; @@ -283,7 +295,7 @@ void gvc_level_bar_set_peak_adjustment (GvcLevelBar *bar, GtkAdjustment *adjustment) { - g_return_if_fail (GVC_LEVEL_BAR (bar)); + g_return_if_fail (GVC_IS_LEVEL_BAR (bar)); g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); if (bar->priv->peak_adjustment != NULL) { @@ -309,7 +321,7 @@ void gvc_level_bar_set_rms_adjustment (GvcLevelBar *bar, GtkAdjustment *adjustment) { - g_return_if_fail (GVC_LEVEL_BAR (bar)); + g_return_if_fail (GVC_IS_LEVEL_BAR (bar)); g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); if (bar->priv->rms_adjustment != NULL) { @@ -512,7 +524,7 @@ curved_rectangle (cairo_t *cr, x1 = x0 + width; y1 = y0 + height; - if (!width || !height) + if (width == 0.0 || height == 0.0) return; if (width / 2 < radius) { @@ -752,6 +764,9 @@ gvc_level_bar_init (GvcLevelBar *bar) bar); gtk_widget_set_has_window (GTK_WIDGET (bar), FALSE); + + atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (bar)), + ATK_ROLE_STATIC); } static void |