summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-12-07 22:15:09 -0500
committerCosimo Cecchi <cosimoc@gnome.org>2012-12-11 09:35:43 -0500
commite0bfbaf1a6dbcaa3ab384dd22ee246050b9aee65 (patch)
tree29da81d2a363f3ea64170badc8e8ca848ae7fa4c
parent91b8cd27d86ec1d9b6c02a93f36d9c6c1e0cc43e (diff)
downloadclutter-gtk-e0bfbaf1a6dbcaa3ab384dd22ee246050b9aee65.tar.gz
embed: be more careful when adding and removing the filter function
The intention of the current code seems to be adding a global event filter instead of one per realized embed; the filter is unconditionally removed in unrealize() though. This is a problem if an embed is unrealized and another one is realized later (for instance because a window is destroyed and another window is recreated later). Fix the bug by tracking the number of realized embeds with a counter, and removing the event filter only when the counter reaches zero. https://bugzilla.gnome.org/show_bug.cgi?id=689879
-rw-r--r--clutter-gtk/gtk-clutter-embed.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/clutter-gtk/gtk-clutter-embed.c b/clutter-gtk/gtk-clutter-embed.c
index 065f20f..6cdc110 100644
--- a/clutter-gtk/gtk-clutter-embed.c
+++ b/clutter-gtk/gtk-clutter-embed.c
@@ -78,6 +78,8 @@ G_DEFINE_TYPE (GtkClutterEmbed, gtk_clutter_embed, GTK_TYPE_CONTAINER);
#define GTK_CLUTTER_EMBED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_CLUTTER_TYPE_EMBED, GtkClutterEmbedPrivate))
+static gint num_filter = 0;
+
struct _GtkClutterEmbedPrivate
{
ClutterActor *stage;
@@ -339,15 +341,11 @@ gtk_clutter_embed_realize (GtkWidget *widget)
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) &&
GDK_IS_X11_WINDOW (window))
{
- static gboolean has_filter = FALSE;
-
clutter_x11_set_stage_foreign (CLUTTER_STAGE (priv->stage), GDK_WINDOW_XID (window));
- if (G_UNLIKELY (!has_filter))
- {
- gdk_window_add_filter (NULL, gtk_clutter_filter_func, widget);
- has_filter = TRUE;
- }
+ if (num_filter == 0)
+ gdk_window_add_filter (NULL, gtk_clutter_filter_func, widget);
+ num_filter++;
}
else
#endif
@@ -355,15 +353,11 @@ gtk_clutter_embed_realize (GtkWidget *widget)
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32) &&
GDK_IS_WIN32_WINDOW (window))
{
- static gboolean has_filter = FALSE;
-
clutter_win32_set_stage_foreign (CLUTTER_STAGE (priv->stage), GDK_WINDOW_HWND (window));
- if (G_UNLIKELY (!has_filter))
- {
- gdk_window_add_filter (NULL, gtk_clutter_filter_func, widget);
- has_filter = TRUE;
- }
+ if (num_filter == 0)
+ gdk_window_add_filter (NULL, gtk_clutter_filter_func, widget);
+ num_filter++;
}
#endif
@@ -380,7 +374,12 @@ gtk_clutter_embed_unrealize (GtkWidget *widget)
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
- gdk_window_remove_filter (NULL, gtk_clutter_filter_func, widget);
+ if (num_filter > 0)
+ {
+ num_filter--;
+ if (num_filter == 0)
+ gdk_window_remove_filter (NULL, gtk_clutter_filter_func, widget);
+ }
if (priv->stage != NULL)
clutter_actor_hide (priv->stage);