unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* RE: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-04 16:17 Marshall, Simon
  2006-07-05  8:26 ` martin rudalics
  2006-07-05 12:19 ` martin rudalics
  0 siblings, 2 replies; 17+ messages in thread
From: Marshall, Simon @ 2006-07-04 16:17 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'emacs-devel@gnu.org'

> The attached patch is a first approximation.  I've been able 
> to test this on Windows 98 only, hence I would be glad to 
> hear if this works in a general context too - simply 
> customize the variable `mouse-autoselect-window'.

Hi Martin, thanks, when it works it certainly is an improvement.  A few
comments though, with a Solaris 8 build with LUCID toolbars.

- A value of nil for mouse-autoselect-window doesn't seem to stop it
selecting!  I think the xterm.c check should be for
!NILP(mouse_autoselect_window) now.

- When I tried to see how the lisp functions mouse-autoselect-window-cancel,
mouse-autoselect-window-start and mouse-autoselect-window-select were called
(by adding message forms to them), I got an instant abort() when
handle_one_xevent() called mouse_autoselect_window_function (bound to
mouse-autoselect-window-start) and something called an Feval():

  [5] abort(), line 464 in "emacs.c"
  [6] Feval(form = 1619100224), line 2127 in "eval.c"
  [7] Fprogn(args = -1598899992), line 434 in "eval.c"
  [8] funcall_lambda(fun = -1598900616, nargs = 2, arg_vector = 0xffbec1f8),
line 3084 in "eval.c"
  [9] Ffuncall(nargs = 3, args = 0xffbec1f4), line 2959 in "eval.c"
  [10] call2(fn = 544825944, arg1 = -2138684416, arg2 = -2138684416), line
2711 in "eval.c"
=>[11] handle_one_xevent(dpyinfo = 0x83ae00, eventp = 0xffbec8a0, finish =
0xffbec894, hold_quit = 0xffbed970), line 6591 in "xterm.c"

In fact, setting mouse-autoselect-window to a number, doing ESC C-x on the
defun of mouse-autoselect-window-cancel or mouse-autoselect-window-start,
and moving the mouse is enough to trigger this abort even with one window.

- I think the uncertainty over the actual delay is more than a little odd.
It is more than frustrating to have to wait perhaps twice the amount of time
(in fact the doc string says the amount of time is any multiple of
mouse-autoselect-window).  Perhaps the problem is that
mouse_autoselect_window_function is run even if the window has not changed?
(Currently it is run if mouse_autoselect_window is a number, regardless of
whether the window has changed or not.)  If it were only to run if the
window has changed, perhaps mouse-autoselect-window-start can set
mouse-autoselect-window-position to (mouse-position)?

Unfortunately, it's a little difficult for me to play around with the lisp
code - I can only avoid an abort by make/make recompile/make each time.

If you can work out how to make it stable I can help test etc.  Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-04 16:17 Marshall, Simon
@ 2006-07-05  8:26 ` martin rudalics
  2006-07-05 12:19 ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-05  8:26 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'rms@gnu.org',
	'emacs-devel@gnu.org'

Hi Simon, thanks for testing this.

 > - A value of nil for mouse-autoselect-window doesn't seem to stop it
 > selecting!  I think the xterm.c check should be for
 > !NILP(mouse_autoselect_window) now.

Correct.  It should have been done as in w32term.

 > In fact, setting mouse-autoselect-window to a number, doing ESC C-x on the
 > defun of mouse-autoselect-window-cancel or mouse-autoselect-window-start,
 > and moving the mouse is enough to trigger this abort even with one window.

I don't get an abort but I'm 100% busy when edebugging this.  Hardly an
improvement.

 > - I think the uncertainty over the actual delay is more than a little odd.
 > It is more than frustrating to have to wait perhaps twice the amount of time
 > (in fact the doc string says the amount of time is any multiple of
 > mouse-autoselect-window).  Perhaps the problem is that
 > mouse_autoselect_window_function is run even if the window has not changed?
 > (Currently it is run if mouse_autoselect_window is a number, regardless of
 > whether the window has changed or not.)  If it were only to run if the
 > window has changed, perhaps mouse-autoselect-window-start can set
 > mouse-autoselect-window-position to (mouse-position)?

That was my initial approach and it worked pretty well.  But (re-)read
my previous observation with respect to this:

 >> 1. Suppose I have two windows - SW is the selected one and UW the
 >> unselected one.  I move the mouse to the menubar as described in Simon's
 >> original scenario.  UW should not be selected here.  However, I then
 >> change my mind and move the mouse to UW.  I suppose that UW should be
 >> selected now - agreed?  (It's important to clear this since the current
 >> autoselect mechanism triggers iff the mouse moves from the selected
 >> window to an unselected one.)

With other words, once I leave a window with the mouse and move to the
menubar, I won't autselect another window before I cross a window border
again.  I was afraid that some people would find this counterintuitive.

 > Unfortunately, it's a little difficult for me to play around with the lisp
 > code - I can only avoid an abort by make/make recompile/make each time.
 >
 > If you can work out how to make it stable I can help test etc.  Simon.

Probably, doing this in `handle-select-window' is more practical indeed.
(In case of doubt, Stefan's always right.)  Anyway, I'll try to find a
more practicable solution.  Thanks again for the report.  martin.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-04 16:17 Marshall, Simon
  2006-07-05  8:26 ` martin rudalics
@ 2006-07-05 12:19 ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-05 12:19 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'rms@gnu.org',
	'emacs-devel@gnu.org'

[-- Attachment #1: Type: text/plain, Size: 106 bytes --]

Please try the attached patch - it's based on Stefan's suggestion to
use `handle-select-window'.  martin.

[-- Attachment #2: autoselect-window.patch --]
[-- Type: text/plain, Size: 9858 bytes --]

*** dispextern.h	Sun Jul  2 09:50:00 2006
--- dispextern.h	Wed Jul  5 11:45:28 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 mouse_autoselect_window;
  extern int unibyte_display_via_language_environment;

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

*** macterm.c	Sun Jul  2 09:50:00 2006
--- macterm.c	Wed Jul  5 12:02:28 2006
***************
*** 10562,10568 ****
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (mouse_autoselect_window)
  			{
  			  Lisp_Object window;

--- 10562,10568 ----
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (!NILP (mouse_autoselect_window))
  			{
  			  Lisp_Object window;


*** msdos.c	Sun Jul  2 12:09:26 2006
--- msdos.c	Wed Jul  5 12:02:46 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 (mouse_autoselect_window))
  	    {
  	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
  						      mouse_last_x,

*** w32term.c	Sun Jul  2 09:50:02 2006
--- w32term.c	Wed Jul  5 12:02:08 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 (mouse_autoselect_window))
  		{
  		  Lisp_Object window;
  		  int x = LOWORD (msg.msg.lParam);

*** xdisp.c	Sun Jul  2 09:50:02 2006
--- xdisp.c	Wed Jul  5 13:57:26 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 mouse_autoselect_window;

  /* Non-zero means draw tool bar buttons raised when the mouse moves
     over them.  */
***************
*** 23933,23941 ****
  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.
--- 23933,23946 ----
  See `set-window-redisplay-end-trigger'.  */);
    Vredisplay_end_trigger_functions = Qnil;

!   DEFVAR_LISP ("mouse-autoselect-window", &mouse_autoselect_window,
!      doc: /* *Non-nil means autoselect windows with mouse pointer.
! If nil, do not autoselect windows.  If t, autoselection occurs instantaneously.
! A number means delay autoselection by that many seconds: A window is selected iff
! Emacs can establish that the mouse has remained in that window quiescent for the
! time indicated by the delay.  A delay of less than 0.1 seconds is automatically
! translated into a delay of 0.1 seconds.  */);
!   mouse_autoselect_window = Qnil;

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

*** xterm.c	Sun Jul  2 12:10:00 2006
--- xterm.c	Wed Jul  5 12:03:04 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 (mouse_autoselect_window))
                {
                  Lisp_Object window;


*** cus-start.el	Sun Jul  2 09:49:56 2006
--- cus-start.el	Sun Jul  2 11:40:24 2006
***************
*** 360,365 ****
--- 360,370 ----
  					    (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)
+ 					      (number :tag "Delay" 0.5)
+ 					      (const :tag "Immediate" t))
+ 				      "21.3")
  	     ;; 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
--- 374,379 ----

*** window.el	Mon Jul  3 17:35:12 2006
--- window.el	Wed Jul  5 13:57:36 2006
***************
*** 777,792 ****
    "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,853 ----
    "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)))
!       (if (numberp mouse-autoselect-window)
! 	  (autoselect-window-start)
! 	(when mouse-autoselect-window
! 	  (run-hooks 'mouse-leave-buffer-hook))
! 	(select-window window)))))
! 
! (defvar autoselect-window-timer nil
!   "Timer used by timer-driven window autoselection.")
! 
! (defvar autoselect-window-position nil
!   "Last mouse position calculated during timer-driven window autoselection.")
! 
! (defun autoselect-window-cancel ()
!   "Terminate timer-driven window autoselection."
!   (when (timerp autoselect-window-timer)
!     (cancel-timer autoselect-window-timer))
!   (remove-hook 'pre-command-hook 'autoselect-window-cancel))
! 
! (defun autoselect-window-start ()
!   "Initiate timer-driven window autoselection.
! This function is called when the mouse was moved and the variable
! `mouse-autoselect-window' has a numeric value."
!   (autoselect-window-cancel)
!   ;; Avoid a zero delay here, use 0.1 secs as minimum.
!   (let ((delay (max mouse-autoselect-window 0.1)))
!     (setq autoselect-window-position (mouse-position))
!     (setq autoselect-window-timer
! 	  (run-at-time t delay 'autoselect-window-select))
!     (add-hook 'pre-command-hook 'autoselect-window-cancel)))
! 
! (defun autoselect-window-select ()
!   "Select window with timer-driven autoselection of windows.
! Select window where the mouse appears provided the mouse has not moved
! for at least `mouse-autoselect-window' seconds and the window is not yet
! selected.  The minibuffer window is selected iff the minibuffer is
! active."
!   (condition-case nil
!       (let ((mouse-position (mouse-position)))
! 	(if (equal mouse-position autoselect-window-position)
! 	    ;; mouse-position has stabilized, try to select a new window.
! 	    (let* ((mouse-x-pos (cadr mouse-position))
! 		   (mouse-y-pos (cddr mouse-position))
! 		   (frame (car mouse-position))
! 		   (window (window-at mouse-x-pos mouse-y-pos frame)))
! 	      (cond
! 	       ((and window (not (eq window (selected-window)))
! 		     (or (not (window-minibuffer-p window))
! 			 (eq window (active-minibuffer-window)))
! 		     (let ((edges (window-inside-edges window)))
! 		       (and (<= (nth 0 edges) mouse-x-pos)
! 			    (<= mouse-x-pos (nth 2 edges))
! 			    (<= (nth 1 edges) mouse-y-pos)
! 			    (<= mouse-y-pos (nth 3 edges)))))
! 		(autoselect-window-cancel)
! 		(run-hooks 'mouse-leave-buffer-hook)
! 		(unless (window-minibuffer-p (selected-window))
! 		  (select-window window)))
! 	       ((and window (eq window (selected-window)))
! 		(autoselect-window-cancel))))
! 	  ;; mouse-position has not stabilized yet, record new position.
! 	  (setq autoselect-window-position mouse-position)))
!     (error nil)))

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


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
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: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-06 11:43 Marshall, Simon
  2006-07-07  9:35 ` martin rudalics
  0 siblings, 1 reply; 17+ messages in thread
From: Marshall, Simon @ 2006-07-06 11:43 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'rms@gnu.org',
	'emacs-devel@gnu.org'

> Please try the attached patch - it's based on Stefan's 
> suggestion to use `handle-select-window'.  martin.

Hi Martin, thanks, I can play with the lisp now.

One problem I see with this implementation is that it also waits for twice
the delay.  The reason can be seen in the sequence of events when the mouse
is moved to a new window:

- handle-select-window calls autoselect-window-start.

- autoselect-window-start sets autoselect-window-position to
(mouse-position).  However, this position appears to be the position
*before* the mouse movement.

- autoselect-window-start starts a timer to run autoselect-window-select
after the specified delay.

- when autoselect-window-select runs after the first timeout, it checks to
see if autoselect-window-position is equal to (mouse-position), which cannot
be true even if the mouse has not moved again.  So, window selection does
not occur, and it just sets autoselect-window-position to (mouse-position).

- when autoselect-window-select runs after the second timeout, and the mouse
has not moved, autoselect-window-position is equal to (mouse-position) and
window selection occurs.

To be honest, I'd be quite happy with the feature if it did not try to
detect for a quiescent mouse as it would still be a big improvement.  In
that case I guess the implementation would not need to use (mouse-position)
and the above problem would not occur.

If it could be made to work, it would be a bonus (though perhaps should be
an additional option, i.e., delay or delay with quiescence).  Of course, one
simple hack/workaround would be to use (/ mouse-autoselect-window 2.0) for
the timer delay, though I'd be interested to see why mouse-position returns
what it does.

Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-06 11:43 Marshall, Simon
@ 2006-07-07  9:35 ` martin rudalics
  0 siblings, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-07  9:35 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'rms@gnu.org',
	'emacs-devel@gnu.org'

[-- Attachment #1: Type: text/plain, Size: 2764 bytes --]

 > One problem I see with this implementation is that it also waits for twice
 > the delay.  The reason can be seen in the sequence of events when the mouse
 > is moved to a new window:
 >
 > - handle-select-window calls autoselect-window-start.
 >
 > - autoselect-window-start sets autoselect-window-position to
 > (mouse-position).  However, this position appears to be the position
 > *before* the mouse movement.

It's the first row/column after the mouse has crossed the window border.
Try by yourself: Take two windows of fixed size one above the other and
move the mouse between them.  The cddrs of autoselect-window-position
calculated by autoselect-window-start should differ by one no matter
where mouse movement started or ended.  In any case `window-at' for
autoselect-window-position should always return the window you move to.

 > - autoselect-window-start starts a timer to run autoselect-window-select
 > after the specified delay.
 >
 > - when autoselect-window-select runs after the first timeout, it checks to
 > see if autoselect-window-position is equal to (mouse-position), which cannot
 > be true even if the mouse has not moved again.

If you move from the lower window to the upper window and stop movement
exactly at the mode line of the upper window (that is, if you move the
mouse by a few pixels only) it can be true.

 > So, window selection does
 > not occur, and it just sets autoselect-window-position to (mouse-position).
 >
 > - when autoselect-window-select runs after the second timeout, and the mouse
 > has not moved, autoselect-window-position is equal to (mouse-position) and
 > window selection occurs.

Hopefully.  In my experience, the timeout before the last can be
annoying too.  Sometimes I'm just off by one character.

 > To be honest, I'd be quite happy with the feature if it did not try to
 > detect for a quiescent mouse as it would still be a big improvement.  In
 > that case I guess the implementation would not need to use (mouse-position)
 > and the above problem would not occur.
 >
 > If it could be made to work, it would be a bonus (though perhaps should be
 > an additional option, i.e., delay or delay with quiescence).

OK, I moved everything back to mouse.el and added a customizable
variable `mouse-autoselect-quiescent'.  Using a number as value for that
variable checks whether movement was restricted to that many chars
around the last position.  This leaves future users a number of choices.

 > Of course, one
 > simple hack/workaround would be to use (/ mouse-autoselect-window 2.0) for
 > the timer delay,

That would be ugly.

 > though I'd be interested to see why mouse-position returns
 > what it does.

I think that `mouse-position' does the best it can.  Mice are
unpredictable ...


[-- Attachment #2: autoselect-window.patch --]
[-- Type: text/plain, Size: 12090 bytes --]

*** dispextern.h	Sun Jul  2 09:50:00 2006
--- dispextern.h	Wed Jul  5 11:45:28 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 mouse_autoselect_window;
  extern int unibyte_display_via_language_environment;

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

*** macterm.c	Sun Jul  2 09:50:00 2006
--- macterm.c	Wed Jul  5 12:02:28 2006
***************
*** 10562,10568 ****
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (mouse_autoselect_window)
  			{
  			  Lisp_Object window;

--- 10562,10568 ----
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (!NILP (mouse_autoselect_window))
  			{
  			  Lisp_Object window;


*** msdos.c	Sun Jul  2 12:09:26 2006
--- msdos.c	Wed Jul  5 12:02:46 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 (mouse_autoselect_window))
  	    {
  	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
  						      mouse_last_x,

*** w32term.c	Sun Jul  2 09:50:02 2006
--- w32term.c	Wed Jul  5 12:02:08 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 (mouse_autoselect_window))
  		{
  		  Lisp_Object window;
  		  int x = LOWORD (msg.msg.lParam);

*** xdisp.c	Sun Jul  2 09:50:02 2006
--- xdisp.c	Fri Jul  7 10:46:38 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 mouse_autoselect_window;

  /* Non-zero means draw tool bar buttons raised when the mouse moves
     over them.  */
***************
*** 23933,23941 ****
  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.
--- 23933,23950 ----
  See `set-window-redisplay-end-trigger'.  */);
    Vredisplay_end_trigger_functions = Qnil;

!   DEFVAR_LISP ("mouse-autoselect-window", &mouse_autoselect_window,
!      doc: /* *Non-nil means autoselect window with mouse pointer.
! If nil, do not autoselect windows.  A 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
! \(see `mouse-autoselect-quiescent').   A delay of less than 0.1 seconds
! is automatically translated into a delay of 0.1 seconds.  Any other value
! means autoselection occurs instantaneously.
! 
! Autoselection does not unselect the minibuffer and selects the minibuffer
! iff it is active.  */);
!   mouse_autoselect_window = Qnil;

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

*** xterm.c	Sun Jul  2 12:10:00 2006
--- xterm.c	Wed Jul  5 12:03:04 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 (mouse_autoselect_window))
                {
                  Lisp_Object window;


*** cus-start.el	Sun Jul  2 09:49:56 2006
--- cus-start.el	Sun Jul  2 11:40:24 2006
***************
*** 360,365 ****
--- 360,370 ----
  					    (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)
+ 					      (number :tag "Delay" 0.5)
+ 					      (const :tag "Immediate" t))
+ 				      "21.3")
  	     ;; 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
--- 374,379 ----

*** mouse.el	Wed Jul  5 11:33:32 2006
--- mouse.el	Fri Jul  7 11:26:26 2006
***************
*** 1729,1734 ****
--- 1729,1829 ----
  			    (overlay-start mouse-secondary-overlay)
  			    (overlay-end mouse-secondary-overlay)))))))

+ (defvar mouse-autoselect-window-timer nil
+   "Timer used by timer-driven window selection.")
+ 
+ (defvar mouse-autoselect-window-position nil
+   "Last mouse position calculated during timer-driven window selection.")
+ 
+ (defvar mouse-autoselect-window-at nil
+   "Window at `mouse-autoselect-window-position'.")
+ 
+ (defcustom mouse-autoselect-quiescent nil
+   "Check mouse quiescence in timer-driven window selection.
+ A value of nil means that Emacs selects a window when the mouse has
+ remained in that window for `mouse-autoselect-window' seconds.  A number
+ has Emacs select the window iff the mouse has not moved by that many
+ characters for `mouse-autoselect-window' seconds.  Any other value means
+ Emacs selects the window iff the mouse position has not changed for at
+ least `mouse-autoselect-window' seconds.
+ 
+ Settings for this variable are honored iff `mouse-autoselect-window' has
+ a numeric value."
+   :type '(choice (const :tag "Off" nil)
+ 		 (const :tag "On" t)
+ 		 (integer :tag "Chars" 1))
+   :group 'display)
+ 
+ (defun mouse-autoselect-window-cancel ()
+   "Terminate timer-driven window autoselection."
+   (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 ()
+   "Initiate timer-driven window selection.
+ This function is called when the mouse was moved and the variable
+ `mouse-autoselect-window' has a numeric value."
+   (mouse-autoselect-window-cancel)
+   (when (numberp mouse-autoselect-window)
+     ;; Avoid a non-sensical delay here: Use 0.1 secs as minimum.
+     (let ((delay (max mouse-autoselect-window 0.1)))
+       (setq mouse-autoselect-window-position (mouse-position))
+       (setq mouse-autoselect-window-at
+ 	    (window-at (cadr mouse-autoselect-window-position)
+ 		       (cddr mouse-autoselect-window-position)
+ 		       (car mouse-autoselect-window-position)))
+       (setq mouse-autoselect-window-timer
+ 	    (run-at-time t delay 'mouse-autoselect-window-select))
+       (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))))
+ 
+ (defun mouse-autoselect-window-select ()
+   "Select window with timer-driven autoselection of windows.
+ Select window where the mouse appears provided the mouse has not moved
+ for at least `mouse-autoselect-window' seconds and the window is not yet
+ selected.  The minibuffer window is selected iff the minibuffer is
+ active."
+   (condition-case nil
+       (let* ((mouse-position (mouse-position))
+ 	     (mouse-x-pos (cadr mouse-position))
+ 	     (mouse-y-pos (cddr mouse-position))
+ 	     (frame (car mouse-position))
+ 	     (window (window-at mouse-x-pos mouse-y-pos frame)))
+ 	(cond
+ 	 ((and window (not (eq window (selected-window)))
+ 	       (or (and (not mouse-autoselect-quiescent)
+ 			(eq window mouse-autoselect-window-at))
+ 		   (and (numberp mouse-autoselect-quiescent)
+ 			(and (eq frame (car mouse-autoselect-window-position))
+ 			     (<= (abs (- mouse-x-pos
+ 					 (cadr mouse-autoselect-window-position)))
+ 				 mouse-autoselect-quiescent)
+ 			     (<= (abs (- mouse-y-pos
+ 					 (cddr mouse-autoselect-window-position)))
+ 				 mouse-autoselect-quiescent)))
+ 		   (equal mouse-position mouse-autoselect-window-position))
+ 	       (or (not (window-minibuffer-p window))
+ 		   (eq window (active-minibuffer-window)))
+ 	       (let ((edges (window-inside-edges window)))
+ 		 (and (<= (nth 0 edges) mouse-x-pos)
+ 		      (<= mouse-x-pos (nth 2 edges))
+ 		      (<= (nth 1 edges) mouse-y-pos)
+ 		      (<= mouse-y-pos (nth 3 edges)))))
+ 	  ;; mouse-position has stabilized in another window.
+ 	  (mouse-autoselect-window-cancel)
+ 	  (unless (window-minibuffer-p (selected-window))
+ 	    (run-hooks 'mouse-leave-buffer-hook)
+ 	    (select-window window)))
+ 	 ((and window (eq window (selected-window)))
+ 	  ;; mouse-position has stabilized in same window.
+ 	  (mouse-autoselect-window-cancel))
+ 	 (t
+ 	  ;; mouse-position has not stabilized yet, record new position and
+ 	  ;; window.
+ 	  (setq mouse-autoselect-window-position mouse-position)
+ 	  (setq mouse-autoselect-window-at window))))
+     (error nil)))
+ 
  \f
  (defcustom mouse-buffer-menu-maxlen 20
    "*Number of buffers in one pane (submenu) of the buffer menu.

*** window.el	Mon Jul  3 17:35:12 2006
--- window.el	Fri Jul  7 10:02:00 2006
***************
*** 777,792 ****
    "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,796 ----
    "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)))
!       (if (numberp mouse-autoselect-window)
! 	  (mouse-autoselect-window-start)
! 	(when mouse-autoselect-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)


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
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: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-17 14:07 Marshall, Simon
  2006-07-17 15:52 ` martin rudalics
  0 siblings, 1 reply; 17+ messages in thread
From: Marshall, Simon @ 2006-07-17 14:07 UTC (permalink / raw)
  Cc: 'cyd@stupidchicken.com', 'rms@gnu.org',
	'emacs-devel@gnu.org'

> OK, I moved everything back to mouse.el and added a 
> customizable variable `mouse-autoselect-quiescent'.  Using a 
> number as value for that variable checks whether movement was 
> restricted to that many chars around the last position.  This 
> leaves future users a number of choices.

Thanks.  I've only just had a chance to start playing with it, I'll let you
know if there's any problem with it.

I do see switches happening before mouse-autoselect-window has elapsed, but
I haven't figured out why.  It looks as if the timer is just triggered
early.

I would remove references to "timer" in the doc string of
mouse-autoselect-quiescent, since it refers to an implementation detail not
a feature.  That terminology is not used by mouse-autoselect-window.

Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-17 14:07 Marshall, Simon
@ 2006-07-17 15:52 ` martin rudalics
  0 siblings, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-17 15:52 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

 > I do see switches happening before mouse-autoselect-window has elapsed, but
 > I haven't figured out why.  It looks as if the timer is just triggered
 > early.

In `mouse-autoselect-window-start' please replace

   (run-at-time t delay 'mouse-autoselect-window-select))

by

   (run-at-time delay delay 'mouse-autoselect-window-select))

Sorry.  I never looked at the implementation of `run-at-time'.  With a
time argument t it calls `timer-next-integral-multiple-of-time' to
recalculate the value of time which gives strange results here.  Recall
that the timer starts running when you cross the window border, not when
you start moving the mouse.

 > I would remove references to "timer" in the doc string of
 > mouse-autoselect-quiescent, since it refers to an implementation detail not
 > a feature.  That terminology is not used by mouse-autoselect-window.

There is one reference, namely

   "Check mouse quiescence in timer-driven window selection."

Is

   "Check mouse quiescence in delayed autoselection of windows."

better?

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

* RE: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-17 16:18 Marshall, Simon
  2006-07-17 17:59 ` martin rudalics
  2006-07-18 13:37 ` Richard Stallman
  0 siblings, 2 replies; 17+ messages in thread
From: Marshall, Simon @ 2006-07-17 16:18 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

> In `mouse-autoselect-window-start' please replace
> 
>    (run-at-time t delay 'mouse-autoselect-window-select))
> 
> by
> 
>    (run-at-time delay delay 'mouse-autoselect-window-select))

Duh, I noticed that but didn't realise it was the cause.

> There is one reference, namely
> 
>    "Check mouse quiescence in timer-driven window selection."
> 
> Is
> 
>    "Check mouse quiescence in delayed autoselection of windows."
> 
> better?

Yes, that's what I meant, though "delayed window autoselection" might be
cleaner.

I guess rms might want to cast his eyes over the doc strings anyway.  I
would be puzzled by the min value of 0.1s for mouse-autoselect-window - it's
arbitrary.  Is it really necessary to impose any limit?

Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-17 16:18 Marshall, Simon
@ 2006-07-17 17:59 ` martin rudalics
  2006-07-18 13:37 ` Richard Stallman
  1 sibling, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-17 17:59 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

 > I guess rms might want to cast his eyes over the doc strings anyway.  I
 > would be puzzled by the min value of 0.1s for mouse-autoselect-window - it's
 > arbitrary.  Is it really necessary to impose any limit?

It's an awful hack have to avoid error messages like

     run-at-time: Invalid repetition interval

and customize does not provide a thing like positive numbers to my
knowledge.  How about using a restricted-sexp with an anonymous lambda
in cus-start.el?

(mouse-autoselect-window display
			 (choice
			  (const :tag "Off" :value nil)
			  (const :tag "Immediate" :value t)
			  (restricted-sexp :tag "Delay by secs"
					   :value 0.5
					   :match-alternatives
					   ((lambda (val) (and (numberp val) (> val 0))))))
			 "21.3")

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

* RE: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-18 11:21 Marshall, Simon
  2006-07-19  9:56 ` martin rudalics
  0 siblings, 1 reply; 17+ messages in thread
From: Marshall, Simon @ 2006-07-18 11:21 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

Hi Martin, I occasionally get this (taken from *Messages*):

mouse-autoselect-window-start: Wrong type argument: numberp, nil

I just caught it with debug-on-error, though I'm not sure quite how to read
it as it looks like 2 errors have occurred.  The way I read it, we are in
the process of switching to the *Backtrace* window when the error
(presumably) happened again:

Debugger entered--Lisp error: (wrong-type-argument numberp nil)
  window-at(nil nil #<frame test2/CONTRACT.in 0xd1a200>)
  mouse-autoselect-window-start()
  handle-select-window((select-window (#<window 47 on *Backtrace*>)))
  call-interactively(handle-select-window)

But it is kind-of what I guessed, that the error is thrown by window-at
because mouse-position returns nil for X and Y.

I can fairly easily reproduce this with emacs -Q if I move from the selected
first frame to a second frame and then off that second frame quickly when
(a) the second frame has split windows, (b) the second frame's selected
window (ie, when the second frame is selected) and its point is covered by
the first frame.

The amount of time spent in the second frame does not seem to depend on
mouse-autoselect-window.  Maybe it has more to do with whether Emacs gets
the chance to get some info out of X before the mouse has moved off the
second frame.  I use Solaris CDE on a PC running Exceed, which may
complicate/slow things.

Maybe the only fix is to be tolerant of nil for X and Y from mouse-position.

Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-17 16:18 Marshall, Simon
  2006-07-17 17:59 ` martin rudalics
@ 2006-07-18 13:37 ` Richard Stallman
  2006-07-19 10:05   ` martin rudalics
  2006-08-28  5:57   ` martin rudalics
  1 sibling, 2 replies; 17+ messages in thread
From: Richard Stallman @ 2006-07-18 13:37 UTC (permalink / raw)
  Cc: rudalics, emacs-devel

    I guess rms might want to cast his eyes over the doc strings anyway.

Could someone send me that code so I can look at them?
I wasn't following this thread.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-18 11:21 [simon.marshall@misys.com: mouse-autoselect-window needs a de lay] Marshall, Simon
@ 2006-07-19  9:56 ` martin rudalics
  2006-07-19 11:00   ` Kim F. Storm
  0 siblings, 1 reply; 17+ messages in thread
From: martin rudalics @ 2006-07-19  9:56 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

[-- Attachment #1: Type: text/plain, Size: 2192 bytes --]

Hi Simon.

 > Hi Martin, I occasionally get this (taken from *Messages*):
 >
 > mouse-autoselect-window-start: Wrong type argument: numberp, nil
 >
 > I just caught it with debug-on-error, though I'm not sure quite how to read
 > it as it looks like 2 errors have occurred.  The way I read it, we are in
 > the process of switching to the *Backtrace* window when the error
 > (presumably) happened again:
 >
 > Debugger entered--Lisp error: (wrong-type-argument numberp nil)
 >   window-at(nil nil #<frame test2/CONTRACT.in 0xd1a200>)
 >   mouse-autoselect-window-start()
 >   handle-select-window((select-window (#<window 47 on *Backtrace*>)))
 >   call-interactively(handle-select-window)
 >
 > But it is kind-of what I guessed, that the error is thrown by window-at
 > because mouse-position returns nil for X and Y.
 >
 > I can fairly easily reproduce this with emacs -Q if I move from the selected
 > first frame to a second frame and then off that second frame quickly when
 > (a) the second frame has split windows, (b) the second frame's selected
 > window (ie, when the second frame is selected) and its point is covered by
 > the first frame.

I can obtain the error too, even when running two distinct Emacs
processes with one frame each.  Obviously, `mouse-position' _should_
return nil whenever it's not able to determine a meaningful position,
hence I can't put the blame on that.

 > The amount of time spent in the second frame does not seem to depend on
 > mouse-autoselect-window.

I suppose you tell that from using an autoselect timeout in your window
manager that differs from `mouse-autoselect-window'.

 > Maybe it has more to do with whether Emacs gets
 > the chance to get some info out of X before the mouse has moved off the
 > second frame.  I use Solaris CDE on a PC running Exceed, which may
 > complicate/slow things.

Honestly, I expected many more problems when switching frames than you
encountered so far.

 > Maybe the only fix is to be tolerant of nil for X and Y from mouse-position.

The only thing I can offer is to wrap this in a `condition-case' and
have `handle-select-window' do it's usual stuff when
`mouse-autoselect-window-start' fails.

martin

[-- Attachment #2: autoselect-window.patch --]
[-- Type: text/plain, Size: 12385 bytes --]

*** dispextern.h	Sun Jul  2 09:50:00 2006
--- dispextern.h	Wed Jul  5 11:45:28 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 mouse_autoselect_window;
  extern int unibyte_display_via_language_environment;

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

*** macterm.c	Sun Jul  2 09:50:00 2006
--- macterm.c	Wed Jul  5 12:02:28 2006
***************
*** 10562,10568 ****
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (mouse_autoselect_window)
  			{
  			  Lisp_Object window;

--- 10562,10568 ----
  		  else
  		    {
  		      /* Generate SELECT_WINDOW_EVENTs when needed.  */
! 		      if (!NILP (mouse_autoselect_window))
  			{
  			  Lisp_Object window;


*** msdos.c	Sun Jul  2 12:09:26 2006
--- msdos.c	Wed Jul  5 12:02:46 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 (mouse_autoselect_window))
  	    {
  	      mouse_window = window_from_coordinates (SELECTED_FRAME(),
  						      mouse_last_x,

*** w32term.c	Sun Jul  2 09:50:02 2006
--- w32term.c	Wed Jul  5 12:02:08 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 (mouse_autoselect_window))
  		{
  		  Lisp_Object window;
  		  int x = LOWORD (msg.msg.lParam);

*** xdisp.c	Sun Jul  2 09:50:02 2006
--- xdisp.c	Wed Jul 19 11:06:30 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 mouse_autoselect_window;

  /* Non-zero means draw tool bar buttons raised when the mouse moves
     over them.  */
***************
*** 23933,23941 ****
  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.
--- 23933,23949 ----
  See `set-window-redisplay-end-trigger'.  */);
    Vredisplay_end_trigger_functions = Qnil;

!   DEFVAR_LISP ("mouse-autoselect-window", &mouse_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 \(see `mouse-autoselect-quiescent').
! Any other value means autoselection occurs instantaneously.
! 
! Autoselection does not unselect the minibuffer and selects the
! minibuffer iff it is active.  */);
!   mouse_autoselect_window = Qnil;

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

*** xterm.c	Sun Jul  2 12:10:00 2006
--- xterm.c	Wed Jul  5 12:03:04 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 (mouse_autoselect_window))
                {
                  Lisp_Object window;

*** cus-start.el	Sun Jul  2 09:49:56 2006
--- cus-start.el	Wed Jul 19 11:07:46 2006
***************
*** 360,365 ****
--- 360,374 ----
  					    (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" :value nil)
+ 				       (const :tag "Immediate" :value t)
+ 				       (restricted-sexp :tag "Delay by secs"
+ 							:value 0.5
+ 							:match-alternatives
+ 							((lambda (val) (and (numberp val) (> val 0))))))
+ 				      "21.3")
  	     ;; 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
--- 378,383 ----

*** mouse.el	Wed Jul  5 11:33:32 2006
--- mouse.el	Wed Jul 19 11:11:44 2006
***************
*** 1729,1734 ****
--- 1729,1835 ----
  			    (overlay-start mouse-secondary-overlay)
  			    (overlay-end mouse-secondary-overlay)))))))

+ (defvar mouse-autoselect-window-timer nil
+   "Timer used by delayed window autoselection.")
+ 
+ (defvar mouse-autoselect-window-position nil
+   "Last mouse position calculated during delayed window autoselection.")
+ 
+ (defvar mouse-autoselect-window-at nil
+   "Window at `mouse-autoselect-window-position'.")
+ 
+ (defcustom mouse-autoselect-quiescent nil
+   "Specify mouse quiescence in delayed window autoselection.
+ A value of nil means that Emacs may autoselect a window if the mouse has
+ remained within that window for `mouse-autoselect-window' seconds.  An
+ integer has Emacs select the window iff the mouse has not moved by that
+ many characters within `mouse-autoselect-window' seconds.  Any other
+ value means Emacs selects the window iff the mouse position has not
+ changed for at least `mouse-autoselect-window' seconds.
+ 
+ Settings for this variable are honored iff `mouse-autoselect-window' has
+ a numeric value."
+   :type '(choice (const :tag "Off" nil)
+ 		 (const :tag "On" t)
+ 		 (integer :tag "Chars" 1))
+   :group 'display)
+ 
+ (defun mouse-autoselect-window-cancel ()
+   "Terminate delayed window autoselection."
+   (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 ()
+   "Start delayed window autoselection.
+ This function should be called when the mouse has crossed a window
+ border and the variable `mouse-autoselect-window' has a numeric value.
+ The return value is non-nil iff delayed autoselection could be
+ successfully started."
+   (condition-case nil
+       (progn
+ 	(mouse-autoselect-window-cancel)
+ 	(when (and (numberp mouse-autoselect-window)
+ 		   (> mouse-autoselect-window 0))
+ 	  (setq mouse-autoselect-window-position (mouse-position))
+ 	  (when (setq mouse-autoselect-window-at
+ 		      (window-at (cadr mouse-autoselect-window-position)
+ 				 (cddr mouse-autoselect-window-position)
+ 				 (car mouse-autoselect-window-position)))
+ 	    (setq mouse-autoselect-window-timer
+ 		  (run-at-time
+ 		   mouse-autoselect-window mouse-autoselect-window
+ 		   'mouse-autoselect-window-select))
+ 	    (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))))
+     (error nil)))
+ 
+ (defun mouse-autoselect-window-select ()
+   "Select window with delayed window autoselection.
+ If `mouse-position' has stabilized in a non-selected window, select that
+ window.  The minibuffer window is selected iff the minibuffer is active.
+ `mouse-autoselect-quiescent' specifies how mouse-position stabilizes.
+ This function is run by `mouse-autoselect-window-timer'."
+   (condition-case nil
+       (let* ((mouse-position (mouse-position))
+ 	     (mouse-x-pos (cadr mouse-position))
+ 	     (mouse-y-pos (cddr mouse-position))
+ 	     (frame (car mouse-position))
+ 	     (window (window-at mouse-x-pos mouse-y-pos frame)))
+ 	(cond
+ 	 ((and window (not (eq window (selected-window)))
+ 	       (or (and (not mouse-autoselect-quiescent)
+ 			(eq window mouse-autoselect-window-at))
+ 		   (and (integerp mouse-autoselect-quiescent)
+ 			(and (eq frame (car mouse-autoselect-window-position))
+ 			     (<= (abs (- mouse-x-pos
+ 					 (cadr mouse-autoselect-window-position)))
+ 				 mouse-autoselect-quiescent)
+ 			     (<= (abs (- mouse-y-pos
+ 					 (cddr mouse-autoselect-window-position)))
+ 				 mouse-autoselect-quiescent)))
+ 		   (equal mouse-position mouse-autoselect-window-position))
+ 	       (or (not (window-minibuffer-p window))
+ 		   (eq window (active-minibuffer-window)))
+ 	       (let ((edges (window-inside-edges window)))
+ 		 (and (<= (nth 0 edges) mouse-x-pos)
+ 		      (<= mouse-x-pos (nth 2 edges))
+ 		      (<= (nth 1 edges) mouse-y-pos)
+ 		      (<= mouse-y-pos (nth 3 edges)))))
+ 	  ;; mouse-position has stabilized in another window.
+ 	  (mouse-autoselect-window-cancel)
+ 	  (unless (window-minibuffer-p (selected-window))
+ 	    (run-hooks 'mouse-leave-buffer-hook)
+ 	    (select-window window)))
+ 	 ((and window (eq window (selected-window)))
+ 	  ;; mouse-position has stabilized in same window.
+ 	  (mouse-autoselect-window-cancel))
+ 	 (t
+ 	  ;; mouse-position has not stabilized yet, record new position and
+ 	  ;; window.
+ 	  (setq mouse-autoselect-window-position mouse-position)
+ 	  (setq mouse-autoselect-window-at window))))
+     (error nil)))
+ 
  \f
  (defcustom mouse-buffer-menu-maxlen 20
    "*Number of buffers in one pane (submenu) of the buffer menu.

*** window.el	Mon Jul  3 17:35:12 2006
--- window.el	Wed Jul 19 10:40:24 2006
***************
*** 777,792 ****
    "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,797 ----
    "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)
! 		   (> mouse-autoselect-window 0)
! 		   (mouse-autoselect-window-start))
! 	(when mouse-autoselect-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)


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
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: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-18 13:37 ` Richard Stallman
@ 2006-07-19 10:05   ` martin rudalics
  2006-08-28  5:57   ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-19 10:05 UTC (permalink / raw)
  Cc: Marshall, Simon, emacs-devel

>     I guess rms might want to cast his eyes over the doc strings anyway.
> 
> Could someone send me that code so I can look at them?
> I wasn't following this thread.

Simon's still finding bugs.  I'll send you the code as soon as it has
stabilized a little.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-19  9:56 ` martin rudalics
@ 2006-07-19 11:00   ` Kim F. Storm
  2006-07-19 12:35     ` martin rudalics
  0 siblings, 1 reply; 17+ messages in thread
From: Kim F. Storm @ 2006-07-19 11:00 UTC (permalink / raw)
  Cc: Marshall, Simon, 'emacs-devel@gnu.org'

martin rudalics <rudalics@gmx.at> writes:

>> Maybe the only fix is to be tolerant of nil for X and Y from mouse-position.
>
> The only thing I can offer is to wrap this in a `condition-case' and
> have `handle-select-window' do it's usual stuff when
> `mouse-autoselect-window-start' fails.

I haven't studied the details of the patch, so just a general comment:

Lisp vars exported from C are normally named with a V prefix, like
this:

extern Lisp_Object Vmouse_autoselect_window;

Since you seem to touch on all occurrences of mouse_autoselect_window, could
you please make it use the "proper" name.

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

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

* RE: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
@ 2006-07-19 11:14 Marshall, Simon
  0 siblings, 0 replies; 17+ messages in thread
From: Marshall, Simon @ 2006-07-19 11:14 UTC (permalink / raw)
  Cc: 'emacs-devel@gnu.org'

>  > The amount of time spent in the second frame does not seem to depend on
>  > mouse-autoselect-window.
> 
> I suppose you tell that from using an autoselect timeout in 
> your window
> manager that differs from `mouse-autoselect-window'.

FWIW, I probably wasn't clear - I meant the amount of time spent in the
second frame _to trigger the bug_ does not seem to depend on
mouse-autoselect-window, ie, its not anything to do with the autoselect
window functionality itself.

>  > Maybe the only fix is to be tolerant of nil for X and Y from
mouse-position.
> 
> The only thing I can offer is to wrap this in a `condition-case' and
> have `handle-select-window' do it's usual stuff when
> `mouse-autoselect-window-start' fails.

Thanks, I'll let you know if I see any other problems.  Simon.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-19 11:00   ` Kim F. Storm
@ 2006-07-19 12:35     ` martin rudalics
  0 siblings, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-07-19 12:35 UTC (permalink / raw)
  Cc: Marshall, Simon, 'emacs-devel@gnu.org'

> Lisp vars exported from C are normally named with a V prefix, like
> this:
> 
> extern Lisp_Object Vmouse_autoselect_window;
> 
> Since you seem to touch on all occurrences of mouse_autoselect_window, could
> you please make it use the "proper" name.

Thanks, I forgot to change this.

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

* Re: [simon.marshall@misys.com: mouse-autoselect-window needs a de lay]
  2006-07-18 13:37 ` Richard Stallman
  2006-07-19 10:05   ` martin rudalics
@ 2006-08-28  5:57   ` martin rudalics
  1 sibling, 0 replies; 17+ messages in thread
From: martin rudalics @ 2006-08-28  5:57 UTC (permalink / raw)
  Cc: Marshall, Simon, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 52 bytes --]

Attached find ChangeLog entries and patch for this.

[-- Attachment #2: autoselect-window.patch --]
[-- Type: text/plain, Size: 15834 bytes --]

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"


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
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

end of thread, other threads:[~2006-08-28  5:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-18 11:21 [simon.marshall@misys.com: mouse-autoselect-window needs a de lay] Marshall, Simon
2006-07-19  9:56 ` martin rudalics
2006-07-19 11:00   ` Kim F. Storm
2006-07-19 12:35     ` martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2006-07-19 11:14 Marshall, Simon
2006-07-17 16:18 Marshall, Simon
2006-07-17 17:59 ` martin rudalics
2006-07-18 13:37 ` Richard Stallman
2006-07-19 10:05   ` martin rudalics
2006-08-28  5:57   ` martin rudalics
2006-07-17 14:07 Marshall, Simon
2006-07-17 15:52 ` martin rudalics
2006-07-06 11:43 Marshall, Simon
2006-07-07  9:35 ` martin rudalics
2006-07-04 16:17 Marshall, Simon
2006-07-05  8:26 ` martin rudalics
2006-07-05 12:19 ` martin rudalics

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).