/usr/share/sawfish/site-lisp/merlin/uglicon.jl is in sawfish-merlin-ugliness 1.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | ;; merlin/uglicon.jl -- window icons
;; version 0.2
;; Copyright (C) 2000-2001 merlin <merlin@merlin.org>
;; http://merlin.org/sawfish/
;; this 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.
;; this 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 sawfish; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;;;;;;;;;;;;;;;;;
;; INSTALLATION ;;
;;;;;;;;;;;;;;;;;;
;; Create a directory ~/.sawfish/lisp/merlin and then put this file there:
;; mkdir -p ~/.sawfish/lisp/merlin
;; mv uglicon.jl ~/.sawfish/lisp/merlin
;; You also need merlin/util.jl and probably want merlin/ugliness.jl.
(define-structure merlin.uglicon
(export
get-window-icon)
(open
rep
rep.io.files
sawfish.wm.colors
sawfish.wm.custom
sawfish.wm.images
sawfish.wm.misc
sawfish.wm.ext.match-window
sawfish.wm.windows.subrs
merlin.util)
(defgroup uglicon "Window icons" :group appearance)
(defcustom uglicon-ignore-hints t
"Ignore icons from window hints."
:type boolean
:group (appearance uglicon)
; :depends cycle-show-window-icons
:after-set (lambda () (uglicon-reset)))
(defcustom uglicon-search-filesystem t
"Search the file system for window icons."
:type boolean
:group (appearance uglicon)
; :depends cycle-show-window-icons
:after-set (lambda () (uglicon-reset)))
(defcustom uglicon-path "/usr/share/pixmaps:/usr/share/icons:/usr/share/icons/gnome/48x48/apps:/usr/share/icons/hicolor/48x48/apps"
"Path to search for icons."
:tooltip "Colon separated paths."
:type string
:user-level expert
:group (appearance uglicon)
:depends uglicon-search-filesystem
:after-set (lambda () (uglicon-reset)))
(defcustom uglicon-prefixes ",gnome-"
"Icon prefixes to look for."
:tooltip "Comma separated prefixes."
:type string
:user-level expert
:group (appearance uglicon)
:depends uglicon-search-filesystem
:after-set (lambda () (uglicon-reset)))
(defcustom uglicon-suffixes "png,xpm"
"Icon suffixes to look for."
:tooltip "Comma separated suffixes."
:type string
:user-level expert
:group (appearance uglicon)
:depends uglicon-search-filesystem
:after-set (lambda () (uglicon-reset)))
(defcustom uglicon-width 48
"Maximum width of window icons."
:type number
:range (1 . 128)
:user-level expert
:group (appearance uglicon))
(defcustom uglicon-height 48
"Maximum height of window icons."
:type number
:range (1 . 128)
:user-level expert
:group (appearance uglicon))
(define-match-window-property 'window-icon 'appearance 'file)
(define uglicon-cache) ;; TODO: periodically purge the cache?
(define uglicon-split-path)
(define uglicon-split-suffixes)
(define uglicon-split-prefixes)
(define (uglicon-reset)
(setq uglicon-cache '())
(setq uglicon-split-path (split uglicon-path ":"))
(setq uglicon-split-suffixes (split uglicon-suffixes ","))
(setq uglicon-split-prefixes (split uglicon-prefixes ",")))
(uglicon-reset)
;; returns a cons cell of the key and entry
(define (cache-get key creator)
(let ((cached (cdr (assoc key uglicon-cache))))
(unless cached
(when (setq cached (creator))
(setq uglicon-cache (cons (cons key cached) uglicon-cache))))
(and cached (cons key cached))))
(define (load-icon file)
(cache-get file
(lambda ()
(when (file-exists-p file)
(make-image file)))))
(define (locate-icon name)
(cache-get name
(lambda ()
(catch 'out
(mapc
(lambda (dir)
(mapc
(lambda (prefix)
(mapc
(lambda (suffix)
(let ((where (expand-file-name (concat prefix name "." suffix) dir)))
(when (file-exists-p where)
(throw 'out (make-image where)))))
uglicon-split-suffixes))
uglicon-split-prefixes))
uglicon-split-path)
nil))))
(define (window-icon window) ;; TODO: this should not really be cached; should provide a purge mechanism...
(cache-get (format nil "win<0x%x>" (window-id window))
(lambda ()
(window-icon-image window))))
(define (scale-icon icon max)
(let ((key (format nil "%s-scale:%dx%d" (car icon) (car max) (cdr max))))
(cache-get key
(lambda ()
(let ((dims (image-dimensions (cdr icon))))
(if (and (<= (car dims) (car max)) (<= (cdr dims) (cdr max)))
(cdr icon)
(scale-image (cdr icon)
(min (car max) (quotient (* (car dims) (cdr max)) (cdr dims)))
(min (cdr max) (quotient (* (car max) (cdr dims)) (car dims))))))))))
(define (fade-icon icon fade)
(let*
((rgb (color-rgb-8 fade))
(key (format nil "%s-fade:%02x/%02x/%02x" (car icon) (nth 0 rgb) (nth 1 rgb) (nth 2 rgb))))
(cache-get key
(lambda ()
(let ((icon (copy-image (cdr icon))))
(image-map
(lambda (pixel)
(list
(quotient (+ (nth 0 pixel) (nth 0 rgb)) 2)
(quotient (+ (nth 1 pixel) (nth 1 rgb)) 2)
(quotient (+ (nth 2 pixel) (nth 2 rgb)) 2)
(nth 3 pixel))) icon) icon)))))
(define (unknown-icon)
(or (and uglicon-search-filesystem (locate-icon "unknown"))
(cache-get "unknown"
(lambda () ;; TODO: Make it pretty
(bevel-image (make-sized-image uglicon-width uglicon-height (get-color "gray")) 2 t 50)))))
(define (window-icon-name window)
(let ((class (get-x-text-property window 'WM_CLASS)))
(and class (>= (length class) 2)
(translate-string (aref class 1) downcase-table))))
(define (get-window-icon window #!key (max-size (cons uglicon-width uglicon-height)) (fade-to nil))
(let ((icon (or (and (window-get window 'window-icon) (load-icon (window-get window 'window-icon)))
(and (not uglicon-ignore-hints) (window-icon window))
(and uglicon-search-filesystem (window-icon-name window) (locate-icon (window-icon-name window)))
(unknown-icon))))
(setq icon (scale-icon icon max-size))
(when fade-to
(setq icon (fade-icon icon fade-to)))
(cdr icon))))
|