Index: src/backend/bacon-video-widget-gst-0.10.c
===================================================================
RCS file: /cvs/gnome/totem/src/backend/bacon-video-widget-gst-0.10.c,v
retrieving revision 1.100
diff -p -u -B -r1.100 bacon-video-widget-gst-0.10.c
--- src/backend/bacon-video-widget-gst-0.10.c	29 Nov 2006 23:13:24 -0000	1.100
+++ src/backend/bacon-video-widget-gst-0.10.c	30 Nov 2006 19:25:25 -0000
@@ -106,6 +106,7 @@ static const gchar *video_props_str[4] =
   GCONF_PREFIX "/hue"
 };
 
+/* FIXME group gboolean:s together into bitfield (guint .... : 1) ! */
 struct BaconVideoWidgetPrivate
 {
   BaconVideoWidgetAspectRatio  ratio_type;
@@ -184,6 +185,9 @@ struct BaconVideoWidgetPrivate
    * which may change asynchronously or during buffering */
   GstState                     target_state;
   gboolean                     buffering;
+
+  /* toplevel configure-event handler */
+  guint                        toplevel_configure_handler_id;
 };
 
 static void bacon_video_widget_set_property (GObject * object,
@@ -413,15 +417,18 @@ bacon_video_widget_realize (GtkWidget * 
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
   
   /* Connect to configure event on the top level window */
-  g_signal_connect (G_OBJECT (gtk_widget_get_toplevel (widget)),
-      "configure-event", G_CALLBACK (bacon_video_widget_configure_event), bvw);
+  bvw->priv->toplevel_configure_handler_id =
+	  g_signal_connect (gtk_widget_get_toplevel (widget),
+			    "configure-event",
+			    G_CALLBACK (bacon_video_widget_configure_event),
+			    bvw);
 
   /* get screen size changes */
   g_signal_connect (G_OBJECT (gtk_widget_get_screen (widget)),
       "size-changed", G_CALLBACK (size_changed_cb), bvw);
 
   /* nice hack to show the logo fullsize, while still being resizable */
-  get_media_size (BACON_VIDEO_WIDGET (widget), &w, &h);
+  get_media_size (bvw, &w, &h);
   totem_widget_set_preferred_size (widget, w, h);
 
 #ifdef HAVE_NVTV
@@ -430,6 +437,16 @@ bacon_video_widget_realize (GtkWidget * 
   } 
 #endif
 
+  if (bvw->priv->xoverlay) {
+     XID window;
+
+     bvw_update_interface_implementations (bvw);
+
+     window = GDK_WINDOW_XWINDOW (bvw->priv->video_window);
+     g_print ("Setting XID %u\n", window);
+     gst_x_overlay_set_xwindow_id (bvw->priv->xoverlay, window);
+  }
+
   bvw->priv->have_xvidmode = bacon_resize_init ();
 }
 
@@ -443,12 +460,14 @@ bacon_video_widget_unrealize (GtkWidget 
   nvtv_simple_exit();
 #endif
 
+  g_signal_handler_disconnect (gtk_widget_get_toplevel (widget),
+			       bvw->priv->toplevel_configure_handler_id);
+
   gdk_window_set_user_data (bvw->priv->video_window, NULL);
   gdk_window_destroy (bvw->priv->video_window);
   bvw->priv->video_window = NULL;
 
-  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
-    GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
 }
 
 static void
@@ -786,7 +805,9 @@ bacon_video_widget_class_init (BaconVide
   object_class = (GObjectClass *) klass;
   widget_class = (GtkWidgetClass *) klass;
 
-  parent_class = gtk_type_class (gtk_box_get_type ());
+  parent_class = g_type_class_peek_parent (klass);
+
+  g_type_class_add_private (object_class, sizeof (BaconVideoWidgetPrivate));
 
   /* GtkWidget */
   widget_class->size_request = bacon_video_widget_size_request;
@@ -914,22 +935,21 @@ bacon_video_widget_class_init (BaconVide
 static void
 bacon_video_widget_init (BaconVideoWidget * bvw)
 {
-  g_return_if_fail (bvw != NULL);
-  g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
+  BaconVideoWidgetPrivate *priv;
 
   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (bvw), GTK_CAN_FOCUS);
   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (bvw), GTK_NO_WINDOW);
   GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (bvw), GTK_DOUBLE_BUFFERED);
 
-  bvw->priv = g_new0 (BaconVideoWidgetPrivate, 1);
+  bvw->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (bvw, BACON_TYPE_VIDEO_WIDGET, BaconVideoWidgetPrivate);
   bvw->com = g_new0 (BaconVideoWidgetCommon, 1);
   
-  bvw->priv->update_id = 0;
-  bvw->priv->tagcache = NULL;
-  bvw->priv->audiotags = NULL;
-  bvw->priv->videotags = NULL;
+  priv->update_id = 0;
+  priv->tagcache = NULL;
+  priv->audiotags = NULL;
+  priv->videotags = NULL;
 
-  bvw->priv->lock = g_mutex_new ();
+  priv->lock = g_mutex_new ();
 }
 
 static void
@@ -1033,7 +1053,7 @@ bvw_handle_element_message (BaconVideoWi
     }
   } else if (strcmp (type_name, "prepare-xwindow-id") == 0 ||
       strcmp (type_name, "have-xwindow-id") == 0) {
-    /* we handle these synchroneously or want to ignore them */
+    /* we handle these synchronously or want to ignore them */
     goto done;
   }
 
@@ -1636,7 +1656,6 @@ bacon_video_widget_finalize (GObject * o
 
   g_mutex_free (bvw->priv->lock);
 
-  g_free (bvw->priv);
   g_free (bvw->com);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -2350,7 +2369,7 @@ timed_out:
   /* it's taking a long time to open -- just tell totem it was ok, this allows
    * the user to stop the loading process with the normal stop button */
   GST_DEBUG ("state change to %s timed out, returning success and handling "
-      "errors asynchroneously", gst_element_state_get_name (state));
+      "errors asynchronously", gst_element_state_get_name (state));
   bvw->priv->ignore_messages_mask = saved_events;
   return TRUE;
 
@@ -2484,7 +2503,8 @@ bacon_video_widget_open_with_subtitle (B
     if (error) {
       ret = poll_for_state_change (bvw, bvw->priv->play, GST_STATE_PAUSED, error);
     } else {
-      GST_WARNING ("caller not checking error, handling errors asynchroneously");
+      /* FIXME: why is this a warning? it's a good thing to handle thing async */
+      GST_WARNING ("caller not checking error, handling errors asynchronously");
       ret = TRUE;
     }
   } else {
@@ -2549,7 +2569,7 @@ bacon_video_widget_play (BaconVideoWidge
   if (error) {
     ret = poll_for_state_change (bvw, bvw->priv->play, GST_STATE_PLAYING, error);
   } else {
-    GST_WARNING ("caller not checking error details, handling errors asynchroneously");
+    GST_WARNING ("caller not checking error details, handling errors asynchronously");
     ret = TRUE;
   }
 
@@ -2734,8 +2754,7 @@ void
 bacon_video_widget_set_logo (BaconVideoWidget * bvw, gchar * filename)
 {
   GError *error = NULL;
-  
-  g_return_if_fail (bvw != NULL);
+
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
   g_return_if_fail (bvw->priv->logo_pixbuf == NULL);
 
@@ -2751,27 +2770,32 @@ bacon_video_widget_set_logo (BaconVideoW
 void
 bacon_video_widget_set_logo_mode (BaconVideoWidget * bvw, gboolean logo_mode)
 {
-  g_return_if_fail (bvw != NULL);
+  BaconVideoWidgetPrivate *priv;
+
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
+  priv = bvw->priv;
 
-  bvw->priv->logo_mode = logo_mode;
+  logo_mode = logo_mode != FALSE;
 
-  if (bvw->priv->video_window) {
-    if (logo_mode) {
-      gdk_window_hide (bvw->priv->video_window);
-    } else {
-      gdk_window_show (bvw->priv->video_window);
+  if (priv->logo_mode != logo_mode) {
+    priv->logo_mode = logo_mode;
+
+    if (priv->video_window) {
+      if (logo_mode) {
+        gdk_window_hide (priv->video_window);
+      } else {
+        gdk_window_show (priv->video_window);
+      }
     }
-  }
   
-  /* Queue a redraw of the widget */
-  gtk_widget_queue_draw (GTK_WIDGET (bvw));
+    /* Queue a redraw of the widget */
+    gtk_widget_queue_draw (GTK_WIDGET (bvw));
+  }
 }
 
 gboolean
 bacon_video_widget_get_logo_mode (BaconVideoWidget * bvw)
 {
-  g_return_val_if_fail (bvw != NULL, FALSE);
   g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), FALSE);
 
   return bvw->priv->logo_mode;
@@ -4273,7 +4297,7 @@ bacon_video_widget_error_quark (void)
 {
   static GQuark q; /* 0 */
 
-  if (q == 0) {
+  if (G_UNLIKELY (q == 0)) {
     q = g_quark_from_static_string ("bvw-error-quark");
   }
   return q;
@@ -4332,6 +4356,8 @@ bvw_update_interface_implementations (Ba
   if (GST_IS_X_OVERLAY (element)) {
     GST_DEBUG ("Found xoverlay: %s", GST_OBJECT_NAME (element));
     bvw->priv->xoverlay = GST_X_OVERLAY (element);
+
+    g_object_set (bvw->priv->xoverlay, "screen", gdk_screen_get_number (gtk_widget_get_screen (GTK_WIDGET (bvw))), NULL);
   } else {
     GST_DEBUG ("No xoverlay found");
     bvw->priv->xoverlay = NULL;
@@ -4366,7 +4392,7 @@ bvw_update_interface_implementations (Ba
   }
 
   /* Setup brightness and contrast */
-  for (i = 0; i < 4; i++) {
+  for (i = 0; i < G_N_ELEMENTS (video_props_str); i++) {
     confvalue = gconf_client_get_without_default (bvw->priv->gc,
         video_props_str[i], NULL);
     if (confvalue != NULL) {
@@ -4397,7 +4423,8 @@ bvw_element_msg_sync (GstBus *bus, GstMe
 
   /* This only gets sent if we haven't set an ID yet. This is our last
    * chance to set it before the video sink will create its own window */
-  if (gst_structure_has_name (msg->structure, "prepare-xwindow-id")) {
+  if (gst_structure_has_name (msg->structure, "prepare-xwindow-id") &&
+      GTK_WIDGET_REALIZED (GTK_WIDGET (bvw))) {
     XID window;
 
     GST_DEBUG ("Handling sync prepare-xwindow-id message");
@@ -4653,7 +4680,7 @@ bacon_video_widget_new (int width, int h
     bvw_update_interface_implementations (bvw);
   }
 
-  /* we want to catch "prepare-xwindow-id" element messages synchroneously */
+  /* we want to catch "prepare-xwindow-id" element messages synchronously */
   gst_bus_set_sync_handler (bvw->priv->bus, gst_bus_sync_signal_handler, bvw);
 
   bvw->priv->sig_bus_sync = 
