Mercurial > emacs
changeset 8519:7802e26b3bfd
(mouse-drag-mode-line): New function (from mldrag.el,
but changed a little). Put it on mode-line down-mouse-1.
(mouse-select-window): Bind to mode-line drag-mouse-1.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 11 Aug 1994 20:35:31 +0000 |
parents | 44ff33b29c3e |
children | 30a34f79f268 |
files | lisp/mouse.el |
diffstat | 1 files changed, 108 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/mouse.el Thu Aug 11 20:25:20 1994 +0000 +++ b/lisp/mouse.el Thu Aug 11 20:35:31 1994 +0000 @@ -39,6 +39,8 @@ (defvar mouse-yank-at-point nil "*If non-nil, mouse yank commands yank at point instead of at click.") +;; Commands that operate on windows. + (defun mouse-minibuffer-check (event) (let ((w (posn-window (event-start event)))) (and (window-minibuffer-p w) @@ -113,6 +115,110 @@ (split-window-horizontally (min (max new-width first-col) last-col)))))) +(defun mouse-drag-mode-line (start-event) + "Change the height of a window by dragging on the mode line." + (interactive "e") + (let ((done nil) + (echo-keystrokes 0) + (start-event-frame (window-frame (car (car (cdr start-event))))) + (start-event-window (car (car (cdr start-event)))) + (start-nwindows (count-windows t)) + (old-selected-window (selected-window)) + should-enlarge-minibuffer + event mouse minibuffer y top bot edges wconfig params growth) + (setq params (frame-parameters)) + (if (and (not (setq minibuffer (cdr (assq 'minibuffer params)))) + (one-window-p t)) + (error "Attempt to resize sole window")) + (track-mouse + (progn + ;; enlarge-window only works on the selected window, so + ;; we must select the window where the start event originated. + ;; unwind-protect will restore the old selected window later. + (select-window start-event-window) + ;; if this is the bottommost ordinary window, then to + ;; move its modeline the minibuffer must be enlarged. + (setq should-enlarge-minibuffer + (and minibuffer + (not (one-window-p t)) + (= (nth 1 (window-edges minibuffer)) + (nth 3 (window-edges))))) + ;; loop reading events and sampling the position of + ;; the mouse. + (while (not done) + (setq event (read-event) + mouse (mouse-position)) + ;; do nothing if + ;; - there is a switch-frame event. + ;; - the mouse isn't in the frame that we started in + ;; - the mouse isn't in any Emacs frame + ;; drag if + ;; - there is a mouse-movement event + ;; - there is a scroll-bar-movement event + ;; (same as mouse movement for our purposes) + ;; quit if + ;; - there is a keyboard event or some other unknown event + ;; unknown event. + (cond ((integerp event) + (setq done t)) + ((eq (car event) 'switch-frame) + nil) + ((not (memq (car event) + '(mouse-movement scroll-bar-movement))) + (if (consp event) + (setq unread-command-events + (cons event unread-command-events))) + (setq done t)) + ((not (eq (car mouse) start-event-frame)) + nil) + ((null (car (cdr mouse))) + nil) + (t + (setq y (cdr (cdr mouse)) + edges (window-edges) + top (nth 1 edges) + bot (nth 3 edges)) + ;; scale back a move that would make the + ;; window too short. + (cond ((< (- y top -1) window-min-height) + (setq y (+ top window-min-height -1)))) + ;; compute size change needed + (setq growth (- y bot -1) + wconfig (current-window-configuration)) + ;; grow/shrink minibuffer? + (if should-enlarge-minibuffer + (progn + ;; yes. briefly select minibuffer so + ;; enlarge-window will affect the + ;; correct window. + (select-window minibuffer) + ;; scale back shrinkage if it would + ;; make the minibuffer less than 1 + ;; line tall. + (if (and (> growth 0) + (< (- (window-height minibuffer) + growth) + 1)) + (setq growth (1- (window-height minibuffer)))) + (enlarge-window (- growth)) + (select-window start-event-window)) + ;; no. grow/shrink the selected window + (enlarge-window growth)) + ;; if this window's growth caused another + ;; window to be deleted because it was too + ;; short, rescind the change. + ;; + ;; if size change caused space to be stolen + ;; from a window above this one, rescind the + ;; change, but only if we didn't grow/srhink + ;; the minibuffer. minibuffer size changes + ;; can cause all windows to shrink... no way + ;; around it. + (if (or (/= start-nwindows (count-windows t)) + (and (not should-enlarge-minibuffer) + (/= top (nth 1 (window-edges))))) + (set-window-configuration wconfig))))))))) + (defun mouse-set-point (event) "Move point to the position clicked on with the mouse. This should be bound to a mouse click event type." @@ -1343,6 +1449,8 @@ ;; (global-set-key [S-mouse-1] 'mouse-set-mark) (global-set-key [mode-line mouse-1] 'mouse-select-window) +(global-set-key [mode-line drag-mouse-1] 'mouse-select-window) +(global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line) (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows) (global-set-key [mode-line mouse-3] 'mouse-delete-window) (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)