diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c
index d6f7d86..7a4da67 100644
--- a/gdk/quartz/gdkevents-quartz.c
+++ b/gdk/quartz/gdkevents-quartz.c
@@ -605,14 +605,25 @@ find_toplevel_for_mouse_event (NSEvent    *nsevent,
           GdkWindow *grab_toplevel;
           NSWindow *grab_nswindow;
 
-          grab_toplevel = gdk_window_get_effective_toplevel (grab->window);
 
+          grab_toplevel = gdk_window_get_effective_toplevel (grab->window ? grab->window : grab->native_window);
+	  if (!grab_toplevel)
+	      return NULL;
           grab_nswindow = ((GdkWindowImplQuartz *)grab_toplevel->impl)->toplevel;
           point = [grab_nswindow convertScreenToBase:screen_point];
 
           /* Note: x_root and y_root are already right. */
           *x = point.x;
           *y = grab_toplevel->height - point.y;
+	  /* If we're on Lion and within 5 pixels of an edge, then
+	   * assume that the user wants to resize, and return NULL to
+	   * let Quartz get on with it. We check the selector
+	   * isRestorable to see if we're on 10.7.
+	   */
+	  if (([grab_nswindow respondsToSelector:@selector(isRestorable)]) &&
+	      ( *x < 5 || *x > grab_toplevel->width - 5 ||
+		*y > grab_toplevel->height - 5))
+	      return NULL;
 
           return grab_toplevel;
         }
@@ -653,15 +664,15 @@ find_toplevel_for_mouse_event (NSEvent    *nsevent,
             {
               NSRect frame;
 
-              /* If the resize indicator is visible and the event
-               * is in the lower right 15x15 corner, we leave these
+              /* If the resize indicator is visible and the event is
+               * in the lower right 15x15 corner, we leave these
                * events to Cocoa as to be handled as resize events.
                * Applications may have widgets in this area.  These
-               * will most likely be larger than 15x15 and for
-               * scroll bars there are also other means to move
-               * the scroll bar.  Since the resize indicator is
-               * the only way of resizing windows on Mac OS, it
-               * is too important to not make functional.
+               * will most likely be larger than 15x15 and for scroll
+               * bars there are also other means to move the scroll
+               * bar.  Since the resize indicator is the only way of
+               * resizing windows on Mac OS before 10.7, it is too
+               * important to not make functional.
                */
               frame = [toplevel_impl->view bounds];
               if (x_tmp > frame.size.width - GRIP_WIDTH
