- (progn
- ;; if this is the bottommost ordinary window, then to
- ;; move its modeline the minibuffer must be enlarged.
- (setq should-enlarge-minibuffer
- (and minibuffer
- mode-line-p
- (not (one-window-p t))
- (= (nth 1 (window-edges minibuffer))
- (nth 3 (window-edges start-event-window)))))
-
- ;; 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.
- (cond ((not (consp event))
- (setq done t))
-
- ((memq (car event) '(switch-frame select-window))
- nil)
-
- ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
- (when (consp event)
- ;; Do not unread a drag-mouse-1 event since it will cause the
- ;; selection of the window above when dragging the modeline
- ;; above the selected window.
- (unless (eq (car event) 'drag-mouse-1)
- (push 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 start-event-window)
- top (nth 1 edges)
- bot (nth 3 edges))
-
- ;; compute size change needed
- (cond (mode-line-p
- (setq growth (- y bot -1)))
- (t ; header line
- (when (< (- bot y) window-min-height)
- (setq y (- bot window-min-height)))
- ;; The window's top includes the header line!
- (setq growth (- top y))))
- (setq wconfig (current-window-configuration))
-
- ;; Check for an error case.
- (when (and (/= growth 0)
- (not minibuffer)
- (one-window-p t))
- (error "Attempt to resize sole window"))
-
- ;; If we ever move, make sure we don't mistakenly treat
- ;; some unexpected `mouse-1' final event as a sign that
- ;; this whole drag was nothing more than a click.
- (if (/= growth 0) (setq on-link nil))
-
- ;; grow/shrink minibuffer?
- (if should-enlarge-minibuffer
- (unless resize-mini-windows
- (mouse-drag-move-window-bottom start-event-window growth))
- ;; no. grow/shrink the selected window
- ;(message "growth = %d" growth)
- (if mode-line-p
- (mouse-drag-move-window-bottom start-event-window growth)
- (mouse-drag-move-window-top start-event-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/shrink
- ;; the minibuffer. minibuffer size changes
- ;; can cause all windows to shrink... no way
- ;; around it.
- (when (or (/= start-nwindows (count-windows t))
- (and (not should-enlarge-minibuffer)
- (> growth 0)
- mode-line-p
- (/= top
- (nth 1 (window-edges
- ;; Choose right window.
- start-event-window)))))
- (set-window-configuration wconfig)))))
-
- ;; Presumably if this was just a click, the last event should
- ;; be `mouse-1', whereas if this did move the mouse, it should be
- ;; a `drag-mouse-1'. In any case `on-link' would have been nulled
- ;; above if there had been any significant mouse movement.
- (when (and on-link (eq 'mouse-1 (car-safe event)))
- ;; If mouse-2 has never been done by the user, it doesn't
- ;; have the necessary property to be interpreted correctly.
- (put 'mouse-2 'event-kind 'mouse-click)
- (push (cons 'mouse-2 (cdr event)) unread-command-events))))))
+ ;; Loop reading events and sampling the position of the mouse.
+ (while draggable
+ (setq event (read-event))
+ (setq position (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 (Why? -- cyd)
+ ;; (same as mouse movement for our purposes)
+ ;; Quit if
+ ;; - there is a keyboard event or some other unknown event.
+ (cond
+ ((not (consp event))
+ (setq draggable nil))
+ ((memq (car event) '(switch-frame select-window))
+ nil)
+ ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
+ (when (consp event)
+ ;; Do not unread a drag-mouse-1 event to avoid selecting
+ ;; some other window. For vertical line dragging do not
+ ;; unread mouse-1 events either (but only if we dragged at
+ ;; least once to allow mouse-1 clicks get through.
+ (unless (and dragged
+ (if (eq line 'vertical)
+ (memq (car event) '(drag-mouse-1 mouse-1))
+ (eq (car event) 'drag-mouse-1)))
+ (push event unread-command-events)))
+ (setq draggable nil))
+ ((or (not (eq (car position) frame))
+ (null (car (cdr position))))
+ nil)
+ ((eq line 'vertical)
+ ;; Drag vertical divider.
+ (setq growth (- (cadr position)
+ (if (eq side 'right) 0 2)
+ (nth 2 (window-edges window))
+ -1))
+ (unless (zerop growth)
+ (setq dragged t))
+ (adjust-window-trailing-edge window growth t))
+ (draggable
+ ;; Drag horizontal divider.
+ (setq growth
+ (if (eq line 'mode)
+ (- (cddr position) (nth 3 (window-edges window)) -1)
+ ;; The window's top includes the header line!
+ (- (nth 3 (window-edges window)) (cddr position))))
+ (unless (zerop growth)
+ (setq dragged t))
+ (adjust-window-trailing-edge window (if (eq line 'mode)
+ growth
+ (- growth)))))))
+ ;; Process the terminating event.
+ (when (and (mouse-event-p event) on-link (not dragged)
+ (mouse--remap-link-click-p start-event event))
+ ;; If mouse-2 has never been done by the user, it doesn't have
+ ;; the necessary property to be interpreted correctly.
+ (put 'mouse-2 'event-kind 'mouse-click)
+ (setcar event 'mouse-2))
+ (push event unread-command-events)))