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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
; SIMPLEST DECORATION
; ===================
;;File: simple-win.gwm -- simple window decoration
;;Author: colas@mirsa.inria.fr (Colas NAHABOO) -- Bull Research FRANCE
;;Revision: 1.6 -- Aug 13 1991
;;State: Exp
;;GWM Version: 1.7
;;============================================================================
;; INITS
;;============================================================================
;; first we declare as screen-dependent all the screen-dependent values we will
;; use (i.e. colors, pop-ups, pixmaps and cursors)
;; this file will normally be loaded once.
(declare-screen-dependent
simple-win.active.background
simple-win.background
simple-win.active.label.background
simple-win.label.background
simple-win.active.label.foreground
simple-win.label.foreground
simple-win.active.label.border
simple-win.label.border
simple-win.context
)
;; We set to their default values all the simple-win.* customizable
;; values that the user hadn't set
;; here we say that some values can be nil, to mean: just use the same value
;; as the inactive value
;; tile can also be given
;; first, the screen-independent ones:
(defaults-to
simple-win.active.font ()
simple-win.font name-font
simple-win.active.label.borderwidth ()
simple-win.label.borderwidth 1
simple-win.label ()
simple-win.legend "top"
simple-win.lpad 1
simple-win.rpad 1
)
;; then the screen-dependent:
;; (we protect the value of the current wob which will be modified by the loop)
(with (wob wob)
(for screen (list-of-screens)
(defaults-to
simple-win.active.background darkgrey
simple-win.background grey
simple-win.active.label.background ()
simple-win.label.background white
simple-win.active.label.foreground ()
simple-win.label.foreground black
simple-win.active.label.border ()
simple-win.label.border black
)
;; we declare the the context (pairs of variables/values) that will be inbedded
;; into the window, accessible in the window wool property of key 'context.
;; these get initilized from their global defaults.
(setq simple-win.context (list
'active-label? ()
'active.background simple-win.active.background
'background simple-win.background
'active.font simple-win.active.font
'font simple-win.font
'active.label.background simple-win.active.label.background
'label.background simple-win.label.background
'active.label.foreground simple-win.active.label.foreground
'label.foreground simple-win.label.foreground
'active.label.borderwidth simple-win.active.label.borderwidth
'label.borderwidth simple-win.label.borderwidth
'active.label.border simple-win.active.label.border
'label.border simple-win.label.border
'label ()
'legend "top"
'lpad 1
'rpad 1
))
))
;;============================================================================
;; FSMs
;;============================================================================
;; here we declare the fsms of the deco.
;; the idea is that all window-dependent values should be accessed through the
;; 'context property-list in the window property-list where they have been
;; put at built tiome, by the main simple-win function.
;; the title bar: will change background color with focus
(: simple-win.titlebar-fsm
(fsm-make
(state-make
(on (user-event 'focus-in)
(wob-background (# 'active.background (# 'context window)))
)
(on (user-event 'focus-out)
(wob-background (# 'background (# 'context window)))
)
standard-title-behavior
standard-behavior))
)
;; here we process optionnaly the window-name by an optional "label"
;; customisation argument that can be a function
(de simple-win.name ()
(with (new-label
(if label
(if
(= (type label) 'string)
label
(eval (list label window-name))
)
window-name
))
(if (and (= (type new-label) 'string) (not (= "" new-label)))
new-label
window-name
)
))
;; the window name plug: may change with focus (two different fsms in each
;; case to make less X calls), and must update name when window name is changed
;; which is forwarded to us by the standard-behavior in the form of a
;; (user-event 'name-change) event
(: simple-win.label-fsm
(fsm-make
(state-make
(on (user-event 'name-change)
(with (context (# 'context window)
label (# 'label context)
font (# 'font context)
background (# 'label.background context)
foreground (# 'label.foreground context)
)
(wob-tile (label-make (simple-win.name)))))
standard-title-behavior
standard-behavior)))
(: simple-win.active.label-fsm
(fsm-make
(setq inactive (state-make
(on (user-event 'focus-in)
(wob-tile (# 'active-label window-property))
active
)
(on (user-event 'name-change)
(with (context (# 'context window)
label (# 'label context)
font (# 'font context)
background (# 'label.background context)
foreground (# 'label.foreground context)
tile (label-make (simple-win.name))
font (# 'active.font context)
background (# 'active.label.background context)
foreground (# 'active.label.foreground context)
atile (label-make (simple-win.name))
)
(## 'inactive-label window tile)
(## 'active-label window atile)
(wob-tile tile)))
standard-title-behavior
standard-behavior))
(setq active (state-make
(on (user-event 'focus-out)
(wob-tile (# 'inactive-label window-property))
inactive
)
(on (user-event 'name-change)
(with (context (# 'context window)
label (# 'label context)
font (# 'font context)
background (# 'label.background context)
foreground (# 'label.foreground context)
tile (label-make (simple-win.name))
font (# 'active.font context)
background (# 'active.label.background context)
foreground (# 'active.label.foreground context)
atile (label-make (simple-win.name))
)
(## 'inactive-label window tile)
(## 'active-label window atile)
(wob-tile atile)))
standard-title-behavior
standard-behavior))
))
;;============================================================================
;; The actual decoration
;;============================================================================
;; for customisation: we build a context as the sum of :
;; - the global defaults: simple-win.context
;; - the value stored by customize under the 'simple-win resource
;; - the arguments passed to simple-win
;; the we obtain a context, that we snapshot by context-save, that we will put
;; on the window itself (via property) for later use by the fsms
(defun simple-win args
(if (= window root-window) ; trap user errors
(trigger-error "Decoration function \"simple-win\" called on root window")
)
(setq simple-icon.oldfont font) ;hack due to bug, we save this value...
(with-eval (+ simple-win.context
(get-context (std-resource-get 'SimpleWin 'simple-win))
args
) ; concatenates the context
;; fix default values which are still ()
(default-if-nil
active.background background
active.font font
active.label.background label.background
active.label.foreground label.foreground
active.label.borderwidth label.borderwidth
active.label.border label.border
)
;; we compute this value to know if we can have a simple fsm if the
;; the title plug isn't supposed to change.
(setq active-label? (not (and
(= active.background background)
(= active.font font)
(= active.label.background label.background)
(= active.label.foreground label.foreground)
(= active.label.borderwidth label.borderwidth)
(= active.label.border label.border)
)))
(with (
fsm window-fsm
context (context-save simple-win.context) ; snapshot
grabs window-grabs
inactive-label (with (
background label.background
foreground label.foreground
borderwidth label.borderwidth
borderpixel label.border
)
(label-make (simple-win.name))
)
;; put context in window property list
property (+ property (list 'context context)
(list
'label label
'inactive-label (if active-label? inactive-label ())
'active-label (if active-label? (with (
font active.font
background active.label.background
foreground active.label.foreground
borderwidth active.label.borderwidth
borderpixel active.label.border
)
(label-make (simple-win.name))
)
()
))))
;; then build the window
(setq simple-win.result (window-make
(if (= legend "top") (simple-win.bar-make))
(if (= legend "left") (simple-win.bar-make))
(if (= legend "right") (simple-win.bar-make))
(if (= legend "base") (simple-win.bar-make))
()
))))
(setq font simple-icon.oldfont) ;hack due to bug
simple-win.result
)
(defun simple-win.bar-make ()
(with (
borderwidth (if (= tile t) 0 1)
fsm simple-win.titlebar-fsm
expr (+
(list 'bar-make)
(list-make lpad)
'((with (
fsm (if active-label? simple-win.active.label-fsm
simple-win.label-fsm
))
(with (borderwidth label.borderwidth)
(plug-make inactive-label)
)))
(list-make rpad)
))
(eval expr)
))
|