• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re(2): Starting the screensaver from code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re(2): Starting the screensaver from code


  • Subject: Re(2): Starting the screensaver from code
  • From: Eric Tilton <email@hidden>
  • Date: Wed, 19 Dec 2001 10:00:18 -0600

Well, knowing if the screensaver is activated, and preventing it from activating are two different problems. If you don't want it to kick in, you want to be proactive about that prevention -- turning it off after you get the notification that it's on is too late :).

One way to get the system to not activate the screensaver (or put the system to sleep, for that matter) is to periodically execute the "UpdateSystemActivity(UsrActivity);" Carbon call. Calling this is as if the user had just moved the mouse, hit a key on the keyboard, or otherwise indicated to the system that she was present and using the machine, and it resets the timers that measure time until power saving measures kick in.

One scenario where you'd use this would be in a display loop/game loop of some kind, that might look this (note that this is a Cocoa event loop, even though it's a Carbon call -- it's an API love-in!):

while(!done) {
NSEvent *event;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NS_DURING

// extract the next event from the queue. we will
// process keyboard and mouse events.
event = [NSApp nextEventMatchingMask: NSAnyEventMask
untilDate: [NSDate dateWithTimeIntervalSinceNow: 45]
inMode: NSDefaultRunLoopMode
dequeue: YES];

if (event == nil) {
// register user activity to prevent screen saver or sleep mode from kicking in
UpdateSystemActivity(UsrActivity);
}
else {
// ... parse the event, do your stuff
}

NS_HANDLER
// global exception handler
NS_ENDHANDLER

[pool release];
}

The event fetcher will time out after 45 seconds have passed, at which point it will called UpdateSystemActivity() and then go right back to waiting for an event. You could use whatever magic number you feel comfortable with, but I believe that 60 seconds is the minimum time for the system to turn on the screensaver or go to sleep (if you set it via defaults instead of the preferences pane, which limits you to 5 minutes).

eric

On Wednesday, December 19, 2001, at 06:28 AM, cocoa-dev-
email@hidden wrote:

Hi David,

On Wed, 12 Dec, 2001, David Hill <email@hidden> wrote:

On 12/11/01 12:51 PM, "Dan Bernstein" <email@hidden> wrote:

Is there any way my application can tell when the screen saver kicks in
(and possibly when it is stopped)? Apparently the workspace doesn't
notify about it.


There isn't a notification right now. If you'd like one, feel free to file
a feature request.

Dave

The following is a must (especially for Apple).

You need to be able to make sure the screensaver does not activate if watching
a QuickTime movie, right ?


Love,
Jens


  • Follow-Ups:
    • Re: Re(2): Starting the screensaver from code
      • From: Eric Tilton <email@hidden>
  • Prev by Date: Re: Syntax Coloring...
  • Next by Date: Re: Re(2): Starting the screensaver from code
  • Previous by thread: Re: Syntax Coloring...
  • Next by thread: Re: Re(2): Starting the screensaver from code
  • Index(es):
    • Date
    • Thread