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

Contents of /mcclim/ports.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (hide annotations)
Mon Apr 29 05:00:33 2002 UTC (11 years, 11 months ago) by brian
Branch: MAIN
Changes since 1.29: +1 -1 lines
OpenGL backend now draws stuff (but not much else).
Misc cleaning up, some regions debugging.
1 mikemac 1.1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2    
3 mikemac 1.19 ;;; (c) copyright 1998,1999,2000,2001 by Michael McDonald (mikemac@mikemac.com)
4 cvs 1.5 ;;; (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 mikemac 1.1
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 mikemac 1.22 (defvar *default-server-path* NIL)
27    
28 brian 1.30 (defvar *server-path-search-order* '(#+gl :opengl :clx :x11 :genera))
29 mikemac 1.22
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 mikemac 1.1
36     (defvar *all-ports* nil)
37    
38     (defclass port ()
39 gilbert 1.21 ()
40     (:documentation
41     "The protocol class that corresponds to a port."))
42    
43     (defclass basic-port (port)
44 mikemac 1.1 ((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 cvs 1.10 (pixmap->mirror :initform (make-hash-table :test #'eq))
56     (mirror->pixmap :initform (make-hash-table :test #'eq))
57 mikemac 1.1 (keyboard-input-focus :initform nil
58     :initarg :keyboard-input-focus
59     :accessor port-keyboard-input-focus)
60 gilbert 1.21 (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 mikemac 1.25 :accessor port-lock)
70     (event-count :initform 0)
71     ))
72 mikemac 1.1
73     (defun find-port (&key (server-path *default-server-path*))
74 mikemac 1.22 (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 mikemac 1.1 (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 gilbert 1.21 (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 mikemac 1.1 (gethash sheet (slot-value port 'sheet->mirror)))
101    
102 gilbert 1.21 (defmethod port-lookup-sheet ((port basic-port) mirror)
103 mikemac 1.1 (gethash mirror (slot-value port 'mirror->sheet)))
104    
105 gilbert 1.21 (defmethod port-register-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
106 mikemac 1.1 (setf (gethash sheet (slot-value port 'sheet->mirror)) mirror)
107     (setf (gethash mirror (slot-value port 'mirror->sheet)) sheet)
108     nil)
109    
110 gilbert 1.21 (defmethod port-unregister-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
111 mikemac 1.1 (remhash sheet (slot-value port 'sheet->mirror))
112     (remhash mirror (slot-value port 'mirror->sheet))
113     nil)
114    
115 gilbert 1.21 (defmethod realize-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
116 mikemac 1.1 (error "Don't know how to realize the mirror of a generic mirrored-sheet"))
117    
118 gilbert 1.21 (defmethod destroy-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
119 rouanet 1.15 (error "Don't know how to destroy the mirror of a generic mirrored-sheet"))
120 mikemac 1.1
121 gilbert 1.21 (defmethod mirror-transformation ((port basic-port) mirror)
122 rouanet 1.16 (declare (ignore mirror))
123     (error "MIRROR-TRANSFORMATION is not implemented for generic ports"))
124    
125 gilbert 1.21 (defmethod port-properties ((port basic-port) indicator)
126 mikemac 1.1 (with-slots (properties) port
127     (getf properties indicator)))
128    
129 gilbert 1.21 (defmethod (setf port-properties) (value (port basic-port) indicator)
130 mikemac 1.1 (with-slots (properties) port
131     (setf (getf properties indicator) value)))
132    
133 gilbert 1.21 (defmethod get-next-event ((port basic-port) &key wait-function timeout)
134 mikemac 1.1 (declare (ignore wait-function timeout))
135     (error "Calling GET-NEXT-EVENT on a PORT protocol class"))
136    
137 mikemac 1.25 (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 gilbert 1.21 (defmethod process-next-event ((port basic-port) &key wait-function timeout)
143 moore 1.26 (let ((event (get-next-event port
144     :wait-function wait-function
145     :timeout timeout)))
146 mikemac 1.1 (cond
147     ((null event) nil)
148     ((eq event :timeout) (values nil :timeout))
149     (t
150 moore 1.27 (distribute-event port event)
151 mikemac 1.1 t))))
152    
153 moore 1.27 ;;; Called in the application frame process.
154 moore 1.26 (defmethod port-wait-on-event-processing ((port basic-port) &key wait-function timeout
155     ((:event-count old-count) nil))
156 mikemac 1.25 (declare (ignorable wait-function))
157 moore 1.29 (with-slots (event-count) port
158     (if *multiprocessing-p*
159 moore 1.26 (let ((old-event-count (or old-count event-count))
160 mikemac 1.25 (flag nil))
161 moore 1.27 (flet ((wait-fn ()
162     (when (not (eql old-event-count event-count))
163     (setq flag t))))
164     (if timeout
165     (process-wait-with-timeout "Wait for event" timeout #'wait-fn)
166     (process-wait "Wait for event" #'wait-fn))
167     (if flag
168     event-count
169 moore 1.29 (values nil :timeout))))
170     (multiple-value-bind (result reason)
171     (process-next-event port
172     :wait-function wait-function
173     :timeout timeout)
174     (values (and result event-count) reason)))))
175 mikemac 1.25
176 gilbert 1.21 (defmethod distribute-event ((port basic-port) event)
177 mikemac 1.1 (cond
178     ((typep event 'keyboard-event)
179 moore 1.27 (dispatch-event (or (port-keyboard-input-focus port) (event-sheet event))
180     event))
181 mikemac 1.1 ((typep event 'window-event)
182 brian 1.28 ; (dispatch-event (window-event-mirrored-sheet event) event)
183 cvs 1.4 (dispatch-event (event-sheet event) event))
184 mikemac 1.1 ((typep event 'pointer-event)
185     (dispatch-event (event-sheet event) event))
186 mikemac 1.23 ((typep event 'window-manager-delete-event)
187     ;; not sure where this type of event should get sent - mikemac
188 moore 1.27 ;; This seems fine; will be handled by the top-level-sheet-pane - moore
189     (dispatch-event (event-sheet event) event))
190 mikemac 1.1 ((typep event 'timer-event)
191     (error "Where do we send timer-events?"))
192     (t
193     (error "Unknown event ~S received in DISTRIBUTE-EVENT" event))))
194    
195 gilbert 1.21 (defmacro with-port-locked ((port) &body body)
196     (let ((fn (gensym "CONT.")))
197     `(labels ((,fn ()
198     ,@body))
199     (declare (dynamic-extent #',fn))
200 moore 1.29 (invoke-with-port-locked ,port #',fn))))
201 gilbert 1.21
202     (defmethod invoke-with-port-locked ((port basic-port) continuation)
203     (with-recursive-lock-held ((port-lock port))
204     (funcall continuation)))
205    
206 mikemac 1.1 (defun map-over-ports (function)
207     (mapc function *all-ports*))
208    
209 gilbert 1.21 (defmethod restart-port ((port basic-port))
210 mikemac 1.1 (reset-watcher port :restart)
211     nil)
212    
213 gilbert 1.21 (defmethod destroy-port ((port basic-port))
214 mikemac 1.1 (reset-watcher port :destroy)
215     (setf *all-ports* (remove port *all-ports*)))
216    
217 gilbert 1.21 (defmethod add-watcher ((port basic-port) watcher)
218 mikemac 1.1 (declare (ignore watcher))
219     nil)
220    
221 gilbert 1.21 (defmethod delete-watcher ((port basic-port) watcher)
222 mikemac 1.1 (declare (ignore watcher))
223     nil)
224    
225 gilbert 1.21 (defmethod reset-watcher ((port basic-port) how)
226 mikemac 1.1 (declare (ignore how))
227     nil)
228    
229 gilbert 1.21 (defmethod make-graft ((port basic-port) &key (orientation :default) (units :device))
230 mikemac 1.1 (let ((graft (make-instance 'graft
231     :port port :mirror nil
232     :orientation orientation :units units)))
233     (push graft (port-grafts port))
234     graft))
235    
236 gilbert 1.21 #||
237     (defmethod make-medium ((port basic-port) sheet)
238 rouanet 1.16 (make-instance 'basic-medium :port port :graft (graft sheet) :sheet sheet))
239 gilbert 1.21 ||#
240 mikemac 1.1
241 cvs 1.10 ;;; Pixmap
242    
243 gilbert 1.21 (defmethod port-lookup-mirror ((port basic-port) (pixmap pixmap))
244 cvs 1.10 (gethash pixmap (slot-value port 'pixmap->mirror)))
245    
246 gilbert 1.21 (defmethod port-lookup-pixmap ((port basic-port) mirror)
247 cvs 1.10 (gethash mirror (slot-value port 'mirror->pixmap)))
248    
249 gilbert 1.21 (defmethod port-register-mirror ((port basic-port) (pixmap pixmap) mirror)
250 cvs 1.10 (setf (gethash pixmap (slot-value port 'pixmap->mirror)) mirror)
251     (setf (gethash mirror (slot-value port 'mirror->pixmap)) pixmap)
252     nil)
253    
254 gilbert 1.21 (defmethod port-unregister-mirror ((port basic-port) (pixmap pixmap) mirror)
255 cvs 1.10 (remhash pixmap (slot-value port 'pixmap->mirror))
256     (remhash mirror (slot-value port 'mirror->pixmap))
257     nil)
258    
259 gilbert 1.21 (defmethod realize-mirror ((port basic-port) (pixmap mirrored-pixmap))
260 cvs 1.10 (declare (ignorable port pixmap))
261     (error "Don't know how to realize the mirror on a generic port"))
262    
263 gilbert 1.21 (defmethod destroy-mirror ((port basic-port) (pixmap mirrored-pixmap))
264 cvs 1.10 (declare (ignorable port pixmap))
265 rouanet 1.15 (error "Don't know how to destroy the mirror on a generic port"))
266 cvs 1.10
267 gilbert 1.21 (defmethod port-allocate-pixmap ((port basic-port) sheet width height)
268 mikemac 1.1 (declare (ignore sheet width height))
269 cvs 1.10 (error "ALLOCATE-PIXMAP is not implemented for generic PORTs"))
270 mikemac 1.1
271 gilbert 1.21 (defmethod port-deallocate-pixmap ((port basic-port) pixmap)
272 mikemac 1.1 (declare (ignore pixmap))
273 cvs 1.10 (error "DEALLOCATE-PIXMAP is not implemented for generic PORTs"))

  ViewVC Help
Powered by ViewVC 1.1.5