gdk: Fix Stage foreign window support

The code is generally wrong, and does not work. We need to skip the
GdkWindow creation when we have a foreing window, but we still need to
create the Cogl onscreen buffer and connect it to the GdkWindow's native
resource.
This commit is contained in:
Emmanuele Bassi 2011-09-29 18:16:48 +01:00
parent f14cbf5bdb
commit f58d393187

View File

@ -107,7 +107,7 @@ clutter_stage_gdk_set_gdk_geometry (ClutterStageGdk *stage)
static void static void
clutter_stage_gdk_get_geometry (ClutterStageWindow *stage_window, clutter_stage_gdk_get_geometry (ClutterStageWindow *stage_window,
ClutterGeometry *geometry) cairo_rectangle_int_t *geometry)
{ {
ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window);
@ -157,12 +157,16 @@ clutter_stage_gdk_unrealize (ClutterStageWindow *stage_window)
{ {
g_object_set_data (G_OBJECT (stage_gdk->window), g_object_set_data (G_OBJECT (stage_gdk->window),
"clutter-stage-window", NULL); "clutter-stage-window", NULL);
if (stage_gdk->foreign_window) if (stage_gdk->foreign_window)
g_object_unref (stage_gdk->window); g_object_unref (stage_gdk->window);
else else
gdk_window_destroy (stage_gdk->window); gdk_window_destroy (stage_gdk->window);
stage_gdk->window = NULL; stage_gdk->window = NULL;
} }
return clutter_stage_window_parent_iface->unrealize (stage_window);
} }
static gboolean static gboolean
@ -177,22 +181,25 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
gboolean use_alpha; gboolean use_alpha;
gfloat width, height; gfloat width, height;
if (stage_gdk->foreign_window && if (!stage_gdk->foreign_window)
stage_gdk->window != NULL) {
if (stage_gdk->window != NULL)
{ {
/* complete realizing the stage */ /* complete realizing the stage */
ClutterGeometry geometry; cairo_rectangle_int_t geometry;
clutter_stage_gdk_get_geometry (stage_window, &geometry); clutter_stage_gdk_get_geometry (stage_window, &geometry);
clutter_actor_set_geometry (CLUTTER_ACTOR (stage_cogl->wrapper), &geometry); clutter_actor_set_size (CLUTTER_ACTOR (stage_cogl->wrapper),
geometry.width,
geometry.height);
gdk_window_ensure_native (stage_gdk->window); gdk_window_ensure_native (stage_gdk->window);
gdk_window_set_events (stage_gdk->window, gdk_window_set_events (stage_gdk->window, CLUTTER_STAGE_GDK_EVENT_MASK);
CLUTTER_STAGE_GDK_EVENT_MASK);
return TRUE; return TRUE;
} }
else
{
attributes.title = NULL; attributes.title = NULL;
g_object_get (stage_cogl->wrapper, g_object_get (stage_cogl->wrapper,
"cursor-visible", &cursor_visible, "cursor-visible", &cursor_visible,
@ -232,25 +239,21 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
attributes.visual = gdk_screen_get_system_visual (backend_gdk->screen); attributes.visual = gdk_screen_get_system_visual (backend_gdk->screen);
} }
if (stage_gdk->window != NULL)
{
g_critical ("Stage realized more than once");
return FALSE;
}
stage_gdk->foreign_window = FALSE; stage_gdk->foreign_window = FALSE;
stage_gdk->window = gdk_window_new (NULL, &attributes, stage_gdk->window = gdk_window_new (NULL, &attributes,
GDK_WA_TITLE | GDK_WA_CURSOR | GDK_WA_VISUAL); GDK_WA_TITLE | GDK_WA_CURSOR | GDK_WA_VISUAL);
gdk_window_ensure_native (stage_gdk->window);
g_free (attributes.title);
}
clutter_stage_gdk_set_gdk_geometry (stage_gdk); clutter_stage_gdk_set_gdk_geometry (stage_gdk);
}
gdk_window_ensure_native (stage_gdk->window);
g_object_set_data (G_OBJECT (stage_gdk->window), g_object_set_data (G_OBJECT (stage_gdk->window),
"clutter-stage-window", stage_gdk); "clutter-stage-window", stage_gdk);
g_free (attributes.title);
stage_cogl->onscreen = cogl_onscreen_new (backend->cogl_context, stage_cogl->onscreen = cogl_onscreen_new (backend->cogl_context,
width, height); width, height);
@ -279,7 +282,9 @@ clutter_stage_gdk_realize (ClutterStageWindow *stage_window)
cogl_object_unref (stage_cogl->onscreen); cogl_object_unref (stage_cogl->onscreen);
stage_cogl->onscreen = NULL; stage_cogl->onscreen = NULL;
if (!stage_gdk->foreign_window)
gdk_window_destroy (stage_gdk->window); gdk_window_destroy (stage_gdk->window);
stage_gdk->window = NULL; stage_gdk->window = NULL;
return FALSE; return FALSE;
@ -570,6 +575,7 @@ clutter_gdk_set_stage_foreign (ClutterStage *stage,
return FALSE; return FALSE;
} }
#if 0
gdk_window_get_user_data (window, &gtk_data); gdk_window_get_user_data (window, &gtk_data);
if (gtk_data != NULL) if (gtk_data != NULL)
{ {
@ -577,6 +583,7 @@ clutter_gdk_set_stage_foreign (ClutterStage *stage,
"Use a child GdkWindow for embedding instead"); "Use a child GdkWindow for embedding instead");
return FALSE; return FALSE;
} }
#endif
closure.stage_gdk = stage_gdk; closure.stage_gdk = stage_gdk;
closure.window = g_object_ref (window); closure.window = g_object_ref (window);