(provide 'mldrag)
(defun mldrag-drag-mode-line (start-event)
"Change the height of the current window with the mouse.
This command should be bound to a down-mouse- event, and is most
usefully bound with the `mode-line' prefix. Holding down a mouse
button and moving the mouse up and down will make the clicked-on
window taller or shorter."
(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"))
(unwind-protect
(track-mouse
(progn
(select-window start-event-window)
(setq should-enlarge-minibuffer
(and minibuffer
(not (one-window-p t))
(= (nth 1 (window-edges minibuffer))
(nth 3 (window-edges)))))
(while (not done)
(setq event (read-event)
mouse (mouse-position))
(cond ((integerp event)
(setq done t))
((eq (car event) 'switch-frame)
nil)
((not (memq (car event)
'(mouse-movement scroll-bar-movement)))
(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))
(cond ((< (- y top -1) window-min-height)
(setq y (+ top window-min-height -1))))
(setq growth (- y bot -1)
wconfig (current-window-configuration))
(if should-enlarge-minibuffer
(progn
(select-window minibuffer)
(if (and (> growth 0)
(< (- (window-height minibuffer)
growth)
1))
(setq growth (1- (window-height minibuffer))))
(enlarge-window (- growth))
(select-window start-event-window))
(enlarge-window growth))
(if (or (/= start-nwindows (count-windows t))
(and (not should-enlarge-minibuffer)
(/= top (nth 1 (window-edges)))))
(set-window-configuration wconfig)))))))
(select-window old-selected-window))))
(defun mldrag-drag-vertical-line (start-event)
"Change the width of the current window with the mouse.
This command should be bound to a down-mouse- event, and is most
usefully bound with the `vertical-line' or the `vertical-scroll-bar'
prefix. Holding down a mouse button and moving the mouse left and
right will make the clicked-on window thinner or wider."
(interactive "e")
(let* ((done nil)
(echo-keystrokes 0)
(start-event-frame (window-frame (car (car (cdr start-event)))))
(scroll-bar-left
(eq (cdr (assq 'vertical-scroll-bars (frame-parameters))) 'left))
(start-event-window (car (car (cdr start-event))))
(start-nwindows (count-windows t))
(old-selected-window (selected-window))
event mouse x left right edges wconfig growth)
(if (one-window-p t)
(error "Attempt to resize sole ordinary window"))
(if scroll-bar-left
(when (= (nth 0 (window-edges start-event-window)) 0)
(error "Attempt to drag leftmost scrollbar"))
(when (>= (nth 2 (window-edges start-event-window))
(frame-width start-event-frame))
(error "Attempt to drag rightmost scrollbar")))
(unwind-protect
(track-mouse
(progn
(select-window start-event-window)
(while (not done)
(setq event (read-event)
mouse (mouse-position))
(cond ((integerp event)
(setq done t))
((eq (car event) 'switch-frame)
nil)
((not (memq (car event)
'(mouse-movement scroll-bar-movement)))
(setq done t))
((not (eq (car mouse) start-event-frame))
nil)
((null (car (cdr mouse)))
nil)
(t
(setq x (car (cdr mouse))
edges (window-edges)
left (nth 0 edges)
right (nth 2 edges))
(if scroll-bar-left
(cond ((< (- right x) window-min-width)
(setq x (- right window-min-width))))
(cond ((< (- x left -1) window-min-width)
(setq x (+ left window-min-width -1)))))
(setq growth (if scroll-bar-left
(- left x)
(- x right -1))
wconfig (current-window-configuration))
(enlarge-window growth t)
(if (or (/= start-nwindows (count-windows t))
(if scroll-bar-left
(/= right (nth 2 (window-edges)))
(/= left (nth 0 (window-edges)))))
(set-window-configuration wconfig)))))))
(select-window old-selected-window))))