Mercurial > emacs
comparison lisp/window.el @ 78994:c864c3573cef
(mouse-autoselect-window-cancel): Don't cancel for
select-window or select-frame events.
(handle-select-window): When autoselecting window set input
focus. Restructure.
author | Martin Rudalics <rudalics@gmx.at> |
---|---|
date | Sat, 06 Oct 2007 10:17:00 +0000 |
parents | 7c8949dbfa0d |
children | 6bdc5346c3fa 5039706521c9 |
comparison
equal
deleted
inserted
replaced
78993:b6585f51bde9 | 78994:c864c3573cef |
---|---|
803 | 803 |
804 (defun mouse-autoselect-window-cancel (&optional force) | 804 (defun mouse-autoselect-window-cancel (&optional force) |
805 "Cancel delayed window autoselection. | 805 "Cancel delayed window autoselection. |
806 Optional argument FORCE means cancel unconditionally." | 806 Optional argument FORCE means cancel unconditionally." |
807 (unless (and (not force) | 807 (unless (and (not force) |
808 ;; Don't cancel while the user drags a scroll bar. | 808 ;; Don't cancel for select-window or select-frame events |
809 (eq this-command 'scroll-bar-toolkit-scroll) | 809 ;; or when the user drags a scroll bar. |
810 (memq (nth 4 (event-end last-input-event)) | 810 (or (memq this-command |
811 '(handle end-scroll))) | 811 '(handle-select-window handle-switch-frame)) |
812 (and (eq this-command 'scroll-bar-toolkit-scroll) | |
813 (memq (nth 4 (event-end last-input-event)) | |
814 '(handle end-scroll))))) | |
812 (setq mouse-autoselect-window-state nil) | 815 (setq mouse-autoselect-window-state nil) |
813 (when (timerp mouse-autoselect-window-timer) | 816 (when (timerp mouse-autoselect-window-timer) |
814 (cancel-timer mouse-autoselect-window-timer)) | 817 (cancel-timer mouse-autoselect-window-timer)) |
815 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) | 818 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel))) |
816 | 819 |
894 | 897 |
895 (defun handle-select-window (event) | 898 (defun handle-select-window (event) |
896 "Handle select-window events." | 899 "Handle select-window events." |
897 (interactive "e") | 900 (interactive "e") |
898 (let ((window (posn-window (event-start event)))) | 901 (let ((window (posn-window (event-start event)))) |
899 (when (and (window-live-p window) | 902 (unless (or (not (window-live-p window)) |
900 ;; Don't switch if we're currently in the minibuffer. | 903 ;; Don't switch if we're currently in the minibuffer. |
901 ;; This tries to work around problems where the minibuffer gets | 904 ;; This tries to work around problems where the |
902 ;; unselected unexpectedly, and where you then have to move | 905 ;; minibuffer gets unselected unexpectedly, and where |
903 ;; your mouse all the way down to the minibuffer to select it. | 906 ;; you then have to move your mouse all the way down to |
904 (not (window-minibuffer-p (selected-window))) | 907 ;; the minibuffer to select it. |
905 ;; Don't switch to a minibuffer window unless it's active. | 908 (window-minibuffer-p (selected-window)) |
906 (or (not (window-minibuffer-p window)) | 909 ;; Don't switch to minibuffer window unless it's active. |
907 (minibuffer-window-active-p window))) | 910 (and (window-minibuffer-p window) |
908 (unless (and (numberp mouse-autoselect-window) | 911 (not (minibuffer-window-active-p window))) |
909 (not (zerop mouse-autoselect-window)) | 912 ;; Don't switch when autoselection shall be delayed. |
910 (not (eq mouse-autoselect-window-state 'select)) | 913 (and (numberp mouse-autoselect-window) |
911 (progn | 914 (not (zerop mouse-autoselect-window)) |
912 ;; Cancel any delayed autoselection. | 915 (not (eq mouse-autoselect-window-state 'select)) |
913 (mouse-autoselect-window-cancel t) | 916 (progn |
914 ;; Start delayed autoselection from current mouse position | 917 ;; Cancel any delayed autoselection. |
915 ;; and window. | 918 (mouse-autoselect-window-cancel t) |
916 (mouse-autoselect-window-start (mouse-position) window) | 919 ;; Start delayed autoselection from current mouse position |
917 ;; Executing a command cancels delayed autoselection. | 920 ;; and window. |
918 (add-hook | 921 (mouse-autoselect-window-start (mouse-position) window) |
919 'pre-command-hook 'mouse-autoselect-window-cancel))) | 922 ;; Executing a command cancels delayed autoselection. |
923 (add-hook | |
924 'pre-command-hook 'mouse-autoselect-window-cancel)))) | |
925 (when mouse-autoselect-window | |
920 ;; Reset state of delayed autoselection. | 926 ;; Reset state of delayed autoselection. |
921 (setq mouse-autoselect-window-state nil) | 927 (setq mouse-autoselect-window-state nil) |
922 (when mouse-autoselect-window | 928 ;; Set input focus to handle cross-frame movement. Bind |
923 ;; Run `mouse-leave-buffer-hook' when autoselecting window. | 929 ;; `focus-follows-mouse' to avoid moving the mouse cursor. |
924 (run-hooks 'mouse-leave-buffer-hook)) | 930 (let (focus-follows-mouse) |
925 (select-window window))))) | 931 (select-frame-set-input-focus (window-frame window))) |
932 ;; Run `mouse-leave-buffer-hook' when autoselecting window. | |
933 (run-hooks 'mouse-leave-buffer-hook)) | |
934 (select-window window)))) | |
926 | 935 |
927 (define-key ctl-x-map "2" 'split-window-vertically) | 936 (define-key ctl-x-map "2" 'split-window-vertically) |
928 (define-key ctl-x-map "3" 'split-window-horizontally) | 937 (define-key ctl-x-map "3" 'split-window-horizontally) |
929 (define-key ctl-x-map "}" 'enlarge-window-horizontally) | 938 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
930 (define-key ctl-x-map "{" 'shrink-window-horizontally) | 939 (define-key ctl-x-map "{" 'shrink-window-horizontally) |