From 5140c532b13fbe892eb1f400a2cc5ef7653325fb Mon Sep 17 00:00:00 2001
From: Tommi Komulainen <tommi.komulainen@iki.fi>
Date: Sat, 14 Jun 2008 20:37:46 +0100
Subject: [PATCH] OSX: don't depend on ClutterGLWindow

Since events are delivered to ClutterGLView, pass the associated
ClutterStage to event translation. Avoids relying on being embedded in
ClutterGLWindow, which allows for easier integration with gtk.
---
 clutter/clutter/osx/clutter-event-osx.c |   18 ++++--------------
 clutter/clutter/osx/clutter-osx.h       |    2 +-
 clutter/clutter/osx/clutter-stage-osx.c |    2 +-
 3 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/clutter/clutter/osx/clutter-event-osx.c b/clutter/clutter/osx/clutter-event-osx.c
index a622cc4..8a12817 100644
--- a/clutter/clutter/osx/clutter-event-osx.c
+++ b/clutter/clutter/osx/clutter-event-osx.c
@@ -38,7 +38,6 @@ static GPollFunc old_poll_func = NULL;
 
 /*************************************************************************/
 @interface NSEvent (Clutter)
-- (ClutterStage*)clutterStage;
 - (gint)clutterTime;
 - (gint)clutterButton;
 - (void)clutterX:(gint*)ptrX y:(gint*)ptrY;
@@ -47,16 +46,6 @@ static GPollFunc old_poll_func = NULL;
 @end
 
 @implementation NSEvent (Clutter)
-- (ClutterStage*)clutterStage
-{
-  ClutterGLWindow *w = (ClutterGLWindow*)[self window];
-  if (![w isKindOfClass:[ClutterGLWindow class]])
-    return NULL;
-
-  ClutterStageOSX *stage_osx = w->stage_osx;
-  return stage_osx->wrapper;
-}
-
 - (gint)clutterTime
 {
   return [self timestamp] * 1000;
@@ -172,7 +161,6 @@ static GPollFunc old_poll_func = NULL;
 static gboolean
 clutter_event_osx_translate (NSEvent *nsevent, ClutterEvent *event)
 {
-  event->any.stage = [nsevent clutterStage];
   event->any.time = [nsevent clutterTime];
 
   switch ([nsevent type])
@@ -243,10 +231,12 @@ clutter_event_osx_translate (NSEvent *nsevent, ClutterEvent *event)
 }
 
 void
-_clutter_event_osx_put (NSEvent *nsevent)
+_clutter_event_osx_put (NSEvent *nsevent, ClutterStage *wrapper)
 {
   ClutterEvent event = { 0, };
-   
+
+  event.any.stage = wrapper;
+
   if (clutter_event_osx_translate (nsevent, &event))
     {
       g_assert (event.type != CLUTTER_NOTHING);
diff --git a/clutter/clutter/osx/clutter-osx.h b/clutter/clutter/osx/clutter-osx.h
index d727138..3c4fc9c 100644
--- a/clutter/clutter/osx/clutter-osx.h
+++ b/clutter/clutter/osx/clutter-osx.h
@@ -34,7 +34,7 @@ G_BEGIN_DECLS
 void _clutter_events_osx_init   (void);
 void _clutter_events_osx_uninit (void);
 
-void _clutter_event_osx_put     (NSEvent *nsevent);
+void _clutter_event_osx_put     (NSEvent *nsevent, ClutterStage *wrapper);
 
 G_END_DECLS
 
diff --git a/clutter/clutter/osx/clutter-stage-osx.c b/clutter/clutter/osx/clutter-stage-osx.c
index a118c17..cb60b36 100644
--- a/clutter/clutter/osx/clutter-stage-osx.c
+++ b/clutter/clutter/osx/clutter-stage-osx.c
@@ -159,7 +159,7 @@ clutter_stage_osx_state_update (ClutterStageOSX   *self,
 /* Simply forward all events that reach our view to clutter. */
 
 #define EVENT_HANDLER(event) -(void)event:(NSEvent *)theEvent { \
-  _clutter_event_osx_put (theEvent);                            \
+  _clutter_event_osx_put (theEvent, self->stage_osx->wrapper);  \
 }
 EVENT_HANDLER(mouseDown)
 EVENT_HANDLER(mouseDragged)
-- 
1.5.5.3

