;; shuffle-window.jl -- "Shuffle" windows
;;
;; Description: This resizes windows and moves others out of the way. I'm
;; probably reinventing the wheel here.
;;
;; Author: Mark Triggs <mst@dishevelled.net>

(require 'smart-tile)
(require 'shrink)

(defun expand-window (w direction)
  "Expand the currently focused window in some direction"
  (let ((offset 10))
    (let ((new-position (case direction
                          ('up (list (window-x w) (- (window-y w) offset)))
                          ('down (list (window-x w) (window-y w)))
                          ('left (list (- (window-x w) offset) (window-y w)))
                          ('right (list (window-x w) (window-y w))))))
      (if (member direction '(up down))
          (apply move-resize-window-to
                 w
                 (append new-position
                         (list (car (window-dimensions w))
                               (+ (cdr (window-dimensions w)) offset))))
        (apply move-resize-window-to
               w
               (append new-position
                       (list (+ (car (window-dimensions w)) offset)
                             (cdr (window-dimensions w)))))))))

(defun shuffle-window (w direction)
  (expand-window w direction)
  (shrink-window (window-touching-p w) direction))

(provide 'shuffle-window)
