/[mcclim]/mcclim/ports.lisp
ViewVC logotype

Contents of /mcclim/ports.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (show annotations)
Thu Feb 28 21:00:10 2002 UTC (12 years, 1 month ago) by mikemac
Branch: MAIN
Changes since 1.24: +23 -1 lines
first cut at port-wait-on-event-processing
1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2
3 ;;; (c) copyright 1998,1999,2000,2001 by Michael McDonald (mikemac@mikemac.com)
4 ;;; (c) copyright 2000 by
5 ;;; Iban Hatchondo (hatchond@emi.u-bordeaux.fr)
6 ;;; Julien Boninfante (boninfan@emi.u-bordeaux.fr)
7 ;;; Robert Strandh (strandh@labri.u-bordeaux.fr)
8
9 ;;; This library is free software; you can redistribute it and/or
10 ;;; modify it under the terms of the GNU Library General Public
11 ;;; License as published by the Free Software Foundation; either
12 ;;; version 2 of the License, or (at your option) any later version.
13 ;;;
14 ;;; This library is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;;; Library General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU Library General Public
20 ;;; License along with this library; if not, write to the
21 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;;; Boston, MA 02111-1307 USA.
23
24 (in-package :CLIM-INTERNALS)
25
26 (defvar *default-server-path* NIL)
27
28 (defvar *server-path-search-order* '(:clx :x11 :genera))
29
30 (defun find-default-server-path ()
31 (loop for port in *server-path-search-order*
32 if (get port :port-type)
33 do (return-from find-default-server-path (list port))
34 finally (error "No CLIM backends have been loaded!")))
35
36 (defvar *all-ports* nil)
37
38 (defclass port ()
39 ()
40 (:documentation
41 "The protocol class that corresponds to a port."))
42
43 (defclass basic-port (port)
44 ((server-path :initform nil
45 :initarg :server-path
46 :reader port-server-path)
47 (properties :initform nil
48 :initarg :properties)
49 (grafts :initform nil
50 :accessor port-grafts)
51 (frame-managers :initform nil
52 :reader frame-managers)
53 (sheet->mirror :initform (make-hash-table :test #'eq))
54 (mirror->sheet :initform (make-hash-table :test #'eq))
55 (pixmap->mirror :initform (make-hash-table :test #'eq))
56 (mirror->pixmap :initform (make-hash-table :test #'eq))
57 (keyboard-input-focus :initform nil
58 :initarg :keyboard-input-focus
59 :accessor port-keyboard-input-focus)
60 (event-process
61 :initform nil
62 :initarg :event-process
63 :accessor port-event-process
64 :documentation "In a multiprocessing environment, the particular process
65 reponsible for calling PROCESS-NEXT-EVENT in a loop.")
66
67 (lock
68 :initform (make-recursive-lock "port lock")
69 :accessor port-lock)
70 (event-count :initform 0)
71 ))
72
73 (defun find-port (&key (server-path *default-server-path*))
74 (if (null server-path)
75 (setq server-path (find-default-server-path)))
76 (if (atom server-path)
77 (setq server-path (list server-path)))
78 (setq server-path (funcall (get (first server-path) :server-path-parser) server-path))
79 (loop for port in *all-ports*
80 if (equal server-path (port-server-path port))
81 do (return port)
82 finally (let ((port-type (get (first server-path) :port-type))
83 port)
84 (if (null port-type)
85 (error "Don't know how to make a port of type ~S" server-path))
86 (setq port (funcall 'make-instance port-type :server-path server-path))
87 (push port *all-ports*)
88 (return port))))
89
90 (defmethod initialize-instance :after ((port basic-port) &rest args)
91 (declare (ignorable args))
92 )
93
94 (defmethod destroy-port :before ((port basic-port))
95 (when *multiprocessing-p*
96 (destroy-process (port-event-process port))
97 (setf (port-event-process port) nil)))
98
99 (defmethod port-lookup-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
100 (gethash sheet (slot-value port 'sheet->mirror)))
101
102 (defmethod port-lookup-sheet ((port basic-port) mirror)
103 (gethash mirror (slot-value port 'mirror->sheet)))
104
105 (defmethod port-register-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
106 (setf (gethash sheet (slot-value port 'sheet->mirror)) mirror)
107 (setf (gethash mirror (slot-value port 'mirror->sheet)) sheet)
108 nil)
109
110 (defmethod port-unregister-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
111 (remhash sheet (slot-value port 'sheet->mirror))
112 (remhash mirror (slot-value port 'mirror->sheet))
113 nil)
114
115 (defmethod realize-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
116 (error "Don't know how to realize the mirror of a generic mirrored-sheet"))
117
118 (defmethod destroy-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
119 (error "Don't know how to destroy the mirror of a generic mirrored-sheet"))
120
121 (defmethod mirror-transformation ((port basic-port) mirror)
122 (declare (ignore mirror))
123 (error "MIRROR-TRANSFORMATION is not implemented for generic ports"))
124
125 (defmethod port-properties ((port basic-port) indicator)
126 (with-slots (properties) port
127 (getf properties indicator)))
128
129 (defmethod (setf port-properties) (value (port basic-port) indicator)
130 (with-slots (properties) port
131 (setf (getf properties indicator) value)))
132
133 (defmethod get-next-event ((port basic-port) &key wait-function timeout)
134 (declare (ignore wait-function timeout))
135 (error "Calling GET-NEXT-EVENT on a PORT protocol class"))
136
137 (defmethod get-next-event :after ((port basic-port) &key wait-function timeout)
138 (declare (ignore wait-function timeout))
139 (with-slots (event-count) port
140 (incf event-count)))
141
142 (defmethod process-next-event ((port basic-port) &key wait-function timeout)
143 (let ((event (get-next-event port :wait-function wait-function :timeout timeout)))
144 (cond
145 ((null event) nil)
146 ((eq event :timeout) (values nil :timeout))
147 (t
148 (distribute-event port event)
149 t))))
150
151 (defmethod port-wait-on-event-processing ((port basic-port) &key wait-function timeout)
152 (declare (ignorable wait-function))
153 (if *multiprocessing-p*
154 (with-slots (event-count) port
155 (let ((old-event-count event-count)
156 (flag nil))
157 (process-wait-with-timeout "Wait for event" timeout
158 #'(lambda ()
159 (when (not (= old-event-count event-count))
160 (setq flag t))))
161 (if flag
162 t
163 (values nil :timeout))))
164 (process-next-event port :wait-function wait-function :timeout timeout)))
165
166 (defmethod distribute-event ((port basic-port) event)
167 (cond
168 ((typep event 'keyboard-event)
169 (dispatch-event (or (port-keyboard-input-focus port)
170 (event-sheet event)) event))
171 ((typep event 'window-event)
172 ; (dispatch-event (window-event-mirrored-sheet event) event))
173 (dispatch-event (event-sheet event) event))
174 ((typep event 'pointer-event)
175 (dispatch-event (event-sheet event) event))
176 ((typep event 'window-manager-delete-event)
177 ;; not sure where this type of event should get sent - mikemac
178 (queue-event (frame-standard-input (pane-frame (event-sheet event))) event))
179 ((typep event 'timer-event)
180 (error "Where do we send timer-events?"))
181 (t
182 (error "Unknown event ~S received in DISTRIBUTE-EVENT" event))))
183
184 (defmacro with-port-locked ((port) &body body)
185 (let ((fn (gensym "CONT.")))
186 `(labels ((,fn ()
187 ,@body))
188 (declare (dynamic-extent #',fn))
189 `(invoke-with-port-locked ,port #',fn))))
190
191 (defmethod invoke-with-port-locked ((port basic-port) continuation)
192 (with-recursive-lock-held ((port-lock port))
193 (funcall continuation)))
194
195 (defun map-over-ports (function)
196 (mapc function *all-ports*))
197
198 (defmethod restart-port ((port basic-port))
199 (reset-watcher port :restart)
200 nil)
201
202 (defmethod destroy-port ((port basic-port))
203 (reset-watcher port :destroy)
204 (setf *all-ports* (remove port *all-ports*)))
205
206 (defmethod add-watcher ((port basic-port) watcher)
207 (declare (ignore watcher))
208 nil)
209
210 (defmethod delete-watcher ((port basic-port) watcher)
211 (declare (ignore watcher))
212 nil)
213
214 (defmethod reset-watcher ((port basic-port) how)
215 (declare (ignore how))
216 nil)
217
218 (defmethod make-graft ((port basic-port) &key (orientation :default) (units :device))
219 (let ((graft (make-instance 'graft
220 :port port :mirror nil
221 :orientation orientation :units units)))
222 (push graft (port-grafts port))
223 graft))
224
225 #||
226 (defmethod make-medium ((port basic-port) sheet)
227 (make-instance 'basic-medium :port port :graft (graft sheet) :sheet sheet))
228 ||#
229
230 ;;; Pixmap
231
232 (defmethod port-lookup-mirror ((port basic-port) (pixmap pixmap))
233 (gethash pixmap (slot-value port 'pixmap->mirror)))
234
235 (defmethod port-lookup-pixmap ((port basic-port) mirror)
236 (gethash mirror (slot-value port 'mirror->pixmap)))
237
238 (defmethod port-register-mirror ((port basic-port) (pixmap pixmap) mirror)
239 (setf (gethash pixmap (slot-value port 'pixmap->mirror)) mirror)
240 (setf (gethash mirror (slot-value port 'mirror->pixmap)) pixmap)
241 nil)
242
243 (defmethod port-unregister-mirror ((port basic-port) (pixmap pixmap) mirror)
244 (remhash pixmap (slot-value port 'pixmap->mirror))
245 (remhash mirror (slot-value port 'mirror->pixmap))
246 nil)
247
248 (defmethod realize-mirror ((port basic-port) (pixmap mirrored-pixmap))
249 (declare (ignorable port pixmap))
250 (error "Don't know how to realize the mirror on a generic port"))
251
252 (defmethod destroy-mirror ((port basic-port) (pixmap mirrored-pixmap))
253 (declare (ignorable port pixmap))
254 (error "Don't know how to destroy the mirror on a generic port"))
255
256 (defmethod port-allocate-pixmap ((port basic-port) sheet width height)
257 (declare (ignore sheet width height))
258 (error "ALLOCATE-PIXMAP is not implemented for generic PORTs"))
259
260 (defmethod port-deallocate-pixmap ((port basic-port) pixmap)
261 (declare (ignore pixmap))
262 (error "DEALLOCATE-PIXMAP is not implemented for generic PORTs"))

  ViewVC Help
Powered by ViewVC 1.1.5