set_invisible_cursor(GdkWindow* pubRefGdkWin) /* adapted from totem */ { GdkBitmap *empty_bitmap; GdkCursor *cursor; GdkColor useless; char invisible_cursor_bits[] = { 0x0 }; useless.red = useless.green = useless.blue = 0; useless.pixel = 0; empty_bitmap = gdk_bitmap_create_from_data(pubRefGdkWin, invisible_cursor_bits, 1, 1); /* When there's no window, there's no bitmap */ if (empty_bitmap == NULL) return; cursor = gdk_cursor_new_from_pixmap(empty_bitmap, empty_bitmap, &useless, &useless, 0, 0); gdk_window_set_cursor(pubRefGdkWin, cursor); gdk_cursor_unref(cursor); g_object_unref(empty_bitmap); } static gint handle_video_cursor(GtkWidget *widget, GdkEventMotion *event) { gdk_window_set_cursor(event->window, NULL); //this never happens return true; } ... GdkWindowAttr attributes; mGtkWidget = gtk_drawing_area_new(); attributes.window_type = GDK_WINDOW_CHILD; attributes.x = 0; attributes.y = 0; attributes.width = 0; attributes.height = 0; attributes.wclass = GDK_INPUT_OUTPUT; attributes.event_mask = GDK_ALL_EVENTS_MASK; gtk_drawing_area_size(GTK_DRAWING_AREA(mGtkWidget),0,0); mGdkWin = gdk_window_new(win, &attributes, GDK_WA_X | GDK_WA_Y); //win is a toplevel window created by the xul application gtk_widget_set_parent_window(mGtkWidget, mGdkWin); gtk_signal_connect(GTK_OBJECT(mGtkWidget), "motion_notify_event", (GtkSignalFunc)handle_video_cursor, NULL); gtk_widget_set_events(mGtkWidget, GDK_ALL_EVENTS_MASK); gdk_window_show(mGdkWin); gtk_widget_show(mGtkWidget); set_invisible_cursor(mGdkWin); ... NS_IMETHODIMP sbGStreamerSimple::Resize() //resize video window and gtkwidget { PRInt32 x, y, width, height; nsCOMPtr boxObject; mVideoOutputElement->GetBoxObject(getter_AddRefs(boxObject)); boxObject->GetX(&x); boxObject->GetY(&y); boxObject->GetWidth(&width); boxObject->GetHeight(&height); PRInt32 newX, newY, newWidth, newHeight; // If we have not received a video size yet, size the video window to the // size of the video output element if(mVideoWidth == 0 && mVideoHeight == 0) { gdk_window_move_resize(mGdkWin, x, y, width, height); gtk_widget_hide(mGtkWidget); gtk_widget_set_size_request(mGtkWidget,(gint)width,(gint)height); gtk_widget_show(mGtkWidget); } else { if(mVideoWidth > 0 && mVideoHeight > 0) { float ratioWidth = (float) width / (float) mVideoWidth; float ratioHeight = (float) height / (float) mVideoHeight; if(ratioWidth < ratioHeight) { newWidth = PRInt32(mVideoWidth * ratioWidth); newHeight = PRInt32(mVideoHeight * ratioWidth); newX = x; newY = ((height - newHeight) / 2) + y; } else { newWidth = PRInt32(mVideoWidth * ratioHeight); newHeight = PRInt32(mVideoHeight * ratioHeight); newX = ((width - newWidth) / 2) + x; newY = y; } gdk_window_move_resize(mGdkWin, newX, newY, newWidth, newHeight); gtk_widget_hide(mGtkWidget); gtk_widget_set_size_request(mGtkWidget,(gint)newWidth,(gint)newHeight); gtk_widget_show(mGtkWidget); } } return NS_OK; }