changeset 98164:2f659932a2fb

(select-frame-set-input-focus): With focus follows mouse move mouse cursor to right window.
author Martin Rudalics <rudalics@gmx.at>
date Sat, 13 Sep 2008 08:28:04 +0000
parents c031cb389639
children 8b39b6502384
files lisp/frame.el
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/frame.el	Fri Sep 12 16:59:57 2008 +0000
+++ b/lisp/frame.el	Sat Sep 13 08:28:04 2008 +0000
@@ -842,13 +842,23 @@
 
 (defun select-frame-set-input-focus (frame)
   "Select FRAME, raise it, and set input focus, if possible."
-    (select-frame frame)
-    (raise-frame frame)
-    ;; Ensure, if possible, that frame gets input focus.
-    (when (memq (window-system frame) '(x w32 ns))
-      (x-focus-frame frame))
-    (when focus-follows-mouse
-      (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
+  (select-frame frame)
+  (raise-frame frame)
+  ;; Ensure, if possible, that frame gets input focus.
+  (when (memq (window-system frame) '(x w32 ns))
+    (x-focus-frame frame))
+  (when focus-follows-mouse
+    ;; When the mouse cursor is not in FRAME's selected window move it
+    ;; there to avoid that some other window gets selected when focus
+    ;; follows mouse.
+    (condition-case nil
+	(let ((window (frame-selected-window frame))
+	      (coordinates (cdr-safe (mouse-position))))
+	  (unless (and (car-safe coordinates)
+		       (coordinates-in-window-p coordinates window))
+	    (let ((edges (window-inside-edges (frame-selected-window frame))))
+	      (set-mouse-position frame (nth 2 edges) (nth 1 edges)))))
+      (error nil))))
 
 (defun other-frame (arg)
   "Select the ARGth different visible frame on current display, and raise it.