From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: [simon.marshall@misys.com: mouse-autoselect-window needs a delay] Date: Mon, 03 Jul 2006 19:47:39 +0200 Message-ID: <44A9583B.1030408@gmx.at> References: <878xnmunvy.fsf@stupidchicken.com> <44A401C6.3050101@gmx.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010402020200090603080604" X-Trace: sea.gmane.org 1151949166 7835 80.91.229.2 (3 Jul 2006 17:52:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 3 Jul 2006 17:52:46 +0000 (UTC) Cc: cyd@stupidchicken.com, simon.marshall@misys.com, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 03 19:52:37 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FxSb3-0002pU-Lj for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2006 19:52:34 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FxSb3-0005nQ-20 for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2006 13:52:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FxSaq-0005mw-4w for emacs-devel@gnu.org; Mon, 03 Jul 2006 13:52:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FxSap-0005mc-Ei for emacs-devel@gnu.org; Mon, 03 Jul 2006 13:52:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FxSap-0005mZ-Bi for emacs-devel@gnu.org; Mon, 03 Jul 2006 13:52:19 -0400 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1FxSoJ-0006sy-HD for emacs-devel@gnu.org; Mon, 03 Jul 2006 14:06:16 -0400 Original-Received: (qmail invoked by alias); 03 Jul 2006 17:52:15 -0000 Original-Received: from N899P004.adsl.highway.telekom.at (EHLO [62.47.56.68]) [62.47.56.68] by mail.gmx.net (mp019) with SMTP; 03 Jul 2006 19:52:15 +0200 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: rms@gnu.org In-Reply-To: X-Y-GMX-Trusted: 0 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:56433 Archived-At: This is a multi-part message in MIME format. --------------010402020200090603080604 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Richard Stallman schrieb: > 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? > > Yes. The question is how to distinguish the two cases. I thought > someone people suggested using a time delay for that, right. > > 2. Currently `mouse-leave-buffer-hook' is not run when autoselecting > a window. I believe this is a bug that should be resolved - agreed? > > Yes, I think so; this should exit an isearch. > > 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'. --------------010402020200090603080604 Content-Type: text/plain; name="mouse-autoselect-window.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mouse-autoselect-window.patch" *** dispextern.h Sun Jul 2 09:50:00 2006 --- dispextern.h Sun Jul 2 11:35:22 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,2697 ---- extern int help_echo_pos; extern struct frame *last_mouse_frame; extern int last_tool_bar_item; ! extern Lisp_Object mouse_autoselect_window; ! extern Lisp_Object mouse_autoselect_window_function; 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 Mon Jul 3 10:03:42 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; *************** *** 10571,10589 **** mouse_pos.v, 0, 0, 0, 0); ! /* Window will be selected only when it is ! not selected now and last mouse movement ! event was not in it. Minibuffer window ! will be selected iff it is active. */ ! if (WINDOWP (window) ! && !EQ (window, last_window) ! && !EQ (window, selected_window)) { inev.kind = SELECT_WINDOW_EVENT; inev.frame_or_window = window; } ! ! last_window=window; } if (!note_mouse_movement (f, &mouse_pos)) help_echo_string = previous_help_echo_string; --- 10571,10596 ---- mouse_pos.v, 0, 0, 0, 0); ! if (NUMBERP (mouse_autoselect_window)) ! /* Let mouse_autoselect_window_function handle this. */ { + if (!NILP (mouse_autoselect_window_function)) + call2 (mouse_autoselect_window_function, + last_window, window); + } + else if (WINDOWP (window) + && !EQ (window, last_window) + && !EQ (window, selected_window)) + /* Window will be selected only when it is + not selected now and last mouse movement + event was not in it. Minibuffer window + will be selected iff it is active. */ + { + call1 (Vrun_hooks, Qmouse_leave_buffer_hook); inev.kind = SELECT_WINDOW_EVENT; inev.frame_or_window = window; } ! last_window = window; } if (!note_mouse_movement (f, &mouse_pos)) help_echo_string = previous_help_echo_string; *** msdos.c Sun Jul 2 12:09:26 2006 --- msdos.c Mon Jul 3 10:03:46 2006 *************** *** 3387,3400 **** mouse_last_x, mouse_last_y, 0, 0, 0, 0); ! /* A window will be selected only when it is not ! selected now, and the last mouse movement event was ! not in it. A minibuffer window will be selected iff ! it is active. */ ! if (WINDOWP (mouse_window) ! && !EQ (mouse_window, last_mouse_window) ! && !EQ (mouse_window, selected_window)) { event.kind = SELECT_WINDOW_EVENT; event.frame_or_window = mouse_window; event.arg = Qnil; --- 3387,3408 ---- mouse_last_x, mouse_last_y, 0, 0, 0, 0); ! if (NUMBERP (mouse_autoselect_window)) ! /* Let mouse_autoselect_window_function handle this. */ { + if (!NILP (mouse_autoselect_window_function)) + call2 (mouse_autoselect_window_function, + last_window, mouse_window); + } + else if (WINDOWP (mouse_window) + && !EQ (mouse_window, last_mouse_window) + && !EQ (mouse_window, selected_window)) + /* A window will be selected only when it is not + selected now, and the last mouse movement event was + not in it. A minibuffer window will be selected iff + it is active. */ + { + call1 (Vrun_hooks, Qmouse_leave_buffer_hook); event.kind = SELECT_WINDOW_EVENT; event.frame_or_window = mouse_window; event.arg = Qnil; *** w32term.c Sun Jul 2 09:50:02 2006 --- w32term.c Sun Jul 2 12:02:38 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); *************** *** 4294,4312 **** window = window_from_coordinates (f, x, y, 0, 0, 0, 0); ! /* Window will be selected only when it is not ! selected now and last mouse movement event was ! not in it. Minibuffer window will be selected ! iff it is active. */ ! if (WINDOWP(window) ! && !EQ (window, last_window) ! && !EQ (window, selected_window)) { inev.kind = SELECT_WINDOW_EVENT; inev.frame_or_window = window; } ! ! last_window=window; } if (!note_mouse_movement (f, &msg.msg)) help_echo_string = previous_help_echo_string; --- 4294,4319 ---- window = window_from_coordinates (f, x, y, 0, 0, 0, 0); ! if (NUMBERP (mouse_autoselect_window)) ! /* Let mouse_autoselect_window_function handle this. */ { + if (!NILP (mouse_autoselect_window_function)) + call2 (mouse_autoselect_window_function, + last_window, window); + } + else if (WINDOWP(window) + && !EQ (window, last_window) + && !EQ (window, selected_window)) + /* Window will be selected only when it is not + selected now and last mouse movement event was + not in it. Minibuffer window will be selected + iff it is active. */ + { + call1 (Vrun_hooks, Qmouse_leave_buffer_hook); inev.kind = SELECT_WINDOW_EVENT; inev.frame_or_window = window; } ! last_window = window; } if (!note_mouse_movement (f, &msg.msg)) help_echo_string = previous_help_echo_string; *** xdisp.c Sun Jul 2 09:50:02 2006 --- xdisp.c Mon Jul 3 19:29:14 2006 *************** *** 256,264 **** Lisp_Object Vfontification_functions; Lisp_Object Qfontification_functions; ! /* 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. */ --- 256,268 ---- Lisp_Object Vfontification_functions; Lisp_Object Qfontification_functions; ! /* Non-nil means automatically select any window when the mouse ! cursor moves into it. If a number wait that many seconds before. */ ! Lisp_Object mouse_autoselect_window; ! ! /* Function called to automatically select a window when the mouse cursor moves into it. */ ! Lisp_Object mouse_autoselect_window_function; /* 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. --- 23937,23958 ---- 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. Note that autoselection does not occur before this ! delay has elapsed at least twice. Hence, a delay of 0.5 secs means that a new ! window may be selected after 1, 1.5, 2, 2.5, ... seconds. A delay of less than ! 0.1 seconds is automatically translated into a delay of 0.1 seconds. */); ! mouse_autoselect_window = Qnil; ! ! DEFVAR_LISP ("mouse-autoselect-window-function", &mouse_autoselect_window_function, ! doc: /* If non-nil, function to run when autoselecting a new window. ! The function is called with two arguments, the window that has been left and the ! window that is entered. */); ! mouse_autoselect_window_function = 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 Mon Jul 3 10:03:50 2006 *************** *** 6583,6600 **** event.xmotion.x, event.xmotion.y, 0, 0, 0, 0); ! /* Window will be selected only when it is not selected now and ! last mouse movement event was not in it. Minibuffer window ! will be selected iff it is active. */ ! if (WINDOWP (window) ! && !EQ (window, last_window) ! && !EQ (window, selected_window)) ! { ! inev.ie.kind = SELECT_WINDOW_EVENT; ! inev.ie.frame_or_window = window; ! } ! ! last_window=window; } if (!note_mouse_movement (f, &event.xmotion)) help_echo_string = previous_help_echo_string; --- 6583,6608 ---- event.xmotion.x, event.xmotion.y, 0, 0, 0, 0); ! if (NUMBERP (mouse_autoselect_window)) ! /* Let mouse_autoselect_window_function handle this. */ ! { ! if (!NILP (mouse_autoselect_window_function)) ! call2 (mouse_autoselect_window_function, ! last_window, window); ! } ! else if (WINDOWP(window) ! && !EQ (window, last_window) ! && !EQ (window, selected_window)) ! /* Window will be selected only when it is not ! selected now and last mouse movement event was ! not in it. Minibuffer window will be selected ! iff it is active. */ ! { ! call1 (Vrun_hooks, Qmouse_leave_buffer_hook); ! inev.ie.kind = SELECT_WINDOW_EVENT; ! inev.ie.frame_or_window = window; ! } ! last_window = window; } if (!note_mouse_movement (f, &event.xmotion)) help_echo_string = previous_help_echo_string; *** cus-start.el Sun Jul 2 11:41:42 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 Sun Jul 2 09:49:56 2006 --- mouse.el Mon Jul 3 19:30:50 2006 *************** *** 1728,1733 **** --- 1728,1793 ---- (buffer-substring (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))))))) + + (defvar mouse-autoselect-window-timer nil + "Timer used by timer-driven window autoselection.") + + (defvar mouse-autoselect-window-position nil + "Last mouse position calculated during timer-driven window autoselection.") + + (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 (last-window current-window) + "Initiate timer-driven window autoselection. + This function is called when the mouse was moved and the variable + `mouse-autoselect-window' has a numeric value. LAST-WINDOW is the last + window where the mouse was seen. CURRENT-WINDOW is the window where the + mouse now appears. Both arguments are currently ignored." + (mouse-autoselect-window-cancel) + (let ((delay (max (if (numberp mouse-autoselect-window) + mouse-autoselect-window + 0.5) + ;; Avoid a zero delay here, use 0.1 secs as minimum. + 0.1))) + ;; Reset `mouse-autoselect-window-position' to nil. We can't set this to + ;; `mouse-position' immediately since we'd risk breaking active region + ;; highlighting and mode-line related functions. As a consequence, a window + ;; can't be selected before `mouse-autoselect-window' has elapsed twice. + (setq mouse-autoselect-window-position nil) + (setq mouse-autoselect-window-timer + (run-at-time t delay 'mouse-autoselect-window-select)) + (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) + + (setq mouse-autoselect-window-function 'mouse-autoselect-window-start) + + (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))) + (if (equal mouse-position mouse-autoselect-window-position) + ;; mouse-position has stabilized, try to select a new window, + ;; cancel timer-driven autoselection in any case. + (let* ((window (window-at (cadr mouse-position) + (cddr mouse-position) + (car mouse-position)))) + (setq mouse-autoselect-window-position nil) + (mouse-autoselect-window-cancel) + (when (and window (not (eq window (selected-window))) + (or (not (window-minibuffer-p window)) + (eq window (active-minibuffer-window)))) + (run-hooks 'mouse-leave-buffer-hook) + (select-window window))) + ;; mouse-position has not stabilized yet, record new position. + (setq mouse-autoselect-window-position mouse-position))) + (error nil))) (defcustom mouse-buffer-menu-maxlen 20 "*Number of buffers in one pane (submenu) of the buffer menu. --------------010402020200090603080604 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------010402020200090603080604--