anchor.diff:            *clip-rect-height* (- y2 *clip-rect-y*))
       #+debug-dirty-rects(format t "Expanded clip rect to ~D,~D ~D,~D~%"
               *clip-rect-x* *clip-rect-y* *clip-rect-width* *clip-rect-height*)))
  +
  +(defun expand-clip-rectangle-by-window (window)
  +  (expand-clip-rectangle (window-x window) (window-y window)
  +                         (width window) (height window)))
  +
  +(defun screen-to-window-coordinates (window x y)
  +  "Convert the screen-relative X,Y coordinates to window-relative coordinates."
  +  (values (- x (window-x window))
  +          (- y (window-y window))))
  +
  +(defun window-to-screen-coordinates (window x y)
  +  "Convert the window-relative X,Y coordinates to screen-relative coordinates."
  +  (values (+ x (window-x window))
  +          (+ y (window-y window))))
   
   (defun 2d-array (data &optional (element-type 't))
     (let* ((width (length (first data)))
  
positive.code:     (setf *mouse-buttons* buttons)
      ;; Dispatch events and stuff...
      ;; Raise windows when clicked on, deal with drag, etc.
      (when (and (not (logbitp 0 buttons))
                 (logbitp 0 changes))
        ;; On left click release, select window.
        (let ((win (window-at-point *mouse-x* *mouse-y*)))
          (when (and win (not (eql win *active-window*)))
            (when *active-window*
              (send-event *active-window* (make-instance 'window-activation-event
                                                         :window *active-window*
                                                         :state nil)))
            (setf *active-window* win)
            (send-event win (make-instance 'window-activation-event
                                           :window win
                                           :state t))
            (when (not (eql (layer win) :bottom))
              (setf *window-list* (remove win *window-list*))
              (push win *window-list*)
              ;; Layering change, redraw everything.
              ;; fixme: don't be lazy. set the cliprect properly.
              (setf *clip-rect-width* (mezzanine.supervisor:framebuffer-width *main-screen*)
                    *clip-rect-height* (mezzanine.supervisor:framebuffer-height *main-screen*)
                    *clip-rect-x* 0
                    *clip-rect-y* 0)))))
      (when (or (not (zerop x-motion))
                (not (zerop y-motion))
                (not (zerop changes)))
        (let ((win (window-at-point *mouse-x* *mouse-y*)))
          (when win
            (send-event win (make-instance 'mouse-event
                                           :window win
                                           :button-state *mouse-buttons*
                                           :button-change changes
                                           :x-position (- *mouse-x* (window-x win))
                                           :y-position (- *mouse-y* (window-y win))
                                           :x-motion x-motion
                                           :y-motion y-motion)))))
      (when (or (not (zerop x-motion))
                (not (zerop y-motion)))
        ;; Mouse position changed, redraw the screen.
        (expand-clip-rectangle old-x old-y (array-dimension *mouse-pointer* 1) (array-dimension *mouse-pointer* 0))
        (expand-clip-rectangle new-x new-y (array-dimension *mouse-pointer* 1) (array-dimension *mouse-pointer* 0)))))
  
  (defun submit-mouse (buttons x-motion y-motion)
    "Submit a mouse event into the input system."
  
negative.code: 
  (defmethod process-event ((event damage-event))
    (let ((window (window event)))
      (multiple-value-bind (win-x win-y)
          (window-to-screen-coordinates window (x event) (y event))
        (multiple-value-bind (clip-x clip-y clip-w clip-h)
            (clip-rectangle win-x win-y (width event) (height event)
                            (window-x window) (window-y window) (width window) (height window))
          (expand-clip-rectangle clip-x clip-y clip-w clip-h)))))
  
  (defun damage-window (window x y width height)
    "Send a window damage event to the compositor."
  