diff options
author | Ronald Bultje <rbultje@src.gnome.org> | 2004-10-07 10:17:00 +0000 |
---|---|---|
committer | Ronald Bultje <rbultje@src.gnome.org> | 2004-10-07 10:17:00 +0000 |
commit | 6bfaf059a9b3b2d6e2d8d28e7610239f49b0d755 (patch) | |
tree | 3569a4328984b47889d7ac4a11689f3219f9dacf | |
parent | 4413bcaed5100514f8ff20e18f106bd781a03dca (diff) | |
download | totem-6bfaf059a9b3b2d6e2d8d28e7610239f49b0d755.tar.gz |
Set a preferred window size. Allows resizing to smaller than this size.
* src/bacon-video-widget-gst.c: (get_media_size),
(bacon_video_widget_realize), (bacon_video_widget_size_request),
(shrink_toplevel), (bacon_video_widget_signal_idler),
(bacon_video_widget_set_logo), (bacon_video_widget_set_visuals),
(bacon_video_widget_set_scale_ratio), (bacon_video_widget_new):
* src/video-utils.c: (cb_unset_size), (cb_set_preferred_size),
(totem_widget_set_preferred_size):
* src/video-utils.h:
Set a preferred window size. Allows resizing to smaller than
this size.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | src/backend/bacon-video-widget-gst.c | 66 | ||||
-rw-r--r-- | src/backend/video-utils.c | 44 | ||||
-rw-r--r-- | src/backend/video-utils.h | 3 | ||||
-rw-r--r-- | src/bacon-video-widget-gst.c | 66 | ||||
-rw-r--r-- | src/video-utils.c | 44 | ||||
-rw-r--r-- | src/video-utils.h | 3 |
7 files changed, 187 insertions, 52 deletions
@@ -1,3 +1,16 @@ +2004-10-07 Ronald S. Bultje <rbultje@ronald.bitfreak.net> + + * src/bacon-video-widget-gst.c: (get_media_size), + (bacon_video_widget_realize), (bacon_video_widget_size_request), + (shrink_toplevel), (bacon_video_widget_signal_idler), + (bacon_video_widget_set_logo), (bacon_video_widget_set_visuals), + (bacon_video_widget_set_scale_ratio), (bacon_video_widget_new): + * src/video-utils.c: (cb_unset_size), (cb_set_preferred_size), + (totem_widget_set_preferred_size): + * src/video-utils.h: + Set a preferred window size. Allows resizing to smaller than + this size. + 2004-10-07 Bastien Nocera <hadess@hadess.net> * src/totem-pl-parser.c: (parse_asx_entry), (parse_asx_entries), diff --git a/src/backend/bacon-video-widget-gst.c b/src/backend/bacon-video-widget-gst.c index 187d484a3..55a9bb513 100644 --- a/src/backend/bacon-video-widget-gst.c +++ b/src/backend/bacon-video-widget-gst.c @@ -12,7 +12,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - *_ + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -188,11 +188,28 @@ static GtkWidgetClass *parent_class = NULL; static int bvw_table_signals[LAST_SIGNAL] = { 0 }; static void +get_media_size (BaconVideoWidget *bvw, gint *width, gint *height) +{ + if (GST_STATE (bvw->priv->play) >= GST_STATE_PAUSED) { + *width = bvw->priv->video_width; + *height = bvw->priv->video_height; + } else { + if (bvw->priv->logo_pixbuf != NULL) { + *width = gdk_pixbuf_get_width (bvw->priv->logo_pixbuf); + *height = gdk_pixbuf_get_height (bvw->priv->logo_pixbuf); + } else { + *width = bvw->priv->init_width; + *height = bvw->priv->init_height; + } + } +} + +static void bacon_video_widget_realize (GtkWidget * widget) { BaconVideoWidget *bvw = BACON_VIDEO_WIDGET (widget); GdkWindowAttr attributes; - gint attributes_mask; + gint attributes_mask, w, h; /* Creating our widget's window */ attributes.window_type = GDK_WINDOW_CHILD; @@ -232,6 +249,10 @@ bacon_video_widget_realize (GtkWidget * widget) gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + /* nice hack to show the logo fullsize, while still being resizable */ + get_media_size (BACON_VIDEO_WIDGET (widget), &w, &h); + totem_widget_set_preferred_size (widget, w, h); } static gboolean @@ -305,20 +326,8 @@ bacon_video_widget_size_request (GtkWidget * widget, { BaconVideoWidget *bvw = BACON_VIDEO_WIDGET (widget); - /* FIXME: intial width, this is minimal, but not "recommended" - * (media size) */ - if (GST_STATE (bvw->priv->play) >= GST_STATE_PAUSED) { - requisition->width = bvw->priv->video_width; - requisition->height = bvw->priv->video_height; - } else { - if (bvw->priv->logo_pixbuf != NULL) { - requisition->width = gdk_pixbuf_get_width (bvw->priv->logo_pixbuf); - requisition->height = gdk_pixbuf_get_height (bvw->priv->logo_pixbuf); - } else { - requisition->width = bvw->priv->init_width; - requisition->height = bvw->priv->init_height; - } - } + requisition->width = bvw->priv->init_width; + requisition->height = bvw->priv->init_height; } static void @@ -525,7 +534,6 @@ shrink_toplevel (BaconVideoWidget * bvw) GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (GTK_WIDGET (bvw)); gtk_window_resize (GTK_WINDOW (toplevel), 1, 1); - gtk_widget_queue_resize (GTK_WIDGET (bvw)); } static gboolean @@ -573,7 +581,11 @@ bacon_video_widget_signal_idler (BaconVideoWidget *bvw) g_signal_emit (G_OBJECT (bvw), bvw_table_signals[SIGNAL_GOT_METADATA], 0, NULL); if (bvw->priv->auto_resize) { + gint w, h; + shrink_toplevel (bvw); + get_media_size (bvw, &w, &h); + totem_widget_set_preferred_size (GTK_WIDGET (bvw), w, h); } else { bacon_video_widget_size_allocate (GTK_WIDGET (bvw), >K_WIDGET (bvw)->allocation); @@ -1188,7 +1200,11 @@ bacon_video_widget_set_logo (BaconVideoWidget * bvw, gchar * filename) filename, error->message); g_error_free (error); } else { + gint w, h; + shrink_toplevel (bvw); + get_media_size (bvw, &w, &h); + totem_widget_set_preferred_size (GTK_WIDGET (bvw), w, h); } } @@ -1420,7 +1436,7 @@ bacon_video_widget_get_visuals_list (BaconVideoWidget * bvw) gboolean bacon_video_widget_set_visuals (BaconVideoWidget * bvw, const char *name) { - //gboolean paused = FALSE; + /*gboolean paused = FALSE;*/ g_return_val_if_fail (bvw != NULL, FALSE); g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), FALSE); @@ -1543,8 +1559,10 @@ bacon_video_widget_set_scale_ratio (BaconVideoWidget * bvw, gfloat ratio) g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw)); g_return_if_fail (GST_IS_ELEMENT (bvw->priv->play)); -// gst_video_widget_set_scale (bvw->priv->vw, ratio); -// gst_video_widget_set_scale_override (bvw->priv->vw, TRUE); +#if 0 + gst_video_widget_set_scale (bvw->priv->vw, ratio); + gst_video_widget_set_scale_override (bvw->priv->vw, TRUE); +#endif shrink_toplevel (bvw); } @@ -1964,12 +1982,8 @@ bacon_video_widget_new (int width, int height, } bvw->priv->media_device = g_strdup ("/dev/dvd"); - if (width <= 0 || height <= 0) { - width = DEFAULT_WIDTH; - height = DEFAULT_HEIGHT; - } - bvw->priv->init_width = width; - bvw->priv->init_height = height; + bvw->priv->init_width = 240; + bvw->priv->init_height = 180; bvw->priv->cursor_shown = TRUE; bvw->priv->logo_mode = TRUE; diff --git a/src/backend/video-utils.c b/src/backend/video-utils.c index 5a3135ae3..8defbfc45 100644 --- a/src/backend/video-utils.c +++ b/src/backend/video-utils.c @@ -350,3 +350,47 @@ totem_time_to_string_text (gint64 msecs) return string; } + +typedef struct _TotemPrefSize { + gint width, height; + gulong sig_id; +} TotemPrefSize; + +static gboolean +cb_unset_size (gpointer data) +{ + GtkWidget *widget = data; + + gtk_widget_queue_resize_no_redraw (widget); + + return FALSE; +} + +static void +cb_set_preferred_size (GtkWidget *widget, GtkRequisition *req, + gpointer data) +{ + TotemPrefSize *size = data; + + req->width = size->width; + req->height = size->height; + + g_signal_handler_disconnect (widget, size->sig_id); + g_free (size); + g_idle_add (cb_unset_size, widget); +} + +void +totem_widget_set_preferred_size (GtkWidget *widget, gint width, + gint height) +{ + TotemPrefSize *size = g_new (TotemPrefSize, 1); + + size->width = width; + size->height = height; + size->sig_id = g_signal_connect (widget, "size-request", + G_CALLBACK (cb_set_preferred_size), + size); + + gtk_widget_queue_resize (widget); +} diff --git a/src/backend/video-utils.h b/src/backend/video-utils.h index d2f285215..f17ae5da9 100644 --- a/src/backend/video-utils.h +++ b/src/backend/video-utils.h @@ -1,5 +1,6 @@ #include <gdk/gdk.h> +#include <gtk/gtk.h> void eel_gdk_window_set_invisible_cursor (GdkWindow *window); void totem_gdk_window_set_always_on_top (GdkWindow *window, gboolean setting); @@ -16,3 +17,5 @@ void totem_pixbuf_mirror (GdkPixbuf *pixbuf); char *totem_time_to_string (gint64 msecs); char *totem_time_to_string_text (gint64 msecs); +void totem_widget_set_preferred_size (GtkWidget *widget, gint width, + gint height); diff --git a/src/bacon-video-widget-gst.c b/src/bacon-video-widget-gst.c index 187d484a3..55a9bb513 100644 --- a/src/bacon-video-widget-gst.c +++ b/src/bacon-video-widget-gst.c @@ -12,7 +12,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - *_ + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -188,11 +188,28 @@ static GtkWidgetClass *parent_class = NULL; static int bvw_table_signals[LAST_SIGNAL] = { 0 }; static void +get_media_size (BaconVideoWidget *bvw, gint *width, gint *height) +{ + if (GST_STATE (bvw->priv->play) >= GST_STATE_PAUSED) { + *width = bvw->priv->video_width; + *height = bvw->priv->video_height; + } else { + if (bvw->priv->logo_pixbuf != NULL) { + *width = gdk_pixbuf_get_width (bvw->priv->logo_pixbuf); + *height = gdk_pixbuf_get_height (bvw->priv->logo_pixbuf); + } else { + *width = bvw->priv->init_width; + *height = bvw->priv->init_height; + } + } +} + +static void bacon_video_widget_realize (GtkWidget * widget) { BaconVideoWidget *bvw = BACON_VIDEO_WIDGET (widget); GdkWindowAttr attributes; - gint attributes_mask; + gint attributes_mask, w, h; /* Creating our widget's window */ attributes.window_type = GDK_WINDOW_CHILD; @@ -232,6 +249,10 @@ bacon_video_widget_realize (GtkWidget * widget) gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + /* nice hack to show the logo fullsize, while still being resizable */ + get_media_size (BACON_VIDEO_WIDGET (widget), &w, &h); + totem_widget_set_preferred_size (widget, w, h); } static gboolean @@ -305,20 +326,8 @@ bacon_video_widget_size_request (GtkWidget * widget, { BaconVideoWidget *bvw = BACON_VIDEO_WIDGET (widget); - /* FIXME: intial width, this is minimal, but not "recommended" - * (media size) */ - if (GST_STATE (bvw->priv->play) >= GST_STATE_PAUSED) { - requisition->width = bvw->priv->video_width; - requisition->height = bvw->priv->video_height; - } else { - if (bvw->priv->logo_pixbuf != NULL) { - requisition->width = gdk_pixbuf_get_width (bvw->priv->logo_pixbuf); - requisition->height = gdk_pixbuf_get_height (bvw->priv->logo_pixbuf); - } else { - requisition->width = bvw->priv->init_width; - requisition->height = bvw->priv->init_height; - } - } + requisition->width = bvw->priv->init_width; + requisition->height = bvw->priv->init_height; } static void @@ -525,7 +534,6 @@ shrink_toplevel (BaconVideoWidget * bvw) GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (GTK_WIDGET (bvw)); gtk_window_resize (GTK_WINDOW (toplevel), 1, 1); - gtk_widget_queue_resize (GTK_WIDGET (bvw)); } static gboolean @@ -573,7 +581,11 @@ bacon_video_widget_signal_idler (BaconVideoWidget *bvw) g_signal_emit (G_OBJECT (bvw), bvw_table_signals[SIGNAL_GOT_METADATA], 0, NULL); if (bvw->priv->auto_resize) { + gint w, h; + shrink_toplevel (bvw); + get_media_size (bvw, &w, &h); + totem_widget_set_preferred_size (GTK_WIDGET (bvw), w, h); } else { bacon_video_widget_size_allocate (GTK_WIDGET (bvw), >K_WIDGET (bvw)->allocation); @@ -1188,7 +1200,11 @@ bacon_video_widget_set_logo (BaconVideoWidget * bvw, gchar * filename) filename, error->message); g_error_free (error); } else { + gint w, h; + shrink_toplevel (bvw); + get_media_size (bvw, &w, &h); + totem_widget_set_preferred_size (GTK_WIDGET (bvw), w, h); } } @@ -1420,7 +1436,7 @@ bacon_video_widget_get_visuals_list (BaconVideoWidget * bvw) gboolean bacon_video_widget_set_visuals (BaconVideoWidget * bvw, const char *name) { - //gboolean paused = FALSE; + /*gboolean paused = FALSE;*/ g_return_val_if_fail (bvw != NULL, FALSE); g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), FALSE); @@ -1543,8 +1559,10 @@ bacon_video_widget_set_scale_ratio (BaconVideoWidget * bvw, gfloat ratio) g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw)); g_return_if_fail (GST_IS_ELEMENT (bvw->priv->play)); -// gst_video_widget_set_scale (bvw->priv->vw, ratio); -// gst_video_widget_set_scale_override (bvw->priv->vw, TRUE); +#if 0 + gst_video_widget_set_scale (bvw->priv->vw, ratio); + gst_video_widget_set_scale_override (bvw->priv->vw, TRUE); +#endif shrink_toplevel (bvw); } @@ -1964,12 +1982,8 @@ bacon_video_widget_new (int width, int height, } bvw->priv->media_device = g_strdup ("/dev/dvd"); - if (width <= 0 || height <= 0) { - width = DEFAULT_WIDTH; - height = DEFAULT_HEIGHT; - } - bvw->priv->init_width = width; - bvw->priv->init_height = height; + bvw->priv->init_width = 240; + bvw->priv->init_height = 180; bvw->priv->cursor_shown = TRUE; bvw->priv->logo_mode = TRUE; diff --git a/src/video-utils.c b/src/video-utils.c index 5a3135ae3..8defbfc45 100644 --- a/src/video-utils.c +++ b/src/video-utils.c @@ -350,3 +350,47 @@ totem_time_to_string_text (gint64 msecs) return string; } + +typedef struct _TotemPrefSize { + gint width, height; + gulong sig_id; +} TotemPrefSize; + +static gboolean +cb_unset_size (gpointer data) +{ + GtkWidget *widget = data; + + gtk_widget_queue_resize_no_redraw (widget); + + return FALSE; +} + +static void +cb_set_preferred_size (GtkWidget *widget, GtkRequisition *req, + gpointer data) +{ + TotemPrefSize *size = data; + + req->width = size->width; + req->height = size->height; + + g_signal_handler_disconnect (widget, size->sig_id); + g_free (size); + g_idle_add (cb_unset_size, widget); +} + +void +totem_widget_set_preferred_size (GtkWidget *widget, gint width, + gint height) +{ + TotemPrefSize *size = g_new (TotemPrefSize, 1); + + size->width = width; + size->height = height; + size->sig_id = g_signal_connect (widget, "size-request", + G_CALLBACK (cb_set_preferred_size), + size); + + gtk_widget_queue_resize (widget); +} diff --git a/src/video-utils.h b/src/video-utils.h index d2f285215..f17ae5da9 100644 --- a/src/video-utils.h +++ b/src/video-utils.h @@ -1,5 +1,6 @@ #include <gdk/gdk.h> +#include <gtk/gtk.h> void eel_gdk_window_set_invisible_cursor (GdkWindow *window); void totem_gdk_window_set_always_on_top (GdkWindow *window, gboolean setting); @@ -16,3 +17,5 @@ void totem_pixbuf_mirror (GdkPixbuf *pixbuf); char *totem_time_to_string (gint64 msecs); char *totem_time_to_string_text (gint64 msecs); +void totem_widget_set_preferred_size (GtkWidget *widget, gint width, + gint height); |