#if defined(HAVE_CLUTTER_GTK_X11)
-#include <clutter/clutter-x11.h>
+#include <clutter/x11/clutter-x11.h>
#include <gdk/gdkx.h>
#elif defined(HAVE_CLUTTER_GTK_WIN32)
#include "gtk-clutter-embed.h"
-static void clutter_container_iface_init (ClutterContainerIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (GtkClutterEmbed,
- gtk_clutter_embed,
- GTK_TYPE_WIDGET,
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
- clutter_container_iface_init));
+G_DEFINE_TYPE (GtkClutterEmbed, gtk_clutter_embed, GTK_TYPE_WIDGET);
#define GTK_CLUTTER_EMBED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_CLUTTER_EMBED, GtkClutterEmbedPrivate))
static void
gtk_clutter_embed_dispose (GObject *gobject)
{
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (gobject)->priv;
+
+ if (priv->stage)
+ {
+ clutter_actor_destroy (priv->stage);
+ priv->stage = NULL;
+ }
+
G_OBJECT_CLASS (gtk_clutter_embed_parent_class)->dispose (gobject);
}
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
/* Make sure the widget is realised before we show */
- gtk_widget_realize (widget);
-
- GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->show (widget);
+ if (!GTK_WIDGET_REALIZED (widget))
+ gtk_widget_realize (widget);
clutter_actor_show (priv->stage);
+
+ GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->show (widget);
}
static void
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
- GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->hide (widget);
-
clutter_actor_hide (priv->stage);
+
+ GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->hide (widget);
}
static void
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
+
+ /* NOTE: GDK_MOTION_NOTIFY above should be safe as Clutter does its own
+ * throtling.
+ */
attributes.event_mask = gtk_widget_get_events (widget)
- | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
- | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK;
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_KEY_PRESS_MASK
+ | GDK_KEY_RELEASE_MASK
+ | GDK_POINTER_MOTION_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
GDK_WINDOW_HWND (widget->window));
#endif /* HAVE_CLUTTER_GTK_{X11,WIN32} */
- clutter_redraw (CLUTTER_STAGE(priv->stage));
+ clutter_actor_queue_redraw (CLUTTER_ACTOR (priv->stage));
gtk_clutter_embed_send_configure (GTK_CLUTTER_EMBED (widget));
}
allocation->width,
allocation->height);
- if (CLUTTER_ACTOR_IS_VISIBLE (priv->stage))
- clutter_actor_queue_redraw (priv->stage);
+ clutter_actor_queue_relayout (priv->stage);
+}
+
+static gboolean
+gtk_clutter_embed_motion_notify_event (GtkWidget *widget,
+ GdkEventMotion *event)
+{
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
+ ClutterEvent cevent = { 0, };
+
+ cevent.type = CLUTTER_MOTION;
+ cevent.any.stage = CLUTTER_STAGE (priv->stage);
+ cevent.motion.x = event->x;
+ cevent.motion.y = event->y;
+ cevent.motion.time = event->time;
+
+ clutter_do_event (&cevent);
+
+ /* doh - motion events can push ENTER/LEAVE events onto Clutters
+ * internal event queue which we do really ever touch (essentially
+ * proxying from gtks queue). The below pumps them back out and
+ * processes.
+ * *could* be side effects with below though doubful as no other
+ * events reach the queue (we shut down event collection). Maybe
+ * a peek_mask type call could be even safer.
+ */
+ while (clutter_events_pending())
+ {
+ ClutterEvent *ev = clutter_event_get ();
+ if (ev)
+ {
+ clutter_do_event (ev);
+ clutter_event_free (ev);
+ }
+ }
+
+ return FALSE;
}
static gboolean
clutter_do_event (&cevent);
- return TRUE;
+ return FALSE;
}
static gboolean
clutter_do_event (&cevent);
- return TRUE;
+ return FALSE;
}
static gboolean
-gtk_clutter_embed_expose_event (GtkWidget *widget, GdkEventExpose *event)
+gtk_clutter_embed_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
if (CLUTTER_ACTOR_IS_VISIBLE (priv->stage))
clutter_actor_queue_redraw (priv->stage);
- return TRUE;
+ return FALSE;
}
static gboolean
-gtk_clutter_embed_map_event (GtkWidget *widget,
- GdkEventAny *event)
+gtk_clutter_embed_map_event (GtkWidget *widget,
+ GdkEventAny *event)
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
*/
CLUTTER_ACTOR_SET_FLAGS (priv->stage, CLUTTER_ACTOR_MAPPED);
- return TRUE;
+ return FALSE;
}
-static void
-gtk_clutter_embed_add (ClutterContainer *container,
- ClutterActor *actor)
-{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
-
- clutter_container_add_actor (stage, actor);
- g_signal_emit_by_name (container, "actor-added", actor);
-}
-
-static void
-gtk_clutter_embed_remove (ClutterContainer *container,
- ClutterActor *actor)
-{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
-
- g_object_ref (actor);
-
- clutter_container_remove_actor (stage, actor);
- g_signal_emit_by_name (container, "actor-removed", actor);
-
- g_object_unref (actor);
-}
-
-static void
-gtk_clutter_embed_foreach (ClutterContainer *container,
- ClutterCallback callback,
- gpointer callback_data)
-{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
-
- clutter_container_foreach (stage, callback, callback_data);
-}
-
-static void
-gtk_clutter_embed_raise (ClutterContainer *container,
- ClutterActor *child,
- ClutterActor *sibling)
-{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
-
- clutter_container_raise_child (stage, child, sibling);
-}
-
-static void
-gtk_clutter_embed_lower (ClutterContainer *container,
- ClutterActor *child,
- ClutterActor *sibling)
-{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
-
- clutter_container_lower_child (stage, child, sibling);
-}
-
-static void
-gtk_clutter_embed_sort_depth_order (ClutterContainer *container)
+static gboolean
+gtk_clutter_embed_focus_out (GtkWidget *widget,
+ GdkEventFocus *event)
{
- GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (container)->priv;
- ClutterContainer *stage = CLUTTER_CONTAINER (priv->stage);
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
- clutter_container_sort_depth_order (stage);
-}
+ /* give back key focus to the stage */
+ clutter_stage_set_key_focus (CLUTTER_STAGE (priv->stage), NULL);
-static void
-clutter_container_iface_init (ClutterContainerIface *iface)
-{
- iface->add = gtk_clutter_embed_add;
- iface->remove = gtk_clutter_embed_remove;
- iface->foreach = gtk_clutter_embed_foreach;
- iface->raise = gtk_clutter_embed_raise;
- iface->lower = gtk_clutter_embed_lower;
- iface->sort_depth_order = gtk_clutter_embed_sort_depth_order;
+ return FALSE;
}
static void
widget_class->button_release_event = gtk_clutter_embed_button_event;
widget_class->key_press_event = gtk_clutter_embed_key_event;
widget_class->key_release_event = gtk_clutter_embed_key_event;
+ widget_class->motion_notify_event = gtk_clutter_embed_motion_notify_event;
widget_class->expose_event = gtk_clutter_embed_expose_event;
widget_class->map_event = gtk_clutter_embed_map_event;
+ widget_class->focus_out_event = gtk_clutter_embed_focus_out;
}
static void
gtk_clutter_embed_init (GtkClutterEmbed *embed)
{
GtkClutterEmbedPrivate *priv;
-#ifdef HAVE_CLUTTER_GTK_X11
- const XVisualInfo *xvinfo;
- GdkVisual *visual;
- GdkColormap *colormap;
-#endif
embed->priv = priv = GTK_CLUTTER_EMBED_GET_PRIVATE (embed);
+ GTK_WIDGET_SET_FLAGS (embed, GTK_CAN_FOCUS);
+
+ /* disable double-buffering: it's automatically provided
+ * by OpenGL
+ */
gtk_widget_set_double_buffered (GTK_WIDGET (embed), FALSE);
- /* note we never ref or unref this */
- priv->stage = clutter_stage_new ();
/* we always create new stages rather than use the default */
- /* priv->stage = clutter_stage_get_default (); */
+ priv->stage = clutter_stage_new ();
+
+ /* we must realize the stage to get it ready for embedding */
+ clutter_actor_realize (priv->stage);
#ifdef HAVE_CLUTTER_GTK_X11
- /* We need to use the colormap from the Clutter visual */
- xvinfo = clutter_x11_get_stage_visual (CLUTTER_STAGE (priv->stage));
- visual = gdk_x11_screen_lookup_visual (gdk_screen_get_default (),
- xvinfo->visualid);
- colormap = gdk_colormap_new (visual, FALSE);
- gtk_widget_set_colormap (GTK_WIDGET (embed), colormap);
+ {
+ const XVisualInfo *xvinfo;
+ GdkVisual *visual;
+ GdkColormap *colormap;
+
+ /* We need to use the colormap from the Clutter visual */
+ xvinfo = clutter_x11_get_stage_visual (CLUTTER_STAGE (priv->stage));
+ visual = gdk_x11_screen_lookup_visual (gdk_screen_get_default (),
+ xvinfo->visualid);
+ colormap = gdk_colormap_new (visual, FALSE);
+ gtk_widget_set_colormap (GTK_WIDGET (embed), colormap);
+ }
#endif
}
/**
* gtk_clutter_init:
+ * @argc: pointer to the arguments count, or %NULL
+ * @argv: pointer to the arguments vector, or %NULL
*
* This function should be called instead of clutter_init() and
* gtk_init().
* Since: 0.8
*/
ClutterInitError
-gtk_clutter_init (int *argc, char ***argv)
+gtk_clutter_init (int *argc,
+ char ***argv)
{
if (!gtk_init_check (argc, argv))
return CLUTTER_INIT_ERROR_GTK;