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 de lay] Date: Wed, 19 Jul 2006 11:56:19 +0200 Message-ID: <44BE01C3.70801@gmx.at> References: <81CCA6588E60BB42BE68BD029ED4826008837542@wimex2.wim.midas-kapiti.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030501000207010309070904" X-Trace: sea.gmane.org 1153303819 11923 80.91.229.2 (19 Jul 2006 10:10:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 19 Jul 2006 10:10:19 +0000 (UTC) Cc: "'emacs-devel@gnu.org'" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 19 12:10:17 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 1G390K-0002vU-4K for ged-emacs-devel@m.gmane.org; Wed, 19 Jul 2006 12:10:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G390J-0004ec-I2 for ged-emacs-devel@m.gmane.org; Wed, 19 Jul 2006 06:10:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G3904-0004eN-HE for emacs-devel@gnu.org; Wed, 19 Jul 2006 06:09:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G3903-0004eA-SC for emacs-devel@gnu.org; Wed, 19 Jul 2006 06:09:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G3903-0004ds-DE for emacs-devel@gnu.org; Wed, 19 Jul 2006 06:09:51 -0400 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1G3938-00050B-7v for emacs-devel@gnu.org; Wed, 19 Jul 2006 06:13:03 -0400 Original-Received: (qmail invoked by alias); 19 Jul 2006 10:09:47 -0000 Original-Received: from N876P005.adsl.highway.telekom.at (EHLO [62.47.53.101]) [62.47.53.101] by mail.gmx.net (mp010) with SMTP; 19 Jul 2006 12:09:47 +0200 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: "Marshall, Simon" In-Reply-To: <81CCA6588E60BB42BE68BD029ED4826008837542@wimex2.wim.midas-kapiti.com> 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:57330 Archived-At: This is a multi-part message in MIME format. --------------030501000207010309070904 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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 #) > mouse-autoselect-window-start() > handle-select-window((select-window (#))) > 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 --------------030501000207010309070904 Content-Type: text/plain; name="autoselect-window.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="autoselect-window.patch" *** 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))) + (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) --------------030501000207010309070904 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 --------------030501000207010309070904--