comparison lisp/window.el @ 90601:a1a25ac6c88a

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 427-436) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 134-136) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-110
author Miles Bader <miles@gnu.org>
date Thu, 14 Sep 2006 09:24:00 +0000
parents 858cb33ae39d 455031002c62
children 7eeafaaa9eab
comparison
equal deleted inserted replaced
90600:84dd84b43e1b 90601:a1a25ac6c88a
775 (bury-buffer buffer)) 775 (bury-buffer buffer))
776 776
777 ;; Maybe get rid of the window. 777 ;; Maybe get rid of the window.
778 (and window (not window-handled) (not window-solitary) 778 (and window (not window-handled) (not window-solitary)
779 (delete-window window)))) 779 (delete-window window))))
780
781 (defvar mouse-autoselect-window-timer nil
782 "Timer used by delayed window autoselection.")
783
784 (defvar mouse-autoselect-window-position nil
785 "Last mouse position recorded by delayed window autoselection.")
786
787 (defvar mouse-autoselect-window-window nil
788 "Last window recorded by delayed window autoselection.")
789
790 (defvar mouse-autoselect-window-now nil
791 "When non-nil don't delay autoselection in `handle-select-window'.")
792
793 (defun mouse-autoselect-window-cancel (&optional force)
794 "Cancel delayed window autoselection.
795 Optional argument FORCE means cancel unconditionally."
796 (unless (and (not force)
797 ;; Don't cancel while the user drags a scroll bar.
798 (eq this-command 'scroll-bar-toolkit-scroll)
799 (memq (nth 4 (event-end last-input-event))
800 '(handle end-scroll)))
801 (setq mouse-autoselect-window-now nil)
802 (when (timerp mouse-autoselect-window-timer)
803 (cancel-timer mouse-autoselect-window-timer))
804 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
805
806 (defun mouse-autoselect-window-start (window)
807 "Start delayed window autoselection.
808 Called when Emacs detects that the mouse has moved to the non-selected
809 window WINDOW and the variable `mouse-autoselect-window' has a numeric,
810 non-zero value. The return value is non-nil iff delayed autoselection
811 started successfully. Delayed window autoselection is canceled when the
812 mouse position has stabilized or a command is executed."
813 ;; Cancel any active window autoselection.
814 (mouse-autoselect-window-cancel t)
815 ;; Record current mouse position in `mouse-autoselect-window-position' and
816 ;; WINDOW in `mouse-autoselect-window-window'.
817 (setq mouse-autoselect-window-position (mouse-position))
818 (setq mouse-autoselect-window-window window)
819 ;; Install timer which runs `mouse-autoselect-window-select' every
820 ;; `mouse-autoselect-window' seconds.
821 (setq mouse-autoselect-window-timer
822 (run-at-time
823 (abs mouse-autoselect-window) (abs mouse-autoselect-window)
824 'mouse-autoselect-window-select))
825 ;; Executing a command cancels window autoselection.
826 (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
827
828 (defun mouse-autoselect-window-select ()
829 "Select window with delayed window autoselection.
830 If the mouse position has stabilized in a non-selected window, select
831 that window. The minibuffer window is selected iff the minibuffer is
832 active. This function is run by `mouse-autoselect-window-timer'."
833 (condition-case nil
834 (let* ((mouse-position (mouse-position))
835 (window (window-at (cadr mouse-position) (cddr mouse-position)
836 (car mouse-position))))
837 (cond
838 ((and window (not (eq window (selected-window)))
839 (or (not (numberp mouse-autoselect-window))
840 (and (> mouse-autoselect-window 0)
841 ;; If `mouse-autoselect-window' is positive, select
842 ;; window if the window is the same as before.
843 (eq window mouse-autoselect-window-window))
844 ;; Otherwise select window iff the mouse is at the same
845 ;; position as before. Observe that the first test after
846 ;; `mouse-autoselect-window-start' usually fails since the
847 ;; value of `mouse-autoselect-window-position' recorded there
848 ;; is the position where the mouse has entered the new window
849 ;; and not necessarily where the mouse has stopped moving.
850 (equal mouse-position mouse-autoselect-window-position))
851 ;; The minibuffer is a candidate window iff it's active.
852 (or (not (window-minibuffer-p window))
853 (eq window (active-minibuffer-window))))
854 ;; Mouse position has stabilized in non-selected window: Cancel window
855 ;; autoselection and try to select that window.
856 (mouse-autoselect-window-cancel t)
857 ;; Select window where mouse appears unless the selected window is the
858 ;; minibuffer. Use `unread-command-events' in order to execute pre-
859 ;; and post-command hooks and trigger idle timers. To avoid delaying
860 ;; autoselection again, temporarily set `mouse-autoselect-window-now'
861 ;; to t.
862 (unless (window-minibuffer-p (selected-window))
863 (setq mouse-autoselect-window-now t)
864 (setq unread-command-events
865 (cons (list 'select-window (list window))
866 unread-command-events))))
867 ((or (and window (eq window (selected-window)))
868 (not (numberp mouse-autoselect-window))
869 (equal mouse-position mouse-autoselect-window-position))
870 ;; Mouse position has either stabilized in the selected window or at
871 ;; `mouse-autoselect-window-position': Cancel window autoselection.
872 (mouse-autoselect-window-cancel t))
873 (t
874 ;; Mouse position has not stabilized yet, record new mouse position in
875 ;; `mouse-autoselect-window-position' and any window at that position
876 ;; in `mouse-autoselect-window-window'.
877 (setq mouse-autoselect-window-position mouse-position)
878 (setq mouse-autoselect-window-window window))))
879 (error nil)))
780 880
781 (defun handle-select-window (event) 881 (defun handle-select-window (event)
782 "Handle select-window events." 882 "Handle select-window events."
783 (interactive "e") 883 (interactive "e")
784 (let ((window (posn-window (event-start event)))) 884 (let ((window (posn-window (event-start event))))
785 (if (and (window-live-p window) 885 (when (and (window-live-p window)
786 ;; Don't switch if we're currently in the minibuffer. 886 ;; Don't switch if we're currently in the minibuffer.
787 ;; This tries to work around problems where the minibuffer gets 887 ;; This tries to work around problems where the minibuffer gets
788 ;; unselected unexpectedly, and where you then have to move 888 ;; unselected unexpectedly, and where you then have to move
789 ;; your mouse all the way down to the minibuffer to select it. 889 ;; your mouse all the way down to the minibuffer to select it.
790 (not (window-minibuffer-p (selected-window))) 890 (not (window-minibuffer-p (selected-window)))
791 ;; Don't switch to a minibuffer window unless it's active. 891 ;; Don't switch to a minibuffer window unless it's active.
792 (or (not (window-minibuffer-p window)) 892 (or (not (window-minibuffer-p window))
793 (minibuffer-window-active-p window))) 893 (minibuffer-window-active-p window)))
794 (select-window window)))) 894 (unless (and (numberp mouse-autoselect-window)
895 (not (zerop mouse-autoselect-window))
896 (not mouse-autoselect-window-now)
897 ;; When `mouse-autoselect-window' has a numeric, non-zero
898 ;; value, delay window autoselection by that value.
899 ;; `mouse-autoselect-window-start' returns non-nil iff it
900 ;; successfully installed a timer for this purpose.
901 (mouse-autoselect-window-start window))
902 ;; Re-enable delayed window autoselection.
903 (setq mouse-autoselect-window-now nil)
904 (when mouse-autoselect-window
905 ;; Run `mouse-leave-buffer-hook' when autoselecting window.
906 (run-hooks 'mouse-leave-buffer-hook))
907 (select-window window)))))
795 908
796 (define-key ctl-x-map "2" 'split-window-vertically) 909 (define-key ctl-x-map "2" 'split-window-vertically)
797 (define-key ctl-x-map "3" 'split-window-horizontally) 910 (define-key ctl-x-map "3" 'split-window-horizontally)
798 (define-key ctl-x-map "}" 'enlarge-window-horizontally) 911 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
799 (define-key ctl-x-map "{" 'shrink-window-horizontally) 912 (define-key ctl-x-map "{" 'shrink-window-horizontally)