/[cmucl]/src/clx/input.lisp
ViewVC logotype

Contents of /src/clx/input.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Mon May 14 14:57:18 1990 UTC (23 years, 11 months ago) by ram
Changes since 1.1: +4 -4 lines
.../systems-work/nnclx/input.lisp, 12-May-90 16:13:04, Edit by Chiles.
  Masked out export of type-error.  This is in accordance with the expectation
  that the system has type-error defined in the "LISP" package.

  There are two definitions for the request-error condition, each exactly the
  same but one is before and one is after the definition for
  REPORT-REQUEST-ERROR.  I masked out the first one and masked in the second.
  This is in accordance with the default sillines the author followed.


1 ;;; -*- Mode: Lisp; Package: Xlib; Log: clx.log -*-
2
3 ;;; This file contains definitions for the DISPLAY object for Common-Lisp X windows version 11
4
5 ;;;
6 ;;; TEXAS INSTRUMENTS INCORPORATED
7 ;;; P.O. BOX 2909
8 ;;; AUSTIN, TEXAS 78769
9 ;;;
10 ;;; Copyright (C) 1987 Texas Instruments Incorporated.
11 ;;;
12 ;;; Permission is granted to any individual or institution to use, copy, modify,
13 ;;; and distribute this software, provided that this complete copyright and
14 ;;; permission notice is maintained, intact, in all copies and supporting
15 ;;; documentation.
16 ;;;
17 ;;; Texas Instruments Incorporated provides this software "as is" without
18 ;;; express or implied warranty.
19 ;;;
20
21 ;;;
22 ;;; Change history:
23 ;;;
24 ;;; Date Author Description
25 ;;; -------------------------------------------------------------------------------------
26 ;;; 12/10/87 LGO Created
27
28 (in-package :xlib)
29
30 (export '(
31 event-listen
32 queue-event
33 process-event
34 make-event-handlers
35 event-handler
36 event-case
37 event-cond
38 discard-current-event
39 request-error
40 value-error
41 window-error
42 pixmap-error
43 atom-error
44 cursor-error
45 font-error
46 match-error
47 drawable-error
48 access-error
49 alloc-error
50 colormap-error
51 gcontext-error
52 id-choice-error
53 name-error
54 length-error
55 implementation-error
56 request-error
57 resource-error
58 unknown-error
59 access-error
60 alloc-error
61 atom-error
62 colormap-error
63 cursor-error
64 drawable-error
65 font-error
66 gcontext-error
67 id-choice-error
68 illegal-request-error
69 length-error
70 match-error
71 name-error
72 pixmap-error
73 value-error
74 window-error
75 implementation-error
76 #-(or ansi-common-lisp CMU) type-error
77 closed-display
78 lookup-error
79 connection-failure
80 reply-length-error
81 reply-timeout
82 sequence-error
83 unexpected-reply
84 missing-parameter
85 invalid-font
86 device-busy
87 get-external-event-code
88 define-extension
89 extension-opcode
90 define-error
91 decode-core-error
92 declare-event
93 ))
94
95 ;; Event Resource
96 (defvar *event-free-list* nil) ;; List of unused (processed) events
97
98 (eval-when (eval compile load)
99 (defconstant *max-events* 64) ;; Maximum number of events supported (the X11 alpha release only has 34)
100 (defvar *event-key-vector* (make-array *max-events* :initial-element nil)
101 "Vector of event keys - See define-event")
102 )
103 (defvar *event-macro-vector* (make-array *max-events* :initial-element nil)
104 "Vector of event handler functions - See declare-event")
105 (defvar *event-handler-vector* (make-array *max-events* :initial-element nil)
106 "Vector of event handler functions - See declare-event")
107 (defvar *event-send-vector* (make-array *max-events* :initial-element nil)
108 "Vector of event sending functions - See declare-event")
109
110 (defun allocate-event ()
111 (or (threaded-atomic-pop *event-free-list* reply-next reply-buffer)
112 (make-reply-buffer *replysize*)))
113
114 (defun deallocate-event (reply-buffer)
115 (declare (type reply-buffer reply-buffer))
116 (setf (reply-size reply-buffer) *replysize*)
117 (threaded-atomic-push reply-buffer *event-free-list* reply-next reply-buffer))
118
119 ;; Extensions are handled as follows:
120 ;; DEFINITION: Use DEFINE-EXTENSION
121 ;;
122 ;; CODE: Use EXTENSION-CODE to get the X11 opcode for an extension.
123 ;; This looks up the code on the display-extension-alist.
124 ;;
125 ;; EVENTS: Use DECLARE-EVENT to define events. This calls ALLOCATE-EXTENSION-EVENT-CODE
126 ;; at LOAD time to define an internal event-code number
127 ;; (stored in the 'event-code property of the event-name)
128 ;; used to index the following vectors:
129 ;; *event-key-vector* Used for getting the event-key
130 ;; *event-macro-vector* Used for getting the event-parameter getting macros
131 ;;
132 ;; The GET-INTERNAL-EVENT-CODE function can be called at runtime to convert
133 ;; a server event-code into an internal event-code used to index the following
134 ;; vectors:
135 ;; *event-handler-vector* Used for getting the event-handler function
136 ;; *event-send-vector* Used for getting the event-sending function
137 ;;
138 ;; The GET-EXTERNAL-EVENT-CODE function can be called at runtime to convert
139 ;; internal event-codes to external (server) codes.
140 ;;
141 ;; ERRORS: Use DEFINE-ERROR to define new error decodings.
142 ;;
143
144
145 ;; Any event-code greater than 34 is for an extension
146 (defparameter *first-extension-event-code* 35)
147
148 (defvar *extensions* nil) ;; alist of (extension-name-symbol events errors)
149
150 (defmacro define-extension (name &key events errors)
151 ;; Define extension NAME with EVENTS and ERRORS.
152 ;; Note: The case of NAME is important.
153 ;; To define the request, Use:
154 ;; (with-buffer-request (display (extension-opcode ,name)) ,@body)
155 ;; See the REQUESTS file for lots of examples.
156 ;; To define event handlers, use declare-event.
157 ;; To define error handlers, use declare-error and define-condition.
158 (declare (type stringable name)
159 (type list events errors))
160 (let ((name-symbol (kintern name)) ;; Intern name in the keyword package
161 (event-list (mapcar #'canonicalize-event-name events)))
162 `(eval-when (compile load eval)
163 (setq *extensions* (cons (list ',name-symbol ',event-list ',errors)
164 (delete ',name-symbol *extensions* :key #'car))))))
165
166 (eval-when (compile eval load)
167 (defun canonicalize-event-name (event)
168 ;; Returns the event name keyword given an event name stringable
169 (declare (type stringable event))
170 (declare (values event-key))
171 (kintern event))
172 ) ;; end eval-when
173
174 (eval-when (compile eval load)
175 (defun allocate-extension-event-code (name)
176 ;; Allocate an event-code for an extension
177 ;; This is executed at COMPILE and LOAD time from DECLARE-EVENT.
178 ;; The event-code is used at compile-time by macros to index the following vectors:
179 ;; *event-key-vector* *event-macro-vector* *event-handler-vector* *event-send-vector*
180 (let ((event-code (get name 'event-code)))
181 (declare (type (or null card8) event-code))
182 (unless event-code
183 ;; First ensure the name is for a declared extension
184 (unless (dolist (extension *extensions*)
185 (when (member name (second extension))
186 (return t)))
187 (x-type-error name 'event-key))
188 (setq event-code (position nil *event-key-vector*
189 :start *first-extension-event-code*))
190 (setf (svref *event-key-vector* event-code) name)
191 (setf (get name 'event-code) event-code))
192 event-code))
193 ) ;; end eval-when
194
195 (defun get-internal-event-code (display code)
196 ;; Given an X11 event-code, return the internal event-code.
197 ;; The internal event-code is used for indexing into the following vectors:
198 ;; *event-key-vector* *event-handler-vector* *event-send-vector*
199 ;; Returns NIL when the event-code is for an extension that isn't handled.
200 (declare (type display display)
201 (type card8 code))
202 (declare (values (or nil card8)))
203 (setq code (logand #x7f code))
204 (if (< code *first-extension-event-code*)
205 code
206 (let* ((code-offset (- code *first-extension-event-code*))
207 (event-extensions (display-event-extensions display))
208 (code (if (< code-offset (length event-extensions))
209 (aref event-extensions code-offset)
210 0)))
211 (declare (type card8 code-offset code))
212 (when (zerop code)
213 (x-cerror "Ignore the event"
214 'unimplemented-event :event-code code :display display))
215 code)))
216
217 (defun get-external-event-code (display event)
218 ;; Given an X11 event name, return the event-code
219 (declare (type display display)
220 (type event-key event))
221 (declare (values card8))
222 (let ((code (get-event-code event)))
223 (declare (type (or null card8) code))
224 (when (>= code *first-extension-event-code*)
225 (setq code (+ *first-extension-event-code*
226 (or (position code (display-event-extensions display))
227 (x-error 'undefined-event :display display :event-name event)))))
228 code))
229
230 (defmacro extension-opcode (display name)
231 ;; Returns the major opcode for extension NAME.
232 ;; This is a macro to enable NAME to be interned for fast run-time
233 ;; retrieval.
234 ;; Note: The case of NAME is important.
235 (declare (type display display)
236 (type stringable name))
237 (declare (values card8))
238 (let ((name-symbol (kintern name))) ;; Intern name in the keyword package
239 `(or (second (assoc ',name-symbol (display-extension-alist ,display)))
240 (x-error 'absent-extension :name ',name-symbol :display ,display))))
241
242 (defun initialize-extensions (display)
243 ;; Initialize extensions for DISPLAY
244 (let ((event-extensions (make-array 16 :element-type 'card8 :initial-element 0))
245 (extension-alist nil))
246 (declare (type vector event-extensions)
247 (type list extension-alist))
248 (dolist (extension *extensions*)
249 (let ((name (first extension))
250 (events (second extension)))
251 (declare (type keyword name)
252 (type list events))
253 (multiple-value-bind (major-opcode first-event first-error)
254 (query-extension display name)
255 (declare (type (or null card8) major-opcode first-event first-error))
256 (when (and major-opcode (plusp major-opcode))
257 (push (list name major-opcode first-event first-error)
258 extension-alist)
259 (when (plusp first-event) ;; When there are extension events
260 ;; Grow extension vector when needed
261 (let ((max-event (- (+ first-event (length events))
262 *first-extension-event-code*)))
263 (declare (type card8 max-event))
264 (when (>= max-event (length event-extensions))
265 (let ((new-extensions (make-array (+ max-event 16) :element-type 'card8
266 :initial-element 0)))
267 (declare (type vector new-extensions))
268 (replace new-extensions event-extensions)
269 (setq event-extensions new-extensions))))
270 (dolist (event events)
271 (declare (type symbol event))
272 (setf (aref event-extensions (- first-event *first-extension-event-code*))
273 (get-event-code event))
274 (incf first-event)))))))
275 (setf (display-event-extensions display) event-extensions)
276 (setf (display-extension-alist display) extension-alist)))
277
278 ;;
279 ;; Reply handlers
280 ;;
281
282 (defvar *pending-command-free-list* nil)
283
284 (defun start-pending-command (display)
285 (declare (type display display))
286 (let ((pending-command (or (threaded-atomic-pop *pending-command-free-list*
287 pending-command-next pending-command)
288 (make-pending-command))))
289 (declare (type pending-command pending-command))
290 (setf (pending-command-reply-buffer pending-command) nil)
291 (setf (pending-command-process pending-command) (current-process))
292 (setf (pending-command-sequence pending-command)
293 (ldb (byte 16 0) (1+ (buffer-request-number display))))
294 ;; Add the pending command to the end of the threaded list of pending
295 ;; commands for the display.
296 (with-event-queue-internal (display)
297 (threaded-nconc pending-command (display-pending-commands display)
298 pending-command-next pending-command))
299 pending-command))
300
301 (defun stop-pending-command (display pending-command)
302 (declare (type display display)
303 (type pending-command pending-command))
304 (with-event-queue-internal (display)
305 ;; Remove the pending command from the threaded list of pending commands
306 ;; for the display.
307 (threaded-delete pending-command (display-pending-commands display)
308 pending-command-next pending-command)
309 ;; Deallocate any reply buffers in this pending command
310 (loop
311 (let ((reply-buffer
312 (threaded-pop (pending-command-reply-buffer pending-command)
313 reply-next reply-buffer)))
314 (declare (type (or null reply-buffer) reply-buffer))
315 (if reply-buffer
316 (deallocate-reply-buffer reply-buffer)
317 (return nil)))))
318 ;; Deallocate this pending-command
319 (threaded-atomic-push pending-command *pending-command-free-list*
320 pending-command-next pending-command)
321 nil)
322
323 ;;;
324
325 (defvar *reply-buffer-free-lists* (make-array 32 :initial-element nil))
326
327 (defun allocate-reply-buffer (size)
328 (declare (type array-index size))
329 (if (index<= size *replysize*)
330 (allocate-event)
331 (let ((index (integer-length (index1- size))))
332 (declare (type array-index index))
333 (or (threaded-atomic-pop (svref *reply-buffer-free-lists* index)
334 reply-next reply-buffer)
335 (make-reply-buffer (index-ash 1 index))))))
336
337 (defun deallocate-reply-buffer (reply-buffer)
338 (declare (type reply-buffer reply-buffer))
339 (let ((size (reply-size reply-buffer)))
340 (declare (type array-index size))
341 (if (index<= size *replysize*)
342 (deallocate-event reply-buffer)
343 (let ((index (integer-length (index1- size))))
344 (declare (type array-index index))
345 (threaded-atomic-push reply-buffer (svref *reply-buffer-free-lists* index)
346 reply-next reply-buffer)))))
347
348 ;;;
349
350 (defun read-error-input (display sequence reply-buffer token)
351 (declare (type display display)
352 (type reply-buffer reply-buffer)
353 (type card16 sequence))
354 (tagbody
355 start
356 (with-event-queue-internal (display)
357 (let ((command
358 ;; Find any pending command with this sequence number.
359 (threaded-dolist (pending-command (display-pending-commands display)
360 pending-command-next pending-command)
361 (when (= (pending-command-sequence pending-command) sequence)
362 (return pending-command)))))
363 (declare (type (or null pending-command) command))
364 (cond ((not (null command))
365 ;; Give this reply to the pending command
366 (threaded-nconc reply-buffer (pending-command-reply-buffer command)
367 reply-next reply-buffer)
368 (process-wakeup (pending-command-process command)))
369 ((member :immediately (display-report-asynchronous-errors display))
370 ;; No pending command and we should report the error immediately
371 (go report-error))
372 (t
373 ;; No pending command found, count this as an asynchronous error
374 (threaded-nconc reply-buffer (display-asynchronous-errors display)
375 reply-next reply-buffer)))))
376 (return-from read-error-input nil)
377 report-error
378 (note-input-complete display token)
379 (apply #'report-error display
380 (prog1 (make-error display reply-buffer t)
381 (deallocate-event reply-buffer)))))
382
383 (defun read-reply-input (display sequence length reply-buffer)
384 (declare (type display display)
385 (type (or null reply-buffer) reply-buffer)
386 (type card16 sequence)
387 (type array-index length))
388 (unwind-protect
389 (progn
390 (when (index< *replysize* length)
391 (let ((repbuf nil))
392 (declare (type (or null reply-buffer) repbuf))
393 (unwind-protect
394 (progn
395 (setq repbuf (allocate-reply-buffer length))
396 (buffer-replace (reply-ibuf8 repbuf) (reply-ibuf8 reply-buffer)
397 0 *replysize*)
398 (deallocate-event (shiftf reply-buffer repbuf nil)))
399 (when repbuf
400 (deallocate-reply-buffer repbuf))))
401 (when (buffer-input display (reply-ibuf8 reply-buffer) *replysize* length)
402 (return-from read-reply-input t))
403 (setf (reply-data-size reply-buffer) length))
404 (with-event-queue-internal (display)
405 ;; Find any pending command with this sequence number.
406 (let ((command
407 (threaded-dolist (pending-command (display-pending-commands display)
408 pending-command-next pending-command)
409 (when (= (pending-command-sequence pending-command) sequence)
410 (return pending-command)))))
411 (declare (type (or null pending-command) command))
412 (when command
413 ;; Give this reply to the pending command
414 (threaded-nconc (shiftf reply-buffer nil)
415 (pending-command-reply-buffer command)
416 reply-next reply-buffer)
417 (process-wakeup (pending-command-process command)))))
418 nil)
419 (when reply-buffer
420 (deallocate-reply-buffer reply-buffer))))
421
422 (defun read-event-input (display code reply-buffer)
423 (declare (type display display)
424 (type card8 code)
425 (type reply-buffer reply-buffer))
426 ;; Push the event in the input buffer on the display's event queue
427 (setf (event-code reply-buffer)
428 (get-internal-event-code display code))
429 (enqueue-event reply-buffer display)
430 nil)
431
432 (defun note-input-complete (display token)
433 (declare (type display display))
434 (when (eq (display-input-in-progress display) token)
435 ;; Indicate that input is no longer in progress
436 (setf (display-input-in-progress display) nil)
437 ;; Let the event process get the first chance to do input
438 (let ((process (display-event-process display)))
439 (when (not (null process))
440 (process-wakeup process)))
441 ;; Then give processes waiting for command responses a chance
442 (unless (display-input-in-progress display)
443 (with-event-queue-internal (display)
444 (threaded-dolist (command (display-pending-commands display)
445 pending-command-next pending-command)
446 (process-wakeup (pending-command-process command)))))))
447
448 (defun read-input (display timeout force-output-p predicate &rest predicate-args)
449 (declare (type display display)
450 (type (or null number) timeout)
451 (type boolean force-output-p)
452 (dynamic-extent predicate-args))
453 (declare (type function predicate)
454 (downward-funarg predicate))
455 (let ((reply-buffer nil)
456 (token (or (current-process) (cons nil nil))))
457 (declare (type (or null reply-buffer) reply-buffer))
458 (unwind-protect
459 (tagbody
460 loop
461 (when (display-dead display)
462 (x-error 'closed-display :display display))
463 (when (apply predicate predicate-args)
464 (return-from read-input nil))
465 ;; Check and see if we have to force output
466 (when (and force-output-p
467 (or (and (not (eq (display-input-in-progress display) token))
468 (not (conditional-store
469 (display-input-in-progress display) nil token)))
470 (null (buffer-listen display))))
471 (go force-output))
472 ;; Ensure that ony one process is reading input.
473 (unless (or (eq (display-input-in-progress display) token)
474 (conditional-store (display-input-in-progress display) nil token))
475 (if (eql timeout 0)
476 (return-from read-input :timeout)
477 (apply #'process-block "CLX Input Lock"
478 #'(lambda (display predicate &rest predicate-args)
479 (declare (type display display)
480 (dynamic-extent predicate-args)
481 (type function predicate)
482 (downward-funarg predicate))
483 (or (apply predicate predicate-args)
484 (null (display-input-in-progress display))
485 (not (null (display-dead display)))))
486 display predicate predicate-args))
487 (go loop))
488 ;; Now start gobbling.
489 (setq reply-buffer (allocate-event))
490 (with-buffer-input (reply-buffer :sizes (8 16 32))
491 (let ((type 0))
492 (declare (type card8 type))
493 ;; Wait for input before we disallow aborts.
494 (unless (eql timeout 0)
495 (let ((eof-p (buffer-input-wait display timeout)))
496 (when eof-p (return-from read-input eof-p))))
497 (without-aborts
498 (let ((eof-p (buffer-input display buffer-bbuf 0 *replysize*
499 (if force-output-p 0 timeout))))
500 (when eof-p
501 (when (eq eof-p :timeout)
502 (if force-output-p
503 (go force-output)
504 (return-from read-input :timeout)))
505 (setf (display-dead display) t)
506 (return-from read-input eof-p)))
507 (setf (reply-data-size reply-buffer) *replysize*)
508 (when (= (the card8 (setq type (read-card8 0))) 1)
509 ;; Normal replies can be longer than *replysize*, so we
510 ;; have to handle them while aborts are still disallowed.
511 (let ((value
512 (read-reply-input
513 display (read-card16 2)
514 (index+ *replysize* (index* (read-card32 4) 4))
515 (shiftf reply-buffer nil))))
516 (when value
517 (return-from read-input value))
518 (go loop))))
519 (if (zerop type)
520 (read-error-input
521 display (read-card16 2) (shiftf reply-buffer nil) token)
522 (read-event-input
523 display (read-card8 0) (shiftf reply-buffer nil)))))
524 (go loop)
525 force-output
526 (note-input-complete display token)
527 (display-force-output display)
528 (setq force-output-p nil)
529 (go loop))
530 (when (not (null reply-buffer))
531 (deallocate-reply-buffer reply-buffer))
532 (note-input-complete display token))))
533
534 (defun report-asynchronous-errors (display mode)
535 (when (and (display-asynchronous-errors display)
536 (member mode (display-report-asynchronous-errors display)))
537 (let ((aborted t))
538 (unwind-protect
539 (loop
540 (let ((error
541 (with-event-queue-internal (display)
542 (threaded-pop (display-asynchronous-errors display)
543 reply-next reply-buffer))))
544 (declare (type (or null reply-buffer) error))
545 (if error
546 (apply #'report-error display
547 (prog1 (make-error display error t)
548 (deallocate-event error)))
549 (return (setq aborted nil)))))
550 ;; If we get aborted out of this, deallocate all outstanding asynchronous
551 ;; errors.
552 (when aborted
553 (with-event-queue-internal (display)
554 (loop
555 (let ((reply-buffer
556 (threaded-pop (display-asynchronous-errors display)
557 reply-next reply-buffer)))
558 (declare (type (or null reply-buffer) reply-buffer))
559 (if reply-buffer
560 (deallocate-event reply-buffer)
561 (return nil))))))))))
562
563 (defun wait-for-event (display timeout force-output-p)
564 (declare (type display display)
565 (type (or null number) timeout)
566 (type boolean force-output-p))
567 (let ((event-process-p (not (eql timeout 0))))
568 (declare (type boolean event-process-p))
569 (unwind-protect
570 (loop
571 (when event-process-p
572 (conditional-store (display-event-process display) nil (current-process)))
573 (let ((eof (read-input
574 display timeout force-output-p
575 #'(lambda (display)
576 (declare (type display display))
577 (or (not (null (display-new-events display)))
578 (and (display-asynchronous-errors display)
579 (member :before-event-handling
580 (display-report-asynchronous-errors display))
581 t)))
582 display)))
583 (when eof (return eof)))
584 ;; Report asynchronous errors here if the user wants us to.
585 (when event-process-p
586 (report-asynchronous-errors display :before-event-handling))
587 (when (not (null (display-new-events display)))
588 (return nil)))
589 (when (and event-process-p
590 (eq (display-event-process display) (current-process)))
591 (setf (display-event-process display) nil)))))
592
593 (defun read-reply (display pending-command)
594 (declare (type display display)
595 (type pending-command pending-command))
596 (loop
597 (when (read-input display nil nil
598 #'(lambda (pending-command)
599 (declare (type pending-command pending-command))
600 (not (null (pending-command-reply-buffer pending-command))))
601 pending-command)
602 (x-error 'closed-display :display display))
603 (let ((reply-buffer
604 (with-event-queue-internal (display)
605 (threaded-pop (pending-command-reply-buffer pending-command)
606 reply-next reply-buffer))))
607 (declare (type reply-buffer reply-buffer))
608 ;; Check for error.
609 (with-buffer-input (reply-buffer)
610 (ecase (read-card8 0)
611 (0 (apply #'report-error display
612 (prog1 (make-error display reply-buffer nil)
613 (deallocate-reply-buffer reply-buffer))))
614 (1 (return reply-buffer)))))))
615
616 ;;;
617
618 (defun event-listen (display &optional (timeout 0))
619 (declare (type display display)
620 (type (or null number) timeout)
621 (values number-of-events-queued eof-or-timeout))
622 ;; Returns the number of events queued locally, if any, else nil. Hangs
623 ;; waiting for events, forever if timeout is nil, else for the specified
624 ;; number of seconds.
625 (let* ((current-event-symbol (car (display-current-event-symbol display)))
626 (current-event (and (boundp current-event-symbol)
627 (symbol-value current-event-symbol)))
628 (queue (or current-event (display-event-queue-head display))))
629 (declare (type symbol current-event-symbol)
630 (type (or null reply-buffer) current-event queue))
631 (if queue
632 (values
633 (with-event-queue-internal (display :timeout timeout)
634 (threaded-length (or current-event (display-event-queue-head display))
635 reply-next reply-buffer))
636 nil)
637 (with-event-queue (display :timeout timeout :inline t)
638 (let ((eof-or-timeout (wait-for-event display timeout nil)))
639 (if eof-or-timeout
640 (values nil eof-or-timeout)
641 (values
642 (with-event-queue-internal (display :timeout timeout)
643 (threaded-length (display-event-queue-head display)
644 reply-next reply-buffer))
645 nil)))))))
646
647 (defun queue-event (display event-key &rest args &key append-p send-event-p &allow-other-keys)
648 ;; The event is put at the head of the queue if append-p is nil, else the tail.
649 ;; Additional arguments depend on event-key, and are as specified above with
650 ;; declare-event, except that both resource-ids and resource objects are accepted
651 ;; in the event components.
652 (declare (type display display)
653 (type event-key event-key)
654 (type boolean append-p send-event-p)
655 (dynamic-extent args))
656 (unless (get event-key 'event-code)
657 (x-type-error event-key 'event-key))
658 (let* ((event (allocate-event))
659 (buffer (reply-ibuf8 event))
660 (event-code (get event-key 'event-code)))
661 (declare (type reply-buffer event)
662 (type buffer-bytes buffer)
663 (type (or null card8) event-code))
664 (unless event-code (x-type-error event-key 'event-key))
665 (setf (event-code event) event-code)
666 (with-display (display)
667 (apply (svref *event-send-vector* event-code) display args)
668 (buffer-replace buffer
669 (display-obuf8 display)
670 0
671 *replysize*
672 (index+ 12 (buffer-boffset display)))
673 (setf (aref buffer 0) (if send-event-p (logior event-code #x80) event-code)
674 (aref buffer 2) 0
675 (aref buffer 3) 0))
676 (with-event-queue (display)
677 (if append-p
678 (enqueue-event event display)
679 (with-event-queue-internal (display)
680 (threaded-requeue event
681 (display-event-queue-head display)
682 (display-event-queue-tail display)
683 reply-next reply-buffer))))))
684
685 (defun enqueue-event (new-event display)
686 (declare (type reply-buffer new-event)
687 (type display display))
688 ;; Place EVENT at the end of the event queue for DISPLAY
689 (let* ((event-code (event-code new-event))
690 (event-key (and (index< event-code (length *event-key-vector*))
691 (svref *event-key-vector* event-code))))
692 (declare (type array-index event-code)
693 (type (or null keyword) event-key))
694 (if (null event-key)
695 (unwind-protect
696 (cerror "Ignore this event" "No handler for ~s event" event-key)
697 (deallocate-event new-event))
698 (with-event-queue-internal (display)
699 (threaded-enqueue new-event
700 (display-event-queue-head display)
701 (display-event-queue-tail display)
702 reply-next reply-buffer)
703 (unless (display-new-events display)
704 (setf (display-new-events display) new-event))))))
705
706
707 (defmacro define-event (name code)
708 `(eval-when (eval compile load)
709 (setf (svref *event-key-vector* ,code) ',name)
710 (setf (get ',name 'event-code) ,code)))
711
712 ;; Event names. Used in "type" field in XEvent structures. Not to be
713 ;; confused with event masks above. They start from 2 because 0 and 1
714 ;; are reserved in the protocol for errors and replies. */
715
716 (define-event :key-press 2)
717 (define-event :key-release 3)
718 (define-event :button-press 4)
719 (define-event :button-release 5)
720 (define-event :motion-notify 6)
721 (define-event :enter-notify 7)
722 (define-event :leave-notify 8)
723 (define-event :focus-in 9)
724 (define-event :focus-out 10)
725 (define-event :keymap-notify 11)
726 (define-event :exposure 12)
727 (define-event :graphics-exposure 13)
728 (define-event :no-exposure 14)
729 (define-event :visibility-notify 15)
730 (define-event :create-notify 16)
731 (define-event :destroy-notify 17)
732 (define-event :unmap-notify 18)
733 (define-event :map-notify 19)
734 (define-event :map-request 20)
735 (define-event :reparent-notify 21)
736 (define-event :configure-notify 22)
737 (define-event :configure-request 23)
738 (define-event :gravity-notify 24)
739 (define-event :resize-request 25)
740 (define-event :circulate-notify 26)
741 (define-event :circulate-request 27)
742 (define-event :property-notify 28)
743 (define-event :selection-clear 29)
744 (define-event :selection-request 30)
745 (define-event :selection-notify 31)
746 (define-event :colormap-notify 32)
747 (define-event :client-message 33)
748 (define-event :mapping-notify 34)
749
750
751 (defmacro declare-event (event-codes &body declares)
752 ;; Used to indicate the keyword arguments for handler functions in
753 ;; process-event and event-case.
754 ;; Generates the functions used in SEND-EVENT.
755 ;; A compiler warning is printed when all of EVENT-CODES are not
756 ;; defined by a preceding DEFINE-EXTENSION.
757 ;; The body is a list of declarations, each of which has the form:
758 ;; (type . items) Where type is a data-type, and items is a list of
759 ;; symbol names. The item order corresponds to the order of fields
760 ;; in the event sent by the server. An item may be a list of items.
761 ;; In this case, each item is aliased to the same event field.
762 ;; This is used to give all events an EVENT-WINDOW item.
763 ;; See the INPUT file for lots of examples.
764 (declare (type (or keyword list) event-codes)
765 (type (alist (field-type symbol) (field-names list))
766 declares))
767 (when (atom event-codes) (setq event-codes (list event-codes)))
768 (setq event-codes (mapcar #'canonicalize-event-name event-codes))
769 (let* ((keywords nil)
770 (name (first event-codes))
771 (get-macro (xintern name '-event-get-macro))
772 (get-function (xintern name '-event-get))
773 (put-function (xintern name '-event-put)))
774 (multiple-value-bind (get-code get-index get-sizes)
775 (get-put-items
776 2 declares nil
777 #'(lambda (type index item args)
778 (flet ((event-get (type index item args)
779 (unless (member type '(pad8 pad16))
780 `(,(kintern item)
781 (,(getify type) ,index ,@args)))))
782 (if (atom item)
783 (event-get type index item args)
784 (mapcan #'(lambda (item)
785 (event-get type index item args))
786 item)))))
787 (declare (ignore get-index))
788 (multiple-value-bind (put-code put-index put-sizes)
789 (get-put-items
790 2 declares t
791 #'(lambda (type index item args)
792 (unless (member type '(pad8 pad16))
793 (if (atom item)
794 (progn
795 (push item keywords)
796 `((,(putify type) ,index ,item ,@args)))
797 (let ((names (mapcar #'(lambda (name) (kintern name))
798 item)))
799 (setq keywords (append item keywords))
800 `((,(putify type) ,index
801 (check-consistency ',names ,@item) ,@args)))))))
802 (declare (ignore put-index))
803 `(within-definition (,name declare-event)
804 (defun ,get-macro (display event-key variable)
805 ;; Note: we take pains to macroexpand the get-code here to enable application
806 ;; code to be compiled without having the CLX macros file loaded.
807 (subst display '%buffer
808 (getf `(:display (the display ,display)
809 :event-key (the keyword ,event-key)
810 :event-code (the card8 (logand #x7f (read-card8 0)))
811 :send-event-p (the boolean (logbitp 7 (read-card8 0)))
812 ,@',(mapcar #'macroexpand get-code))
813 variable)))
814
815 (defun ,get-function (display event handler)
816 (declare (type display display)
817 (type reply-buffer event))
818 (declare (type function handler)
819 (downward-funarg handler))
820 (reading-event (event :display display :sizes (8 16 ,@get-sizes))
821 (funcall handler
822 :display display
823 :event-key (svref *event-key-vector* (event-code event))
824 :event-code (logand #x7f (card8-get 0))
825 :send-event-p (logbitp 7 (card8-get 0))
826 ,@get-code)))
827
828 (defun ,put-function (display &key ,@(setq keywords (nreverse keywords))
829 &allow-other-keys)
830 (declare (type display display))
831 ,(when (member 'sequence keywords)
832 `(unless sequence (setq sequence (display-request-number display))))
833 (with-buffer-output (display :sizes ,put-sizes
834 :index (index+ (buffer-boffset display) 12))
835 ,@put-code))
836
837 ,@(mapcar #'(lambda (name)
838 (allocate-extension-event-code name)
839 `(let ((event-code (or (get ',name 'event-code)
840 (allocate-extension-event-code ',name))))
841 (setf (svref *event-macro-vector* event-code)
842 (function ,get-macro))
843 (setf (svref *event-handler-vector* event-code)
844 (function ,get-function))
845 (setf (svref *event-send-vector* event-code)
846 (function ,put-function))))
847 event-codes)
848 ',name)))))
849
850 (defun check-consistency (names &rest args)
851 ;; Ensure all args are nil or have the same value.
852 ;; Returns the consistent non-nil value.
853 (let ((value (car args)))
854 (dolist (arg (cdr args))
855 (if value
856 (when (and arg (not (eq arg value)))
857 (x-error 'inconsistent-parameters
858 :parameters (mapcan #'list names args)))
859 (setq value arg)))
860 value))
861
862 (declare-event (:key-press :key-release :button-press :button-release)
863 ;; for key-press and key-release, code is the keycode
864 ;; for button-press and button-release, code is the button number
865 (data code)
866 (card16 sequence)
867 (card32 time)
868 (window root (window event-window))
869 ((or null window) child)
870 (int16 root-x root-y x y)
871 (card16 state)
872 (boolean same-screen-p)
873 )
874
875 (declare-event :motion-notify
876 ((data boolean) hint-p)
877 (card16 sequence)
878 (card32 time)
879 (window root (window event-window))
880 ((or null window) child)
881 (int16 root-x root-y x y)
882 (card16 state)
883 (boolean same-screen-p))
884
885 (declare-event (:enter-notify :leave-notify)
886 ((data (member8 :ancestor :virtual :inferior :nonlinear :nonlinear-virtual)) kind)
887 (card16 sequence)
888 (card32 time)
889 (window root (window event-window))
890 ((or null window) child)
891 (int16 root-x root-y x y)
892 (card16 state)
893 ((member8 :normal :grab :ungrab) mode)
894 ((bit 0) focus-p)
895 ((bit 1) same-screen-p))
896
897 (declare-event (:focus-in :focus-out)
898 ((data (member8 :ancestor :virtual :inferior :nonlinear :nonlinear-virtual
899 :pointer :pointer-root :none))
900 kind)
901 (card16 sequence)
902 (window (window event-window))
903 ((member8 :normal :while-grabbed :grab :ungrab) mode))
904
905 (declare-event :keymap-notify
906 ((bit-vector256 0) keymap))
907
908 (declare-event :exposure
909 (card16 sequence)
910 (window (window event-window))
911 (card16 x y width height count))
912
913 (declare-event :graphics-exposure
914 (card16 sequence)
915 (drawable (drawable event-window))
916 (card16 x y width height)
917 (card16 minor) ;; Minor opcode
918 (card16 count)
919 (card8 major))
920
921 (declare-event :no-exposure
922 (card16 sequence)
923 (drawable (drawable event-window))
924 (card16 minor)
925 (card8 major))
926
927 (declare-event :visibility-notify
928 (card16 sequence)
929 (window (window event-window))
930 ((member8 :unobscured :partially-obscured :fully-obscured) state))
931
932 (declare-event :create-notify
933 (card16 sequence)
934 (window (parent event-window) window)
935 (int16 x y)
936 (card16 width height border-width)
937 (boolean override-redirect-p))
938
939 (declare-event :destroy-notify
940 (card16 sequence)
941 (window event-window window))
942
943 (declare-event :unmap-notify
944 (card16 sequence)
945 (window event-window window)
946 (boolean configure-p))
947
948 (declare-event :map-notify
949 (card16 sequence)
950 (window event-window window)
951 (boolean override-redirect-p))
952
953 (declare-event :map-request
954 (card16 sequence)
955 (window (parent event-window) window))
956
957 (declare-event :reparent-notify
958 (card16 sequence)
959 (window event-window window parent)
960 (int16 x y)
961 (boolean override-redirect-p))
962
963 (declare-event :configure-notify
964 (card16 sequence)
965 (window event-window window)
966 ((or null window) above-sibling)
967 (int16 x y)
968 (card16 width height border-width)
969 (boolean override-redirect-p))
970
971 (declare-event :configure-request
972 ((data (member :above :below :top-if :bottom-if :opposite)) stack-mode)
973 (card16 sequence)
974 (window (parent event-window) window)
975 ((or null window) above-sibling)
976 (int16 x y)
977 (card16 width height border-width value-mask))
978
979 (declare-event :gravity-notify
980 (card16 sequence)
981 (window event-window window)
982 (int16 x y))
983
984 (declare-event :resize-request
985 (card16 sequence)
986 (window (window event-window))
987 (card16 width height))
988
989 (declare-event :circulate-notify
990 (card16 sequence)
991 (window event-window window parent)
992 ((member16 :top :bottom) place))
993
994 (declare-event :circulate-request
995 (card16 sequence)
996 (window (parent event-window) window)
997 (pad16 1 2)
998 ((member16 :top :bottom) place))
999
1000 (declare-event :property-notify
1001 (card16 sequence)
1002 (window (window event-window))
1003 (keyword atom) ;; keyword
1004 (card32 time)
1005 ((member16 :new-value :deleted) state))
1006
1007 (declare-event :selection-clear
1008 (card16 sequence)
1009 (card32 time)
1010 (window (window event-window))
1011 (keyword selection) ;; keyword
1012 )
1013
1014 (declare-event :selection-request
1015 (card16 sequence)
1016 (card32 time)
1017 (window (window event-window) requestor)
1018 (keyword selection target)
1019 ((or null keyword) property)
1020 )
1021
1022 (declare-event :selection-notify
1023 (card16 sequence)
1024 (card32 time)
1025 (window (window event-window))
1026 (keyword selection target)
1027 ((or null keyword) property)
1028 )
1029
1030 (declare-event :colormap-notify
1031 (card16 sequence)
1032 (window (window event-window))
1033 ((or null colormap) colormap)
1034 (boolean new-p installed-p))
1035
1036 (declare-event :client-message
1037 (data format)
1038 (card16 sequence)
1039 (window (window event-window))
1040 (keyword type)
1041 ((client-message-sequence format) data))
1042
1043 (declare-event :mapping-notify
1044 (card16 sequence)
1045 ((member8 :modifier :keyboard :pointer) request)
1046 (card8 start) ;; first key-code
1047 (card8 count))
1048
1049
1050 ;;
1051 ;; EVENT-LOOP
1052 ;;
1053
1054 (defun event-loop-setup (display)
1055 (declare (type display display)
1056 (values progv-vars progv-vals
1057 current-event-symbol current-event-discarded-p-symbol))
1058 (let* ((progv-vars (display-current-event-symbol display))
1059 (current-event-symbol (first progv-vars))
1060 (current-event-discarded-p-symbol (second progv-vars)))
1061 (declare (type list progv-vars)
1062 (type symbol current-event-symbol current-event-discarded-p-symbol))
1063 (values
1064 progv-vars
1065 (list (if (boundp current-event-symbol)
1066 ;; The current event is already bound, so bind it to the next
1067 ;; event.
1068 (let ((event (symbol-value current-event-symbol)))
1069 (declare (type (or null reply-buffer) event))
1070 (and event (reply-next (the reply-buffer event))))
1071 ;; The current event isn't bound, so bind it to the head of the
1072 ;; event queue.
1073 (display-event-queue-head display))
1074 nil)
1075 current-event-symbol
1076 current-event-discarded-p-symbol)))
1077
1078 (defun event-loop-step-before (display timeout force-output-p current-event-symbol)
1079 (declare (type display display)
1080 (type (or null number) timeout)
1081 (type boolean force-output-p)
1082 (type symbol current-event-symbol)
1083 (values event eof-or-timeout))
1084 (unless (symbol-value current-event-symbol)
1085 (let ((eof-or-timeout (wait-for-event display timeout force-output-p)))
1086 (when eof-or-timeout
1087 (return-from event-loop-step-before (values nil eof-or-timeout))))
1088 (setf (symbol-value current-event-symbol) (display-new-events display)))
1089 (let ((event (symbol-value current-event-symbol)))
1090 (declare (type reply-buffer event))
1091 (with-event-queue-internal (display)
1092 (when (eq event (display-new-events display))
1093 (setf (display-new-events display) (reply-next event))))
1094 (values event nil)))
1095
1096 (defvar *event-loop-version* 0)
1097
1098 (defun dequeue-event (display event)
1099 (declare (type display display)
1100 (type reply-buffer event)
1101 (values next))
1102 ;; Remove the current event from the event queue
1103 (with-event-queue-internal (display)
1104 (let ((next (reply-next event))
1105 (head (display-event-queue-head display)))
1106 (declare (type (or null reply-buffer) next head))
1107 (when (eq event (display-new-events display))
1108 (setf (display-new-events display) next))
1109 (cond ((eq event head)
1110 (threaded-dequeue (display-event-queue-head display)
1111 (display-event-queue-tail display)
1112 reply-next reply-buffer))
1113 ((null head)
1114 (setq next nil))
1115 (t
1116 (do* ((previous head current)
1117 (current (reply-next previous) (reply-next previous)))
1118 ((or (null current) (eq event current))
1119 (when (eq event current)
1120 (when (eq current (display-event-queue-tail display))
1121 (setf (display-event-queue-tail display) previous))
1122 (setf (reply-next previous) next)))
1123 (declare (type reply-buffer previous)
1124 (type (or null reply-buffer) current)))))
1125 next)))
1126
1127 (defun event-loop-step-after
1128 (display event discard-p current-event-symbol current-event-discarded-p-symbol
1129 &optional aborted)
1130 (declare (type display display)
1131 (type reply-buffer event)
1132 (type boolean discard-p aborted)
1133 (type symbol current-event-symbol current-event-discarded-p-symbol))
1134 (when (and discard-p
1135 (not aborted)
1136 (not (symbol-value current-event-discarded-p-symbol)))
1137 (discard-current-event display))
1138 (let ((next (reply-next event)))
1139 (declare (type (or null reply-buffer) next))
1140 (when (symbol-value current-event-discarded-p-symbol)
1141 (setf (symbol-value current-event-discarded-p-symbol) nil)
1142 (ecase *event-loop-version*
1143 ;; in version 0 discard-current-event dequeues the event.
1144 (0 )
1145 ;; in version 1 event-loop-step-after dequeues the event.
1146 (1 (setq next (dequeue-event display event))))
1147 (deallocate-event event))
1148 (setf (symbol-value current-event-symbol) next)))
1149
1150 (defmacro event-loop ((display event timeout force-output-p discard-p) &body body)
1151 ;; Bind EVENT to the events for DISPLAY.
1152 ;; This is the "GUTS" of process-event and event-case.
1153 `(let ((*event-loop-version* 1)
1154 (.display. ,display)
1155 (.timeout. ,timeout)
1156 (.force-output-p. ,force-output-p)
1157 (.discard-p. ,discard-p))
1158 (declare (type display .display.)
1159 (type (or null number) .timeout.)
1160 (type boolean .force-output-p. .discard-p.))
1161 (with-event-queue (.display. ,@(and timeout `(:timeout .timeout.)))
1162 (multiple-value-bind (.progv-vars. .progv-vals.
1163 .current-event-symbol. .current-event-discarded-p-symbol.)
1164 (event-loop-setup .display.)
1165 (declare (type list .progv-vars. .progv-vals.)
1166 (type symbol .current-event-symbol. .current-event-discarded-p-symbol.))
1167 (progv .progv-vars. .progv-vals.
1168 (loop
1169 (multiple-value-bind (.event. .eof-or-timeout.)
1170 (event-loop-step-before
1171 .display. .timeout. .force-output-p.
1172 .current-event-symbol.)
1173 (declare (type (or null reply-buffer) .event.))
1174 (when (null .event.) (return (values nil .eof-or-timeout.)))
1175 (let ((.aborted. t))
1176 (unwind-protect
1177 (progn
1178 (let ((,event .event.))
1179 (declare (type reply-buffer ,event))
1180 ,@body)
1181 (setq .aborted. nil))
1182 (event-loop-step-after
1183 .display. .event. .discard-p.
1184 .current-event-symbol. .current-event-discarded-p-symbol.
1185 .aborted.))))))))))
1186
1187 (defun discard-current-event (display)
1188 ;; Discard the current event for DISPLAY.
1189 ;; Returns NIL when the event queue is empty, else T.
1190 ;; To ensure events aren't ignored, application code should only call
1191 ;; this when throwing out of event-case or process-next-event, or from
1192 ;; inside even-case, event-cond or process-event when :peek-p is T and
1193 ;; :discard-p is NIL.
1194 (declare (type display display)
1195 (values boolean))
1196 (let* ((symbols (display-current-event-symbol display))
1197 (event
1198 (let ((current-event-symbol (first symbols)))
1199 (declare (type symbol current-event-symbol))
1200 (when (boundp current-event-symbol)
1201 (symbol-value current-event-symbol)))))
1202 (declare (type list symbols)
1203 (type (or null reply-buffer) event))
1204 (unless (null event)
1205 (ecase *event-loop-version*
1206 ;; in version 0 discard-current-event dequeues the event.
1207 (0 (setf (reply-next (the reply-buffer event))
1208 (dequeue-event display event)))
1209 ;; in version 1 event-loop-step-after dequeues the event.
1210 (1 ))
1211 ;; Set the discarded-p flag
1212 (let ((current-event-discarded-p-symbol (second symbols)))
1213 (declare (type symbol current-event-discarded-p-symbol))
1214 (when (boundp current-event-discarded-p-symbol)
1215 (setf (symbol-value current-event-discarded-p-symbol) t)))
1216 ;; Return whether the event queue is empty
1217 (not (null (reply-next (the reply-buffer event)))))))
1218
1219 ;;
1220 ;; PROCESS-EVENT
1221 ;;
1222 (defun process-event (display &key handler timeout peek-p discard-p (force-output-p t))
1223 ;; If force-output-p is true, first invokes display-force-output. Invokes handler
1224 ;; on each queued event until handler returns non-nil, and that returned object is
1225 ;; then returned by process-event. If peek-p is true, then the event is not
1226 ;; removed from the queue. If discard-p is true, then events for which handler
1227 ;; returns nil are removed from the queue, otherwise they are left in place. Hangs
1228 ;; until non-nil is generated for some event, or for the specified timeout (in
1229 ;; seconds, if given); however, it is acceptable for an implementation to wait only
1230 ;; once on network data, and therefore timeout prematurely. Returns nil on
1231 ;; timeout. If handler is a sequence, it is expected to contain handler functions
1232 ;; specific to each event class; the event code is used to index the sequence,
1233 ;; fetching the appropriate handler. Handler is called with raw resource-ids, not
1234 ;; with resource objects. The arguments to the handler are described using declare-event.
1235 ;;
1236 ;; T for peek-p means the event (for which the handler returns non-nil) is not removed
1237 ;; from the queue (it is left in place), NIL means the event is removed.
1238
1239 (declare (type display display)
1240 (type (or null number) timeout)
1241 (type boolean peek-p discard-p force-output-p))
1242 (declare (type t handler)
1243 (downward-funarg #+Genera * #-Genera handler))
1244 (event-loop (display event timeout force-output-p discard-p)
1245 (let* ((event-code (event-code event)) ;; Event decoder defined by DECLARE-EVENT
1246 (event-decoder (and (index< event-code (length *event-handler-vector*))
1247 (svref *event-handler-vector* event-code))))
1248 (declare (type array-index event-code)
1249 (type (or null function) event-decoder))
1250 (if event-decoder
1251 (let ((event-handler (if (functionp handler)
1252 handler
1253 (and (type? handler 'sequence)
1254 (< event-code (length handler))
1255 (elt handler event-code)))))
1256 (if event-handler
1257 (let ((result (funcall event-decoder display event event-handler)))
1258 (when result
1259 (unless peek-p
1260 (discard-current-event display))
1261 (return result)))
1262 (cerror "Ignore this event"
1263 "No handler for ~s event"
1264 (svref *event-key-vector* event-code))))
1265 (cerror "Ignore this event"
1266 "Server Error: event with unknown event code ~d received."
1267 event-code)))))
1268
1269 (defun make-event-handlers (&key (type 'array) default)
1270 (declare (type t type) ;Sequence type specifier
1271 (type function default)
1272 (values sequence)) ;Default handler for initial content
1273 ;; Makes a handler sequence suitable for process-event
1274 (make-sequence type *max-events* :initial-element default))
1275
1276 (defun event-handler (handlers event-key)
1277 (declare (type sequence handlers)
1278 (type event-key event-key)
1279 (values function))
1280 ;; Accessor for a handler sequence
1281 (elt handlers (position event-key *event-key-vector* :test #'eq)))
1282
1283 (defun set-event-handler (handlers event-key handler)
1284 (declare (type sequence handlers)
1285 (type event-key event-key)
1286 (type function handler)
1287 (values handler))
1288 (setf (elt handlers (position event-key *event-key-vector* :test #'eq)) handler))
1289
1290 (defsetf event-handler set-event-handler)
1291
1292 ;;
1293 ;; EVENT-CASE
1294 ;;
1295
1296 (defmacro event-case ((&rest args) &body clauses)
1297 ;; If force-output-p is true, first invokes display-force-output. Executes the
1298 ;; matching clause for each queued event until a clause returns non-nil, and that
1299 ;; returned object is then returned by event-case. If peek-p is true, then the
1300 ;; event is not removed from the queue. If discard-p is true, then events for
1301 ;; which the clause returns nil are removed from the queue, otherwise they are left
1302 ;; in place. Hangs until non-nil is generated for some event, or for the specified
1303 ;; timeout (in seconds, if given); however, it is acceptable for an implementation
1304 ;; to wait only once on network data, and therefore timeout prematurely. Returns
1305 ;; nil on timeout. In each clause, event-or-events is an event-key or a list of
1306 ;; event-keys (but they need not be typed as keywords) or the symbol t or otherwise
1307 ;; (but only in the last clause). The keys are not evaluated, and it is an error
1308 ;; for the same key to appear in more than one clause. Args is the list of event
1309 ;; components of interest; corresponding values (if any) are bound to variables
1310 ;; with these names (i.e., the args are variable names, not keywords, the keywords
1311 ;; are derived from the variable names). An arg can also be a (keyword var) form,
1312 ;; as for keyword args in a lambda lists. If no t/otherwise clause appears, it is
1313 ;; equivalent to having one that returns nil.
1314 (declare (arglist (display &key timeout peek-p discard-p (force-output-p t))
1315 (event-or-events ((&rest args) |...|) &body body) |...|))
1316 ;; Event-case is just event-cond with the whole body in the test-form
1317 `(event-cond ,args
1318 ,@(mapcar
1319 #'(lambda (clause)
1320 `(,(car clause) ,(cadr clause) (progn ,@(cddr clause))))
1321 clauses)))
1322
1323 ;;
1324 ;; EVENT-COND
1325 ;;
1326
1327 (defmacro event-cond ((display &key timeout peek-p discard-p (force-output-p t))
1328 &body clauses)
1329 ;; The clauses of event-cond are of the form:
1330 ;; (event-or-events binding-list test-form . body-forms)
1331 ;;
1332 ;; EVENT-OR-EVENTS event-key or a list of event-keys (but they
1333 ;; need not be typed as keywords) or the symbol t
1334 ;; or otherwise (but only in the last clause). If
1335 ;; no t/otherwise clause appears, it is equivalent
1336 ;; to having one that returns nil. The keys are
1337 ;; not evaluated, and it is an error for the same
1338 ;; key to appear in more than one clause.
1339 ;;
1340 ;; BINDING-LIST The list of event components of interest.
1341 ;; corresponding values (if any) are bound to
1342 ;; variables with these names (i.e., the binding-list
1343 ;; has variable names, not keywords, the keywords are
1344 ;; derived from the variable names). An arg can also
1345 ;; be a (keyword var) form, as for keyword args in a
1346 ;; lambda list.
1347 ;;
1348 ;; The matching TEST-FORM for each queued event is executed until a
1349 ;; clause's test-form returns non-nil. Then the BODY-FORMS are
1350 ;; evaluated, returning the (possibly multiple) values of the last
1351 ;; form from event-cond. If there are no body-forms then, if the
1352 ;; test-form is non-nil, the value of the test-form is returned as a
1353 ;; single value.
1354 ;;
1355 ;; Options:
1356 ;; FORCE-OUTPUT-P When true, first invoke display-force-output if no
1357 ;; input is pending.
1358 ;;
1359 ;; PEEK-P When true, then the event is not removed from the queue.
1360 ;;
1361 ;; DISCARD-P When true, then events for which the clause returns nil
1362 ;; are removed from the queue, otherwise they are left in place.
1363 ;;
1364 ;; TIMEOUT If NIL, hang until non-nil is generated for some event's
1365 ;; test-form. Otherwise return NIL after TIMEOUT seconds have
1366 ;; elapsed.
1367 ;;
1368 (declare (arglist (display &key timeout peek-p discard-p force-output-p)
1369 (event-or-events (&rest args) test-form &body body) |...|))
1370 (let ((event (gensym))
1371 (disp (gensym))
1372 (peek (gensym)))
1373 `(let ((,disp ,display)
1374 (,peek ,peek-p))
1375 (declare (type display ,disp))
1376 (event-loop (,disp ,event ,timeout ,force-output-p ,discard-p)
1377 (event-dispatch (,disp ,event ,peek) ,@clauses)))))
1378
1379 (defun get-event-code (event)
1380 ;; Returns the event code given an event-key
1381 (declare (type event-key event))
1382 (declare (values card8))
1383 (or (get event 'event-code)
1384 (x-type-error event 'event-key)))
1385
1386 (defun universal-event-get-macro (display event-key variable)
1387 (getf
1388 `(:display (the display ,display) :event-key (the keyword ,event-key) :event-code
1389 (the card8 (logand 127 (read-card8 0))) :send-event-p
1390 (the boolean (logbitp 7 (read-card8 0))))
1391 variable))
1392
1393 (defmacro event-dispatch ((display event peek-p) &body clauses)
1394 ;; Helper macro for event-case
1395 ;; CLAUSES are of the form:
1396 ;; (event-or-events binding-list test-form . body-forms)
1397 (let ((event-key (gensym))
1398 (all-events (make-array *max-events* :element-type 'bit :initial-element 0)))
1399 `(reading-event (,event)
1400 (let ((,event-key (svref *event-key-vector* (event-code ,event))))
1401 (case ,event-key
1402 ,@(mapcar
1403 #'(lambda (clause) ; Translate event-cond clause to case clause
1404 (let* ((events (first clause))
1405 (arglist (second clause))
1406 (test-form (third clause))
1407 (body-forms (cdddr clause)))
1408 (flet ((event-clause (display peek-p first-form rest-of-forms)
1409 (if rest-of-forms
1410 `(when ,first-form
1411 (unless ,peek-p (discard-current-event ,display))
1412 (return (progn ,@rest-of-forms)))
1413 ;; No body forms, return the result of the test form
1414 (let ((result (gensym)))
1415 `(let ((,result ,first-form))
1416 (when ,result
1417 (unless ,peek-p (discard-current-event ,display))
1418 (return ,result)))))))
1419
1420 (if (member events '(otherwise t))
1421 ;; code for OTHERWISE clause.
1422 ;; Find all events NOT used by other clauses
1423 (let ((keys (do ((i 0 (1+ i))
1424 (key nil)
1425 (result nil))
1426 ((>= i *max-events*) result)
1427 (setq key (svref *event-key-vector* i))
1428 (when (and key (zerop (aref all-events i)))
1429 (push key result)))))
1430 `(otherwise
1431 (binding-event-values
1432 (,display ,event-key ,(or keys :universal) ,@arglist)
1433 ,(event-clause display peek-p test-form body-forms))))
1434
1435 ;; Code for normal clauses
1436 (let (true-events) ;; canonicalize event-names
1437 (if (consp events)
1438 (progn
1439 (setq true-events (mapcar #'canonicalize-event-name events))
1440 (dolist (event true-events)
1441 (setf (aref all-events (get-event-code event)) 1)))
1442 (setf true-events (canonicalize-event-name events)
1443 (aref all-events (get-event-code true-events)) 1))
1444 `(,true-events
1445 (binding-event-values
1446 (,display ,event-key ,true-events ,@arglist)
1447 ,(event-clause display peek-p test-form body-forms))))))))
1448 clauses))))))
1449
1450 (defmacro binding-event-values ((display event-key event-keys &rest value-list) &body body)
1451 ;; Execute BODY with the variables in VALUE-LIST bound to components of the
1452 ;; EVENT-KEYS events.
1453 (unless (consp event-keys) (setq event-keys (list event-keys)))
1454 (flet ((var-key (var) (kintern (if (consp var) (first var) var)))
1455 (var-symbol (var) (if (consp var) (second var) var)))
1456 ;; VARS is an alist of:
1457 ;; (component-key ((event-key event-key ...) . extraction-code)
1458 ;; ((event-key event-key ...) . extraction-code) ...)
1459 ;; There should probably be accessor macros for this, instead of things like cdadr.
1460 (let ((vars (mapcar #'(lambda (var) (list var)) value-list))
1461 (multiple-p nil))
1462 ;; Fill in the VARS alist with event-keys and extraction-code
1463 (do ((keys event-keys (cdr keys))
1464 (temp nil))
1465 ((endp keys))
1466 (let* ((key (car keys))
1467 (binder (case key
1468 (:universal #'universal-event-get-macro)
1469 (otherwise (svref *event-macro-vector* (get-event-code key))))))
1470 (dolist (var vars)
1471 (let ((code (funcall binder display event-key (var-key (car var)))))
1472 (unless code (warn "~a isn't a component of the ~s event"
1473 (var-key (car var)) key))
1474 (if (setq temp (member code (cdr var) :key #'cdr :test #'equal))
1475 (push key (caar temp))
1476 (push `((,key) . ,code) (cdr var)))))))
1477 ;; Bind all the values
1478 `(let ,(mapcar #'(lambda (var)
1479 (if (cddr var) ;; if more than one binding form
1480 (progn (setq multiple-p t)
1481 (var-symbol (car var)))
1482 (list (var-symbol (car var)) (cdadr var))))
1483 vars)
1484 ;; When some values come from different places, generate code to set them
1485 ,(when multiple-p
1486 `(case ,event-key
1487 ,@(do ((keys event-keys (cdr keys))
1488 (clauses nil) ;; alist of (event-keys bindings)
1489 (clause nil nil)
1490 (temp))
1491 ((endp keys)
1492 (dolist (clause clauses)
1493 (unless (cdar clause) ;; Atomize single element lists
1494 (setf (car clause) (caar clause))))
1495 clauses)
1496 ;; Gather up all the bindings associated with (car keys)
1497 (dolist (var vars)
1498 (when (cddr var) ;; when more than one binding form
1499 (dolist (events (cdr var))
1500 (when (member (car keys) (car events))
1501 ;; Optimize for event-window being the same as some other binding
1502 (if (setq temp (member (cdr events) clause
1503 :key #'caddr
1504 :test #'equal))
1505 (setq clause
1506 (nconc clause `((setq ,(car var) ,(second (car temp))))))
1507 (push `(setq ,(car var) ,(cdr events)) clause))))))
1508 ;; Merge bindings for (car keys) with other bindings
1509 (when clause
1510 (if (setq temp (member clause clauses :key #'cdr :test #'equal))
1511 (push (car keys) (caar temp))
1512 (push `((,(car keys)) . ,clause) clauses))))))
1513 ,@body))))
1514
1515
1516 ;;;-----------------------------------------------------------------------------
1517 ;;; Error Handling
1518 ;;;-----------------------------------------------------------------------------
1519
1520 (eval-when (eval compile load)
1521 (defparameter
1522 *xerror-vector*
1523 '#(unknown-error
1524 request-error ; 1 bad request code
1525 value-error ; 2 integer parameter out of range
1526 window-error ; 3 parameter not a Window
1527 pixmap-error ; 4 parameter not a Pixmap
1528 atom-error ; 5 parameter not an Atom
1529 cursor-error ; 6 parameter not a Cursor
1530 font-error ; 7 parameter not a Font
1531 match-error ; 8 parameter mismatch
1532 drawable-error ; 9 parameter not a Pixmap or Window
1533 access-error ; 10 attempt to access private resource"
1534 alloc-error ; 11 insufficient resources
1535 colormap-error ; 12 no such colormap
1536 gcontext-error ; 13 parameter not a GContext
1537 id-choice-error ; 14 invalid resource ID for this connection
1538 name-error ; 15 font or color name does not exist
1539 length-error ; 16 request length incorrect;
1540 ; internal Xlib error
1541 implementation-error ; 17 server is defective
1542 ))
1543 )
1544
1545 (defun make-error (display event asynchronous)
1546 (declare (type display display)
1547 (type reply-buffer event)
1548 (type boolean asynchronous))
1549 (reading-event (event)
1550 (let* ((error-code (read-card8 1))
1551 (error-key (get-error-key display error-code))
1552 (error-decode-function (get error-key 'error-decode-function))
1553 (params (funcall error-decode-function display event)))
1554 (list* error-code error-key
1555 :asynchronous asynchronous :current-sequence (display-request-number display)
1556 params))))
1557
1558 (defun report-error (display error-code error-key &rest params)
1559 (declare (type display display)
1560 (dynamic-extent params))
1561 ;; All errors (synchronous and asynchronous) are processed by calling
1562 ;; an error handler in the display. The handler is called with the display
1563 ;; as the first argument and the error-key as its second argument. If handler is
1564 ;; an array it is expected to contain handler functions specific to
1565 ;; each error; the error code is used to index the array, fetching the
1566 ;; appropriate handler. Any results returned by the handler are ignored;;
1567 ;; it is assumed the handler either takes care of the error completely,
1568 ;; or else signals. For all core errors, additional keyword/value argument
1569 ;; pairs are:
1570 ;; :major integer
1571 ;; :minor integer
1572 ;; :sequence integer
1573 ;; :current-sequence integer
1574 ;; :asynchronous (member t nil)
1575 ;; For :colormap, :cursor, :drawable, :font, :GContext, :id-choice, :pixmap, and :window
1576 ;; errors another pair is:
1577 ;; :resource-id integer
1578 ;; For :atom errors, another pair is:
1579 ;; :atom-id integer
1580 ;; For :value errors, another pair is:
1581 ;; :value integer
1582 (let* ((handler (display-error-handler display))
1583 (handler-function
1584 (if (type? handler 'sequence)
1585 (elt handler error-code)
1586 handler)))
1587 (apply handler-function display error-key params)))
1588
1589 (defun request-name (code &optional display)
1590 (if (< code (length *request-names*))
1591 (svref *request-names* code)
1592 (dolist (extension (and display (display-extension-alist display)) "unknown")
1593 (when (= code (second extension))
1594 (return (first extension))))))
1595
1596 #-(or ansi-common-lisp excl lcl3.0 CMU)
1597 (define-condition request-error (x-error)
1598 (display
1599 error-key
1600 major
1601 minor
1602 sequence
1603 current-sequence
1604 asynchronous)
1605 (:report report-request-error))
1606
1607 (defun report-request-error (condition stream)
1608 (let ((error-key (request-error-error-key condition))
1609 (asynchronous (request-error-asynchronous condition))
1610 (major (request-error-major condition))
1611 (minor (request-error-minor condition))
1612 (sequence (request-error-sequence condition))
1613 (current-sequence (request-error-current-sequence condition)))
1614 (format stream "~:[~;Asynchronous ~]~a in ~:[request ~d (last request was ~d) ~;current request~2* ~] Code ~d.~d [~a]"
1615 asynchronous error-key (= sequence current-sequence)
1616 sequence current-sequence major minor
1617 (request-name major (request-error-display condition)))))
1618
1619 ;; Since the :report arg is evaluated as (function report-request-error) the
1620 ;; define-condition must come after the function definition.
1621 #+(or ansi-common-lisp excl lcl3.0 CMU)
1622 (define-condition request-error (x-error)
1623 (display
1624 error-key
1625 major
1626 minor
1627 sequence
1628 current-sequence
1629 asynchronous)
1630 (:report report-request-error))
1631
1632 (define-condition resource-error (request-error)
1633 (resource-id)
1634 (:report (lambda (condition stream)
1635 (report-request-error condition stream)
1636 (format stream " ID #x~x" (resource-error-resource-id condition)))))
1637
1638 (define-condition unknown-error (request-error)
1639 (error-code)
1640 (:report (lambda (condition stream)
1641 (report-request-error condition stream)
1642 (format stream " Error Code ~d." (unknown-error-error-code condition)))))
1643
1644 (define-condition access-error (request-error))
1645
1646 (define-condition alloc-error (request-error))
1647
1648 (define-condition atom-error (request-error)
1649 (atom-id)
1650 (:report (lambda (condition stream)
1651 (report-request-error condition stream)
1652 (format stream " Atom-ID #x~x" (atom-error-atom-id condition)))))
1653
1654 (define-condition colormap-error (resource-error))
1655
1656 (define-condition cursor-error (resource-error))
1657
1658 (define-condition drawable-error (resource-error))
1659
1660 (define-condition font-error (resource-error))
1661
1662 (define-condition gcontext-error (resource-error))
1663
1664 (define-condition id-choice-error (resource-error))
1665
1666 (define-condition illegal-request-error (request-error))
1667
1668 (define-condition length-error (request-error))
1669
1670 (define-condition match-error (request-error))
1671
1672 (define-condition name-error (request-error))
1673
1674 (define-condition pixmap-error (resource-error))
1675
1676 (define-condition value-error (request-error)
1677 (value)
1678 (:report (lambda (condition stream)
1679 (report-request-error condition stream)
1680 (format stream " Value ~d." (value-error-value condition)))))
1681
1682 (define-condition window-error (resource-error))
1683
1684 (define-condition implementation-error (request-error))
1685
1686 ;;-----------------------------------------------------------------------------
1687 ;; Internal error conditions signaled by CLX
1688
1689 (define-condition x-type-error (type-error)
1690 (type-string)
1691 (:report (lambda (condition stream)
1692 (format stream "~s isn't a ~a"
1693 (type-error-datum condition)
1694 (or (x-type-error-type-string condition)
1695 (type-error-expected-type condition))))))
1696
1697 (define-condition closed-display (x-error)
1698 (display)
1699 (:report (lambda (condition stream)
1700 (format stream "Attempt to use closed display ~s"
1701 (closed-display-display condition)))))
1702
1703 (define-condition lookup-error (x-error)
1704 (id display type object)
1705 (:report (lambda (condition stream)
1706 (format stream "ID ~d from display ~s should have been a ~s, but was ~s"
1707 (lookup-error-id condition)
1708 (lookup-error-display condition)
1709 (lookup-error-type condition)
1710 (lookup-error-object condition)))))
1711
1712 (define-condition connection-failure (x-error)
1713 (major-version
1714 minor-version
1715 host
1716 display
1717 reason)
1718 (:report (lambda (condition stream)
1719 (format stream "Connection failure to X~d.~d server ~a display ~d: ~a"
1720 (connection-failure-major-version condition)
1721 (connection-failure-minor-version condition)
1722 (connection-failure-host condition)
1723 (connection-failure-display condition)
1724 (connection-failure-reason condition)))))
1725
1726 (define-condition reply-length-error (x-error)
1727 (reply-length
1728 expected-length
1729 display)
1730 (:report (lambda (condition stream)
1731 (format stream "Reply length was ~d when ~d words were expected for display ~s"
1732 (reply-length-error-reply-length condition)
1733 (reply-length-error-expected-length condition)
1734 (reply-length-error-display condition)))))
1735
1736 (define-condition reply-timeout (x-error)
1737 (timeout
1738 display)
1739 (:report (lambda (condition stream)
1740 (format stream "Timeout after waiting ~d seconds for a reply for display ~s"
1741 (reply-timeout-timeout condition)
1742 (reply-timeout-display condition)))))
1743
1744 (define-condition sequence-error (x-error)
1745 (display
1746 req-sequence
1747 msg-sequence)
1748 (:report (lambda (condition stream)
1749 (format stream "Reply out of sequence for display ~s.~% Expected ~d, Got ~d"
1750 (sequence-error-display condition)
1751 (sequence-error-req-sequence condition)
1752 (sequence-error-msg-sequence condition)))))
1753
1754 (define-condition unexpected-reply (x-error)
1755 (display
1756 msg-sequence
1757 req-sequence
1758 length)
1759 (:report (lambda (condition stream)
1760 (format stream "Display ~s received a server reply when none was expected.~@
1761 Last request sequence ~d Reply Sequence ~d Reply Length ~d bytes."
1762 (unexpected-reply-display condition)
1763 (unexpected-reply-req-sequence condition)
1764 (unexpected-reply-msg-sequence condition)
1765 (unexpected-reply-length condition)))))
1766
1767 (define-condition missing-parameter (x-error)
1768 (parameter)
1769 (:report (lambda (condition stream)
1770 (let ((parm (missing-parameter-parameter condition)))
1771 (if (consp parm)
1772 (format stream "One or more of the required parameters ~a is missing."
1773 parm)
1774 (format stream "Required parameter ~a is missing or null." parm))))))
1775
1776 ;; This can be signalled anywhere a pseudo font access fails.
1777 (define-condition invalid-font (x-error)
1778 (font)
1779 (:report (lambda (condition stream)
1780 (format stream "Can't access font ~s" (invalid-font-font condition)))))
1781
1782 (define-condition device-busy (x-error)
1783 (display)
1784 (:report (lambda (condition stream)
1785 (format stream "Device busy for display ~s"
1786 (device-busy-display condition)))))
1787
1788 (define-condition unimplemented-event (x-error)
1789 (display
1790 event-code)
1791 (:report (lambda (condition stream)
1792 (format stream "Event code ~d not implemented for display ~s"
1793 (unimplemented-event-event-code condition)
1794 (unimplemented-event-display condition)))))
1795
1796 (define-condition undefined-event (x-error)
1797 (display
1798 event-name)
1799 (:report (lambda (condition stream)
1800 (format stream "Event code ~d undefined for display ~s"
1801 (undefined-event-event-name condition)
1802 (undefined-event-display condition)))))
1803
1804 (define-condition absent-extension (x-error)
1805 (name display)
1806 (:report (lambda (condition stream)
1807 (format stream "Extension ~a isn't defined for display ~s"
1808 (absent-extension-name condition)
1809 (absent-extension-display condition)))))
1810
1811 (define-condition inconsistent-parameters (x-error)
1812 (parameters)
1813 (:report (lambda (condition stream)
1814 (format stream "inconsistent-parameters:~{ ~s~}"
1815 (inconsistent-parameters-parameters condition)))))
1816
1817 (defun get-error-key (display error-code)
1818 (declare (type display display)
1819 (type array-index error-code))
1820 ;; Return the error-key associated with error-code
1821 (if (< error-code (length *xerror-vector*))
1822 (svref *xerror-vector* error-code)
1823 ;; Search the extensions for the error
1824 (dolist (entry (display-extension-alist display) 'unknown-error)
1825 (let* ((event-name (first entry))
1826 (first-error (fourth entry))
1827 (errors (third (assoc event-name *extensions*))))
1828 (declare (type keyword event-name)
1829 (type array-index first-error)
1830 (type list errors))
1831 (when (and errors
1832 (index<= first-error error-code
1833 (index+ first-error (index- (length errors) 1))))
1834 (return (nth (index- error-code first-error) errors)))))))
1835
1836 (defmacro define-error (error-key function)
1837 ;; Associate a function with ERROR-KEY which will be called with
1838 ;; parameters DISPLAY and REPLY-BUFFER and
1839 ;; returns a plist of keyword/value pairs which will be passed on
1840 ;; to the error handler. A compiler warning is printed when
1841 ;; ERROR-KEY is not defined in a preceding DEFINE-EXTENSION.
1842 ;; Note: REPLY-BUFFER may used with the READING-EVENT and READ-type
1843 ;; macros for getting error fields. See DECODE-CORE-ERROR for
1844 ;; an example.
1845 (declare (type symbol error-key)
1846 (type function function))
1847 ;; First ensure the name is for a declared extension
1848 (unless (or (find error-key *xerror-vector*)
1849 (dolist (extension *extensions*)
1850 (when (member error-key (third extension))
1851 (return t))))
1852 (x-type-error error-key 'error-key))
1853 `(setf (get ',error-key 'error-decode-function) (function ,function)))
1854
1855 ;; All core errors use this, so we make it available to extensions.
1856 (defun decode-core-error (display event &optional arg)
1857 ;; All core errors have the following keyword/argument pairs:
1858 ;; :major integer
1859 ;; :minor integer
1860 ;; :sequence integer
1861 ;; In addition, many have an additional argument that comes from the
1862 ;; same place in the event, but is named differently. When the ARG
1863 ;; argument is specified, the keyword ARG with card32 value starting
1864 ;; at byte 4 of the event is returned with the other keyword/argument
1865 ;; pairs.
1866 (declare (type display display)
1867 (type reply-buffer event)
1868 (type (or null keyword) arg))
1869 (declare (values keyword/arg-plist))
1870 display
1871 (reading-event (event)
1872 (let* ((sequence (read-card16 2))
1873 (minor-code (read-card16 8))
1874 (major-code (read-card8 10))
1875 (result (list :major major-code
1876 :minor minor-code
1877 :sequence sequence)))
1878 (when arg
1879 (setq result (list* arg (read-card32 4) result)))
1880 result)))
1881
1882 (defun decode-resource-error (display event)
1883 (decode-core-error display event :resource-id))
1884
1885 (define-error unknown-error
1886 (lambda (display event)
1887 (list* :error-code (aref (reply-ibuf8 event) 1)
1888 (decode-core-error display event))))
1889
1890 (define-error request-error decode-core-error) ; 1 bad request code
1891
1892 (define-error value-error ; 2 integer parameter out of range
1893 (lambda (display event)
1894 (decode-core-error display event :value)))
1895
1896 (define-error window-error decode-resource-error) ; 3 parameter not a Window
1897
1898 (define-error pixmap-error decode-resource-error) ; 4 parameter not a Pixmap
1899
1900 (define-error atom-error ; 5 parameter not an Atom
1901 (lambda (display event)
1902 (decode-core-error display event :atom-id)))
1903
1904 (define-error cursor-error decode-resource-error) ; 6 parameter not a Cursor
1905
1906 (define-error font-error decode-resource-error) ; 7 parameter not a Font
1907
1908 (define-error match-error decode-core-error) ; 8 parameter mismatch
1909
1910 (define-error drawable-error decode-resource-error) ; 9 parameter not a Pixmap or Window
1911
1912 (define-error access-error decode-core-error) ; 10 attempt to access private resource"
1913
1914 (define-error alloc-error decode-core-error) ; 11 insufficient resources
1915
1916 (define-error colormap-error decode-resource-error) ; 12 no such colormap
1917
1918 (define-error gcontext-error decode-resource-error) ; 13 parameter not a GContext
1919
1920 (define-error id-choice-error decode-resource-error) ; 14 invalid resource ID for this connection
1921
1922 (define-error name-error decode-core-error) ; 15 font or color name does not exist
1923
1924 (define-error length-error decode-core-error) ; 16 request length incorrect;
1925 ; internal Xlib error
1926
1927 (define-error implementation-error decode-core-error) ; 17 server is defective

  ViewVC Help
Powered by ViewVC 1.1.5