aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2006-11-05 12:20:12 +0000
committerEli Zaretskii2006-11-05 12:20:12 +0000
commit6a6af58e32e97da724443792ccfe756f2a5a4873 (patch)
treebed18fe67e2e0cf4de541dbedf99c83b6c4fd629
parent508fb067d7fe7ee20be0dd7ca3232a3017e383f9 (diff)
downloademacs-6a6af58e32e97da724443792ccfe756f2a5a4873.tar.gz
emacs-6a6af58e32e97da724443792ccfe756f2a5a4873.zip
(mouse-autoselect-window-now): Remove variable.
(mouse-autoselect-window-state): New variable. (mouse-autoselect-window-start, mouse-autoselect-window-cancel) (mouse-autoselect-window-select, handle-select-window): Rewritten to make mouse-autoselect-window-timer a one-shot timer. Suspend delayed autoselection during menu or popup dialog.
-rw-r--r--lisp/window.el100
1 files changed, 55 insertions, 45 deletions
diff --git a/lisp/window.el b/lisp/window.el
index ac4fc0b7c96..2316eb916eb 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -795,8 +795,11 @@ and the buffer that is killed or buried is the one in that window."
795(defvar mouse-autoselect-window-window nil 795(defvar mouse-autoselect-window-window nil
796 "Last window recorded by delayed window autoselection.") 796 "Last window recorded by delayed window autoselection.")
797 797
798(defvar mouse-autoselect-window-now nil 798(defvar mouse-autoselect-window-state nil
799 "When non-nil don't delay autoselection in `handle-select-window'.") 799 "When non-nil, special state of delayed window autoselection.
800Possible values are `suspend' \(suspend autoselection after a menu or
801scrollbar interaction\) and `select' \(the next invocation of
802'handle-select-window' shall select the window immediately\).")
800 803
801(defun mouse-autoselect-window-cancel (&optional force) 804(defun mouse-autoselect-window-cancel (&optional force)
802 "Cancel delayed window autoselection. 805 "Cancel delayed window autoselection.
@@ -806,32 +809,26 @@ Optional argument FORCE means cancel unconditionally."
806 (eq this-command 'scroll-bar-toolkit-scroll) 809 (eq this-command 'scroll-bar-toolkit-scroll)
807 (memq (nth 4 (event-end last-input-event)) 810 (memq (nth 4 (event-end last-input-event))
808 '(handle end-scroll))) 811 '(handle end-scroll)))
809 (setq mouse-autoselect-window-now nil) 812 (setq mouse-autoselect-window-state nil)
810 (when (timerp mouse-autoselect-window-timer) 813 (when (timerp mouse-autoselect-window-timer)
811 (cancel-timer mouse-autoselect-window-timer)) 814 (cancel-timer mouse-autoselect-window-timer))
812 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) 815 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
813 816
814(defun mouse-autoselect-window-start (window) 817(defun mouse-autoselect-window-start (mouse-position &optional window suspend)
815 "Start delayed window autoselection. 818 "Start delayed window autoselection.
816Called when Emacs detects that the mouse has moved to the non-selected 819MOUSE-POSITION is the last position where the mouse was seen as returned
817window WINDOW and the variable `mouse-autoselect-window' has a numeric, 820by `mouse-position'. Optional argument WINDOW non-nil denotes the
818non-zero value. The return value is non-nil iff delayed autoselection 821window where the mouse was seen. Optional argument SUSPEND non-nil
819started successfully. Delayed window autoselection is canceled when the 822means suspend autoselection."
820mouse position has stabilized or a command is executed." 823 ;; Record values for MOUSE-POSITION, WINDOW, and SUSPEND.
821 ;; Cancel any active window autoselection. 824 (setq mouse-autoselect-window-position mouse-position)
822 (mouse-autoselect-window-cancel t) 825 (when window (setq mouse-autoselect-window-window window))
823 ;; Record current mouse position in `mouse-autoselect-window-position' and 826 (setq mouse-autoselect-window-state (when suspend 'suspend))
824 ;; WINDOW in `mouse-autoselect-window-window'. 827 ;; Install timer which runs `mouse-autoselect-window-select' after
825 (setq mouse-autoselect-window-position (mouse-position))
826 (setq mouse-autoselect-window-window window)
827 ;; Install timer which runs `mouse-autoselect-window-select' every
828 ;; `mouse-autoselect-window' seconds. 828 ;; `mouse-autoselect-window' seconds.
829 (setq mouse-autoselect-window-timer 829 (setq mouse-autoselect-window-timer
830 (run-at-time 830 (run-at-time
831 (abs mouse-autoselect-window) (abs mouse-autoselect-window) 831 (abs mouse-autoselect-window) nil 'mouse-autoselect-window-select)))
832 'mouse-autoselect-window-select))
833 ;; Executing a command cancels window autoselection.
834 (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
835 832
836(defun mouse-autoselect-window-select () 833(defun mouse-autoselect-window-select ()
837 "Select window with delayed window autoselection. 834 "Select window with delayed window autoselection.
@@ -840,9 +837,21 @@ that window. The minibuffer window is selected iff the minibuffer is
840active. This function is run by `mouse-autoselect-window-timer'." 837active. This function is run by `mouse-autoselect-window-timer'."
841 (condition-case nil 838 (condition-case nil
842 (let* ((mouse-position (mouse-position)) 839 (let* ((mouse-position (mouse-position))
843 (window (window-at (cadr mouse-position) (cddr mouse-position) 840 (window
844 (car mouse-position)))) 841 (condition-case nil
842 (window-at (cadr mouse-position) (cddr mouse-position)
843 (car mouse-position))
844 (error nil))))
845 (cond 845 (cond
846 ((or (menu-or-popup-active-p)
847 (and window
848 (not (coordinates-in-window-p (cdr mouse-position) window))))
849 ;; A menu / popup dialog is active or the mouse is on the scroll-bar
850 ;; of WINDOW, temporarily suspend delayed autoselection.
851 (mouse-autoselect-window-start mouse-position nil t))
852 ((eq mouse-autoselect-window-state 'suspend)
853 ;; Delayed autoselection was temporarily suspended, reenable it.
854 (mouse-autoselect-window-start mouse-position))
846 ((and window (not (eq window (selected-window))) 855 ((and window (not (eq window (selected-window)))
847 (or (not (numberp mouse-autoselect-window)) 856 (or (not (numberp mouse-autoselect-window))
848 (and (> mouse-autoselect-window 0) 857 (and (> mouse-autoselect-window 0)
@@ -851,24 +860,23 @@ active. This function is run by `mouse-autoselect-window-timer'."
851 (eq window mouse-autoselect-window-window)) 860 (eq window mouse-autoselect-window-window))
852 ;; Otherwise select window iff the mouse is at the same 861 ;; Otherwise select window iff the mouse is at the same
853 ;; position as before. Observe that the first test after 862 ;; position as before. Observe that the first test after
854 ;; `mouse-autoselect-window-start' usually fails since the 863 ;; starting autoselection usually fails since the value of
855 ;; value of `mouse-autoselect-window-position' recorded there 864 ;; `mouse-autoselect-window-position' recorded there is the
856 ;; is the position where the mouse has entered the new window 865 ;; position where the mouse has entered the new window and
857 ;; and not necessarily where the mouse has stopped moving. 866 ;; not necessarily where the mouse has stopped moving.
858 (equal mouse-position mouse-autoselect-window-position)) 867 (equal mouse-position mouse-autoselect-window-position))
859 ;; The minibuffer is a candidate window iff it's active. 868 ;; The minibuffer is a candidate window iff it's active.
860 (or (not (window-minibuffer-p window)) 869 (or (not (window-minibuffer-p window))
861 (eq window (active-minibuffer-window)))) 870 (eq window (active-minibuffer-window))))
862 ;; Mouse position has stabilized in non-selected window: Cancel window 871 ;; Mouse position has stabilized in non-selected window: Cancel
863 ;; autoselection and try to select that window. 872 ;; delayed autoselection and try to select that window.
864 (mouse-autoselect-window-cancel t) 873 (mouse-autoselect-window-cancel t)
865 ;; Select window where mouse appears unless the selected window is the 874 ;; Select window where mouse appears unless the selected window is the
866 ;; minibuffer. Use `unread-command-events' in order to execute pre- 875 ;; minibuffer. Use `unread-command-events' in order to execute pre-
867 ;; and post-command hooks and trigger idle timers. To avoid delaying 876 ;; and post-command hooks and trigger idle timers. To avoid delaying
868 ;; autoselection again, temporarily set `mouse-autoselect-window-now' 877 ;; autoselection again, set `mouse-autoselect-window-state'."
869 ;; to t.
870 (unless (window-minibuffer-p (selected-window)) 878 (unless (window-minibuffer-p (selected-window))
871 (setq mouse-autoselect-window-now t) 879 (setq mouse-autoselect-window-state 'select)
872 (setq unread-command-events 880 (setq unread-command-events
873 (cons (list 'select-window (list window)) 881 (cons (list 'select-window (list window))
874 unread-command-events)))) 882 unread-command-events))))
@@ -876,14 +884,12 @@ active. This function is run by `mouse-autoselect-window-timer'."
876 (not (numberp mouse-autoselect-window)) 884 (not (numberp mouse-autoselect-window))
877 (equal mouse-position mouse-autoselect-window-position)) 885 (equal mouse-position mouse-autoselect-window-position))
878 ;; Mouse position has either stabilized in the selected window or at 886 ;; Mouse position has either stabilized in the selected window or at
879 ;; `mouse-autoselect-window-position': Cancel window autoselection. 887 ;; `mouse-autoselect-window-position': Cancel delayed autoselection.
880 (mouse-autoselect-window-cancel t)) 888 (mouse-autoselect-window-cancel t))
881 (t 889 (t
882 ;; Mouse position has not stabilized yet, record new mouse position in 890 ;; Mouse position has not stabilized yet, resume delayed
883 ;; `mouse-autoselect-window-position' and any window at that position 891 ;; autoselection.
884 ;; in `mouse-autoselect-window-window'. 892 (mouse-autoselect-window-start mouse-position window))))
885 (setq mouse-autoselect-window-position mouse-position)
886 (setq mouse-autoselect-window-window window))))
887 (error nil))) 893 (error nil)))
888 894
889(defun handle-select-window (event) 895(defun handle-select-window (event)
@@ -901,14 +907,18 @@ active. This function is run by `mouse-autoselect-window-timer'."
901 (minibuffer-window-active-p window))) 907 (minibuffer-window-active-p window)))
902 (unless (and (numberp mouse-autoselect-window) 908 (unless (and (numberp mouse-autoselect-window)
903 (not (zerop mouse-autoselect-window)) 909 (not (zerop mouse-autoselect-window))
904 (not mouse-autoselect-window-now) 910 (not (eq mouse-autoselect-window-state 'select))
905 ;; When `mouse-autoselect-window' has a numeric, non-zero 911 (progn
906 ;; value, delay window autoselection by that value. 912 ;; Cancel any delayed autoselection.
907 ;; `mouse-autoselect-window-start' returns non-nil iff it 913 (mouse-autoselect-window-cancel t)
908 ;; successfully installed a timer for this purpose. 914 ;; Start delayed autoselection from current mouse position
909 (mouse-autoselect-window-start window)) 915 ;; and window.
910 ;; Re-enable delayed window autoselection. 916 (mouse-autoselect-window-start (mouse-position) window)
911 (setq mouse-autoselect-window-now nil) 917 ;; Executing a command cancels delayed autoselection.
918 (add-hook
919 'pre-command-hook 'mouse-autoselect-window-cancel)))
920 ;; Reset state of delayed autoselection.
921 (setq mouse-autoselect-window-state nil)
912 (when mouse-autoselect-window 922 (when mouse-autoselect-window
913 ;; Run `mouse-leave-buffer-hook' when autoselecting window. 923 ;; Run `mouse-leave-buffer-hook' when autoselecting window.
914 (run-hooks 'mouse-leave-buffer-hook)) 924 (run-hooks 'mouse-leave-buffer-hook))