[rhythmbox] visualizer: rework fullscreen start and stop



commit 3f0482edba782672e0dbd11ca20b4aaa8360c317
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Jul 1 20:20:12 2012 +1000

    visualizer: rework fullscreen start and stop
    
    Rather than reparenting the clutter embed into the fullscreen
    window and back, we now create a new embed for fullscreen mode
    and move the clutter sink actor into it.  At some point, clutter
    stopped being able to handle events when the embed widget gets
    reparented.

 plugins/visualizer/rb-visualizer-fullscreen.c |   20 +-------
 plugins/visualizer/rb-visualizer-fullscreen.h |    2 +-
 plugins/visualizer/rb-visualizer-page.c       |   57 ++++++++++++++++++++-----
 plugins/visualizer/rb-visualizer-page.h       |    1 +
 4 files changed, 51 insertions(+), 29 deletions(-)
---
diff --git a/plugins/visualizer/rb-visualizer-fullscreen.c b/plugins/visualizer/rb-visualizer-fullscreen.c
index b182cb0..460d738 100644
--- a/plugins/visualizer/rb-visualizer-fullscreen.c
+++ b/plugins/visualizer/rb-visualizer-fullscreen.c
@@ -519,7 +519,6 @@ create_controls (RBShell *shell)
 static gboolean
 hide_controls_cb (ClutterActor *controls)
 {
-	rb_debug ("controls pseudo class: %s", mx_stylable_get_style_pseudo_class (MX_STYLABLE (controls)));
 	if (clutter_actor_has_pointer (controls) == FALSE) {
 		g_object_set_data (G_OBJECT (controls), "hide-controls-id", NULL);
 
@@ -636,23 +635,10 @@ rb_visualizer_fullscreen_add_widgets (GtkWidget *window, ClutterActor *stage, RB
 }
 
 void
-rb_visualizer_fullscreen_remove_widgets (ClutterActor *stage)
+rb_visualizer_fullscreen_stop (ClutterActor *stage)
 {
-	ClutterActor *track_info;
 	ClutterActor *controls;
 
-	clutter_threads_enter ();
-
-	track_info = CLUTTER_ACTOR (g_object_steal_data (G_OBJECT (stage), TRACK_INFO_DATA));
-	if (track_info != NULL) {
-		clutter_container_remove_actor (CLUTTER_CONTAINER (stage), track_info);
-	}
-
-	controls = CLUTTER_ACTOR (g_object_steal_data (G_OBJECT (stage), CONTROLS_DATA));
-	if (controls != NULL) {
-		stop_hide_timer (controls);
-		clutter_container_remove_actor (CLUTTER_CONTAINER (stage), controls);
-	}
-
-	clutter_threads_leave ();
+	controls = CLUTTER_ACTOR (g_object_get_data (G_OBJECT (stage), CONTROLS_DATA));
+	stop_hide_timer (controls);
 }
diff --git a/plugins/visualizer/rb-visualizer-fullscreen.h b/plugins/visualizer/rb-visualizer-fullscreen.h
index 9c520f0..ef1b8e6 100644
--- a/plugins/visualizer/rb-visualizer-fullscreen.h
+++ b/plugins/visualizer/rb-visualizer-fullscreen.h
@@ -38,7 +38,7 @@ G_BEGIN_DECLS
 void		rb_visualizer_fullscreen_load_style (GObject *plugin);
 
 void		rb_visualizer_fullscreen_add_widgets (GtkWidget *window, ClutterActor *stage, RBShell *shell);
-void		rb_visualizer_fullscreen_remove_widgets (ClutterActor *stage);
+void		rb_visualizer_fullscreen_stop (ClutterActor *stage);
 
 G_END_DECLS
 
diff --git a/plugins/visualizer/rb-visualizer-page.c b/plugins/visualizer/rb-visualizer-page.c
index 7f64b11..f7f69df 100644
--- a/plugins/visualizer/rb-visualizer-page.c
+++ b/plugins/visualizer/rb-visualizer-page.c
@@ -41,6 +41,8 @@
 
 G_DEFINE_DYNAMIC_TYPE (RBVisualizerPage, rb_visualizer_page, RB_TYPE_DISPLAY_PAGE)
 
+static GtkWidget *create_embed (RBVisualizerPage *page);
+
 enum {
 	PROP_0,
 	PROP_SINK,
@@ -109,9 +111,19 @@ start_fullscreen (RBVisualizerPage *page)
 		page->fullscreen = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 		gtk_window_set_skip_taskbar_hint (GTK_WINDOW (page->fullscreen), TRUE);
 
-		/* maybe need to block the sink? */
+		/* move the texture from the page embed to the new fullscreen embed */
+
+		g_object_ref (page->texture);
+
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->embed));
+		clutter_container_remove_actor (CLUTTER_CONTAINER (stage), page->texture);
 
-		gtk_widget_reparent (page->embed, page->fullscreen);
+		page->fullscreen_embed = create_embed (page);
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->fullscreen_embed));
+		clutter_container_add (CLUTTER_CONTAINER (stage), page->texture, NULL);
+		g_object_unref (page->texture);
+
+		gtk_container_add (GTK_CONTAINER (page->fullscreen), page->fullscreen_embed);
 		gtk_widget_show_all (GTK_WIDGET (page->fullscreen));
 
 		gtk_window_get_position (main_window, &x, &y);
@@ -121,7 +133,6 @@ start_fullscreen (RBVisualizerPage *page)
 		gtk_window_set_transient_for (GTK_WINDOW (page->fullscreen), main_window);
 		g_object_unref (main_window);
 
-		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->embed));
 		rb_visualizer_fullscreen_add_widgets (page->fullscreen, stage, shell);
 		g_object_unref (shell);
 	}
@@ -136,12 +147,21 @@ stop_fullscreen (RBVisualizerPage *page)
 		ClutterActor *stage;
 
 		rb_debug ("stopping fullscreen display");
-		gtk_widget_reparent (page->embed, GTK_WIDGET (page));
+
+		g_object_ref (page->texture);
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->fullscreen_embed));
+		rb_visualizer_fullscreen_stop (stage);
+		clutter_container_remove_actor (CLUTTER_CONTAINER (stage), page->texture);
+
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->embed));
+		clutter_container_add (CLUTTER_CONTAINER (stage), page->texture, NULL);
+
+		g_object_unref (page->texture);
+
 		gtk_widget_destroy (GTK_WIDGET (page->fullscreen));
 		page->fullscreen = NULL;
 
-		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->embed));
-		rb_visualizer_fullscreen_remove_widgets (stage);
+		page->fullscreen_embed = NULL;
 	}
 
 	set_action_state (page, FALSE);
@@ -197,6 +217,22 @@ resize_sink_texture (ClutterActor *stage, ClutterActorBox *box, ClutterAllocatio
 }
 
 
+static GtkWidget *
+create_embed (RBVisualizerPage *page)
+{
+	ClutterActor *stage;
+	GtkWidget *embed;
+
+	embed = gtk_clutter_embed_new ();
+
+	stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (embed));
+	g_signal_connect_object (stage, "allocation-changed", G_CALLBACK (resize_sink_texture), page->texture, 0);
+	g_signal_connect_object (stage, "button-press-event", G_CALLBACK (stage_button_press_cb), page, 0);
+	g_signal_connect_object (stage, "key-release-event", G_CALLBACK (stage_key_release_cb), page, 0);
+
+	return embed;
+}
+
 static gboolean
 impl_show_popup (RBDisplayPage *page)
 {
@@ -209,17 +245,16 @@ static void
 impl_selected (RBDisplayPage *bpage)
 {
 	RBVisualizerPage *page = RB_VISUALIZER_PAGE (bpage);
-	ClutterActor *stage;
 
 	RB_DISPLAY_PAGE_CLASS (rb_visualizer_page_parent_class)->selected (bpage);
 
 	if (page->embed == NULL) {
-		page->embed = gtk_clutter_embed_new ();
+		ClutterActor *stage;
+
+		page->embed = create_embed (page);
 
 		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (page->embed));
-		g_signal_connect_object (stage, "allocation-changed", G_CALLBACK (resize_sink_texture), page->texture, 0);
-		g_signal_connect_object (stage, "button-press-event", G_CALLBACK (stage_button_press_cb), page, 0);
-		g_signal_connect_object (stage, "key-release-event", G_CALLBACK (stage_key_release_cb), page, 0);
+
 		clutter_container_add (CLUTTER_CONTAINER (stage), page->texture, NULL);
 
 		gtk_box_pack_start (GTK_BOX (page), page->embed, TRUE, TRUE, 0);
diff --git a/plugins/visualizer/rb-visualizer-page.h b/plugins/visualizer/rb-visualizer-page.h
index a2524f2..f021d6a 100644
--- a/plugins/visualizer/rb-visualizer-page.h
+++ b/plugins/visualizer/rb-visualizer-page.h
@@ -51,6 +51,7 @@ struct _RBVisualizerPage
 	ClutterActor *texture;
 
 	GtkWidget *fullscreen;
+	GtkWidget *fullscreen_embed;
 
 	GtkWidget *popup;
 	GtkToggleAction *fullscreen_action;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]