unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
@ 2006-09-03 15:17 Richard Stallman
  2006-09-03 16:02 ` David Kastrup
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Richard Stallman @ 2006-09-03 15:17 UTC (permalink / raw)


Would people please comment on this bug fix?

------- Start of forwarded message -------
Date: Mon, 28 Aug 2006 07:57:29 +0200
From: martin rudalics <rudalics@gmx.at>
MIME-Version: 1.0
To:  rms@gnu.org
CC: "Marshall, Simon" <simon.marshall@misys.com>,  emacs-devel@gnu.org
Subject: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a	de
 lay]
In-Reply-To: <E1G2plT-00018h-Cu@fencepost.gnu.org>
Content-Type: multipart/mixed;
 boundary="------------060704020205070207060105"
X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=failed 
	version=3.0.4

This is a multi-part message in MIME format.
- --------------060704020205070207060105
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Attached find ChangeLog entries and patch for this.

- --------------060704020205070207060105
Content-Type: text/plain;
 name="autoselect-window.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="autoselect-window.patch"

2006-08-27  Martin Rudalics  <rudalics@gmx.at>

	* xdisp.c (mouse_autoselect_window): Removed.
	(Vmouse_autoselect_window): New variable.  DEFVAR_LISP it.
	* dispextern.h (mouse_autoselect_window): Remove extern.
	(Vmouse_autoselect_window): Add extern.
	* macterm.c (XTread_socket): Test Vmouse_autoselect_window
	instead of mouse_autoselect_window.
	* msdos.c (dos_rawgetc): Likewise.
	* w32term.c (w32_read_socket): Likewise.
	* xterm.c (handle_one_xevent): Likewise.

2006-08-27  Martin Rudalics  <rudalics@gmx.at>

	* window.el (mouse-autoselect-window-timer)
	(mouse-autoselect-window-position)
	(mouse-autoselect-window-window)
	(mouse-autoselect-window-now): New variables for delayed
	window autoselection.
	(mouse-autoselect-window-cancel)
	(mouse-autoselect-window-select)
	(mouse-autoselect-window-start): New functions for delayed
	window autoselection: Wait to autoselect a new window so that
	just moving over a window doesn't inadvertently select it.
	(handle-select-window): Call `mouse-autoselect-window-start'
	when delayed window autoselection is enabled.
	* cus-start.el (mouse-autoselect-window): Change
	customization options to handle delayed window autoselection.	
	* emacs-lisp/eldoc.el: Use `eldoc-add-command-completions' to
      	add `handle-select-window' to the set of commands after which
	it is allowed to print in the echo area.


*** dispextern.h	Tue Aug 15 10:01:00 2006
- --- dispextern.h	Sun Aug 27 19:09:48 2006
***************
*** 2690,2696 ****
  extern int help_echo_pos;
  extern struct frame *last_mouse_frame;
  extern int last_tool_bar_item;
! extern int mouse_autoselect_window;
  extern int unibyte_display_via_language_environment;

  extern void reseat_at_previous_visible_line_start P_ ((struct it *));
- --- 2690,2696 ----
  extern int help_echo_pos;
  extern struct frame *last_mouse_frame;
  extern int last_tool_bar_item;
! extern Lisp_Object Vmouse_autoselect_window;
  extern int unibyte_display_via_language_environment;

  extern void reseat_at_previous_visible_line_start P_ ((struct it *));

*** macterm.c	Tue Aug 15 10:01:02 2006
- --- macterm.c	Sun Aug 27 19:11:18 2006
***************
*** 10564,10570 ****
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (mouse_autoselect_window)
  			{
  			  Lisp_Object window;

- --- 10564,10570 ----
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (!NILP (Vmouse_autoselect_window))
  			{
  			  Lisp_Object window;


*** msdos.c	Tue Aug 15 10:01:02 2006
- --- msdos.c	Sun Aug 27 19:12:00 2006
***************
*** 3381,3387 ****
  	    }

  	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 	  if (mouse_autoselect_window)
  	    {
  	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
  						      mouse_last_x,
- --- 3381,3387 ----
  	    }

  	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 	  if (!NILP (Vmouse_autoselect_window))
  	    {
  	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
  						      mouse_last_x,

*** w32term.c	Tue Aug 15 10:01:02 2006
- --- w32term.c	Sun Aug 27 19:12:36 2006
***************
*** 4286,4292 ****
  	  if (f)
  	    {
  	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 	      if (mouse_autoselect_window)
  		{
  		  Lisp_Object window;
  		  int x = LOWORD (msg.msg.lParam);
- --- 4286,4292 ----
  	  if (f)
  	    {
  	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 	      if (!NILP (Vmouse_autoselect_window))
  		{
  		  Lisp_Object window;
  		  int x = LOWORD (msg.msg.lParam);

*** xdisp.c	Tue Aug 15 10:01:02 2006
- --- xdisp.c	Sun Aug 27 19:15:12 2006
***************
*** 258,264 ****

  /* Non-zero means automatically select any window when the mouse
     cursor moves into it.  */
! int mouse_autoselect_window;

  /* Non-zero means draw tool bar buttons raised when the mouse moves
     over them.  */
- --- 258,264 ----

  /* Non-zero means automatically select any window when the mouse
     cursor moves into it.  */
! Lisp_Object Vmouse_autoselect_window;

  /* Non-zero means draw tool bar buttons raised when the mouse moves
     over them.  */
***************
*** 23962,23970 ****
  See `set-window-redisplay-end-trigger'.  */);
    Vredisplay_end_trigger_functions = Qnil;

!   DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window,
!     doc: /* *Non-nil means autoselect window with mouse pointer.  */);
!   mouse_autoselect_window = 0;

    DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
      doc: /* *Non-nil means automatically resize tool-bars.
- --- 23962,23982 ----
  See `set-window-redisplay-end-trigger'.  */);
    Vredisplay_end_trigger_functions = Qnil;

!   DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window,
!      doc: /* *Non-nil means autoselect window with mouse pointer.
! If nil, do not autoselect windows.  A positive number means delay
! autoselection by that many seconds: A window is selected iff Emacs
! can establish that the mouse has remained within that window for the
! time indicated by the delay.  A negative number has a similar effect
! but actually selects the window only after the mouse stopped moving.
! \(Since Emacs compares mouse positions for this purpose, you will
! occasionally wait twice that time before the window gets selected.\)
! Any other value means autoselect window instantaneously when the
! mouse pointer enters it.
! 
! Autoselection does not unselect the minibuffer and selects the
! minibuffer iff it is active.  */);
!   Vmouse_autoselect_window = Qnil;

    DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
      doc: /* *Non-nil means automatically resize tool-bars.

*** xterm.c	Tue Aug 15 10:01:02 2006
- --- xterm.c	Sun Aug 27 19:15:32 2006
***************
*** 6575,6581 ****
            {

              /* Generate SELECT_WINDOW_EVENTs when needed.  */
!             if (mouse_autoselect_window)
                {
                  Lisp_Object window;

- --- 6575,6581 ----
            {

              /* Generate SELECT_WINDOW_EVENTs when needed.  */
!             if (!NILP (Vmouse_autoselect_window))
                {
                  Lisp_Object window;


*** cus-start.el	Tue Aug 15 10:00:50 2006
- --- cus-start.el	Sun Aug 27 19:18:32 2006
***************
*** 360,365 ****
- --- 360,372 ----
  					    (other :tag "Unlimited" t)))
  	     (unibyte-display-via-language-environment mule boolean)
  	     (blink-cursor-alist cursor alist "22.1")
+              (mouse-autoselect-window
+ 	      display
+ 	      (choice
+ 	       (const :tag "Off (nil)" :value nil)
+ 	       (const :tag "Immediate" :value t)
+ 	       (number :tag "Delay by secs" :value 0.5))
+ 	      "22.1")
  	     ;; xfaces.c
  	     (scalable-fonts-allowed display boolean)
  	     ;; xfns.c
***************
*** 369,375 ****
  	     (x-gtk-show-hidden-files menu boolean "22.1")
  	     (x-gtk-whole-detached-tool-bar x boolean "22.1")
  	     ;; xterm.c
- -              (mouse-autoselect-window display boolean "21.3")
  	     (x-use-underline-position-properties display boolean "21.3")
  	     (x-stretch-cursor display boolean "21.1")))
        this symbol group type standard version native-p
- --- 376,381 ----

*** window.el	Tue Aug 15 10:00:52 2006
- --- window.el	Sun Aug 27 19:21:02 2006
***************
*** 777,797 ****
      ;; Maybe get rid of the window.
      (and window (not window-handled) (not window-solitary)
  	 (delete-window window))))

  (defun handle-select-window (event)
    "Handle select-window events."
    (interactive "e")
    (let ((window (posn-window (event-start event))))
!     (if (and (window-live-p window)
! 	     ;; Don't switch if we're currently in the minibuffer.
! 	     ;; This tries to work around problems where the minibuffer gets
! 	     ;; unselected unexpectedly, and where you then have to move
! 	     ;; your mouse all the way down to the minibuffer to select it.
! 	     (not (window-minibuffer-p (selected-window)))
! 	     ;; Don't switch to a minibuffer window unless it's active.
! 	     (or (not (window-minibuffer-p window))
! 		 (minibuffer-window-active-p window)))
! 	(select-window window))))

  (define-key ctl-x-map "2" 'split-window-vertically)
  (define-key ctl-x-map "3" 'split-window-horizontally)
- --- 777,910 ----
      ;; Maybe get rid of the window.
      (and window (not window-handled) (not window-solitary)
  	 (delete-window window))))
+ \f
+ (defvar mouse-autoselect-window-timer nil
+   "Timer used by delayed window autoselection.")
+ 
+ (defvar mouse-autoselect-window-position nil
+   "Last mouse position recorded by delayed window autoselection.")
+ 
+ (defvar mouse-autoselect-window-window nil
+   "Last window recorded by delayed window autoselection.")
+ 
+ (defvar mouse-autoselect-window-now nil
+   "When non-nil don't delay autoselection in `handle-select-window'.")
+ 
+ (defun mouse-autoselect-window-cancel (&optional force)
+   "Cancel delayed window autoselection.
+ Optional argument FORCE means cancel unconditionally."
+   (unless (and (not force)
+ 	       ;; Don't cancel while the user drags a scroll bar.
+ 	       (eq this-command 'scroll-bar-toolkit-scroll)
+ 	       (memq (nth 4 (event-end last-input-event))
+ 		     '(handle end-scroll)))
+     (setq mouse-autoselect-window-now nil)
+     (when (timerp mouse-autoselect-window-timer)
+       (cancel-timer mouse-autoselect-window-timer))
+     (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
+ 
+ (defun mouse-autoselect-window-start (window)
+   "Start delayed window autoselection.
+ Called when Emacs detects that the mouse has moved to the non-selected
+ window WINDOW and the variable `mouse-autoselect-window' has a numeric,
+ non-zero value.  The return value is non-nil iff delayed autoselection
+ started successfully.  Delayed window autoselection is canceled when the
+ mouse position has stabilized or a command is executed."
+   ;; Cancel any active window autoselection.
+   (mouse-autoselect-window-cancel t)
+   ;; Record current mouse position in `mouse-autoselect-window-position' and
+   ;; WINDOW in `mouse-autoselect-window-window'.
+   (setq mouse-autoselect-window-position (mouse-position))
+   (setq mouse-autoselect-window-window window)
+   ;; Install timer which runs `mouse-autoselect-window-select' every
+   ;; `mouse-autoselect-window' seconds.
+   (setq mouse-autoselect-window-timer
+ 	(run-at-time
+ 	 (abs mouse-autoselect-window) (abs mouse-autoselect-window)
+ 	 'mouse-autoselect-window-select))
+   ;; Executing a command cancels window autoselection.
+   (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
+ 
+ (defun mouse-autoselect-window-select ()
+   "Select window with delayed window autoselection.
+ If the mouse position has stabilized in a non-selected window, select
+ that window.  The minibuffer window is selected iff the minibuffer is
+ active.  This function is run by `mouse-autoselect-window-timer'."
+   (condition-case nil
+       (let* ((mouse-position (mouse-position))
+ 	     (window (window-at (cadr mouse-position) (cddr mouse-position)
+ 				(car mouse-position))))
+ 	(cond
+ 	 ((and window (not (eq window (selected-window)))
+ 	       (or (not (numberp mouse-autoselect-window))
+ 		   (and (> mouse-autoselect-window 0)
+ 			;; If `mouse-autoselect-window' is positive, select
+ 			;; window if the window is the same as before.
+ 			(eq window mouse-autoselect-window-window))
+ 		   ;; Otherwise select window iff the mouse is at the same
+ 		   ;; position as before.  Observe that the first test after
+ 		   ;; `mouse-autoselect-window-start' usually fails since the
+ 		   ;; value of `mouse-autoselect-window-position' recorded there
+ 		   ;; is the position where the mouse has entered the new window
+ 		   ;; and not necessarily where the mouse has stopped moving.
+ 		   (equal mouse-position mouse-autoselect-window-position))
+ 	       ;; The minibuffer is a candidate window iff it's active.
+ 	       (or (not (window-minibuffer-p window))
+ 		   (eq window (active-minibuffer-window))))
+ 	  ;; Mouse position has stabilized in non-selected window: Cancel window
+ 	  ;; autoselection and try to select that window.
+ 	  (mouse-autoselect-window-cancel t)
+ 	  ;; Select window where mouse appears unless the selected window is the
+ 	  ;; minibuffer.  Use `unread-command-events' in order to execute pre-
+ 	  ;; and post-command hooks and trigger idle timers.  To avoid delaying
+ 	  ;; autoselection again, temporarily set `mouse-autoselect-window-now'
+ 	  ;; to t.
+ 	  (unless (window-minibuffer-p (selected-window))
+ 	    (setq mouse-autoselect-window-now t)
+ 	    (setq unread-command-events
+ 		  (cons (list 'select-window (list window))
+ 			unread-command-events))))
+ 	 ((or (and window (eq window (selected-window)))
+ 	      (not (numberp mouse-autoselect-window))
+ 	      (equal mouse-position mouse-autoselect-window-position))
+ 	  ;; Mouse position has either stabilized in the selected window or at
+ 	  ;; `mouse-autoselect-window-position': Cancel window autoselection.
+ 	  (mouse-autoselect-window-cancel t))
+ 	 (t
+ 	  ;; Mouse position has not stabilized yet, record new mouse position in
+ 	  ;; `mouse-autoselect-window-position' and any window at that position
+ 	  ;; in `mouse-autoselect-window-window'.
+ 	  (setq mouse-autoselect-window-position mouse-position)
+ 	  (setq mouse-autoselect-window-window window))))
+     (error nil)))

  (defun handle-select-window (event)
    "Handle select-window events."
    (interactive "e")
    (let ((window (posn-window (event-start event))))
!     (when (and (window-live-p window)
! 	       ;; Don't switch if we're currently in the minibuffer.
! 	       ;; This tries to work around problems where the minibuffer gets
! 	       ;; unselected unexpectedly, and where you then have to move
! 	       ;; your mouse all the way down to the minibuffer to select it.
! 	       (not (window-minibuffer-p (selected-window)))
! 	       ;; Don't switch to a minibuffer window unless it's active.
! 	       (or (not (window-minibuffer-p window))
! 		   (minibuffer-window-active-p window)))
!       (unless (and (numberp mouse-autoselect-window)
! 		   (not (zerop mouse-autoselect-window))
! 		   (not mouse-autoselect-window-now)
! 		   ;; When `mouse-autoselect-window' has a numeric, non-zero
! 		   ;; value, delay window autoselection by that value.
! 		   ;; `mouse-autoselect-window-start' returns non-nil iff it
! 		   ;; successfully installed a timer for this purpose.
! 		   (mouse-autoselect-window-start window))
! 	;; Re-enable delayed window autoselection.
! 	(setq mouse-autoselect-window-now nil)
! 	(when mouse-autoselect-window
! 	  ;; Run `mouse-leave-buffer-hook' when autoselecting window.
! 	  (run-hooks 'mouse-leave-buffer-hook))
! 	(select-window window)))))

  (define-key ctl-x-map "2" 'split-window-vertically)
  (define-key ctl-x-map "3" 'split-window-horizontally)

*** emacs-lisp/eldoc.el	Tue Apr 11 16:23:56 2006
- --- emacs-lisp/eldoc.el	Sun Aug 27 19:19:06 2006
***************
*** 432,438 ****
  ;; Prime the command list.
  (eldoc-add-command-completions
   "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
!  "delete-window"
   "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
   "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
   "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
- --- 432,438 ----
  ;; Prime the command list.
  (eldoc-add-command-completions
   "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
!  "delete-window" "handle-select-window"
   "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
   "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
   "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"


- --------------060704020205070207060105--
------- End of forwarded message -------

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 15:17 [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]] Richard Stallman
@ 2006-09-03 16:02 ` David Kastrup
  2006-09-03 16:37   ` David Kastrup
  2006-09-04  9:16   ` martin rudalics
  2006-09-03 17:05 ` Chong Yidong
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 17+ messages in thread
From: David Kastrup @ 2006-09-03 16:02 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> Would people please comment on this bug fix?
>
> From: martin rudalics <rudalics@gmx.at>
> Subject: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a	de
>  lay]

I think a delay is the wrong thing to do here since it makes stuff
unpredictable.  The right fix, in my opinion, would be lazy focus
change: only when a keyboard or mouse event occurs in the new window,
is the focus changed.  That has the disadvantage that the user may be
surprised by the change since the old window appears to have focus
before typing a key.

In order to mitigate the surprise, it might be reasonable to visibly
unfocus the old window (by the different highlighting of the mode line
and the different cursor type), but not refocus a different window
before an event occurs.

A more radical approach would be to move toolbar and menubar just
above the currently selected window.  This would also require less
mouse movement, but would likely earn us an award for the most weird
user interface look ever.

I don't think it is reasonable to expect to sort this out before the
release.  I think that there are several viable possibilities, and
we'd need the feedback of testers trying each of those out for several
weeks before it would be viable to decide on a sensible strategy.

I don't think that the delay stuff is a good strategy: it brakes and
confuses the user when he indeed wants to change focus, and it causes
hectic when he doesn't.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 16:02 ` David Kastrup
@ 2006-09-03 16:37   ` David Kastrup
  2006-09-04  9:16   ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: David Kastrup @ 2006-09-03 16:37 UTC (permalink / raw)
  Cc: emacs-devel

David Kastrup <dak@gnu.org> writes:

> Richard Stallman <rms@gnu.org> writes:
>
>> Would people please comment on this bug fix?
>>
>> From: martin rudalics <rudalics@gmx.at> Subject: Re:
>> [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
>
> I think a delay is the wrong thing to do here since it makes stuff
> unpredictable.  The right fix, in my opinion, would be lazy focus
> change: only when a keyboard or mouse event occurs in the new
> window, is the focus changed.  That has the disadvantage that the
> user may be surprised by the change since the old window appears to
> have focus before typing a key.
>
> In order to mitigate the surprise, it might be reasonable to visibly
> unfocus the old window (by the different highlighting of the mode
> line and the different cursor type), but not refocus a different
> window before an event occurs.

A different possibility would be to change focus visibly, but when the
mouse pointer moves out of the window and, for example, onto toolbar
or menu bar, refocus back to the original window if no intervening
event occured.

This would imply that you could not change focus only by moving the
mouse if the first action in the new window was using the toolbar or
menu bar.  It would also mean quite more flicker than the "just
unfocus" variant.

Anyway:

> I don't think it is reasonable to expect to sort this out before the
> release.  I think that there are several viable possibilities, and
> we'd need the feedback of testers trying each of those out for several
> weeks before it would be viable to decide on a sensible strategy.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 15:17 [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]] Richard Stallman
  2006-09-03 16:02 ` David Kastrup
@ 2006-09-03 17:05 ` Chong Yidong
  2006-09-04  9:27   ` martin rudalics
  2006-09-03 21:43 ` Kim F. Storm
  2006-09-05 15:20 ` Stefan Monnier
  3 siblings, 1 reply; 17+ messages in thread
From: Chong Yidong @ 2006-09-03 17:05 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> Would people please comment on this bug fix?

I think it is a feature, not a bug.

> From: martin rudalics <rudalics@gmx.at>
> Subject: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a	de lay]
> To:  rms@gnu.org
> CC: "Marshall, Simon" <simon.marshall@misys.com>,  emacs-devel@gnu.org
>
> This is a multi-part message in MIME format.
> - --------------060704020205070207060105
> Content-Type: text/plain; charset=ISO-8859-15; format=flowed
> Content-Transfer-Encoding: 7bit
>
> Attached find ChangeLog entries and patch for this.
>
> - --------------060704020205070207060105
> Content-Type: text/plain;
>  name="autoselect-window.patch"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline;
>  filename="autoselect-window.patch"
>
> 2006-08-27  Martin Rudalics  <rudalics@gmx.at>
>
> 	* xdisp.c (mouse_autoselect_window): Removed.
> 	(Vmouse_autoselect_window): New variable.  DEFVAR_LISP it.
> 	* dispextern.h (mouse_autoselect_window): Remove extern.
> 	(Vmouse_autoselect_window): Add extern.
> 	* macterm.c (XTread_socket): Test Vmouse_autoselect_window
> 	instead of mouse_autoselect_window.
> 	* msdos.c (dos_rawgetc): Likewise.
> 	* w32term.c (w32_read_socket): Likewise.
> 	* xterm.c (handle_one_xevent): Likewise.
>
> 2006-08-27  Martin Rudalics  <rudalics@gmx.at>
>
> 	* window.el (mouse-autoselect-window-timer)
> 	(mouse-autoselect-window-position)
> 	(mouse-autoselect-window-window)
> 	(mouse-autoselect-window-now): New variables for delayed
> 	window autoselection.
> 	(mouse-autoselect-window-cancel)
> 	(mouse-autoselect-window-select)
> 	(mouse-autoselect-window-start): New functions for delayed
> 	window autoselection: Wait to autoselect a new window so that
> 	just moving over a window doesn't inadvertently select it.
> 	(handle-select-window): Call `mouse-autoselect-window-start'
> 	when delayed window autoselection is enabled.
> 	* cus-start.el (mouse-autoselect-window): Change
> 	customization options to handle delayed window autoselection.	
> 	* emacs-lisp/eldoc.el: Use `eldoc-add-command-completions' to
>       	add `handle-select-window' to the set of commands after which
> 	it is allowed to print in the echo area.
>
>
> *** dispextern.h	Tue Aug 15 10:01:00 2006
> - --- dispextern.h	Sun Aug 27 19:09:48 2006
> ***************
> *** 2690,2696 ****
>   extern int help_echo_pos;
>   extern struct frame *last_mouse_frame;
>   extern int last_tool_bar_item;
> ! extern int mouse_autoselect_window;
>   extern int unibyte_display_via_language_environment;
>
>   extern void reseat_at_previous_visible_line_start P_ ((struct it *));
> - --- 2690,2696 ----
>   extern int help_echo_pos;
>   extern struct frame *last_mouse_frame;
>   extern int last_tool_bar_item;
> ! extern Lisp_Object Vmouse_autoselect_window;
>   extern int unibyte_display_via_language_environment;
>
>   extern void reseat_at_previous_visible_line_start P_ ((struct it *));
>
> *** macterm.c	Tue Aug 15 10:01:02 2006
> - --- macterm.c	Sun Aug 27 19:11:18 2006
> ***************
> *** 10564,10570 ****
>   		  else
>   		    {
>   		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 		      if (mouse_autoselect_window)
>   			{
>   			  Lisp_Object window;
>
> - --- 10564,10570 ----
>   		  else
>   		    {
>   		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 		      if (!NILP (Vmouse_autoselect_window))
>   			{
>   			  Lisp_Object window;
>
>
> *** msdos.c	Tue Aug 15 10:01:02 2006
> - --- msdos.c	Sun Aug 27 19:12:00 2006
> ***************
> *** 3381,3387 ****
>   	    }
>
>   	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	  if (mouse_autoselect_window)
>   	    {
>   	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
>   						      mouse_last_x,
> - --- 3381,3387 ----
>   	    }
>
>   	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	  if (!NILP (Vmouse_autoselect_window))
>   	    {
>   	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
>   						      mouse_last_x,
>
> *** w32term.c	Tue Aug 15 10:01:02 2006
> - --- w32term.c	Sun Aug 27 19:12:36 2006
> ***************
> *** 4286,4292 ****
>   	  if (f)
>   	    {
>   	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	      if (mouse_autoselect_window)
>   		{
>   		  Lisp_Object window;
>   		  int x = LOWORD (msg.msg.lParam);
> - --- 4286,4292 ----
>   	  if (f)
>   	    {
>   	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	      if (!NILP (Vmouse_autoselect_window))
>   		{
>   		  Lisp_Object window;
>   		  int x = LOWORD (msg.msg.lParam);
>
> *** xdisp.c	Tue Aug 15 10:01:02 2006
> - --- xdisp.c	Sun Aug 27 19:15:12 2006
> ***************
> *** 258,264 ****
>
>   /* Non-zero means automatically select any window when the mouse
>      cursor moves into it.  */
> ! int mouse_autoselect_window;
>
>   /* Non-zero means draw tool bar buttons raised when the mouse moves
>      over them.  */
> - --- 258,264 ----
>
>   /* Non-zero means automatically select any window when the mouse
>      cursor moves into it.  */
> ! Lisp_Object Vmouse_autoselect_window;
>
>   /* Non-zero means draw tool bar buttons raised when the mouse moves
>      over them.  */
> ***************
> *** 23962,23970 ****
>   See `set-window-redisplay-end-trigger'.  */);
>     Vredisplay_end_trigger_functions = Qnil;
>
> !   DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window,
> !     doc: /* *Non-nil means autoselect window with mouse pointer.  */);
> !   mouse_autoselect_window = 0;
>
>     DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
>       doc: /* *Non-nil means automatically resize tool-bars.
> - --- 23962,23982 ----
>   See `set-window-redisplay-end-trigger'.  */);
>     Vredisplay_end_trigger_functions = Qnil;
>
> !   DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window,
> !      doc: /* *Non-nil means autoselect window with mouse pointer.
> ! If nil, do not autoselect windows.  A positive number means delay
> ! autoselection by that many seconds: A window is selected iff Emacs
> ! can establish that the mouse has remained within that window for the
> ! time indicated by the delay.  A negative number has a similar effect
> ! but actually selects the window only after the mouse stopped moving.
> ! \(Since Emacs compares mouse positions for this purpose, you will
> ! occasionally wait twice that time before the window gets selected.\)
> ! Any other value means autoselect window instantaneously when the
> ! mouse pointer enters it.
> ! 
> ! Autoselection does not unselect the minibuffer and selects the
> ! minibuffer iff it is active.  */);
> !   Vmouse_autoselect_window = Qnil;
>
>     DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
>       doc: /* *Non-nil means automatically resize tool-bars.
>
> *** xterm.c	Tue Aug 15 10:01:02 2006
> - --- xterm.c	Sun Aug 27 19:15:32 2006
> ***************
> *** 6575,6581 ****
>             {
>
>               /* Generate SELECT_WINDOW_EVENTs when needed.  */
> !             if (mouse_autoselect_window)
>                 {
>                   Lisp_Object window;
>
> - --- 6575,6581 ----
>             {
>
>               /* Generate SELECT_WINDOW_EVENTs when needed.  */
> !             if (!NILP (Vmouse_autoselect_window))
>                 {
>                   Lisp_Object window;
>
>
> *** cus-start.el	Tue Aug 15 10:00:50 2006
> - --- cus-start.el	Sun Aug 27 19:18:32 2006
> ***************
> *** 360,365 ****
> - --- 360,372 ----
>   					    (other :tag "Unlimited" t)))
>   	     (unibyte-display-via-language-environment mule boolean)
>   	     (blink-cursor-alist cursor alist "22.1")
> +              (mouse-autoselect-window
> + 	      display
> + 	      (choice
> + 	       (const :tag "Off (nil)" :value nil)
> + 	       (const :tag "Immediate" :value t)
> + 	       (number :tag "Delay by secs" :value 0.5))
> + 	      "22.1")
>   	     ;; xfaces.c
>   	     (scalable-fonts-allowed display boolean)
>   	     ;; xfns.c
> ***************
> *** 369,375 ****
>   	     (x-gtk-show-hidden-files menu boolean "22.1")
>   	     (x-gtk-whole-detached-tool-bar x boolean "22.1")
>   	     ;; xterm.c
> - -              (mouse-autoselect-window display boolean "21.3")
>   	     (x-use-underline-position-properties display boolean "21.3")
>   	     (x-stretch-cursor display boolean "21.1")))
>         this symbol group type standard version native-p
> - --- 376,381 ----
>
> *** window.el	Tue Aug 15 10:00:52 2006
> - --- window.el	Sun Aug 27 19:21:02 2006
> ***************
> *** 777,797 ****
>       ;; Maybe get rid of the window.
>       (and window (not window-handled) (not window-solitary)
>   	 (delete-window window))))
>
>   (defun handle-select-window (event)
>     "Handle select-window events."
>     (interactive "e")
>     (let ((window (posn-window (event-start event))))
> !     (if (and (window-live-p window)
> ! 	     ;; Don't switch if we're currently in the minibuffer.
> ! 	     ;; This tries to work around problems where the minibuffer gets
> ! 	     ;; unselected unexpectedly, and where you then have to move
> ! 	     ;; your mouse all the way down to the minibuffer to select it.
> ! 	     (not (window-minibuffer-p (selected-window)))
> ! 	     ;; Don't switch to a minibuffer window unless it's active.
> ! 	     (or (not (window-minibuffer-p window))
> ! 		 (minibuffer-window-active-p window)))
> ! 	(select-window window))))
>
>   (define-key ctl-x-map "2" 'split-window-vertically)
>   (define-key ctl-x-map "3" 'split-window-horizontally)
> - --- 777,910 ----
>       ;; Maybe get rid of the window.
>       (and window (not window-handled) (not window-solitary)
>   	 (delete-window window))))
> + \f
> + (defvar mouse-autoselect-window-timer nil
> +   "Timer used by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-position nil
> +   "Last mouse position recorded by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-window nil
> +   "Last window recorded by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-now nil
> +   "When non-nil don't delay autoselection in `handle-select-window'.")
> + 
> + (defun mouse-autoselect-window-cancel (&optional force)
> +   "Cancel delayed window autoselection.
> + Optional argument FORCE means cancel unconditionally."
> +   (unless (and (not force)
> + 	       ;; Don't cancel while the user drags a scroll bar.
> + 	       (eq this-command 'scroll-bar-toolkit-scroll)
> + 	       (memq (nth 4 (event-end last-input-event))
> + 		     '(handle end-scroll)))
> +     (setq mouse-autoselect-window-now nil)
> +     (when (timerp mouse-autoselect-window-timer)
> +       (cancel-timer mouse-autoselect-window-timer))
> +     (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
> + 
> + (defun mouse-autoselect-window-start (window)
> +   "Start delayed window autoselection.
> + Called when Emacs detects that the mouse has moved to the non-selected
> + window WINDOW and the variable `mouse-autoselect-window' has a numeric,
> + non-zero value.  The return value is non-nil iff delayed autoselection
> + started successfully.  Delayed window autoselection is canceled when the
> + mouse position has stabilized or a command is executed."
> +   ;; Cancel any active window autoselection.
> +   (mouse-autoselect-window-cancel t)
> +   ;; Record current mouse position in `mouse-autoselect-window-position' and
> +   ;; WINDOW in `mouse-autoselect-window-window'.
> +   (setq mouse-autoselect-window-position (mouse-position))
> +   (setq mouse-autoselect-window-window window)
> +   ;; Install timer which runs `mouse-autoselect-window-select' every
> +   ;; `mouse-autoselect-window' seconds.
> +   (setq mouse-autoselect-window-timer
> + 	(run-at-time
> + 	 (abs mouse-autoselect-window) (abs mouse-autoselect-window)
> + 	 'mouse-autoselect-window-select))
> +   ;; Executing a command cancels window autoselection.
> +   (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
> + 
> + (defun mouse-autoselect-window-select ()
> +   "Select window with delayed window autoselection.
> + If the mouse position has stabilized in a non-selected window, select
> + that window.  The minibuffer window is selected iff the minibuffer is
> + active.  This function is run by `mouse-autoselect-window-timer'."
> +   (condition-case nil
> +       (let* ((mouse-position (mouse-position))
> + 	     (window (window-at (cadr mouse-position) (cddr mouse-position)
> + 				(car mouse-position))))
> + 	(cond
> + 	 ((and window (not (eq window (selected-window)))
> + 	       (or (not (numberp mouse-autoselect-window))
> + 		   (and (> mouse-autoselect-window 0)
> + 			;; If `mouse-autoselect-window' is positive, select
> + 			;; window if the window is the same as before.
> + 			(eq window mouse-autoselect-window-window))
> + 		   ;; Otherwise select window iff the mouse is at the same
> + 		   ;; position as before.  Observe that the first test after
> + 		   ;; `mouse-autoselect-window-start' usually fails since the
> + 		   ;; value of `mouse-autoselect-window-position' recorded there
> + 		   ;; is the position where the mouse has entered the new window
> + 		   ;; and not necessarily where the mouse has stopped moving.
> + 		   (equal mouse-position mouse-autoselect-window-position))
> + 	       ;; The minibuffer is a candidate window iff it's active.
> + 	       (or (not (window-minibuffer-p window))
> + 		   (eq window (active-minibuffer-window))))
> + 	  ;; Mouse position has stabilized in non-selected window: Cancel window
> + 	  ;; autoselection and try to select that window.
> + 	  (mouse-autoselect-window-cancel t)
> + 	  ;; Select window where mouse appears unless the selected window is the
> + 	  ;; minibuffer.  Use `unread-command-events' in order to execute pre-
> + 	  ;; and post-command hooks and trigger idle timers.  To avoid delaying
> + 	  ;; autoselection again, temporarily set `mouse-autoselect-window-now'
> + 	  ;; to t.
> + 	  (unless (window-minibuffer-p (selected-window))
> + 	    (setq mouse-autoselect-window-now t)
> + 	    (setq unread-command-events
> + 		  (cons (list 'select-window (list window))
> + 			unread-command-events))))
> + 	 ((or (and window (eq window (selected-window)))
> + 	      (not (numberp mouse-autoselect-window))
> + 	      (equal mouse-position mouse-autoselect-window-position))
> + 	  ;; Mouse position has either stabilized in the selected window or at
> + 	  ;; `mouse-autoselect-window-position': Cancel window autoselection.
> + 	  (mouse-autoselect-window-cancel t))
> + 	 (t
> + 	  ;; Mouse position has not stabilized yet, record new mouse position in
> + 	  ;; `mouse-autoselect-window-position' and any window at that position
> + 	  ;; in `mouse-autoselect-window-window'.
> + 	  (setq mouse-autoselect-window-position mouse-position)
> + 	  (setq mouse-autoselect-window-window window))))
> +     (error nil)))
>
>   (defun handle-select-window (event)
>     "Handle select-window events."
>     (interactive "e")
>     (let ((window (posn-window (event-start event))))
> !     (when (and (window-live-p window)
> ! 	       ;; Don't switch if we're currently in the minibuffer.
> ! 	       ;; This tries to work around problems where the minibuffer gets
> ! 	       ;; unselected unexpectedly, and where you then have to move
> ! 	       ;; your mouse all the way down to the minibuffer to select it.
> ! 	       (not (window-minibuffer-p (selected-window)))
> ! 	       ;; Don't switch to a minibuffer window unless it's active.
> ! 	       (or (not (window-minibuffer-p window))
> ! 		   (minibuffer-window-active-p window)))
> !       (unless (and (numberp mouse-autoselect-window)
> ! 		   (not (zerop mouse-autoselect-window))
> ! 		   (not mouse-autoselect-window-now)
> ! 		   ;; When `mouse-autoselect-window' has a numeric, non-zero
> ! 		   ;; value, delay window autoselection by that value.
> ! 		   ;; `mouse-autoselect-window-start' returns non-nil iff it
> ! 		   ;; successfully installed a timer for this purpose.
> ! 		   (mouse-autoselect-window-start window))
> ! 	;; Re-enable delayed window autoselection.
> ! 	(setq mouse-autoselect-window-now nil)
> ! 	(when mouse-autoselect-window
> ! 	  ;; Run `mouse-leave-buffer-hook' when autoselecting window.
> ! 	  (run-hooks 'mouse-leave-buffer-hook))
> ! 	(select-window window)))))
>
>   (define-key ctl-x-map "2" 'split-window-vertically)
>   (define-key ctl-x-map "3" 'split-window-horizontally)
>
> *** emacs-lisp/eldoc.el	Tue Apr 11 16:23:56 2006
> - --- emacs-lisp/eldoc.el	Sun Aug 27 19:19:06 2006
> ***************
> *** 432,438 ****
>   ;; Prime the command list.
>   (eldoc-add-command-completions
>    "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
> !  "delete-window"
>    "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
>    "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
>    "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
> - --- 432,438 ----
>   ;; Prime the command list.
>   (eldoc-add-command-completions
>    "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
> !  "delete-window" "handle-select-window"
>    "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
>    "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
>    "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
>
>
> - --------------060704020205070207060105--
> ----------
>
>
>
> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 15:17 [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]] Richard Stallman
  2006-09-03 16:02 ` David Kastrup
  2006-09-03 17:05 ` Chong Yidong
@ 2006-09-03 21:43 ` Kim F. Storm
  2006-09-05 15:20 ` Stefan Monnier
  3 siblings, 0 replies; 17+ messages in thread
From: Kim F. Storm @ 2006-09-03 21:43 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> Would people please comment on this bug fix?

I think it is a good change.

It doesn't change current semantics when mouse-autoselect-window == t,
but does the right thing (IMO) by adding a delayed selection option.

I haven't tested the specific change though.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 16:02 ` David Kastrup
  2006-09-03 16:37   ` David Kastrup
@ 2006-09-04  9:16   ` martin rudalics
  2006-09-04 14:05     ` Kim F. Storm
  2006-09-04 17:18     ` Richard Stallman
  1 sibling, 2 replies; 17+ messages in thread
From: martin rudalics @ 2006-09-04  9:16 UTC (permalink / raw)
  Cc: rms, emacs-devel

 > I think a delay is the wrong thing to do here since it makes stuff
 > unpredictable.

Delays are the standard approach window managers adopted for focus
follows mouse and window auto-raising.

 > The right fix, in my opinion, would be lazy focus
 > change: only when a keyboard or mouse event occurs in the new window,
 > is the focus changed.  That has the disadvantage that the user may be
 > surprised by the change since the old window appears to have focus
 > before typing a key.

That could be added.  But it would violate the principle of least
surprise.  In my experience, the `mode-line-inactive' face and the
`cursor-in-non-selected-windows' option handle feedback pretty well.

 > In order to mitigate the surprise, it might be reasonable to visibly
 > unfocus the old window (by the different highlighting of the mode line
 > and the different cursor type), but not refocus a different window
 > before an event occurs.

That would be disconcerting, IMHO.

 > A more radical approach would be to move toolbar and menubar just
 > above the currently selected window.  This would also require less
 > mouse movement, but would likely earn us an award for the most weird
 > user interface look ever.

I recall someone proposing the use of popup menus instead.  There's also
the possibility to access the menubar via F10 or the ALT key.  However,
clients of `mouse-autoselect-window' are probably inclined to access the
menubar with the mouse too.

 > I don't think it is reasonable to expect to sort this out before the
 > release.  I think that there are several viable possibilities, and
 > we'd need the feedback of testers trying each of those out for several
 > weeks before it would be viable to decide on a sensible strategy.

Simon and me have been testing this intensively for an entire month.
Emacs developers apparently either don't use `mouse-autoselect-window'
or don't use the menubar.  Otherwise they would have complained earlier.
Hence, for testing this any further we need a broader audience.

 > I don't think that the delay stuff is a good strategy: it brakes and
 > confuses the user when he indeed wants to change focus, and it causes
 > hectic when he doesn't.

That's what I thought before I started implementing this.  Currently, I
use a value of -0.5, that is, wait for about a second after I started
moving the mouse and select the other window iff the mouse doesn't move
any more.  So far I didn't notice any confusion with these settings.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 17:05 ` Chong Yidong
@ 2006-09-04  9:27   ` martin rudalics
  2006-09-04 14:07     ` Kim F. Storm
  0 siblings, 1 reply; 17+ messages in thread
From: martin rudalics @ 2006-09-04  9:27 UTC (permalink / raw)
  Cc: rms, emacs-devel

 >>Would people please comment on this bug fix?
 >
 >
 > I think it is a feature, not a bug.

If you want to use the mouse to access the menubar from a lower window
but the upper window is selected before you even get there, then I'd
consider that a misfeature.  Note that `mouse-autoselect-window' is new
with Emacs 22.1.  I think it's better not to introduce a misfeature in
the first place.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-04  9:16   ` martin rudalics
@ 2006-09-04 14:05     ` Kim F. Storm
  2006-09-05  9:21       ` martin rudalics
  2006-09-04 17:18     ` Richard Stallman
  1 sibling, 1 reply; 17+ messages in thread
From: Kim F. Storm @ 2006-09-04 14:05 UTC (permalink / raw)
  Cc: rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> I don't think that the delay stuff is a good strategy: it brakes and
>> confuses the user when he indeed wants to change focus, and it causes
>> hectic when he doesn't.
>
> That's what I thought before I started implementing this.  Currently, I
> use a value of -0.5, that is, wait for about a second after I started
> moving the mouse and select the other window iff the mouse doesn't move
> any more.  So far I didn't notice any confusion with these settings.

To me it makes more sense if this "move and stop" is the default method
(ie. selected with a positive delay value).  The negative value could
be for experts which want just the move delay.

But why not separate the two timeout settings, e.g. make it a cons with
the "move delay" in the car and "stopped delay" in the cdr.  That's
easy to set via customize.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-04  9:27   ` martin rudalics
@ 2006-09-04 14:07     ` Kim F. Storm
  0 siblings, 0 replies; 17+ messages in thread
From: Kim F. Storm @ 2006-09-04 14:07 UTC (permalink / raw)
  Cc: Chong Yidong, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>>>Would people please comment on this bug fix?
>>
>>
>> I think it is a feature, not a bug.
>
> If you want to use the mouse to access the menubar from a lower window
> but the upper window is selected before you even get there, then I'd
> consider that a misfeature.  Note that `mouse-autoselect-window' is new
> with Emacs 22.1.  I think it's better not to introduce a misfeature in
> the first place.

Yes, we should fix(!) this before the release.  

Personally, I found the current mouse-autoselect-window completely
useless, and quickly turned it off again.  With your changes I'll give
it another chance (haven't had time yet).

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-04  9:16   ` martin rudalics
  2006-09-04 14:05     ` Kim F. Storm
@ 2006-09-04 17:18     ` Richard Stallman
  1 sibling, 0 replies; 17+ messages in thread
From: Richard Stallman @ 2006-09-04 17:18 UTC (permalink / raw)
  Cc: emacs-devel

     > The right fix, in my opinion, would be lazy focus
     > change: only when a keyboard or mouse event occurs in the new window,
     > is the focus changed.  That has the disadvantage that the user may be
     > surprised by the change since the old window appears to have focus
     > before typing a key.

    That could be added.  But it would violate the principle of least
    surprise.  In my experience, the `mode-line-inactive' face and the
    `cursor-in-non-selected-windows' option handle feedback pretty well.

I really dislike that approach.

     > In order to mitigate the surprise, it might be reasonable to visibly
     > unfocus the old window (by the different highlighting of the mode line
     > and the different cursor type), but not refocus a different window
     > before an event occurs.

    That would be disconcerting, IMHO.

Also, I don't see how it would help.

     > A more radical approach would be to move toolbar and menubar just
     > above the currently selected window.  This would also require less
     > mouse movement, but would likely earn us an award for the most weird
     > user interface look ever.

    I recall someone proposing the use of popup menus instead.  There's also
    the possibility to access the menubar via F10 or the ALT key.  However,
    clients of `mouse-autoselect-window' are probably inclined to access the
    menubar with the mouse too.

We can't consider making such complex changes now, and I think they
would be really hard, so I doubt we should consider them later either.

    That's what I thought before I started implementing this.  Currently, I
    use a value of -0.5, that is, wait for about a second after I started
    moving the mouse and select the other window iff the mouse doesn't move
    any more.  So far I didn't notice any confusion with these settings.

I want to proceed with this approach, so I ask
people to study this patch in detail.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-04 14:05     ` Kim F. Storm
@ 2006-09-05  9:21       ` martin rudalics
  2006-09-05 11:02         ` Kim F. Storm
  0 siblings, 1 reply; 17+ messages in thread
From: martin rudalics @ 2006-09-05  9:21 UTC (permalink / raw)
  Cc: rms, emacs-devel

 > To me it makes more sense if this "move and stop" is the default method
 > (ie. selected with a positive delay value).  The negative value could
 > be for experts which want just the move delay.

The absolute value of the delay is used to set up a timer whenever the
mouse crosses a window border.  Usually though, the mouse pointer
already appears at a completely different position at the moment I
install the timer.  Unfortunately, I can't access that position easily.

When the timer triggers I do (provided other conditions apply as well)

- for a positive delay select the window,

- for a negative delay check whether mouse-position is the same as the
   last time I checked.

Now, the very first "last time I checked" occurs at the window border as
I explained above.  Hence the first time the timer fires, the recorded
mouse-positions are usually _not_ equal and I have to restart the timer
until they are.  In practice this means that if I set the delay to -1
and move to the center of another window in a single stroke, the window
is selected after 2 seconds which is more than 1 seconds after the mouse
stopped moving.  Since this is slightly counterintuitive I wouldn't want
to make that the default.

 > But why not separate the two timeout settings, e.g. make it a cons with
 > the "move delay" in the car and "stopped delay" in the cdr.  That's
 > easy to set via customize.

Currently, there is only one delay.  Do you think I should use two
different delays?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-05  9:21       ` martin rudalics
@ 2006-09-05 11:02         ` Kim F. Storm
  2006-09-05 11:06           ` David Kastrup
  2006-09-05 12:53           ` martin rudalics
  0 siblings, 2 replies; 17+ messages in thread
From: Kim F. Storm @ 2006-09-05 11:02 UTC (permalink / raw)
  Cc: rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> To me it makes more sense if this "move and stop" is the default method
>> (ie. selected with a positive delay value).  The negative value could
>> be for experts which want just the move delay.
>
> The absolute value of the delay is used to set up a timer whenever the
> mouse crosses a window border.  Usually though, the mouse pointer
> already appears at a completely different position at the moment I
> install the timer.  Unfortunately, I can't access that position easily.

Don't (mouse-position) or (mouse-pixel-position) give the current position
when you install the timer?


> When the timer triggers I do (provided other conditions apply as well)
>
> - for a positive delay select the window,

Do we really need that option?

>
> - for a negative delay check whether mouse-position is the same as the
>   last time I checked.

That's what I think should be the default ... don't select the window until
the mouse movement stops.  But detect that quickly!

>
> Now, the very first "last time I checked" occurs at the window border as
> I explained above.  Hence the first time the timer fires, the recorded
> mouse-positions are usually _not_ equal and I have to restart the timer
> until they are.  In practice this means that if I set the delay to -1
> and move to the center of another window in a single stroke, the window
> is selected after 2 seconds which is more than 1 seconds after the mouse
> stopped moving.  Since this is slightly counterintuitive I wouldn't want
> to make that the default.

Can't you just use a (fixed) 0.1 second timer the first time ?

>> But why not separate the two timeout settings, e.g. make it a cons with
>> the "move delay" in the car and "stopped delay" in the cdr.  That's
>> easy to set via customize.
>
> Currently, there is only one delay.  Do you think I should use two
> different delays?

No.  One timer "mouse-movement-stopped-timeout" would be ok.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-05 11:02         ` Kim F. Storm
@ 2006-09-05 11:06           ` David Kastrup
  2006-09-05 12:53           ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: David Kastrup @ 2006-09-05 11:06 UTC (permalink / raw)
  Cc: martin rudalics, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> martin rudalics <rudalics@gmx.at> writes:
>
>> When the timer triggers I do (provided other conditions apply as well)
>>
>> - for a positive delay select the window,
>
> Do we really need that option?
>
>>
>> - for a negative delay check whether mouse-position is the same as the
>>   last time I checked.
>
> That's what I think should be the default ... don't select the window until
> the mouse movement stops.  But detect that quickly!

[...]
>
> Can't you just use a (fixed) 0.1 second timer the first time ?

That does not sound like anything that could work reliably on a loaded
machine, or a networked X11 session.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-05 11:02         ` Kim F. Storm
  2006-09-05 11:06           ` David Kastrup
@ 2006-09-05 12:53           ` martin rudalics
  2006-09-05 13:12             ` David Kastrup
  1 sibling, 1 reply; 17+ messages in thread
From: martin rudalics @ 2006-09-05 12:53 UTC (permalink / raw)
  Cc: rms, emacs-devel

 > Don't (mouse-position) or (mouse-pixel-position) give the current position
 > when you install the timer?

No.  I use `mouse-position' and it gives the position where the mouse
pointer crosses the window border, in the window I move to.  I didn't
try `mouse-pixel-position' but IMO it would be a bug if it did refer to
another position.

 >>When the timer triggers I do (provided other conditions apply as well)
 >>
 >>- for a positive delay select the window,
 >
 >
 > Do we really need that option?

A simple delay is standard for focus follows mouse policies.  I don't
really want to omit that.

 >>- for a negative delay check whether mouse-position is the same as the
 >>  last time I checked.
 >
 >
 > That's what I think should be the default ... don't select the window until
 > the mouse movement stops.  But detect that quickly!

You can always set the delay to a very small value.  In my experience
less than 0.2 seconds never sensibly delays selection but may select the
window too quickly.  It depends on your mouse mileage though, personally
I like nervous mice.

 > Can't you just use a (fixed) 0.1 second timer the first time ?

It's been one of my first attempts to deal with the problem (and I used
exactly 0.1 seconds IIRC).  It didn't work reliably though, and I didn't
try to find out why.  Maybe another timer ...

 >>Currently, there is only one delay.  Do you think I should use two
 >>different delays?
 >
 >
 > No.  One timer "mouse-movement-stopped-timeout" would be ok.
 >

What about a cons with the delay in the car and a boolean for
"dont-select-while-mouse-moves" in the cdr?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-05 12:53           ` martin rudalics
@ 2006-09-05 13:12             ` David Kastrup
  2006-09-05 15:59               ` martin rudalics
  0 siblings, 1 reply; 17+ messages in thread
From: David Kastrup @ 2006-09-05 13:12 UTC (permalink / raw)
  Cc: emacs-devel, rms, Kim F. Storm

martin rudalics <rudalics@gmx.at> writes:

>> Don't (mouse-position) or (mouse-pixel-position) give the current position
>> when you install the timer?
>
> No.  I use `mouse-position' and it gives the position where the mouse
> pointer crosses the window border, in the window I move to.  I didn't
> try `mouse-pixel-position' but IMO it would be a bug if it did refer to
> another position.
>
>>>When the timer triggers I do (provided other conditions apply as well)
>>>
>>>- for a positive delay select the window,
>>
>>
>> Do we really need that option?
>
> A simple delay is standard for focus follows mouse policies.  I don't
> really want to omit that.

It is not at all standard.  For example, GNOME does not offer anything
like that in its Window Preferences.  What it _does_ offer is a dialog

Window Selection

[ ] Select windows when the mouse moves over them

    [ ] Raise selected windows after an interval
    Interval before raising: [0.0-10.0, default 0.5] seconds

Deactivating any of those lines will deactivate the following lines.
The default is "off" for all options.

I actually know of no window manager offering a delay before select.
If at all, they have delay before raise.

Raising a window is an action that changes the window configuration,
so avoiding unintentional raising is a good idea there.  The
equivalent of window raising in Emacs would probably be something like
delete-other-windows (which we certainly would not want to do) or
other window-configuration changing things.

> You can always set the delay to a very small value.  In my
> experience less than 0.2 seconds never sensibly delays selection but
> may select the window too quickly.  It depends on your mouse mileage
> though, personally I like nervous mice.

And unloaded machines and non-networked X11 connections.  But not
everybody is running Emacs on a machine of his dreams all of the time.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-03 15:17 [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]] Richard Stallman
                   ` (2 preceding siblings ...)
  2006-09-03 21:43 ` Kim F. Storm
@ 2006-09-05 15:20 ` Stefan Monnier
  3 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2006-09-05 15:20 UTC (permalink / raw)
  Cc: emacs-devel

> Would people please comment on this bug fix?

Looks OK to me.


        Stefan "who used mouse-autoselect-window every since it appeared"


> ------- Start of forwarded message -------
> Date: Mon, 28 Aug 2006 07:57:29 +0200
> From: martin rudalics <rudalics@gmx.at>
> MIME-Version: 1.0
> To:  rms@gnu.org
> CC: "Marshall, Simon" <simon.marshall@misys.com>,  emacs-devel@gnu.org
> Subject: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a	de
>  lay]
> In-Reply-To: <E1G2plT-00018h-Cu@fencepost.gnu.org>
> Content-Type: multipart/mixed;
>  boundary="------------060704020205070207060105"
> X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=failed 
> 	version=3.0.4

> This is a multi-part message in MIME format.
> - --------------060704020205070207060105
> Content-Type: text/plain; charset=ISO-8859-15; format=flowed
> Content-Transfer-Encoding: 7bit

> Attached find ChangeLog entries and patch for this.

> - --------------060704020205070207060105
> Content-Type: text/plain;
>  name="autoselect-window.patch"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline;
>  filename="autoselect-window.patch"

> 2006-08-27  Martin Rudalics  <rudalics@gmx.at>

> 	* xdisp.c (mouse_autoselect_window): Removed.
> 	(Vmouse_autoselect_window): New variable.  DEFVAR_LISP it.
> 	* dispextern.h (mouse_autoselect_window): Remove extern.
> 	(Vmouse_autoselect_window): Add extern.
> 	* macterm.c (XTread_socket): Test Vmouse_autoselect_window
> 	instead of mouse_autoselect_window.
> 	* msdos.c (dos_rawgetc): Likewise.
> 	* w32term.c (w32_read_socket): Likewise.
> 	* xterm.c (handle_one_xevent): Likewise.

> 2006-08-27  Martin Rudalics  <rudalics@gmx.at>

> 	* window.el (mouse-autoselect-window-timer)
> 	(mouse-autoselect-window-position)
> 	(mouse-autoselect-window-window)
> 	(mouse-autoselect-window-now): New variables for delayed
> 	window autoselection.
> 	(mouse-autoselect-window-cancel)
> 	(mouse-autoselect-window-select)
> 	(mouse-autoselect-window-start): New functions for delayed
> 	window autoselection: Wait to autoselect a new window so that
> 	just moving over a window doesn't inadvertently select it.
> 	(handle-select-window): Call `mouse-autoselect-window-start'
> 	when delayed window autoselection is enabled.
> 	* cus-start.el (mouse-autoselect-window): Change
> 	customization options to handle delayed window autoselection.	
> 	* emacs-lisp/eldoc.el: Use `eldoc-add-command-completions' to
>       	add `handle-select-window' to the set of commands after which
> 	it is allowed to print in the echo area.


> *** dispextern.h	Tue Aug 15 10:01:00 2006
> - --- dispextern.h	Sun Aug 27 19:09:48 2006
> ***************
> *** 2690,2696 ****
>   extern int help_echo_pos;
>   extern struct frame *last_mouse_frame;
>   extern int last_tool_bar_item;
> ! extern int mouse_autoselect_window;
>   extern int unibyte_display_via_language_environment;

>   extern void reseat_at_previous_visible_line_start P_ ((struct it *));
> - --- 2690,2696 ----
>   extern int help_echo_pos;
>   extern struct frame *last_mouse_frame;
>   extern int last_tool_bar_item;
> ! extern Lisp_Object Vmouse_autoselect_window;
>   extern int unibyte_display_via_language_environment;

>   extern void reseat_at_previous_visible_line_start P_ ((struct it *));

> *** macterm.c	Tue Aug 15 10:01:02 2006
> - --- macterm.c	Sun Aug 27 19:11:18 2006
> ***************
> *** 10564,10570 ****
>   		  else
>   		    {
>   		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 		      if (mouse_autoselect_window)
>   			{
>   			  Lisp_Object window;

> - --- 10564,10570 ----
>   		  else
>   		    {
>   		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 		      if (!NILP (Vmouse_autoselect_window))
>   			{
>   			  Lisp_Object window;


> *** msdos.c	Tue Aug 15 10:01:02 2006
> - --- msdos.c	Sun Aug 27 19:12:00 2006
> ***************
> *** 3381,3387 ****
>   	    }

>   	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	  if (mouse_autoselect_window)
>   	    {
>   	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
>   						      mouse_last_x,
> - --- 3381,3387 ----
>   	    }

>   	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	  if (!NILP (Vmouse_autoselect_window))
>   	    {
>   	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
>   						      mouse_last_x,

> *** w32term.c	Tue Aug 15 10:01:02 2006
> - --- w32term.c	Sun Aug 27 19:12:36 2006
> ***************
> *** 4286,4292 ****
>   	  if (f)
>   	    {
>   	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	      if (mouse_autoselect_window)
>   		{
>   		  Lisp_Object window;
>   		  int x = LOWORD (msg.msg.lParam);
> - --- 4286,4292 ----
>   	  if (f)
>   	    {
>   	      /* Generate SELECT_WINDOW_EVENTs when needed.  */
> ! 	      if (!NILP (Vmouse_autoselect_window))
>   		{
>   		  Lisp_Object window;
>   		  int x = LOWORD (msg.msg.lParam);

> *** xdisp.c	Tue Aug 15 10:01:02 2006
> - --- xdisp.c	Sun Aug 27 19:15:12 2006
> ***************
> *** 258,264 ****

>   /* Non-zero means automatically select any window when the mouse
>      cursor moves into it.  */
> ! int mouse_autoselect_window;

>   /* Non-zero means draw tool bar buttons raised when the mouse moves
>      over them.  */
> - --- 258,264 ----

>   /* Non-zero means automatically select any window when the mouse
>      cursor moves into it.  */
> ! Lisp_Object Vmouse_autoselect_window;

>   /* Non-zero means draw tool bar buttons raised when the mouse moves
>      over them.  */
> ***************
> *** 23962,23970 ****
>   See `set-window-redisplay-end-trigger'.  */);
>     Vredisplay_end_trigger_functions = Qnil;

> !   DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window,
> !     doc: /* *Non-nil means autoselect window with mouse pointer.  */);
> !   mouse_autoselect_window = 0;

>     DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
>       doc: /* *Non-nil means automatically resize tool-bars.
> - --- 23962,23982 ----
>   See `set-window-redisplay-end-trigger'.  */);
>     Vredisplay_end_trigger_functions = Qnil;

> !   DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window,
> !      doc: /* *Non-nil means autoselect window with mouse pointer.
> ! If nil, do not autoselect windows.  A positive number means delay
> ! autoselection by that many seconds: A window is selected iff Emacs
> ! can establish that the mouse has remained within that window for the
> ! time indicated by the delay.  A negative number has a similar effect
> ! but actually selects the window only after the mouse stopped moving.
> ! \(Since Emacs compares mouse positions for this purpose, you will
> ! occasionally wait twice that time before the window gets selected.\)
> ! Any other value means autoselect window instantaneously when the
> ! mouse pointer enters it.
> ! 
> ! Autoselection does not unselect the minibuffer and selects the
> ! minibuffer iff it is active.  */);
> !   Vmouse_autoselect_window = Qnil;

>     DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p,
>       doc: /* *Non-nil means automatically resize tool-bars.

> *** xterm.c	Tue Aug 15 10:01:02 2006
> - --- xterm.c	Sun Aug 27 19:15:32 2006
> ***************
> *** 6575,6581 ****
>             {

>               /* Generate SELECT_WINDOW_EVENTs when needed.  */
> !             if (mouse_autoselect_window)
>                 {
>                   Lisp_Object window;

> - --- 6575,6581 ----
>             {

>               /* Generate SELECT_WINDOW_EVENTs when needed.  */
> !             if (!NILP (Vmouse_autoselect_window))
>                 {
>                   Lisp_Object window;


> *** cus-start.el	Tue Aug 15 10:00:50 2006
> - --- cus-start.el	Sun Aug 27 19:18:32 2006
> ***************
> *** 360,365 ****
> - --- 360,372 ----
>   					    (other :tag "Unlimited" t)))
>   	     (unibyte-display-via-language-environment mule boolean)
>   	     (blink-cursor-alist cursor alist "22.1")
> +              (mouse-autoselect-window
> + 	      display
> + 	      (choice
> + 	       (const :tag "Off (nil)" :value nil)
> + 	       (const :tag "Immediate" :value t)
> + 	       (number :tag "Delay by secs" :value 0.5))
> + 	      "22.1")
>   	     ;; xfaces.c
>   	     (scalable-fonts-allowed display boolean)
>   	     ;; xfns.c
> ***************
> *** 369,375 ****
>   	     (x-gtk-show-hidden-files menu boolean "22.1")
>   	     (x-gtk-whole-detached-tool-bar x boolean "22.1")
>   	     ;; xterm.c
> - -              (mouse-autoselect-window display boolean "21.3")
>   	     (x-use-underline-position-properties display boolean "21.3")
>   	     (x-stretch-cursor display boolean "21.1")))
>         this symbol group type standard version native-p
> - --- 376,381 ----

> *** window.el	Tue Aug 15 10:00:52 2006
> - --- window.el	Sun Aug 27 19:21:02 2006
> ***************
> *** 777,797 ****
>       ;; Maybe get rid of the window.
>       (and window (not window-handled) (not window-solitary)
>   	 (delete-window window))))

>   (defun handle-select-window (event)
>     "Handle select-window events."
>     (interactive "e")
>     (let ((window (posn-window (event-start event))))
> !     (if (and (window-live-p window)
> ! 	     ;; Don't switch if we're currently in the minibuffer.
> ! 	     ;; This tries to work around problems where the minibuffer gets
> ! 	     ;; unselected unexpectedly, and where you then have to move
> ! 	     ;; your mouse all the way down to the minibuffer to select it.
> ! 	     (not (window-minibuffer-p (selected-window)))
> ! 	     ;; Don't switch to a minibuffer window unless it's active.
> ! 	     (or (not (window-minibuffer-p window))
> ! 		 (minibuffer-window-active-p window)))
> ! 	(select-window window))))

>   (define-key ctl-x-map "2" 'split-window-vertically)
>   (define-key ctl-x-map "3" 'split-window-horizontally)
> - --- 777,910 ----
>       ;; Maybe get rid of the window.
>       (and window (not window-handled) (not window-solitary)
>   	 (delete-window window))))
> + \f
> + (defvar mouse-autoselect-window-timer nil
> +   "Timer used by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-position nil
> +   "Last mouse position recorded by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-window nil
> +   "Last window recorded by delayed window autoselection.")
> + 
> + (defvar mouse-autoselect-window-now nil
> +   "When non-nil don't delay autoselection in `handle-select-window'.")
> + 
> + (defun mouse-autoselect-window-cancel (&optional force)
> +   "Cancel delayed window autoselection.
> + Optional argument FORCE means cancel unconditionally."
> +   (unless (and (not force)
> + 	       ;; Don't cancel while the user drags a scroll bar.
> + 	       (eq this-command 'scroll-bar-toolkit-scroll)
> + 	       (memq (nth 4 (event-end last-input-event))
> + 		     '(handle end-scroll)))
> +     (setq mouse-autoselect-window-now nil)
> +     (when (timerp mouse-autoselect-window-timer)
> +       (cancel-timer mouse-autoselect-window-timer))
> +     (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
> + 
> + (defun mouse-autoselect-window-start (window)
> +   "Start delayed window autoselection.
> + Called when Emacs detects that the mouse has moved to the non-selected
> + window WINDOW and the variable `mouse-autoselect-window' has a numeric,
> + non-zero value.  The return value is non-nil iff delayed autoselection
> + started successfully.  Delayed window autoselection is canceled when the
> + mouse position has stabilized or a command is executed."
> +   ;; Cancel any active window autoselection.
> +   (mouse-autoselect-window-cancel t)
> +   ;; Record current mouse position in `mouse-autoselect-window-position' and
> +   ;; WINDOW in `mouse-autoselect-window-window'.
> +   (setq mouse-autoselect-window-position (mouse-position))
> +   (setq mouse-autoselect-window-window window)
> +   ;; Install timer which runs `mouse-autoselect-window-select' every
> +   ;; `mouse-autoselect-window' seconds.
> +   (setq mouse-autoselect-window-timer
> + 	(run-at-time
> + 	 (abs mouse-autoselect-window) (abs mouse-autoselect-window)
> + 	 'mouse-autoselect-window-select))
> +   ;; Executing a command cancels window autoselection.
> +   (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
> + 
> + (defun mouse-autoselect-window-select ()
> +   "Select window with delayed window autoselection.
> + If the mouse position has stabilized in a non-selected window, select
> + that window.  The minibuffer window is selected iff the minibuffer is
> + active.  This function is run by `mouse-autoselect-window-timer'."
> +   (condition-case nil
> +       (let* ((mouse-position (mouse-position))
> + 	     (window (window-at (cadr mouse-position) (cddr mouse-position)
> + 				(car mouse-position))))
> + 	(cond
> + 	 ((and window (not (eq window (selected-window)))
> + 	       (or (not (numberp mouse-autoselect-window))
> + 		   (and (> mouse-autoselect-window 0)
> + 			;; If `mouse-autoselect-window' is positive, select
> + 			;; window if the window is the same as before.
> + 			(eq window mouse-autoselect-window-window))
> + 		   ;; Otherwise select window iff the mouse is at the same
> + 		   ;; position as before.  Observe that the first test after
> + 		   ;; `mouse-autoselect-window-start' usually fails since the
> + 		   ;; value of `mouse-autoselect-window-position' recorded there
> + 		   ;; is the position where the mouse has entered the new window
> + 		   ;; and not necessarily where the mouse has stopped moving.
> + 		   (equal mouse-position mouse-autoselect-window-position))
> + 	       ;; The minibuffer is a candidate window iff it's active.
> + 	       (or (not (window-minibuffer-p window))
> + 		   (eq window (active-minibuffer-window))))
> + 	  ;; Mouse position has stabilized in non-selected window: Cancel window
> + 	  ;; autoselection and try to select that window.
> + 	  (mouse-autoselect-window-cancel t)
> + 	  ;; Select window where mouse appears unless the selected window is the
> + 	  ;; minibuffer.  Use `unread-command-events' in order to execute pre-
> + 	  ;; and post-command hooks and trigger idle timers.  To avoid delaying
> + 	  ;; autoselection again, temporarily set `mouse-autoselect-window-now'
> + 	  ;; to t.
> + 	  (unless (window-minibuffer-p (selected-window))
> + 	    (setq mouse-autoselect-window-now t)
> + 	    (setq unread-command-events
> + 		  (cons (list 'select-window (list window))
> + 			unread-command-events))))
> + 	 ((or (and window (eq window (selected-window)))
> + 	      (not (numberp mouse-autoselect-window))
> + 	      (equal mouse-position mouse-autoselect-window-position))
> + 	  ;; Mouse position has either stabilized in the selected window or at
> + 	  ;; `mouse-autoselect-window-position': Cancel window autoselection.
> + 	  (mouse-autoselect-window-cancel t))
> + 	 (t
> + 	  ;; Mouse position has not stabilized yet, record new mouse position in
> + 	  ;; `mouse-autoselect-window-position' and any window at that position
> + 	  ;; in `mouse-autoselect-window-window'.
> + 	  (setq mouse-autoselect-window-position mouse-position)
> + 	  (setq mouse-autoselect-window-window window))))
> +     (error nil)))

>   (defun handle-select-window (event)
>     "Handle select-window events."
>     (interactive "e")
>     (let ((window (posn-window (event-start event))))
> !     (when (and (window-live-p window)
> ! 	       ;; Don't switch if we're currently in the minibuffer.
> ! 	       ;; This tries to work around problems where the minibuffer gets
> ! 	       ;; unselected unexpectedly, and where you then have to move
> ! 	       ;; your mouse all the way down to the minibuffer to select it.
> ! 	       (not (window-minibuffer-p (selected-window)))
> ! 	       ;; Don't switch to a minibuffer window unless it's active.
> ! 	       (or (not (window-minibuffer-p window))
> ! 		   (minibuffer-window-active-p window)))
> !       (unless (and (numberp mouse-autoselect-window)
> ! 		   (not (zerop mouse-autoselect-window))
> ! 		   (not mouse-autoselect-window-now)
> ! 		   ;; When `mouse-autoselect-window' has a numeric, non-zero
> ! 		   ;; value, delay window autoselection by that value.
> ! 		   ;; `mouse-autoselect-window-start' returns non-nil iff it
> ! 		   ;; successfully installed a timer for this purpose.
> ! 		   (mouse-autoselect-window-start window))
> ! 	;; Re-enable delayed window autoselection.
> ! 	(setq mouse-autoselect-window-now nil)
> ! 	(when mouse-autoselect-window
> ! 	  ;; Run `mouse-leave-buffer-hook' when autoselecting window.
> ! 	  (run-hooks 'mouse-leave-buffer-hook))
> ! 	(select-window window)))))

>   (define-key ctl-x-map "2" 'split-window-vertically)
>   (define-key ctl-x-map "3" 'split-window-horizontally)

> *** emacs-lisp/eldoc.el	Tue Apr 11 16:23:56 2006
> - --- emacs-lisp/eldoc.el	Sun Aug 27 19:19:06 2006
> ***************
> *** 432,438 ****
>   ;; Prime the command list.
>   (eldoc-add-command-completions
>    "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
> !  "delete-window"
>    "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
>    "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
>    "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
> - --- 432,438 ----
>   ;; Prime the command list.
>   (eldoc-add-command-completions
>    "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
> !  "delete-window" "handle-select-window"
>    "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
>    "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
>    "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"


> - --------------060704020205070207060105--
> ------- End of forwarded message -------


> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]]
  2006-09-05 13:12             ` David Kastrup
@ 2006-09-05 15:59               ` martin rudalics
  0 siblings, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-09-05 15:59 UTC (permalink / raw)
  Cc: emacs-devel, rms, Kim F. Storm

 >>A simple delay is standard for focus follows mouse policies.  I don't
 >>really want to omit that.
 >
 >
 > It is not at all standard.  For example, GNOME does not offer anything
 > like that in its Window Preferences.  What it _does_ offer is a dialog
 >
 > Window Selection
 >
 > [ ] Select windows when the mouse moves over them
 >
 >     [ ] Raise selected windows after an interval
 >     Interval before raising: [0.0-10.0, default 0.5] seconds
 >
 > Deactivating any of those lines will deactivate the following lines.
 > The default is "off" for all options.

I thought about KDE's "delay focus".  Anyway `mouse-autoselect-window'
was and is by default nil.  The question Kim raised was whether mouse
quiescence should be considered in the first place when delayed
autoselection is on.  In this context I considered a simple timeout
"standard" because I know of implementations based on timeouts.  I'm not
aware of attempts to check mouse quiescence with respect to focus
follows mouse.

 > I actually know of no window manager offering a delay before select.
 > If at all, they have delay before raise.

In general, window managers don't have the problem that selecting an
option from a menu-/toolbar should be interpreted in the context of a
particular window showing a particular buffer.

 >>You can always set the delay to a very small value.  In my
 >>experience less than 0.2 seconds never sensibly delays selection but
 >>may select the window too quickly.  It depends on your mouse mileage
 >>though, personally I like nervous mice.
 >
 >
 > And unloaded machines and non-networked X11 connections.  But not
 > everybody is running Emacs on a machine of his dreams all of the time.

Correct.  That's why this has to be more customizable.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-09-05 15:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-03 15:17 [rudalics@gmx.at: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]] Richard Stallman
2006-09-03 16:02 ` David Kastrup
2006-09-03 16:37   ` David Kastrup
2006-09-04  9:16   ` martin rudalics
2006-09-04 14:05     ` Kim F. Storm
2006-09-05  9:21       ` martin rudalics
2006-09-05 11:02         ` Kim F. Storm
2006-09-05 11:06           ` David Kastrup
2006-09-05 12:53           ` martin rudalics
2006-09-05 13:12             ` David Kastrup
2006-09-05 15:59               ` martin rudalics
2006-09-04 17:18     ` Richard Stallman
2006-09-03 17:05 ` Chong Yidong
2006-09-04  9:27   ` martin rudalics
2006-09-04 14:07     ` Kim F. Storm
2006-09-03 21:43 ` Kim F. Storm
2006-09-05 15:20 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).