From: Trent Buck
Subject: XCheckTypedEvent in CLX
Date: 
Message-ID: <20050202191059.70cfeede@harpo.marx>
As an exercise, I'm rewriting a little X11 window mangler (in C / Xlib)
in CL / CLX.

I've worked out most everything, except how to duplicate
XCheckTypedEvent functionality.  From the man page:

    The XCheckTypedEvent function searches the event queue and then any
    events available on the server connection for the first event that
    matches the specified type.  If it finds a match, XCheckTypedEvent
    removes that event, copies it into the specified XEvent structure,
    and returns True.  The other events in the queue are not discarded.
    If the event is not available, XCheckTypedEvent returns False, and
    the out- put buffer will have been flushed.

AFAICT, I need to write a process-event loop or similar.  Any
suggestions?

PS: I've tested with SBCL; should work on others.

References:
  http://twb.ath.cx/~twb/src/misc/tinywm.lisp
  http://incise.org/files/dev/tinywm-1.1.tgz
  http://ratpoison.elektrubadur.se/TinyWM

-- 
-trent
Is your life organized by the signs of the Zodiac?
`Pull handle to inflate' and `No sharp objects'?  Words to live by.
 -- Kevin Goebel, Berry Kercheval

From: Rob Warnock
Subject: Re: XCheckTypedEvent in CLX
Date: 
Message-ID: <qbmdnZuG39QVX53fRVn-3g@speakeasy.net>
Trent Buck  <·········@tznvy.pbz> wrote:
+---------------
| As an exercise, I'm rewriting a little X11 window mangler (in C / Xlib)
| in CL / CLX.
| 
| I've worked out most everything, except how to duplicate
| XCheckTypedEvent functionality.  From the man page:
| 
|     The XCheckTypedEvent function searches the event queue and then any
|     events available on the server connection for the first event that
|     matches the specified type.  If it finds a match, XCheckTypedEvent
|     removes that event, copies it into the specified XEvent structure,
|     and returns True.  The other events in the queue are not discarded.
|     If the event is not available, XCheckTypedEvent returns False, and
|     the out- put buffer will have been flushed.
| 
| AFAICT, I need to write a process-event loop or similar.  Any
| suggestions?
+---------------

Look in the CLX source distribution. The "trapezoid.lisp" example
[in CMUCL-19a it's in "src/clx/test/trapezoid.lisp"] has a simple
event loop that might serve as an example...


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Alan Crowe
Subject: Re: XCheckTypedEvent in CLX
Date: 
Message-ID: <86zmymj3bw.fsf@cawtech.freeserve.co.uk>
Trent Buck wrote:
> As an exercise, I'm rewriting a little X11 window mangler
> (in C / Xlib) in CL / CLX.

> I've worked out most everything, except how to duplicate
> XCheckTypedEvent functionality.

I've only used EVENT-CASE (page 12-123 of the CLX
Programmer's Reference)

I've puzzled over the previous page describing
HANDLER-FUNCTION and PROCESS-EVENT.

I guess that there is no function HANDLER-FUNCTION, it
is just a template for the function that the application
programmer needs to write so that it may be passed to
PROCESS-EVENT.

It looks as though one can do most of XCheckTypedEvent with
PROCESS-EVENT by including the check for a matching event in
ones own handler-function and returning NIL on mis-matches.

I hope that helps. I don't understand X and have a bad
feeling that I have totally misunderstood your question.

Alan Crowe
Edinburgh
Scotland
From: Shawn Betts
Subject: Re: XCheckTypedEvent in CLX
Date: 
Message-ID: <871xbv5p0u.fsf@rogueboner.lamenet.tmp>
Trent Buck <·········@tznvy.pbz> writes:

> As an exercise, I'm rewriting a little X11 window mangler (in C / Xlib)
> in CL / CLX.
> 
> I've worked out most everything, except how to duplicate
> XCheckTypedEvent functionality.  From the man page:
> 
>     The XCheckTypedEvent function searches the event queue and then any
>     events available on the server connection for the first event that
>     matches the specified type.  If it finds a match, XCheckTypedEvent
>     removes that event, copies it into the specified XEvent structure,
>     and returns True.  The other events in the queue are not discarded.
>     If the event is not available, XCheckTypedEvent returns False, and
>     the out- put buffer will have been flushed.
> 
> AFAICT, I need to write a process-event loop or similar.  Any
> suggestions?

Hi Trent,

look at the docs for xlib:process-event. It calls a handler function
on each event that comes in until the function returns non-nil. At
that time process-event returns the non-nil value and the event is
consumed.

(defvar *display* ...)

(defun read-key-event (&rest event-slots &key display event-key &allow-other-keys)
  (case event-key
    ((:key-press :key-release)
      ;; eat the event
      (format t "Eating a ~a event." event-key)
      t)
    (t nil)))

(xlib:process-event *display* :handler #'read-key-event)

-Shawn