Mercurial > emacs
comparison lisp/window.el @ 90650:02cf29720f31
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 490-504)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 161-163)
- Update from CVS
- Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-130
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 07 Nov 2006 23:22:48 +0000 |
parents | 7eeafaaa9eab 97a25a5ed8a9 |
children | 95d0cdf160ea |
comparison
equal
deleted
inserted
replaced
90649:d53934e7ddef | 90650:02cf29720f31 |
---|---|
793 "Last mouse position recorded by delayed window autoselection.") | 793 "Last mouse position recorded by delayed window autoselection.") |
794 | 794 |
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. |
800 Possible values are `suspend' \(suspend autoselection after a menu or | |
801 scrollbar 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. |
803 Optional argument FORCE means cancel unconditionally." | 806 Optional argument FORCE means cancel unconditionally." |
804 (unless (and (not force) | 807 (unless (and (not force) |
805 ;; Don't cancel while the user drags a scroll bar. | 808 ;; Don't cancel while the user drags a scroll bar. |
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. |
816 Called when Emacs detects that the mouse has moved to the non-selected | 819 MOUSE-POSITION is the last position where the mouse was seen as returned |
817 window WINDOW and the variable `mouse-autoselect-window' has a numeric, | 820 by `mouse-position'. Optional argument WINDOW non-nil denotes the |
818 non-zero value. The return value is non-nil iff delayed autoselection | 821 window where the mouse was seen. Optional argument SUSPEND non-nil |
819 started successfully. Delayed window autoselection is canceled when the | 822 means suspend autoselection." |
820 mouse 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. |
838 If the mouse position has stabilized in a non-selected window, select | 835 If the mouse position has stabilized in a non-selected window, select |
839 that window. The minibuffer window is selected iff the minibuffer is | 836 that window. The minibuffer window is selected iff the minibuffer is |
840 active. This function is run by `mouse-autoselect-window-timer'." | 837 active. 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) |
849 ;; If `mouse-autoselect-window' is positive, select | 858 ;; If `mouse-autoselect-window' is positive, select |
850 ;; window if the window is the same as before. | 859 ;; window if the window is the same as before. |
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)))) |
875 ((or (and window (eq window (selected-window))) | 883 ((or (and window (eq window (selected-window))) |
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) |
890 "Handle select-window events." | 896 "Handle select-window events." |
891 (interactive "e") | 897 (interactive "e") |
899 ;; Don't switch to a minibuffer window unless it's active. | 905 ;; Don't switch to a minibuffer window unless it's active. |
900 (or (not (window-minibuffer-p window)) | 906 (or (not (window-minibuffer-p window)) |
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)) |
915 (select-window window))))) | 925 (select-window window))))) |
916 | 926 |