0
|
1 ;; live-icon.el --- make frame icons represent the current frame contents
|
|
2
|
|
3 ;; Copyright (C) 1995 Rich Williams <rdw@hplb.hpl.hp.com>
|
|
4 ;; Copyright (C) 1995 Jamie Zawinski <jwz@netscape.com>
|
|
5
|
|
6 ;; Authors: Rich Williams <rdw@hplb.hpl.hp.com>
|
|
7 ;; Jamie Zawinski <jwz@netscape.com>
|
|
8
|
|
9 ;; Version 1.2
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
16
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
0
|
27
|
|
28 ;;; Synched up with: Not in FSF.
|
|
29
|
|
30 ;; Generates little pixmaps representing the contents of your frames.
|
|
31
|
|
32 ;; #### This thing is somewhat of a mess and could stand some clean-up.
|
|
33
|
|
34 (defun live-icon-colour-name-from-face (face &optional bg-p)
|
|
35 "Do backward compatible things to faces and colours"
|
|
36 (if (and (boundp 'emacs-major-version)
|
|
37 (or (> emacs-major-version 19)
|
|
38 (and (= emacs-major-version 19)
|
|
39 (>= emacs-minor-version 12))))
|
|
40 (let ((colour (if bg-p
|
|
41 (face-background face)
|
|
42 (face-foreground face))))
|
|
43 (if (consp colour)
|
|
44 (setq colour (cdr (car colour))))
|
|
45 (if (color-instance-p colour)
|
|
46 (setq colour (color-instance-name colour)))
|
|
47 (if (specifierp colour)
|
|
48 (setq colour (color-name colour)))
|
|
49 (if colour
|
|
50 (let ((hack (format "%s" colour)))
|
|
51 (if (string-match "(?\\([^)]*\\))?" hack)
|
|
52 (substring hack (match-beginning 1) (match-end 1))
|
|
53 hack))))
|
|
54 (let ((p (if bg-p (face-background face) (face-foreground face))))
|
|
55 (and (pixelp p)
|
|
56 (pixel-name p)))))
|
|
57
|
|
58 (defun live-icon-alloc-colour (cmv colour)
|
|
59 "Allocate a colour and a char from the magic vector"
|
|
60 (let ((bob (assoc colour (aref cmv 0)))
|
|
61 (jim (aref cmv 2)))
|
|
62 (if bob
|
|
63 (cdr bob)
|
|
64 (aset cmv 0 (cons (cons colour jim) (aref cmv 0)))
|
|
65 (aset cmv 1 (1+ (aref cmv 1)))
|
|
66 (aset cmv 2 (1+ jim))
|
|
67 jim)))
|
|
68
|
|
69 (defun live-icon-from-frame (&optional frame)
|
|
70 "Calculates the live-icon XPM of FRAME."
|
|
71 (if (not frame)
|
|
72 (setq frame (selected-screen)))
|
|
73 (save-excursion
|
|
74 (select-screen frame)
|
|
75 (let* ((w (screen-width))
|
|
76 (h (screen-height))
|
|
77 (pix (make-vector h nil))
|
|
78 (ny 0)
|
|
79 (cmv (vector nil 0 ?A))
|
|
80 (d (live-icon-alloc-colour
|
|
81 cmv (pixel-name (face-background 'default))))
|
|
82 (m (live-icon-alloc-colour
|
|
83 cmv (pixel-name (face-background 'modeline))))
|
|
84 (x (live-icon-alloc-colour
|
|
85 cmv (pixel-name (face-foreground 'default))))
|
|
86 y)
|
|
87 (let ((loop 0))
|
|
88 (while (< loop h)
|
|
89 (aset pix loop (make-string w d))
|
|
90 (setq loop (1+ loop))))
|
|
91 (mapcar #'(lambda (win)
|
|
92 (save-excursion
|
|
93 (save-window-excursion
|
|
94 (select-window win)
|
|
95 (save-restriction
|
|
96 (setq y ny
|
|
97 ny (+ ny (1- (window-height))))
|
|
98 (aset pix (- ny 2) (make-string w m))
|
|
99 (widen)
|
|
100 (if (> (window-end) (window-start))
|
|
101 (narrow-to-region (window-start)
|
|
102 (1- (window-end))))
|
|
103 (goto-char (point-min))
|
|
104 (while (and (not (eobp))
|
|
105 (< y (1- ny)))
|
|
106 (while (and (not (eolp))
|
|
107 (< (current-column) w))
|
|
108 (if (> (char-after (point)) 32)
|
|
109 (let* ((ex (extent-at (point) (current-buffer) 'face))
|
|
110 (f (if ex (extent-face ex)))
|
|
111 (z (if f (live-icon-colour-name-from-face f)))
|
|
112 (c (if z (live-icon-alloc-colour cmv z) x)))
|
|
113 (aset (aref pix y) (current-column) c)))
|
|
114 (forward-char 1))
|
|
115 (setq y (1+ y))
|
|
116 (forward-line 1))))))
|
|
117 (sort (if (fboundp 'window-list)
|
|
118 (window-list)
|
|
119 (let* ((w (screen-root-window))
|
|
120 (ws nil))
|
|
121 (while (not (memq (setq w (next-window w)) ws))
|
|
122 (setq ws (cons w ws)))
|
|
123 ws))
|
|
124 (if (fboundp 'window-pixel-edges)
|
|
125 #'(lambda (won woo)
|
|
126 (< (nth 1 (window-pixel-edges won))
|
|
127 (nth 1 (window-pixel-edges woo))))
|
|
128 #'(lambda (won woo)
|
|
129 (< (nth 1 (window-edges won))
|
|
130 (nth 1 (window-edges woo)))))))
|
|
131 (concat "/* XPM */\nstatic char icon[] = {\n"
|
|
132 (format "\"%d %d %d 1\",\n" w (* h 2) (aref cmv 1))
|
|
133 (mapconcat #'(lambda (colour-entry)
|
|
134 (format "\"%c c %s\""
|
|
135 (cdr colour-entry)
|
|
136 (car colour-entry)))
|
|
137 (aref cmv 0)
|
|
138 ",\n")
|
|
139 ",\n"
|
|
140 (mapconcat #'(lambda (scan-line)
|
|
141 (concat "\"" scan-line "\"," "\n"
|
|
142 ;; "\"" scan-line "\""
|
|
143 "\"" (make-string w d) "\","
|
|
144 ))
|
|
145 pix
|
|
146 ",\n")
|
|
147 "};\n"))))
|
|
148
|
|
149
|
|
150 (defun live-icon-start-ppm-stuff (&optional frame)
|
|
151 "Start a live icon conversion going"
|
|
152 (interactive)
|
|
153 (if (not frame)
|
|
154 (setq frame (selected-screen)))
|
|
155 (let ((buf (get-buffer-create " *live-icon*")))
|
|
156 (message "live-icon...(backgrounding)")
|
|
157 (save-excursion
|
|
158 (set-buffer buf)
|
|
159 (erase-buffer))
|
|
160 (set-process-sentinel
|
|
161 (start-process-shell-command "live-icon"
|
|
162 buf
|
|
163 "xwd"
|
|
164 "-id" (format "%s" (x-window-id frame)) "|"
|
|
165 "xwdtopnm" "|"
|
|
166 "pnmscale" "-xysize" "64" "64" "|"
|
|
167 "ppmquant" "256" "|"
|
|
168 "ppmtoxpm")
|
|
169 #'(lambda (p s)
|
|
170 (message "live-icon...(munching)")
|
|
171 (save-excursion
|
|
172 (set-buffer " *live-icon*")
|
|
173 (goto-char (point-min))
|
|
174 (search-forward "/* XPM */")
|
|
175 (x-set-screen-icon-pixmap frame
|
|
176 (make-pixmap
|
|
177 (buffer-substring
|
|
178 (match-beginning 0) (point-max)))))
|
|
179 (message "live-icon...... done"))))
|
|
180 nil)
|
|
181
|
|
182
|
|
183 (defun live-icon-one-frame (&optional frame)
|
|
184 "Gives FRAME (defaulting to (selected-frame)) a live icon."
|
|
185 (interactive)
|
|
186 ; (message "Updating live icon...")
|
|
187 (if (not frame)
|
|
188 (setq frame (selected-screen)))
|
|
189 (x-set-screen-icon-pixmap frame (make-pixmap (live-icon-from-frame frame)))
|
|
190 ; (message "Updating live icon... done")
|
|
191 )
|
|
192
|
|
193 (defun live-icon-all-frames ()
|
|
194 "Gives all your frames live-icons."
|
|
195 (interactive)
|
|
196 (message "Updating live icons...")
|
|
197 (mapcar #'(lambda (fr)
|
|
198 (x-set-screen-icon-pixmap
|
|
199 fr (make-pixmap (live-icon-from-frame fr))))
|
|
200 (screen-list))
|
|
201 (message "Updating live icons... done"))
|
|
202
|
|
203 (add-hook 'unmap-screen-hook 'live-icon-one-frame)
|
|
204 ;;(start-itimer "live-icon" 'live-icon-all-frames 120 120)
|
|
205
|
|
206
|
|
207
|
|
208 (defun live-icon-goto-position (x y)
|
|
209 (let (window edges)
|
|
210 (catch 'done
|
|
211 (walk-windows
|
|
212 #'(lambda (w)
|
|
213 (setq edges (window-edges w))
|
|
214 (if (and (>= x (nth 0 edges))
|
|
215 (<= x (nth 2 edges))
|
|
216 (>= y (nth 1 edges))
|
|
217 (<= y (nth 3 edges)))
|
|
218 (throw 'done (setq window w))))
|
|
219 nil t))
|
|
220 (if (not window)
|
|
221 nil
|
|
222 (select-window window)
|
|
223 (move-to-window-line (- y (nth 1 edges)))
|
|
224 (move-to-column (- x (nth 0 edges)))
|
|
225 )))
|
|
226
|
|
227 (defun live-icon-make-image (width height)
|
|
228 (let* ((text-aspect 1.5)
|
|
229 (xscale (/ (/ (* (screen-width) 1.0) width) text-aspect))
|
|
230 (yscale (/ (* (screen-height) 1.0) height))
|
|
231 (x 0)
|
|
232 (y 0)
|
|
233 (cmv (vector nil 0 ?A))
|
|
234 (default-fg (live-icon-alloc-colour
|
|
235 cmv (pixel-name (face-foreground 'default))))
|
|
236 (default-bg (live-icon-alloc-colour
|
|
237 cmv (pixel-name (face-background 'default))))
|
|
238 (modeline-bg (live-icon-alloc-colour
|
|
239 cmv (pixel-name (face-background 'modeline))))
|
|
240 (lines (make-vector height nil)))
|
|
241 ;;
|
|
242 ;; Put in the text.
|
|
243 ;;
|
|
244 (save-excursion
|
|
245 (save-window-excursion
|
|
246 (while (< y height)
|
|
247 (aset lines y (make-string width default-bg))
|
|
248 (setq x 0)
|
|
249 (while (< x width)
|
|
250 (let ((sx (floor (* x xscale)))
|
|
251 (sy (floor (* y yscale))))
|
|
252 (live-icon-goto-position sx sy)
|
|
253 (let* ((extent (extent-at (point) (current-buffer) 'face))
|
|
254 (face (if extent (extent-face extent)))
|
|
255 (name (if face (live-icon-colour-name-from-face
|
|
256 face (<= (char-after (point)) 32))))
|
|
257 (color (if name
|
|
258 (live-icon-alloc-colour cmv name)
|
|
259 (if (<= (or (char-after (point)) 0) 32)
|
|
260 default-bg default-fg))))
|
|
261 (aset (aref lines y) x color)))
|
|
262 (setq x (1+ x)))
|
|
263 (setq y (1+ y)))))
|
|
264 ;;
|
|
265 ;; Now put in the modelines.
|
|
266 ;;
|
|
267 (let (sx sy)
|
|
268 (walk-windows
|
|
269 #'(lambda (w)
|
|
270 (let ((edges (window-edges w)))
|
|
271 (setq x (nth 0 edges)
|
|
272 y (nth 3 edges)
|
|
273 sx (floor (/ x xscale))
|
|
274 sy (floor (/ y yscale)))
|
|
275 (while (and (< x (1- (nth 2 edges)))
|
|
276 (< sx (length (aref lines 0))))
|
|
277 (aset (aref lines sy) sx modeline-bg)
|
|
278 (if (> sy 0)
|
|
279 (aset (aref lines (1- sy)) sx modeline-bg))
|
|
280 (setq x (1+ x)
|
|
281 sx (floor (/ x xscale))))
|
|
282 (if (>= sx (length (aref lines 0)))
|
|
283 (setq sx (1- sx)))
|
|
284 (while (>= y (nth 1 edges))
|
|
285 (aset (aref lines sy) sx modeline-bg)
|
|
286 (setq y (1- y)
|
|
287 sy (floor (/ y yscale))))))
|
|
288 nil nil))
|
|
289 ;;
|
|
290 ;; Now put in the top and left edges
|
|
291 ;;
|
|
292 (setq x 0)
|
|
293 (while (< x width)
|
|
294 (aset (aref lines 0) x modeline-bg)
|
|
295 (setq x (1+ x)))
|
|
296 (setq y 0)
|
|
297 (while (< y height)
|
|
298 (aset (aref lines y) 0 modeline-bg)
|
|
299 (setq y (1+ y)))
|
|
300 ;;
|
|
301 ;; Now make the XPM
|
|
302 ;;
|
|
303 (concat "/* XPM */\nstatic char icon[] = {\n"
|
|
304 (format "\"%d %d %d 1\",\n"
|
|
305 width
|
|
306 ;; (* height 2)
|
|
307 height
|
|
308 (aref cmv 1))
|
|
309 (mapconcat #'(lambda (colour-entry)
|
|
310 (format "\"%c c %s\""
|
|
311 (cdr colour-entry)
|
|
312 (car colour-entry)))
|
|
313 (aref cmv 0)
|
|
314 ",\n")
|
|
315 ",\n"
|
|
316 (mapconcat #'(lambda (scan-line)
|
|
317 (concat "\"" scan-line "\"," "\n"
|
|
318 ;; "\"" scan-line "\""
|
|
319 ;; "\"" (make-string width default-bg)
|
|
320 ;; "\","
|
|
321 ))
|
|
322 lines
|
|
323 ",\n")
|
|
324 "};\n")))
|
|
325
|
|
326 (provide 'live-icon)
|
|
327 ;;; live-icon.el ends here
|