Index: workspace.c
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.c,v
retrieving revision 1.52
diff -u -r1.52 workspace.c
--- workspace.c	17 Dec 2003 16:01:00 -0000	1.52
+++ workspace.c	14 Jan 2004 16:37:25 -0000
@@ -21,6 +21,7 @@
 
 #include <config.h>
 #include "workspace.h"
+#include "frame.h"
 #include "errors.h"
 #include "prefs.h"
 #include <X11/Xatom.h>
@@ -770,7 +771,30 @@
 
   while (tmp)
     {
-      if (((MetaWindow*) tmp->data) != not_this_one)
+      MetaWindow * tmpwindow = (MetaWindow*) tmp->data;
+      int x, y, root_x, root_y;
+      Window root, child;
+      unsigned int mask;
+      gboolean same_screen;
+
+      meta_error_trap_push (tmpwindow->display);
+      same_screen = XQueryPointer (tmpwindow->display->xdisplay,
+				   tmpwindow->xwindow,
+				   &root, &child,
+				   &root_x, &root_y, &x, &y, &mask);
+      meta_error_trap_pop (tmpwindow->display, TRUE);
+
+      gboolean mouse_in_window = (
+	 (tmpwindow->frame == NULL &&
+          POINT_IN_RECT (root_x, root_y, tmpwindow->rect))
+        ||
+         (tmpwindow->frame &&
+          POINT_IN_RECT(root_x, root_y, tmpwindow->frame->rect))
+        );
+      gboolean we_dont_care =
+        meta_prefs_get_focus_mode() == META_FOCUS_MODE_CLICK;
+
+      if ((tmpwindow != not_this_one) && (mouse_in_window || we_dont_care))
         {
           window = tmp->data;
 	  break;
@@ -779,6 +803,21 @@
       tmp = tmp->next;
     }
 
+  if ((!window) && (meta_prefs_get_focus_mode() == META_FOCUS_MODE_SLOPPY))
+    {
+      tmp = workspace->mru_list;  
+      while (tmp)
+        {
+          if (((MetaWindow*) tmp->data) != not_this_one)
+            {
+  	      window = tmp->data;
+  	      break;
+  	    }
+
+  	  tmp = tmp->next;
+	}
+    }
+
   if (window)
     {
       meta_topic (META_DEBUG_FOCUS,
@@ -793,8 +832,16 @@
     }
   else
     {
-      meta_topic (META_DEBUG_FOCUS, "No MRU window to focus found\n");
-      meta_workspace_focus_top_window (workspace, not_this_one);
+      if (meta_prefs_get_focus_mode () != META_FOCUS_MODE_MOUSE)
+        {
+          /* Is this a workaround to a bug where a window that should
+             appear in the MRU list but doesn't?  If this isn't just
+             an ugly workaround to such a bug, in what circumstances
+             is this used?  Could someone please document this?
+             Thanks.  */
+          meta_topic (META_DEBUG_FOCUS, "No MRU window to focus found\n");
+          meta_workspace_focus_top_window (workspace, not_this_one);
+        }
     }
 }
 
