anchor.diff:      (key-press-event *window-list* key)))
   
   (defun decode-mouse-packet (byte-1 byte-2 byte-3)
  -  (values (logtest byte-1 #b001) ; button-1
  -          (logtest byte-1 #b010) ; button-2
  -          (logtest byte-1 #b100) ; button-3
  -          nil ; button-4
  -          nil ; button-5
  +  (values (logand byte-1 #b111) ; buttons 1 to 3
             (logior byte-2 (if (logtest byte-1 #b00010000) -256 0)) ; x-motion
             (- (logior byte-3 (if (logtest byte-1 #b00100000) -256 0))) ; y-motion
             0)) ; z-motion
   
  +(defvar *mouse-button-state* 0
  +  "Bits representing the state of each button. 1 is pressed, 0 is released.")
  +
  +(defun map-windows (fn &optional reverse)
  +  "Invoke FN on each window. If REVERSE is true, then windows are visited in
  +reverse Z-order."
  +  (when *window-list*
  +    (if reverse
  +        (do ((window (window-prev *window-list*) (window-prev window)))
  +            ((eql window *window-list*)
  +             (funcall fn *window-list*))
  +          (funcall fn window))
  +        (progn
  +          (funcall fn *window-list*)
  +          (do ((window (window-next *window-list*) (window-next window)))
  +              ((eql window *window-list*))
  +            (funcall fn window))))))
  +
  +(defun window-at (x y)
  +  "Find the highest window at (X,Y), NIL if no window there."
  +  (let ((result nil))
  +    (tagbody
  +       (map-windows (lambda (win)
  +                      (multiple-value-bind (win-x win-y)
  +                          (window-position win)
  +                        (let* ((dims (array-dimensions (window-frontbuffer win)))
  +                               (width (second dims))
  +                               (height (first dims)))
  +                          (when (and (<= win-x x (+ win-x width -1))
  +                                     (<= win-y y (+ win-y height -1)))
  +                            (setf result win)
  +                            (go end))))))
  +     end)
  +    result))
  +
   (defun process-mouse-packet (byte-1 byte-2 byte-3)
  -  (multiple-value-bind (button-1 button-2 button-3 button-4 button-5 x-motion y-motion z-motion)
  +  (multiple-value-bind (buttons x-motion y-motion z-motion)
         (decode-mouse-packet byte-1 byte-2 byte-3)
       (when *screens*
         (let* ((screen (first *screens*))
  
positive.code:       (rotatef (screen-backbuffer screen) (screen-framebuffer screen))
        (funcall (screen-flip-function screen)))))
  
  (defgeneric key-press-event (window character))
  (defmethod key-press-event ((window window) character))
  
  (defun handle-keypress (key)
    (let ((command (gethash key *global-keybindings*)))
      (when command
  
negative.code:            (dims (array-dimensions src-buffer))
             (width (second dims))
             (height (first dims)))
        (bitblt height width src-buffer 0 0 fb y x))))
  
  (defun compose-all-displays ()
    (when *screens*
  