File: outline.jl

package info (click to toggle)
sawfish 1%3A1.3.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,636 kB
  • ctags: 1,327
  • sloc: lisp: 22,765; ansic: 15,810; sh: 10,203; makefile: 675; perl: 19
file content (119 lines) | stat: -rw-r--r-- 3,767 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
;; anim-outline.jl -- simple window animations
;; $Id: outline.jl,v 1.8 2002/03/24 10:12:26 jsh Exp $

;; Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>

;; This file is part of sawmill.

;; sawmill is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; sawmill is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with sawmill; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

(define-structure sawfish.wm.animation.outline

    (export make-outline-animator)

    (open rep
	  sawfish.wm.misc
	  sawfish.wm.events
	  sawfish.wm.windows
	  sawfish.wm.window-anim
	  sawfish.wm.util.window-outline
	  rep.io.timers)

  (define-structure-alias anim-outline sawfish.wm.animation.outline)

  (defvar anim-outline-icon-coords (cons (screen-width) (screen-height)))

  (defvar anim-outline-steps 16)
  (defvar anim-outline-delay 20)

  (define (anim-outline-run w mode initial-coords initial-dims
			    final-coords final-dims)
    (let ((step 0)
	  (x-step (quotient (- (car final-coords) (car initial-coords))
			    anim-outline-steps))
	  (y-step (quotient (- (cdr final-coords) (cdr initial-coords))
			    anim-outline-steps))
	  (w-step (quotient (- (car final-dims) (car initial-dims))
			    anim-outline-steps))
	  (h-step (quotient (- (cdr final-dims) (cdr initial-dims))
			    anim-outline-steps))
	  (coords (cons (car initial-coords) (cdr initial-coords)))
	  (dims (cons (car initial-dims) (cdr initial-dims)))
	  timer)

      (define (stop)
	(delete-timer timer)
	(record-window-animator w nil)
	(ungrab-server))

      (define (protect fun)
	(call-with-exception-handler fun (lambda (ex)
					   (stop)
					   (raise-exception ex))))
      
      (define (clear)
	(unless (zerop step)
	  (protect (lambda ()
		     (erase-window-outline mode (car coords) (cdr coords)
					   (car dims) (cdr dims))))))

      (define (frame)
	(protect (lambda ()
		   (clear)
		   (if (>= step anim-outline-steps)
		       (stop)
		     (rplaca coords (+ (car coords) x-step))
		     (rplacd coords (+ (cdr coords) y-step))
		     (rplaca dims (+ (car dims) w-step))
		     (rplacd dims (+ (cdr dims) h-step))
		     (draw-window-outline mode (car coords) (cdr coords)
					  (car dims) (cdr dims))
		     (setq step (1+ step))
		     (set-timer timer)))))

      (define (animator win op)
	(declare (unused win))
	(when (eq op 'stop)
	  (clear)
	  (stop)))

      ;; kludged.. there may be Expose events waiting
      (accept-x-input)

      (grab-server)
      (record-window-animator w animator)
      (setq timer (make-timer frame nil anim-outline-delay))))

  (define (anim-outline-entry mode w op #!optional action)
    (when (eq op 'start)
      (case action
	((iconified)
	 (if (window-get w 'iconified)
	     (anim-outline-run w mode (window-position w)
			       (window-frame-dimensions w)
			       (or (window-get w 'icon-position)
				   anim-outline-icon-coords)
			       '(1 . 1)))))))

  (define (make-outline-animator mode)
    (lambda (w op #!optional action)
      (anim-outline-entry mode w op action)))

  (define wireframe-animator (make-outline-animator 'box))
  (define solid-animator (make-outline-animator 'solid))

  ;;###autoload
  (define-window-animator 'wireframe wireframe-animator)
  (define-window-animator 'solid solid-animator))