ScreenSaverView/EnergySaver conflict question

0 views
Skip to first unread message

Richard

unread,
Jan 17, 2004, 2:02:03 PM1/17/04
to
I have a screen saver that is doing some background computation while
running, and I want this computation to continue until the screen saver
ends. The computation requires some clean-up: I need to take some action
as part of stopping it, I can't just have it die. I had been initiating
my background computation in [savermodule startAnimation] and cleaning
up and stopping it in [savermodule stopAnimation].

Problem: I've discovered that, when Energy Saver puts the monitor to
sleep, the screen saver is informed of this, and sends "stopAnimation"
to the screen saver module. I don't want to stop my computation just
because the screen has been put to sleep.

Partial solution: No big deal, I just don't use [savermodule
stopAnimation] as the signal to clean up and stop my background
computation. I've confirmed the screenSaverEngine is still running, and
the computation can continue.

New problem: How do I tell when the screen saver has *really* quit?
stopAnimation isn't good for this purpose, as it responds to the screen
sleep. I've been looking for some detectable event that is equivalent to
the screen saver coming back to life, but haven't found one yet.

Things I've tried

- dealloc of my ScreenSaverView doesn't get called
- NSWindowWillClose notification on the main window doesn't get called
- NSApplicationWillTerminate on the screen saver engine application
doesn't get called
- resignFirstResponder doesn't get called

Things I've thought of but haven't tried:

- Become the delegate of the screenSaverEngine application and respond
to appWillTerminate or appShouldTerminate. I don't like this because
the application already has a delegate and I don't want to interfere
with what it's doing

- Spin off a separate subtask, which stays running and gets somehow
notified when the ScreenSaverEngine application terminates, then handles
the cleanup and termination of the background computation (which is
being run in a separate task) through appleEvents or other IAC. This
would work but seems like a lot of work for such a simple problem.

Ideas I intend to investigate:

- WindowServer sends out various notifications. Is there something there?
- Is there any other service that might be sending interesting
notifications?
- Somehow detect the monitor-off event from the power manager and use
this fact (such as ignoring a stopAnimation that immediately follows a
power-off)


I would welcome any suggestions on other approaches. Actual solutions
are, of course, also welcome.

Thanks
Slart

Michael Ash

unread,
Jan 17, 2004, 5:13:10 PM1/17/04
to
In article <43o8-7w5o-5D3F5...@nr-ott02.bellnexxia.net>,
Richard <43o8...@dea.spamcon.org> wrote:

> Things I've thought of but haven't tried:
>
> - Become the delegate of the screenSaverEngine application and respond
> to appWillTerminate or appShouldTerminate. I don't like this because
> the application already has a delegate and I don't want to interfere
> with what it's doing

I doubt that this will work, either. If NSApplication is not sending
termination notifications, it's not going to be sending termination
delegate messages either. My guess would be that the screensaver engine
is either being killed by a signal, or it's exiting in a more direct
manner. If it's a signal, you may be able to trap it and clean up from
your signal handler.

> - Spin off a separate subtask, which stays running and gets somehow
> notified when the ScreenSaverEngine application terminates, then handles
> the cleanup and termination of the background computation (which is
> being run in a separate task) through appleEvents or other IAC. This
> would work but seems like a lot of work for such a simple problem.

This is not really that hard. The easiest thing I can think of offhand
is to set up a pipe between the parent and child, which will be closed
when the parent exits no matter what happens. The child can use that as
its cue to clean up. Otherwise, NSWorkspace has some notifications for
when apps are launched and quit that you could use.

Reply all
Reply to author
Forward
0 new messages