comparison lisp/mouse.el @ 284:558f606b08ae r21-0b40

Import from CVS: tag r21-0b40
author cvs
date Mon, 13 Aug 2007 10:34:13 +0200
parents c42ec1d1cded
children 57709be46d1b
comparison
equal deleted inserted replaced
283:fa3d41851a08 284:558f606b08ae
1335 ((or extent glyph-extent) 1335 ((or extent glyph-extent)
1336 '(selection-pointer-glyph text-pointer-glyph)) 1336 '(selection-pointer-glyph text-pointer-glyph))
1337 ((event-over-modeline-p event) 1337 ((event-over-modeline-p event)
1338 '(modeline-pointer-glyph nontext-pointer-glyph 1338 '(modeline-pointer-glyph nontext-pointer-glyph
1339 text-pointer-glyph)) 1339 text-pointer-glyph))
1340 ((and (event-over-vertical-divider-p event)
1341 (specifier-instance vertical-divider-draggable-p
1342 (event-window event)))
1343 '(divider-pointer-glyph nontext-pointer-glyph
1344 text-pointer-glyph))
1340 (point '(text-pointer-glyph)) 1345 (point '(text-pointer-glyph))
1341 (buffer '(nontext-pointer-glyph text-pointer-glyph)) 1346 (buffer '(nontext-pointer-glyph text-pointer-glyph))
1342 (t '(nontext-pointer-glyph text-pointer-glyph)))) 1347 (t '(nontext-pointer-glyph text-pointer-glyph))))
1343 pointer) 1348 pointer)
1344 (and user-pointer (glyphp user-pointer) 1349 (and user-pointer (glyphp user-pointer)
1397 'mouse-face))) 1402 'mouse-face)))
1398 (highlight-extent extent t))))) 1403 (highlight-extent extent t)))))
1399 nil) 1404 nil)
1400 1405
1401 (setq mouse-motion-handler 'default-mouse-motion-handler) 1406 (setq mouse-motion-handler 'default-mouse-motion-handler)
1407
1408 ;;
1409 ;; Vertical divider dragging
1410 ;;
1411 (defun drag-window-divider (event)
1412 "Handle resizing windows by dragging window dividers.
1413 This is an intenal function, normally bound to button1 event in
1414 window-divider-map. You would not call it, but you may bind it to
1415 other mouse buttons."
1416 (interactive "e")
1417 (if (not (specifier-instance vertical-divider-draggable-p
1418 (event-window event)))
1419 (error "Not over a window!"))
1420 (letf* ((window (event-window event))
1421 (frame (event-channel event))
1422 (last-timestamp (event-timestamp event))
1423 (doit t)
1424 ((specifier-instance vertical-divider-shadow-thickness window)
1425 (- (specifier-instance vertical-divider-shadow-thickness window))))
1426 (while doit
1427 (let ((old-right (caddr (window-pixel-edges window)))
1428 (old-left (car (window-pixel-edges window)))
1429 (backup-conf (current-window-configuration frame))
1430 (old-edges-all-windows (mapcar 'window-pixel-edges (window-list))))
1431
1432 ;; This is borrowed from modeline.el:
1433 ;; requeue event and quit if this is a misc-user, eval or
1434 ;; keypress event.
1435 ;; quit if this is a button press or release event, or if the event
1436 ;; occurred in some other frame.
1437 ;; drag if this is a mouse motion event and the time
1438 ;; between this event and the last event is greater than
1439 ;; drag-modeline-event-lag.
1440 ;; do nothing if this is any other kind of event.
1441 (setq event (next-event event))
1442 (cond ((or (misc-user-event-p event)
1443 (key-press-event-p event))
1444 (setq unread-command-events (nconc unread-command-events
1445 (list event))
1446 doit nil))
1447 ((button-release-event-p event)
1448 (setq doit nil))
1449 ((button-event-p event)
1450 (setq doit nil))
1451 ((not (motion-event-p event))
1452 (dispatch-event event))
1453 ((not (eq frame (event-frame event)))
1454 (setq doit nil))
1455 ((< (abs (- (event-timestamp event) last-timestamp))
1456 drag-modeline-event-lag))
1457 (t
1458 (setq last-timestamp (event-timestamp event))
1459 ;; Enlarge the window, calculating change in characters
1460 ;; of default font. Do not let the window to become
1461 ;; less than alolwed minimum (not because that's critical
1462 ;; for the code performance, just the visual effect is
1463 ;; better: when cursor goes to the left of the next left
1464 ;; divider, the vindow being resized shrinks to minimal
1465 ;; size.
1466 (enlarge-window (max (- window-min-width (window-width window))
1467 (/ (- (event-x-pixel event) old-right)
1468 (face-width 'default window)))
1469 t window)
1470 ;; Backout the change if some windows got deleted, or
1471 ;; if the change caused more than two windows to resize
1472 ;; (shifting the whole stack right is ugly), or if the
1473 ;; left window side has slipped (right side cannot be
1474 ;; moved any funrther to the right, so enlarge-window
1475 ;; plays bad games with the left edge.
1476 (if (or (/= (count-windows) (length old-edges-all-windows))
1477 (/= old-left (car (window-pixel-edges window)))
1478 ;; This check is very hairy. We allow any number
1479 ;; of left edges to change, but only to the same
1480 ;; new value. Similar procedure is for the right edges.
1481 (let ((all-that-bad nil)
1482 (new-left-ok nil)
1483 (new-right-ok nil))
1484 (mapcar* (lambda (window old-edges)
1485 (let ((new (car (window-pixel-edges window))))
1486 (if (/= new (car old-edges))
1487 (if (and new-left-ok
1488 (/= new-left-ok new))
1489 (setq all-that-bad t)
1490 (setq new-left-ok new)))))
1491 (window-list) old-edges-all-windows)
1492 (mapcar* (lambda (window old-edges)
1493 (let ((new (caddr (window-pixel-edges window))))
1494 (if (/= new (caddr old-edges))
1495 (if (and new-right-ok
1496 (/= new-right-ok new))
1497 (setq all-that-bad t)
1498 (setq new-right-ok new)))))
1499 (window-list) old-edges-all-windows)
1500 all-that-bad))
1501 (set-window-configuration backup-conf))))
1502 ))))
1503
1504 (setq vertical-divider-map (make-keymap))
1505 (define-key vertical-divider-map 'button1 'drag-window-divider)
1402 1506
1403 ;;; mouse.el ends here 1507 ;;; mouse.el ends here