GNOME Bugzilla – Bug 695132
gtk_widget_get_opacity should return original opacity value
Last modified: 2013-05-23 12:36:06 UTC
In GTK+ 3.7, window opacity handling has changed a bit. It now goes through a generic widget opacity process and the requested opacity value gets manipulated a bit (converted to an int). However... when a client app requests the opacity back, it gets this manipulated number, modified back into a double. I believe most clients expect to receive the original opacity value. For example, the fading "camera flash" effect in gnome-screenshot and cheese both do something like the following: static gboolean cheese_flash_opacity_fade (gpointer data) { CheeseFlash *flash = data; CheeseFlashPrivate *flash_priv = CHEESE_FLASH_GET_PRIVATE (flash); GtkWindow *flash_window = flash_priv->window; double opacity = gtk_window_get_opacity (flash_window); /* exponentially decrease */ gtk_window_set_opacity (flash_window, opacity * 0.95); if (opacity <= 0.01) { /* the flasher has finished when we reach the quit value */ gtk_widget_hide (GTK_WIDGET (flash_window)); return FALSE; } return TRUE; } With GTK+ 3.7.10, this will get stuck forever at opacity 0.039216. (It gets reduced to 0.037255, which gets rounded to 10, which gets returned back as 0.039216.) This code is making the assumption that get() will return what set() was given. Which doesn't seem like a bad assumption. Please have GtkWidget save the original value to set() and return it in get().
Actually, it's not just an assumption that get() will return what set() was given. It's explicitly mentioned in the gtk-doc comments: /** * gtk_window_get_opacity: * @window: a #GtkWindow * * Fetches the requested opacity for this window. See * gtk_window_set_opacity(). * * Return value: the requested opacity for this window. * * Since: 2.12 * Deprecated: 3.8: Use gtk_widget_get_opacity instead. **/
seb128 says this is fixed in 3.8.1. Not sure which commit.