Animate screen savers, and interact with the screen saver infrastructure. Use functions that help you produce random values and centering rectangles.
Language
- Swift
- Objective-C
SDK
- macOS 10.0+
Overview
The Screen Saver framework defines the interface for subclasses to interact with the Screen Effects user interface feature. Screen Effects modules need to be written in Objective-C with its user interface implemented using Cocoa.
Screen Saver Framework Classes
The Screen Saver framework consists of the ScreenSaverView class, an abstract subclass of NSView. ScreenSaverView defines an interface for animating screen savers, instantiating small preview versions of the screen saver view (for display in the system preferences, for example), and for providing a configuration sheet to set various properties of the screen saver.
The ScreenSaverDefaults class is a subclass of NSUserDefaults and provides an interface to the standard user preferences storage system.
In addition, the Screen Saver framework provides a number of functions commonly required by screen saver applications including producing random values and centering rectangles.
Call Order
When macOS starts your screen saver, the following things happen:
The screen fades to black.
Your module is instantiated and its
initroutine is called.The window is created.
Your module is installed in the window.
Your window is activated and its order is set. The
drawRectcall is called at this point.Note
You should draw your initial state in the drawRect call. This initial state will be visible during the fade in that follows.
The screen fades in, revealing your window in the front.
Your
startAnimationmethod is called. This method should not do any drawing.Note
If you override this method, be sure to call the method in your superclass.
Drawing continues. Your
animateOneFrameis called repeatedly.The user takes some action.
Your
stopAnimationmethod is called.Note
If you override this method, be sure to call the method in your superclass.
Note
The stopAnimation or startAnimation methods do not immediately start or stop animation. In particular, it is not safe to assume that your animateOneFrame method will not execute (or continue to execute) after you call stopAnimation.
Do not attempt to use stopAnimation to gate against animation occurring while you modify preferences or other state variables. It is not a mutex.
Binary Compatibility
Because screen savers are plug-ins for the screen saver engine, a screen saver can only be supported if its binary contains a slice for the architecture of the running engine. As with any application, the screen saver engine normally runs using the most recent architecture supported by a given computer (assuming that the engine has a slice for that architecture).
For full compatibility, this means that on Intel-based Macs, a screen saver must contain (at least) an i386 slice (compiled for the oldest OS version you wish to support) and an x86_64 slice (compiled for version 10.6 and later). On PowerPC, macOS uses a 32-bit screen saver engine.