* </accessibility>
* <child internal-child="accessible">
* <object class="AtkObject" id="a11y-button1">
- * <property name="AtkObject::name">Clickable Button</property>
+ * <property name="accessible-name">Clickable Button</property>
* </object>
* </child>
* </object>
/* SizeGroup related flags */
guint have_size_groups : 1;
+ guint opacity_group : 1;
guint norender_children : 1;
guint norender : 1; /* Don't expose windows, instead recurse via draw */
/* The widget's parent */
GtkWidget *parent;
+ /* Animations and other things to update on clock ticks */
+ GList *tick_callbacks;
+
#ifdef G_ENABLE_DEBUG
/* Number of gtk_widget_push_verify_invariants () */
guint verifying_invariants_count;
GdkDevice *device,
gboolean recurse,
gboolean enabled);
+
+static void gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
+ GtkWidget *widget);
+
static gboolean event_window_is_still_viewable (GdkEvent *event);
static void gtk_cairo_set_event (cairo_t *cr,
GdkEventExpose *event);
-static void gtk_widget_update_norender (GtkWidget *widget);
+static void gtk_widget_propagate_alpha (GtkWidget *widget);
/* --- variables --- */
static gpointer gtk_widget_parent_class = NULL;
tmp_event = _gtk_cairo_get_event (cr);
push_group =
- widget->priv->alpha != 255 &&
- (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
+ widget->priv->opacity_group ||
+ (widget->priv->alpha != 255 &&
+ (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
if (push_group)
{
tmp_event = _gtk_cairo_get_event (cr);
push_group =
- widget->priv->alpha != 255 &&
- (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
+ widget->priv->opacity_group ||
+ (widget->priv->alpha != 255 &&
+ (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
if (push_group)
{
* restore it. The signal emission takes care of calling cairo_save()
* before and cairo_restore() after invoking the handler.
*
+ * The signal handler will get a @cr with a clip region already set to the
+ * widget's dirty region, i.e. to the area that needs repainting. Complicated
+ * widgets that want to avoid redrawing themselves completely can get the full
+ * extents of the clip region with gdk_cairo_get_clip_rectangle(), or they can
+ * get a finer-grained representation of the dirty region with
+ * cairo_copy_clip_rectangle_list().
+ *
* Returns: %TRUE to stop other handlers from being invoked for the event.
% %FALSE to propagate the event further.
*
g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
- gtk_widget_update_norender (widget);
+ gtk_widget_propagate_alpha (widget);
gtk_widget_pop_verify_invariants (widget);
g_object_unref (widget);
gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
}
+typedef struct _GtkTickCallbackInfo GtkTickCallbackInfo;
+
+struct _GtkTickCallbackInfo
+{
+ guint refcount;
+
+ guint id;
+ GtkTickCallback callback;
+ gpointer user_data;
+ GDestroyNotify notify;
+
+ guint destroyed : 1;
+};
+
+static void
+ref_tick_callback_info (GtkTickCallbackInfo *info)
+{
+ info->refcount++;
+}
+
+static void
+unref_tick_callback_info (GtkWidget *widget,
+ GtkTickCallbackInfo *info,
+ GList *link)
+{
+ GtkWidgetPrivate *priv = widget->priv;
+
+ info->refcount--;
+ if (info->refcount == 0)
+ {
+ priv->tick_callbacks = g_list_delete_link (priv->tick_callbacks, link);
+ if (info->notify)
+ info->notify (info->user_data);
+ g_slice_free (GtkTickCallbackInfo, info);
+ }
+
+ if (priv->tick_callbacks == NULL && priv->realized)
+ {
+ GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
+ g_signal_handlers_disconnect_by_func (frame_clock,
+ (gpointer) gtk_widget_on_frame_clock_update,
+ widget);
+ gdk_frame_clock_end_updating (frame_clock);
+ }
+}
+
+static void
+destroy_tick_callback_info (GtkWidget *widget,
+ GtkTickCallbackInfo *info,
+ GList *link)
+{
+ if (!info->destroyed)
+ {
+ info->destroyed = TRUE;
+ unref_tick_callback_info (widget, info, link);
+ }
+}
+
+static void
+gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
+ GtkWidget *widget)
+{
+ GtkWidgetPrivate *priv = widget->priv;
+ GList *l;
+
+ g_object_ref (widget);
+
+ for (l = priv->tick_callbacks; l;)
+ {
+ GtkTickCallbackInfo *info = l->data;
+ GList *next;
+
+ ref_tick_callback_info (info);
+ if (!info->destroyed)
+ {
+ if (info->callback (widget,
+ frame_clock,
+ info->user_data) == G_SOURCE_REMOVE)
+ {
+ destroy_tick_callback_info (widget, info, l);
+ }
+ }
+
+ next = l->next;
+ unref_tick_callback_info (widget, info, l);
+ l = next;
+ }
+
+ g_object_unref (widget);
+}
+
+static guint tick_callback_id;
+
+/**
+ * gtk_widget_add_tick_callback:
+ * @widget: a #GtkWidget
+ * @callback: function to call for updating animations
+ * @user_data: data to pass to @callback
+ * @notify: function to call to free @user_data when the callback is removed.
+ *
+ * Queues a animation frame update and adds a callback to be called
+ * before each frame. Until the tick callback is removed, it will be
+ * called frequently (usually at the frame rate of the output device
+ * or as quickly as the application an be repainted, whichever is
+ * slower). For this reason, is most suitable for handling graphics
+ * that change every frame or every few frames. The tick callback does
+ * not automatically imply a relayout or repaint. If you want a
+ * repaint or relayout, and aren't changing widget properties that
+ * would trigger that (for example, changing the text of a #GtkLabel),
+ * then you will have to call gtk_widget_queue_resize() or
+ * gtk_widget_queue_draw_area() yourself.
+ *
+ * gdk_frame_clock_get_frame_time() should generally be used for timing
+ * continuous animations and
+ * gdk_frame_timings_get_predicted_presentation_time() if you are
+ * trying to display isolated frames at particular times.
+ *
+ * This is a more convenient alternative to connecting directly to the
+ * #GdkFrameClock::update signal of #GdkFrameClock, since you don't
+ * have to worry about when a #GdkFrameClock is assigned to a widget.
+ *
+ * Returns: an id for the connection of this callback. Remove the callback
+ * by passing it to gtk_widget_remove_tick_callback()
+ *
+ * Since: 3.8
+ */
+guint
+gtk_widget_add_tick_callback (GtkWidget *widget,
+ GtkTickCallback callback,
+ gpointer user_data,
+ GDestroyNotify notify)
+{
+ GtkWidgetPrivate *priv;
+ GtkTickCallbackInfo *info;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ priv = widget->priv;
+
+ if (priv->tick_callbacks == NULL && priv->realized)
+ {
+ GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
+ g_signal_connect (frame_clock, "update",
+ G_CALLBACK (gtk_widget_on_frame_clock_update),
+ widget);
+ gdk_frame_clock_begin_updating (frame_clock);
+ }
+
+ info = g_slice_new0 (GtkTickCallbackInfo);
+
+ info->refcount = 1;
+ info->id = ++tick_callback_id;
+ info->callback = callback;
+ info->user_data = user_data;
+ info->notify = notify;
+
+ priv->tick_callbacks = g_list_prepend (priv->tick_callbacks,
+ info);
+
+ return info->id;
+}
+
+/**
+ * gtk_widget_remove_tick_callback:
+ * @widget: a #GtkWidget
+ * @id: an id returned by gtk_widget_add_tick_callback()
+ *
+ * Removes a tick callback previously registered with
+ * gtk_widget_add_tick_callback().
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_remove_tick_callback (GtkWidget *widget,
+ guint id)
+{
+ GtkWidgetPrivate *priv;
+ GList *l;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ priv = widget->priv;
+
+ for (l = priv->tick_callbacks; l; l = l->next)
+ {
+ GtkTickCallbackInfo *info = l->data;
+ if (info->id == id)
+ destroy_tick_callback_info (widget, info, l);
+ }
+}
+
+static void
+gtk_widget_connect_frame_clock (GtkWidget *widget,
+ GdkFrameClock *frame_clock)
+{
+ GtkWidgetPrivate *priv = widget->priv;
+
+ if (GTK_IS_CONTAINER (widget))
+ _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
+
+ if (priv->tick_callbacks != NULL)
+ {
+ g_signal_connect (frame_clock, "update",
+ G_CALLBACK (gtk_widget_on_frame_clock_update),
+ widget);
+ gdk_frame_clock_begin_updating (frame_clock);
+ }
+
+ if (priv->context)
+ gtk_style_context_set_frame_clock (priv->context, frame_clock);
+}
+
+static void
+gtk_widget_disconnect_frame_clock (GtkWidget *widget,
+ GdkFrameClock *frame_clock)
+{
+ GtkWidgetPrivate *priv = widget->priv;
+
+ if (GTK_IS_CONTAINER (widget))
+ _gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
+
+ if (priv->tick_callbacks)
+ {
+ g_signal_handlers_disconnect_by_func (frame_clock,
+ (gpointer) gtk_widget_on_frame_clock_update,
+ widget);
+ gdk_frame_clock_end_updating (frame_clock);
+ }
+
+ if (priv->context)
+ gtk_style_context_set_frame_clock (priv->context, NULL);
+}
+
/**
* gtk_widget_realize:
* @widget: a #GtkWidget
_gtk_widget_enable_device_events (widget);
gtk_widget_update_devices_mask (widget, TRUE);
+ gtk_widget_connect_frame_clock (widget,
+ gtk_widget_get_frame_clock (widget));
+
gtk_widget_pop_verify_invariants (widget);
}
}
if (widget->priv->mapped)
gtk_widget_unmap (widget);
+ gtk_widget_disconnect_frame_clock (widget,
+ gtk_widget_get_frame_clock (widget));
+
g_signal_emit (widget, widget_signals[UNREALIZE], 0);
g_assert (!widget->priv->mapped);
gtk_widget_set_realized (widget, FALSE);
_gtk_size_group_queue_resize (widget, 0);
}
+/**
+ * gtk_widget_get_frame_clock:
+ * @widget: a #GtkWidget
+ *
+ * Obtains the frame clock for a widget. The frame clock is a global
+ * "ticker" that can be used to drive animations and repaints. The
+ * most common reason to get the frame clock is to call
+ * gdk_frame_clock_get_frame_time(), in order to get a time to use for
+ * animating. For example you might record the start of the animation
+ * with an initial value from gdk_frame_clock_get_frame_time(), and
+ * then update the animation by calling
+ * gdk_frame_clock_get_frame_time() again during each repaint.
+ *
+ * gdk_frame_clock_request_phase() will result in a new frame on the
+ * clock, but won't necessarily repaint any widgets. To repaint a
+ * widget, you have to use gtk_widget_queue_draw() which invalidates
+ * the widget (thus scheduling it to receive a draw on the next
+ * frame). gtk_widget_queue_draw() will also end up requesting a frame
+ * on the appropriate frame clock.
+ *
+ * A widget's frame clock will not change while the widget is
+ * mapped. Reparenting a widget (which implies a temporary unmap) can
+ * change the widget's frame clock.
+ *
+ * Unrealized widgets do not have a frame clock.
+ *
+ * Return value: (transfer none): a #GdkFrameClock (or #NULL if widget is unrealized)
+ *
+ * Since: 3.0
+ */
+GdkFrameClock*
+gtk_widget_get_frame_clock (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ if (widget->priv->realized)
+ {
+ /* We use gtk_widget_get_toplevel() here to make it explicit that
+ * the frame clock is a property of the toplevel that a widget
+ * is anchored to; gdk_window_get_toplevel() will go up the
+ * hierarchy anyways, but should squash any funny business with
+ * reparenting windows and widgets.
+ */
+ GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+ GdkWindow *window = gtk_widget_get_window (toplevel);
+ g_assert (window != NULL);
+
+ return gdk_window_get_frame_clock (window);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
/**
* gtk_widget_size_request:
* @widget: a #GtkWidget
gtk_widget_queue_compute_expand (parent);
}
- gtk_widget_update_norender (widget);
+ gtk_widget_propagate_alpha (widget);
gtk_widget_pop_verify_invariants (widget);
}
priv->anchored = new_anchored;
+ /* This can only happen with gtk_widget_reparent() */
+ if (priv->realized)
+ {
+ if (new_anchored)
+ gtk_widget_connect_frame_clock (widget,
+ gtk_widget_get_frame_clock (widget));
+ else
+ gtk_widget_disconnect_frame_clock (widget,
+ gtk_widget_get_frame_clock (info->previous_toplevel));
+ }
+
g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
do_screen_change (widget, info->previous_screen, info->new_screen);
/* gtk_object_destroy() will already hold a refcount on object */
GtkWidget *widget = GTK_WIDGET (object);
GtkWidgetPrivate *priv = widget->priv;
+ GList *l;
if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
{
gtk_grab_remove (widget);
+ for (l = priv->tick_callbacks; l;)
+ {
+ GList *next = l->next;
+ destroy_tick_callback_info (widget, l->data, l);
+ l = next;
+ }
+
if (priv->style)
g_object_unref (priv->style);
priv->style = gtk_widget_get_default_style ();
if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
gdk_window_set_opacity (window,
- (priv->norender || priv->norender_children) ? 0.0 : 1.0);
+ priv->norender_children ? 0.0 : 1.0);
}
/**
gdk_window_set_support_multidevice (priv->window, support_multidevice);
}
-static void apply_norender (GtkWidget *widget, gboolean norender);
+/* There are multiple alpha related sources. First of all the user can specify alpha
+ * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
+ * are multiplied together to form the total alpha. Secondly, the user can specify
+ * an opacity group for a widget, which means we must essentially handle it as having alpha.
+ *
+ * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
+ * group we directly set the opacity of widget->window. This will cause gdk to properly
+ * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
+ *
+ * However, if the widget is not windowed, or the user specified an opacity group for the
+ * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
+ * implementation of this would break for windowed widgets or descendant widgets with
+ * windows, as these would not be handled by the ::draw signal. To handle this we set
+ * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
+ * to make the draw signal propagate to *all* child widgets/windows.
+ *
+ * Note: We don't make all child windows fully transparent, we stop at the first one
+ * in each branch when propagating down the hierarchy.
+ */
-static void
-apply_norender_cb (GtkWidget *widget, gpointer norender)
-{
- apply_norender (widget, GPOINTER_TO_INT (norender));
-}
+/* This is called when priv->alpha or priv->opacity_group group changes, and should
+ * update priv->norender and GdkWindow opacity for this widget and any children that
+ * needs changing. It is also called whenver the parent changes, the parents
+ * norender_children state changes, or the has_window state of the widget changes.
+ */
static void
-propagate_norender_non_window (GtkWidget *widget, gboolean norender)
+gtk_widget_propagate_alpha (GtkWidget *widget)
{
+ GtkWidgetPrivate *priv = widget->priv;
+ GtkWidget *parent;
+ gboolean norender, norender_children;
GList *l;
- g_assert (!gtk_widget_get_has_window (widget));
-
- for (l = widget->priv->registered_windows; l != NULL; l = l->next)
- gdk_window_set_opacity (l->data,
- norender ? 0 : widget->priv->alpha / 255.0);
-
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget), apply_norender_cb,
- GINT_TO_POINTER (norender));
-}
-
-static void
-apply_norender (GtkWidget *widget, gboolean norender)
-{
- if (widget->priv->norender == norender)
- return;
+ parent = priv->parent;
- widget->priv->norender = norender;
+ norender =
+ /* If this widget has an opacity group, never render it */
+ priv->opacity_group ||
+ /* If the parent has norender_children, propagate that here */
+ (parent != NULL && parent->priv->norender_children);
+
+ /* Windowed widget children should norender if: */
+ norender_children =
+ /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
+ !gtk_widget_get_has_window (widget) &&
+ ( /* norender is set, or */
+ norender ||
+ /* widget has an alpha */
+ priv->alpha != 255
+ );
if (gtk_widget_get_has_window (widget))
{
- if (widget->priv->window != NULL)
- gdk_window_set_opacity (widget->priv->window,
- norender ? 0 : widget->priv->alpha / 255.0);
+ if (priv->window != NULL && !gdk_window_has_native (priv->window))
+ gdk_window_set_opacity (priv->window,
+ norender ? 0 : priv->alpha / 255.0);
+ }
+ else /* !has_window */
+ {
+ for (l = priv->registered_windows; l != NULL; l = l->next)
+ {
+ GdkWindow *w = l->data;
+ if (!gdk_window_has_native (w))
+ gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
+ }
}
- else
- propagate_norender_non_window (widget, norender | widget->priv->norender_children);
-}
-
-/* This is called when the norender_children state of a non-window widget changes,
- * its parent changes, or its has_window state changes. It means we need
- * to update the norender of all the windows owned by the widget and those
- * of child widgets, up to and including the first windowed widgets in the hierarchy.
- */
-static void
-gtk_widget_update_norender (GtkWidget *widget)
-{
- gboolean norender;
- GtkWidget *parent;
-
- parent = widget->priv->parent;
- norender =
- parent != NULL &&
- (parent->priv->norender_children ||
- (parent->priv->norender && !gtk_widget_get_has_window (parent)));
+ priv->norender = norender;
+ if (priv->norender_children != norender_children)
+ {
+ priv->norender_children = norender_children;
- apply_norender (widget, norender);
+ if (GTK_IS_CONTAINER (widget))
+ gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
+ }
- /* The above may not have propagated to children if norender_children changed but
- not norender, so we need to enforce propagation. */
- if (!gtk_widget_get_has_window (widget))
- propagate_norender_non_window (widget, norender | widget->priv->norender_children);
+ if (gtk_widget_get_realized (widget))
+ gtk_widget_queue_draw (widget);
}
static void
priv->alpha = alpha;
- if (gtk_widget_get_has_window (widget))
- {
- if (priv->window != NULL)
- gdk_window_set_opacity (priv->window,
- priv->norender ? 0 : priv->alpha / 255.0);
- }
- else
- {
- /* For non windowed widgets we can't use gdk_window_set_opacity() directly, as there is
- no GdkWindow at the right place in the hierarchy. For no-window widget this is not a problem,
- as we just push an opacity group in the draw marshaller.
+ gtk_widget_propagate_alpha (widget);
- However, that only works for non-window descendant widgets. If any descendant has a
- window that window will not normally be rendered in the draw signal, so the opacity
- group will not work for it.
+}
- To fix this we set all such windows to a zero opacity, meaning they don't get drawn
- by gdk, and instead we set a NULL _gtk_cairo_get_event during expose so that the draw
- handler recurses into windowed widgets.
+static void
+gtk_widget_set_has_opacity_group (GtkWidget *widget,
+ gboolean has_opacity_group)
+{
+ GtkWidgetPrivate *priv;
- We do this by setting "norender_children", which means that any windows in this widget
- or its ancestors (stopping at the first such windows at each branch in the hierarchy)
- are set to zero opacity. This is then propagated into all necessary children as norender,
- which controls whether a window should be exposed or not.
- */
- priv->norender_children = priv->alpha != 255;
- gtk_widget_update_norender (widget);
- }
+ g_return_if_fail (GTK_IS_WIDGET (widget));
- if (gtk_widget_get_realized (widget))
- gtk_widget_queue_draw (widget);
+ priv = widget->priv;
+
+ has_opacity_group = !!has_opacity_group;
+
+ if (priv->opacity_group == has_opacity_group)
+ return;
+
+ priv->opacity_group = has_opacity_group;
+
+ gtk_widget_propagate_alpha (widget);
}
/**
opacity = CLAMP (opacity, 0.0, 1.0);
alpha = round (opacity * 255);
+
+ /* As a kind of hack for internal use we treat an alpha very
+ close to 1.0 (rounds to 255) but not 1.0 as specifying that
+ we want the opacity group behaviour wrt draw handling, but
+ not actually an alpha value. See bug #687842 for discussions. */
+ gtk_widget_set_has_opacity_group (widget,
+ alpha == 255 && opacity != 1.0);
+
if (alpha == priv->user_alpha)
return;
priv->user_alpha = alpha;
gtk_widget_update_alpha (widget);
+
}
/**
if (G_UNLIKELY (priv->context == NULL))
{
GdkScreen *screen;
+ GdkFrameClock *frame_clock;
priv->context = gtk_style_context_new ();
if (screen)
gtk_style_context_set_screen (priv->context, screen);
+ frame_clock = gtk_widget_get_frame_clock (widget);
+ if (frame_clock)
+ gtk_style_context_set_frame_clock (priv->context, frame_clock);
+
if (priv->parent)
gtk_style_context_set_parent (priv->context,
gtk_widget_get_style_context (priv->parent));