File: server.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 (98 lines) | stat: -rw-r--r-- 3,384 bytes parent folder | download | duplicates (5)
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
;; server.jl -- execute forms on demand
;; $Id: server.jl,v 1.13 2000/09/11 07:44:42 john Exp $

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

;; Commentary:

;; The protocol is something like:

;;	1. Send a ClientMessage event to the window identified by the
;;	property _SAWFISH_REQUEST_WIN on the root window, event mask 0,
;;	with the event's window field set to the root window, type
;;	_SAWFISH_REQUEST, format 32. data.l[0] = protocol version (1),
;;	data.l[1] = window to use for properties, data.l[2] = property
;;	containing form to evaluate, data.l[3] is non-zero if a result
;;	it required.

;;	2. The wm reads and evaluates the form from the specified
;;	property on the specified window.

;;	3. If a result is required it overwrites the form with its
;;	value, and assumes that the client will delete the property
;;	after it has read it. If no result is required, it will delete
;;	the property after having read it.

;; The result is a string, it's first byte defines whether an error
;; occurred or not, \001 if okay, \002 if an error
(define-structure sawfish.wm.server

    (export server-eval
	    server-net-init
	    server-net-exit)

    (open rep
	  rep.system
	  sawfish.wm.misc
	  sawfish.wm.windows)

  (defconst protocol-version 1)

  (define server-window nil)

  (define (server-eval form)
    (let ((print-escape t))
      (condition-case error-data
	  (progn
	    (setq form (read-from-string form))
	    (format nil "\001%S" (user-eval form)))
	(error
	 (format nil "\002%S" error-data)))))

  (define (server-client-message-handler w type data)
    (when (and server-window (eq w 'root)
	       (eq type '_SAWFISH_REQUEST)
	       (= (aref data 0) protocol-version))
      (let* ((window (aref data 1))
	     (prop (x-atom-name (aref data 2)))
	     (needs-result (/= (aref data 3) 0))
	     (form-data (get-x-property window prop)))
	(if needs-result
	    (set-x-property
	     window prop (server-eval (nth 2 form-data)) 'STRING 8)
	  (delete-x-property window prop)
	  (server-eval (nth 2 form-data)))
	t)))

  (define (server-net-init)
    (unless server-window
      (setq server-window (create-window 'root -100 -100 10 10))
      (set-x-property 'root '_SAWFISH_REQUEST_WIN
		      (vector server-window) 'CARDINAL 32)
      (set-x-property server-window '_SAWFISH_REQUEST_WIN
		      (vector server-window) 'CARDINAL 32)))

  (define (server-net-exit)
    (when server-window
      (delete-x-property 'root '_SAWFISH_REQUEST_WIN)
      (destroy-window server-window)
      (setq server-window nil)))

  (add-hook 'client-message-hook server-client-message-handler)
  (add-hook 'before-exit-hook server-net-exit))