File: gaol.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-- 4,241 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
#| gaol.jl -- protected environment for themes

   $Id: gaol.jl,v 1.35 2002/11/03 04:23:45 jsh Exp $

   Copyright (C) 1999, 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.gaol

    (export make-gaol
	    gaol-load
	    gaol-eval
	    gaol-add
	    gaol-define
	    gaol-define-special
	    define-gaol-structure)

    (open rep
	  rep.io.files
	  sawfish.wm.colors
	  sawfish.wm.cursors
	  sawfish.wm.events
	  sawfish.wm.fonts
	  sawfish.wm.images
	  sawfish.wm.misc
	  rep.util.gaol)

  ;; safe functions in the core module
  (define safe-functions
    '(get-color-rgb get-color color-name color-rgb colorp get-cursor
      cursorp get-font get-font-typed font-type-exists-p font-name
      fontp font-type text-width font-height font-ascent font-descent
      screen-width screen-height get-x-property get-x-text-property
      list-x-properties x-atom x-atom-name make-image
      make-image-from-x-drawable copy-image
      flip-image-horizontally flip-image-vertically
      flip-image-diagonally image-get
      image-put imagep image-dimensions image-border set-image-border
      image-shape-color set-image-shape-color image-modifier
      set-image-modifier make-sized-image bevel-image clear-image
      tile-image scale-image composite-images crop-image
      make-keymap bind-keys unbind-keys keymapp eventp
      image-ref image-set image-map image-fill color-rgb-8 uniquify-list))

  (define safe-specials
    '(default-foreground display-name canonical-display-name
      default-font default-frame nil-frame frame-part-classes
      decorate-transients batch-mode))

  (define safe-features '(sawfish.wm.util.gtkrc
			  sawfish.wm.util.x
			  ;; compatibility
			  gtkrc x))
  (define fully-safe-features '(rep.io.timers rep.data.tables
				rep.data.records rep.data.ring
				rep.data.queues rep.data.symbol-table
				sawfish.wm.util.gradient
				sawfish.wm.util.recolor-image
				sawfish.wm.theming.make-theme
				;; compatibility
				timers gradient make-theme))

;;; functions

  (defmacro gaol-add vars
    `(mapc (lambda (x) (gaol-define x (symbol-value x))) ',vars))

  (defun gaol:require (feature)
    (cond ((memq feature fully-safe-features) (gaol-open feature))
	  ((memq feature safe-features) (load-module feature))
	  (t (error "Gaolled code trying to require %s" feature))))

;;; initialize the gaol envrironment

  ;; for backwards compatibility, / is integer division in themes, use
  ;; `divide' for real division
  (gaol-define 'divide /)
  (gaol-define '/ quotient)

  ;; use safe version of require
  (gaol-define 'require gaol:require)

  ;; add standard bindings
  (mapc (lambda (x)
	  (if (boundp x)
	      (gaol-define x (symbol-value x))
	    (format standard-error "warning: %s unbound\n" x))) safe-functions)
  (mapc gaol-define-special safe-specials)

  ;; a plugin, so easier to do this here..
  (call-after-load "sawfish.wm.util.x"
   (lambda ()
     (require 'sawfish.wm.util.x)
     (mapc (lambda (x) (gaol-define x (symbol-value x)))
	   '(x-create-gc x-change-gc x-destroy-gc x-gc-p
	     x-create-pixmap x-create-bitmap x-change-window-attributes
	     x-window-p x-destroy-drawable x-drawable-p
	     x-pixmap-p x-bitmap-p x-drawable-id x-drawable-width
	     x-drawable-height x-window-id x-window-back-buffer
	     x-window-swap-buffers x-clear-window x-draw-string
	     x-draw-line x-draw-rectangle x-fill-rectangle
	     x-draw-arc x-fill-arc x-fill-polygon x-copy-area
	     x-draw-image x-grab-image-from-drawable x-gc-set-dashes)))))