Source

xwem / lisp / xwem-theme.el

  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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
;;; xwem-theme.el --- Themes support for xwem.

;; Copyright (C) 2004 by Free Software Foundation, Inc.

;; Author: Zajcev Evgeny <zevlg@yandex.ru>
;; Created: Tue Nov 23 14:49:41 MSK 2004
;; Keywords: xwem
;; X-CVS: $Id$

;; This file is part of XWEM.

;; XWEM 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.

;; XWEM 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 XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with: Not in FSF

;;; Commentary:

;; 

;;; Code:

(require 'xwem-load)
(require 'xwem-strokes)                 ; for xwem-strokes-face

(defgroup xwem-theme nil
  "Group to customize xwem themes."
  :prefix "xwem-theme-"
  :group 'xwem)

(defcustom xwem-theme-default
  `((face xwem-tabber-face
     (((frame-selected tab-selected)
       (:foreground "white" :background "green4" :bold t))
      ((delimiter-left frame-selected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-selected)
       (:foreground "black"))

      ((frame-selected tab-nonselected)
       (:foreground "black" :background "gray80"))
      ((delimiter-left frame-selected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-nonselected)
       (:foreground "black"))

      ((frame-nonselected tab-selected)
       (:foreground "gray80" :background "DarkGreen" :bold t))
      ((delimiter-left frame-nonselected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-selected)
       (:foreground "black"))

      ((frame-nonselected tab-nonselected)
       (:foreground "black" :background "gray40"))
      ((delimiter-left frame-nonselected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-nonselected)
       (:foreground "black"))

      (t (:foreground "white"))))

    (face x-border-face
     (((selected) (:foreground "green"))
      (t (:foreground "gray80"))))

    (face xwem-frame-inner-border-face
     (((light nonselected)
       (:foreground "gray80" :background "gray80"))
      ((medium nonselected)
       (:foreground "gray50" :background "gray50"))
      ((dark nonselected)
       (:foreground "gray20" :background "gray20"))
      ((light selected)
       (:foreground "cyan2" :background "cyan2"))
      ((medium selected)
       (:foreground "royalblue" :background "royalblue"))
      ((dark selected)
       (:foreground "blue4" :background "blue4"))))

    (face xwem-launch-dock-face
     (((background-light)
       (:foreground "gray70"))
      ((background-light shadow-light)
       (:foreground "white"))
      ((background-light shadow-dark)
       (:foreground "black"))
      ((background-dark)
       (:foreground "gray 50"))
      ((background-dark shadow-light)
       (:foreground "white"))
      ((background-dark shadow-dark)
       (:foreground "black"))
      (t (:foreground "gray70" :background "black"))))

    (face xwem-strokes-face
     (((background light)
       (:foreground "red4" :background "black"))
      ((background dark)
       (:foreground "red" :background "black"))
      ((background begin light)
       (:foreground "magenta4" :background "black"
        :line-width 12 :cap-style X-CapRound))
      ((background begin dark)
       (:foreground "magenta" :background "black"
        :line-width 12 :cap-style X-CapRound))))

    (face xwem-tray-delimiter-face
     (((background light)
       (:foreground "gray40"))
      ((background light shadow)
       (:foreground "gray30"))
      ((background dark)
       (:foreground "gray70"))
      ((background dark shadow)
       (:foreground "gray80"))))

    (face xwem-window-outline-face
     (((frame-selected win-selected)
       (:foreground "green" :background "green4" :line-width 4))
      ((frame-selected win-nonselected)
       (:foreground "gray70" :background "gray70" :line-width 4))
      ((frame-nonselected win-selected)
       (:foreground "green3" :background "green4" :line-width 4))
      ((frame-nonselected win-nonselected)
       (:foreground "gray60" :background "gray40" :line-width 4))))

    (face xwem-window-delimiter-face
     (((horizontal)
       (:foreground "royalblue" :background "black"))
      ((horizontal shadow)
       (:foreground "blue4" :background "black"))
      ((horizontal light shadow)
       (:foreground "cyan" :background "black"))
      ((vertical)
       (:foreground "royalblue" :background "black"))
      ((shadow vertical)
       (:foreground "blue4" :background "black"))
      ((light shadow vertical)
       (:foreground "cyan" :background "black"))
      (t (:foreground "gray20" :background "black"))))

    ;; Frames properties
    (frame-property inner-border-width 8)
    (frame-property inner-border-thickness 2)
    (frame-property title-height 18)

    ;; Clients properties
    (client-property x-border-width 2)

    ;; Custom settings
    (custom xwem-cursor-help-foreground-color "#00BB00")
    (custom xwem-cursor-help-background-color "#009900")
    (custom xwem-root-cursor-foreground-color "white")
    (custom xwem-root-cursor-background-color "black")
    (custom xwem-frame-cursor-foreground-color "#111111")
    (custom xwem-frame-cursor-background-color "#EEEEEE")
    )
  "Default xwem theme."
  :type 'xwem-theme
  :group 'xwem-theme)

(defcustom xwem-theme-extrim
  `((face xwem-tabber-face
     (((frame-selected tab-selected)
       (:foreground "white" :background "gray20"
        :font "-*-fixed-medium-r-*-*-12-*-*-*-*-*-*-*" :bold t))
      ((delimiter-left frame-selected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-selected)
       (:foreground "black"))

      ((frame-selected tab-nonselected)
       (:foreground "black" :background "gray80" :font "-*-fixed-medium-r-*-*-12-*-*-*-*-*-*-*"))
      ((delimiter-left frame-selected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-selected tab-nonselected)
       (:foreground "black"))

      ((frame-nonselected tab-selected)
       (:foreground "gray80" :background "gray40"
        :font "-*-fixed-medium-r-*-*-12-*-*-*-*-*-*-*" :bold t))
      ((delimiter-left frame-nonselected tab-selected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-selected)
       (:foreground "black"))

      ((frame-nonselected tab-nonselected)
       (:foreground "black" :background "gray40" :font "-*-fixed-medium-r-*-*-12-*-*-*-*-*-*-*"))
      ((delimiter-left frame-nonselected tab-nonselected)
       (:foreground "white"))
      ((delimiter-right frame-nonselected tab-nonselected)
       (:foreground "black"))

      (t (:foreground "white"))))

    (face x-border-face
     (((selected) (:foreground "white"))
      (t (:foreground "dark"))))

    (face xwem-frame-inner-border-face
     (((light nonselected)
       (:foreground "gray80"))
      ((medium nonselected)
       (:foreground "gray50"))
      ((dark nonselected)
       (:foreground "gray20"))
      ((light selected)
       (:foreground "white"))
      ((medium selected)
       (:foreground "gray50"))
      ((dark selected)
       (:foreground "dark"))))

    (face xwem-launch-dock-face
     (((background-light)
       (:foreground "gray70"))
      ((background-light shadow-light)
       (:foreground "white"))
      ((background-light shadow-dark)
       (:foreground "black"))
      ((background-dark)
       (:foreground "gray50"))
      ((background-dark shadow-light)
       (:foreground "white"))
      ((background-dark shadow-dark)
       (:foreground "black"))
      (t (:foreground "gray70" :background "black"))))

    (face xwem-strokes-face
     (((background light)
       (:foreground "dimgray" :background "black"))
      ((background dark)
       (:foreground "lightgray" :background "black"))
      ((background begin light)
       (:foreground "darkslategrey" :background "black"
        :line-width 12 :cap-style X-CapRound))
      ((background begin dark)
       (:foreground "grey" :background "black"
        :line-width 12 :cap-style X-CapRound))
      (t (:foreground "dimgray" :background "black"
          :line-width 6 :cap-style X-CapRound
          :subwindow-mode X-IncludeInferiors
          :function (eval xwem-strokes-gc-function)))))

    (face xwem-tray-delimiter-face
     (((background light)
       (:foreground "gray40"))
      ((background light shadow)
       (:foreground "gray30"))
      ((background dark)
       (:foreground "gray70"))
      ((background dark shadow)
       (:foreground "gray80"))))

    (face xwem-window-outline-face
     (((frame-selected win-selected)
       (:foreground "dark" :background "dark"))
      ((frame-selected win-nonselected)
       (:foreground "gray50" :background "gray50"))
      ((frame-nonselected win-selected)
       (:foreground "gray20" :background "gray20"))
      ((frame-nonselected win-nonselected)
       (:foreground "gray60" :background "gray40"))))

    (face xwem-window-delimiter-face
     (((horizontal)
       (:foreground "gray30" :background "black"))
      ((horizontal shadow)
       (:foreground "gray10" :background "black"))
      ((horizontal light shadow)
       (:foreground "gray80" :background "black"))
      ((vertical)
       (:foreground "gray10" :background "black"))
      ((shadow vertical)
       (:foreground "gray40" :background "black"))
      ((light shadow vertical)
       (:foreground "white" :background "black"))
      (t (:foreground "gray20" :background "black"))))

    ;; Frames properties
    (frame-property inner-border-width 3)
    (frame-property inner-border-thickness 1)
    (frame-property title-height 12)

    ;; Clients properties
    (client-property x-border-width 3)

    ;; Custom settings
    (custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")
    )
  "Extrimal xwem theme."
  :type 'xwem-theme
  :group 'xwem-theme)

;;;; Cursor themes
(defconst xwem-cursor-default-theme
  '((custom xwem-cursor-help-foreground-color "#00BB00")
    (custom xwem-cursor-help-background-color "#009900")
    (custom xwem-root-cursor-foreground-color "white")
    (custom xwem-root-cursor-background-color "black")
    (custom xwem-frame-cursor-foreground-color "#111111")
    (custom xwem-frame-cursor-background-color "#EEEEEE")))

(defconst xwem-cursor-extrim-theme
  `((custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")))

(defconst xwem-cursor-ocean-theme
  `((custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")))

(defconst xwem-cursor-spring-theme
  `((custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")))

(defconst xwem-cursor-winter-theme
  `((custom xwem-cursor-help-foreground-color "#888888")
    (custom xwem-cursor-help-background-color "#080808")
    (custom xwem-root-cursor-foreground-color "black")
    (custom xwem-root-cursor-background-color "white")
    (custom xwem-frame-cursor-foreground-color "white")
    (custom xwem-frame-cursor-background-color "black")))

(defvar xwem-cursor-themes
  '((default . xwem-cursor-default-theme)
    (extrim . xwem-cursor-extrim-theme)
    (ocean . xwem-cursor-ocean-theme)
    (spring . xwem-cursor-spring-theme)
    (winter . xwem-cursor-winter-theme))
  "Alist of themes for cursors colors.
Alist in form \(THEME-NAME . THEME-VAR\).")

;;;; Frame themes
(defconst xwem-frame-default-theme
  '((frame-property inner-border-width 8)
    (frame-property inner-border-thickness 2)
    (frame-property title-height 18)))

(defconst xwem-frame-extrim-theme
  '((frame-property inner-border-width 3)
    (frame-property inner-border-thickness 1)
    (frame-property title-height 12)))

(defvar xwem-frame-themes
  '((default . xwem-frame-default-theme)
    (extrim . xwem-frame-extrim-theme))
  "Alist of themes for frame.
Alist in form \(THEME-NAME . THEME-VAR\).")

;;; Internal variables
(defvar xwem-managing-themes nil
  "List of themes to manage clients.")


(defvar xwem-face-themes nil
  "List of themes for xwem faces.")

(defvar xwem-frame-themes nil
  "List of themes for frames.")

(defvar xwem-client-themes nil
  "List of themes for clients.")

(defvar xwem-theme-themes '(xwem-theme-default xwem-theme-extrim)
  "List of themes.")
  
(defun xwem-theme-apply-face-spec (face spec domain)
  "Apply to FACE it spec."
  (let (tag-set vplist tt tv vfont)
    (while spec
      (setq tag-set (car (car spec))
            vplist (cadr (car spec))
            vfont nil)

      ;; Apply attributes
      (while vplist
        (setq tt (car vplist)
              tv (cadr vplist))
        (cond ((eq tt :foreground)
               (xwem-set-face-foreground face tv tag-set domain))
              ((eq tt :background)
               (xwem-set-face-background face tv tag-set domain))
              ((eq tt :line-style)
               (xwem-set-face-line-style face tv tag-set domain))
              ((eq tt :line-width)
               (xwem-set-face-line-width face tv tag-set domain))
              ((eq tt :cap-style)
               (xwem-set-face-cap-style face tv tag-set domain))
              ((eq tt :join-style)
               (xwem-set-face-join-style face tv tag-set domain))
              ((eq tt :function)
               (xwem-set-face-function face tv tag-set domain))
              ((eq tt :subwindow-mode)
               (xwem-set-face-subwindow-mode face tv tag-set domain))
              ((eq tt :graphics-exposures)
               (xwem-set-face-graphics-exposures face tv tag-set domain))
              ((eq tt :font)
               (setq vfont tv)
               (xwem-set-face-font face tv tag-set domain))
              ((eq tt :bold)
               (if tv
                   (setq tv (or (x-make-font-bold (or vfont (face-font-name face)))
                                (or vfont (face-font-name face '(default)))))
                 (setq tv (or (x-make-font-unbold (or vfont (face-font-name face)))
                              (or vfont (face-font-name face '(default))))))
               (setq vfont tv)
               (xwem-set-face-font face tv tag-set domain))
              ((eq tt :italic)
               (if tv
                   (setq tv (or (x-make-font-italic (or vfont (face-font-name face)))
                                (or vfont (face-font-name face '(default)))))
                 (setq tv (or (x-make-font-unitalic (face-font-name face))
                              (or vfont (face-font-name face '(default))))))
               (setq vfont tv)
               (xwem-set-face-font face tv tag-set domain)))
        (setq vplist (cddr vplist)))
      (setq spec (cdr spec)))))

(defun xwem-theme-apply (theme &optional domain)
  "Apply theme to DOMAIN.
If DOMAIN is omitted, apply THEME globally."
  (mapc (lambda (tspec)
          (case (car tspec)
            (face
             (xwem-theme-apply-face-spec (cadr tspec) (caddr tspec) domain))

            (frame-property
             (if (and domain (xwem-frame-p domain))
                 (xwem-frame-set-property domain (cadr tspec) (caddr tspec))
               (mapc (lambda (f)
                       (xwem-frame-set-property f (cadr tspec) (caddr tspec)))
                     (xwem-frames-list))))

            (client-property
             (if (and domain (xwem-cl-p domain))
                 (xwem-client-set-property domain (cadr tspec) (caddr tspec))
               (mapc (lambda (c)
                       (xwem-client-set-property c (cadr tspec) (caddr tspec)))
                     (xwem-clients-list))))

            (custom
             (customize-set-variable (cadr tspec) (caddr tspec)))))
        theme))

;;;###autoload(autoload 'xwem-theme-set "xwem-theme" nil t)
(define-xwem-command xwem-theme-set (theme &optional domain)
  "Interactively set theme."
  (xwem-interactive (list (xwem-completing-read "XWEM Theme [default]: "
                                                (mapcar (lambda (el)
                                                          (last (split-string (symbol-name el) "-")))
                                                        xwem-theme-themes)
                                                nil t)
                          (xwem-completing-read "XWEM Domain [global]: "
                                                '(("client") ("window") ("frame"))
                                                nil t)))

  ;; Fix theme
  (if (string= "" theme)
      (setq theme xwem-theme-default)
    (setq theme (symbol-value (intern (concat "xwem-theme-" theme)))))

  ;; Fix domain
  (cond ((string= "client" domain)
         (setq domain (xwem-cl-selected)))
        ((string= "window" domain)
         (setq domain (xwem-win-selected)))
        ((string= "frame" domain)
         (setq domain (xwem-frame-selected)))
        (t (setq domain nil)))

  (xwem-theme-apply theme domain))


(provide 'xwem-theme)

;;; xwem-theme.el ends here