[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multifinder



>Can anyone tell me how to detect a switch to another application from within
>an application written in mcl?  I need to catch any and all attempts to leave
>my lisp application since it has a tools palette that I need to "hide" in
>order to avoid system crashes in other applications.  The same holds true
>for DA's.  

Here is a hack that will do it...Try the sample code at the bottom.
It was originally written when I had to hide the menubar for my
application,
but wanted to be good citizen and restore it when I got swapped out...

Hmm, guess that implies that I'm not sure it will work for a DA popping
up...though I'm pretty sure I would have tested that before I mixed this in
with the menubar-hide code.

No guarantee this will work for all versions of M[A]CL, but it ain't broke
on me yet...

It also alters *event-hook*, which may not be a good plan for something as
picuyane as this, but it works.

OTOH, who guarentees that if I set *event-hook* to #'foo, and then someone
else sets *event-hook* to #'bar.  Well, you get the picture.  Does 2.0
final have some mechanism for a LIST of event-handlers to handle an event?

;;;;I should have defined some constants for the numbers used in
my-event-hook,
;;;;but I don't have the right volume of IM to get the names right...
;;;;Also, forthcoming changes to MCL 2.0 will probably supersede this code.
;;;;HACK!!!

(defparameter *suspend-functions* ()
  "A list of functions that will be called when the Application is
placed in the background."
)

(defparameter *resume-functions* ()
  "A list of functions that will be called when the Application is
brought back into the foreground."
)

(defmethod suspend-event-handler ((arg null))
  "arg
Calls each function in *suspend-functions*.
Any specialization should be sure to call-next-method."
  (declare (ignore arg))
  (mapc #'funcall *suspend-functions*)
)

(defmethod resume-event-handler ((arg null))
  "arg
Calls each function in *resume-functions*.
Any specialization should be sure to call-next-method."
  (declare (ignore arg))
  (mapc #'funcall *resume-functions*)
)

(defun my-event-hook ()
  "Checks if *current-event* is a suspend or resume.
If so, calls suspend-event-handler or resume-event-handler.
Returns NIL."
  (let ((what (rref *current-event* :EventRecord.What))
        (message (rref *current-event* :EventRecord.Message))
       )
    (cond
      ((= what 15)
       (cond
         ((= message 16777218) (suspend-event-handler nil))
         ((= message 16777217) (resume-event-handler nil))
       )
      )
    )
    nil
) )

(setq *eventhook* #'my-event-hook)

#|

(defun elvis ()
  (print "Elvis has left the building.")
  (ed-beep)
)

(defun pheonix ()
  (print "We're Back.")
  (ed-beep)
  (ed-beep)
)

(push #'elvis *suspend-functions*)
(push #'pheonix *resume-functions*)

;(setq *eventhook* nil)

|#




"TANSTAAFL" Rich lynch@ils.nwu.edu