diff options
author | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-05 18:36:08 +0200 |
---|---|---|
committer | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-05 18:40:48 +0200 |
commit | a5c2798e02dd487c6441e18f266faaa69dcb7a02 (patch) | |
tree | 6fd2b387e4ee6b6178d2c8984423e95d14e0b9e1 | |
parent | 779e11f6d89efced9c8a81ae2a7d089f3b5722b5 (diff) |
Rearrange CheeseTexture
Create window in the init function. Wait for the stage to be mapped
before to map the video window, install a x11 event handler to map-unmap
the window with the parent (stage window).
-rw-r--r-- | src/cheese-stage.c | 86 | ||||
-rw-r--r-- | src/cheese-texture.c | 101 |
2 files changed, 90 insertions, 97 deletions
diff --git a/src/cheese-stage.c b/src/cheese-stage.c index 59c93c8..089290d 100644 --- a/src/cheese-stage.c +++ b/src/cheese-stage.c @@ -35,48 +35,6 @@ #define W 160 #define H 120 - -/*static ClutterX11FilterReturn event_filter (XEvent * ev, ClutterEvent * cev, - gpointer unused); - -static ClutterX11FilterReturn -event_filter (XEvent * ev, ClutterEvent * cev, gpointer data) -{ - Window *windows = (Window *) data; - gint i; - switch (ev->type) { - case MapRequest: - g_message ("map request"); - return CLUTTER_X11_FILTER_CONTINUE; - case MapNotify: - if (ev->xmap.window == windows[N_ACTORS]) { - g_message ("stage map"); -// XMapSubwindows (ev->xmap.display, ev->xmap.window); - for (i = 0; i < N_ACTORS; i++) { - XMapWindow (ev->xmap.display, windows[i]); - } - XSync (ev->xmap.display, FALSE); - } else - g_message ("map"); - XMapSubwindows (ev->xmap.display, ev->xmap.window); - return CLUTTER_X11_FILTER_CONTINUE; - case UnmapNotify: - if (ev->xmap.window == windows[N_ACTORS]) { - g_message ("stage unmap"); -// XUnmapSubwindows (ev->xmap.display, ev->xmap.window); - for (i = 0; i < N_ACTORS; i++) { - XUnmapWindow (ev->xmap.display, windows[i]); - } - XSync (ev->xmap.display, FALSE); - } else - g_message ("unmap"); - return CLUTTER_X11_FILTER_CONTINUE; - default: - return CLUTTER_X11_FILTER_CONTINUE; - } -} -*/ - static GstBusSyncReply create_window (GstBus * bus, GstMessage * message, gpointer data) { @@ -100,7 +58,7 @@ create_window (GstBus * bus, GstMessage * message, gpointer data) g_object_get (G_OBJECT (actor[count]), "window", &win, NULL); g_message ("adding actor: %d win: %d", count, win); gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), - win); + win); count++; } @@ -110,26 +68,6 @@ create_window (GstBus * bus, GstMessage * message, gpointer data) return GST_BUS_DROP; } -#if 0 -void -apply_fx (GstElement * element, const gchar * fx) -{ - GEnumClass *p_class; - - /* from fxtest ;) */ - /* heeeellppppp!! */ - p_class = - G_PARAM_SPEC_ENUM (g_object_class_find_property (G_OBJECT_GET_CLASS - (G_OBJECT (data)), "effect") - )->enum_class; - - g_print ("setting: %s - %s\n", fx, g_enum_get_value_by_nick (p_class, - fx)->value_name); - g_object_set (G_OBJECT (element), "effect", g_enum_get_value_by_nick (p_class, - fx)->value, NULL); -} -#endif - int main (int argc, char *argv[]) { @@ -165,17 +103,20 @@ main (int argc, char *argv[]) } stage = clutter_stage_get_default (); + clutter_actor_set_size (CLUTTER_ACTOR (stage), W * COLS + (COLS - 1), H * ROWS + (ROWS - 1)); - + clutter_color_from_string (&color, "DarkSlateGrey"); clutter_stage_set_color (CLUTTER_STAGE (stage), &color); + // clutter_stage_set_user_resizable (stage, TRUE); for (i = 0; i < N_ACTORS; i++) { actor[i] = cheese_texture_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), - actor[i]); + clutter_actor_set_scale_with_gravity (actor[i], 0.95, 0.95, + CLUTTER_GRAVITY_CENTER); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor[i]); clutter_actor_set_position (actor[i], xpos, ypos); if (xpos > (COLS - 1) * W) { xpos = 0; @@ -184,10 +125,17 @@ main (int argc, char *argv[]) xpos += W + 1; clutter_actor_show (actor[i]); } -// clutter_x11_add_filter (event_filter, actor); + +/* desc = g_strdup_printf ("v4l2src ! " + "video/x-raw-yuv, width=640, height=480, framerate=30/1 ! " + "videoscale ! videorate ! " + "video/x-raw-yuv, width=%d, height=%d, framerate=15/1 ! " + "identity", W, H); +*/ desc = g_strdup_printf ("videotestsrc ! " - "video/x-raw-rgb, width=%d, height=%d !" "identity", W, H); + "video/x-raw-rgb, width=%d, height=%d, framerate=10/1 ! ffmpegcolorspace ! identity", + W, H); pipeline = GST_PIPELINE (gst_pipeline_new (NULL)); srcbin = gst_parse_bin_from_description (desc, TRUE, NULL); @@ -200,7 +148,7 @@ main (int argc, char *argv[]) for (i = 0; i < N_ACTORS; i++) { queue[i] = gst_element_factory_make ("queue", NULL); - sink[i] = gst_element_factory_make ("glimagesink", NULL); + sink[i] = gst_element_factory_make ("ximagesink", NULL); gst_bin_add_many (GST_BIN (pipeline), queue[i], sink[i], NULL); } diff --git a/src/cheese-texture.c b/src/cheese-texture.c index 65a967c..1c4754f 100644 --- a/src/cheese-texture.c +++ b/src/cheese-texture.c @@ -37,63 +37,108 @@ G_DEFINE_TYPE (CheeseTexture, cheese_texture, CLUTTER_GLX_TYPE_TEXTURE_PIXMAP); struct _CheeseTexturePrivate { /* stuff */ - gpointer stuff; + Window parent; }; +static ClutterX11FilterReturn +on_x_event_filter (XEvent * xev, ClutterEvent * cev, gpointer data); + +static ClutterX11FilterReturn +on_x_event_filter (XEvent * xev, ClutterEvent * cev, gpointer data) +{ + CheeseTexture *self = CHEESE_TEXTURE (data); + CheeseTexturePrivate *priv = self->priv = CHEESE_TEXTURE_GET_PRIVATE (self); + + Window window; + + if (xev->xany.window != priv->parent) + return CLUTTER_X11_FILTER_CONTINUE; + + g_object_get (self, "window", &window, NULL); + if (window == None) + return; + + switch (xev->type) { + case MapNotify: + g_message ("stage mapped %d", xev->xmap.window); + XMapWindow (xev->xmap.display, window); + break; + case UnmapNotify: + g_message ("stage unmapped %d", xev->xmap.window); + XUnmapWindow (xev->xmap.display, window); + break; + default: + break; + } + return CLUTTER_X11_FILTER_CONTINUE; +} + static void -cheese_texture_class_init (CheeseTextureClass *klass) +cheese_texture_dispose (GObject *object) { -/* GObjectClass *gobject_class = (GObjectClass *) klass; */ -/* ClutterActorClass *actor_class = (ClutterActorClass *) klass; */ + CheeseTexture *self = CHEESE_TEXTURE (object); + Window window; - g_type_class_add_private (klass, sizeof (CheeseTexturePrivate)); + g_object_get (self, "window", &window, NULL); + + clutter_x11_remove_filter (on_x_event_filter, NULL); + + G_OBJECT_CLASS (cheese_texture_parent_class)->dispose (object); + + if (window != None) + XDestroyWindow (clutter_x11_get_default_display (), window); } static void -cheese_texture_init (CheeseTexture *self) +cheese_texture_class_init (CheeseTextureClass * klass) { - CheeseTexturePrivate *priv; + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - priv = self->priv = CHEESE_TEXTURE_GET_PRIVATE (self); + g_type_class_add_private (klass, sizeof (CheeseTexturePrivate)); + + gobject_class->dispose = cheese_texture_dispose; } -ClutterActor * -cheese_texture_new (void) +static void +cheese_texture_init (CheeseTexture * self) { + CheeseTexturePrivate *priv = self->priv = CHEESE_TEXTURE_GET_PRIVATE (self); Display *disp; Window win; Window stage_win; XSetWindowAttributes attr; unsigned long mask; - + ClutterActor *stage; - ClutterActor *self; - /* require xcomposite */ - g_assert (clutter_x11_has_composite_extension ()); + disp = clutter_x11_get_default_display (); - disp = clutter_x11_get_default_display (); - stage = clutter_stage_get_default (); stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); attr.background_pixel = BlackPixel (disp, DefaultScreen (disp)); - attr.event_mask = SubstructureNotifyMask; - mask = CWBackPixel | CWEventMask; + attr.override_redirect = True; + attr.event_mask = SubstructureNotifyMask | StructureNotifyMask; + mask = CWEventMask | CWBackPixel | CWOverrideRedirect; win = XCreateWindow (disp, stage_win, - 0, 0, DEFAULT_W, DEFAULT_H, 0, - CopyFromParent, InputOutput, CopyFromParent, - mask, &attr); - + 0, 0, DEFAULT_W, DEFAULT_H, 0, + CopyFromParent, InputOutput, CopyFromParent, mask, &attr); + + priv->parent = stage_win; + XCompositeRedirectWindow (disp, win, CompositeRedirectManual); - XMapRaised (disp, win); - XSync (disp, FALSE); - g_message ("created win: %d", win); - - self = g_object_new (CHEESE_TYPE_TEXTURE, - "window", win, "automatic-updates", TRUE, NULL); + g_object_set (self, "window", win, "automatic-updates", TRUE, NULL); + + clutter_x11_add_filter (on_x_event_filter, self); +} + +ClutterActor * +cheese_texture_new (void) +{ + ClutterActor *self = g_object_new (CHEESE_TYPE_TEXTURE, NULL); return self; } |