From e8aa9b0440e03e7002323922f862342db51c5f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Dec 2015 12:34:30 +0100 Subject: [PATCH] Add a way to highlight resizing widgets https://bugzilla.gnome.org/show_bug.cgi?id=759586 --- docs/reference/gtk/running.sgml | 4 ++++ gtk/gtkdebug.h | 3 ++- gtk/gtkmain.c | 1 + gtk/gtkwidget.c | 22 +++++++++++++++++++++ gtk/gtkwidgetprivate.h | 4 ++++ gtk/inspector/visual.c | 14 ++++++++++++++ gtk/inspector/visual.ui | 34 +++++++++++++++++++++++++++++++++ 7 files changed, 81 insertions(+), 1 deletion(-) diff --git a/docs/reference/gtk/running.sgml b/docs/reference/gtk/running.sgml index a826dca828..7f3812046a 100644 --- a/docs/reference/gtk/running.sgml +++ b/docs/reference/gtk/running.sgml @@ -214,6 +214,10 @@ additional environment variables. updates Visual feedback about window updates + + resize + Highlight resizing widgets + The special value all can be used to turn on all diff --git a/gtk/gtkdebug.h b/gtk/gtkdebug.h index 40d42d797a..e78dd6837f 100644 --- a/gtk/gtkdebug.h +++ b/gtk/gtkdebug.h @@ -54,7 +54,8 @@ typedef enum { GTK_DEBUG_NO_PIXEL_CACHE = 1 << 16, GTK_DEBUG_INTERACTIVE = 1 << 17, GTK_DEBUG_TOUCHSCREEN = 1 << 18, - GTK_DEBUG_ACTIONS = 1 << 19 + GTK_DEBUG_ACTIONS = 1 << 19, + GTK_DEBUG_RESIZE = 1 << 20 } GtkDebugFlag; #ifdef G_ENABLE_DEBUG diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 45134703fb..36237ae16c 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -181,6 +181,7 @@ static const GDebugKey gtk_debug_keys[] = { {"interactive", GTK_DEBUG_INTERACTIVE}, {"touchscreen", GTK_DEBUG_TOUCHSCREEN}, {"actions", GTK_DEBUG_ACTIONS}, + {"resize", GTK_DEBUG_RESIZE} }; #endif /* G_ENABLE_DEBUG */ diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index ff7dc0d59f..e72b563f81 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -4356,6 +4356,9 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class) priv->alloc_needed = TRUE; priv->alloc_needed_on_child = TRUE; priv->focus_on_click = TRUE; +#ifdef G_ENABLE_DEBUG + priv->highlight_resize = FALSE; +#endif switch (_gtk_widget_get_direction (widget)) { @@ -5927,6 +5930,9 @@ gtk_widget_size_allocate_with_baseline (GtkWidget *widget, gtk_widget_push_verify_invariants (widget); #ifdef G_ENABLE_DEBUG + priv->highlight_resize = TRUE; + gtk_widget_queue_draw (widget); + if (gtk_widget_get_resize_needed (widget)) { g_warning ("Allocating size to %s %p without calling gtk_widget_get_preferred_width/height(). " @@ -6978,6 +6984,22 @@ _gtk_widget_draw_internal (GtkWidget *widget, cairo_restore (cr); } } + + if (GTK_DEBUG_CHECK (RESIZE) && + widget->priv->highlight_resize) + { + GtkAllocation alloc; + gtk_widget_get_allocation (widget, &alloc); + + cairo_rectangle (cr, 0, 0, alloc.width, alloc.height); + cairo_set_source_rgba (cr, 1, 0, 0, 0.2); + cairo_fill (cr); + + gtk_widget_queue_draw (widget); + + widget->priv->highlight_resize = FALSE; + + } #endif if (cairo_status (cr) && diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index e3f8a135de..18bc98030c 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -45,6 +45,10 @@ struct _GtkWidgetPrivate guint direction : 2; +#ifdef G_ENABLE_DEBUG + guint highlight_resize : 1; +#endif + guint in_destruction : 1; guint toplevel : 1; guint anchored : 1; diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c index d21a6b7f24..d96925637d 100644 --- a/gtk/inspector/visual.c +++ b/gtk/inspector/visual.c @@ -185,6 +185,19 @@ pixelcache_activate (GtkSwitch *sw) redraw_everything (); } +static void +widget_resize_activate (GtkSwitch *sw) +{ + guint flags = gtk_get_debug_flags (); + + if (gtk_switch_get_active (sw)) + flags |= GTK_DEBUG_RESIZE; + else + flags &= ~GTK_DEBUG_RESIZE; + + gtk_set_debug_flags (flags); +} + static void fill_gtk (const gchar *path, GHashTable *t) @@ -699,6 +712,7 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass) gtk_widget_class_bind_template_callback (widget_class, rendering_mode_changed); gtk_widget_class_bind_template_callback (widget_class, baselines_activate); gtk_widget_class_bind_template_callback (widget_class, pixelcache_activate); + gtk_widget_class_bind_template_callback (widget_class, widget_resize_activate); gtk_widget_class_bind_template_callback (widget_class, software_gl_activate); gtk_widget_class_bind_template_callback (widget_class, software_surface_activate); gtk_widget_class_bind_template_callback (widget_class, texture_rectangle_activate); diff --git a/gtk/inspector/visual.ui b/gtk/inspector/visual.ui index adb7cf290f..d00fdebc80 100644 --- a/gtk/inspector/visual.ui +++ b/gtk/inspector/visual.ui @@ -492,6 +492,40 @@ + + + True + False + + + True + horizontal + 10 + 40 + + + True + Show Widget Resizes + start + baseline + 0.0 + + + + + True + end + baseline + + + + True + + + + + + True