Technical Q&As


TB 05 - Creating Screen Savers (1-May-95): Updated


Q I am trying to create a simple screen saver. I have some questions about the QuickDraw global qd and current Grafport. My code patches a _GetNextEvent trap to determine the amount of time the machine is idle, performs an operation, and then calls the real _GetNextEvent, which is saved at load time. My problem is that there is no qd, because my code is not an application, and it resides in the system heap. All of my attempts to get current GrafPort have failed. Therefore, I cannot draw anything on the screen.

How can I accomplish this? If the system calls my code, what is the current GrafPort (or how can I get one)? I tried creating my own GrafPort, but it didn't work.

A Avoid patching anything, if at all possible -- especially _GetNextEvent. You can install a JGNEFilter procedure to check for system activity.

The current GrafPort is a QuickDraw global, and QuickDraw globals are part of the A5 world. Since your screen saver is stand-alone code, and you don't have your own A5 world, you can't obtain the current GrafPort. If you attempt to, you are likely to get a window or dialog GrafPort, probably from the front-most application. This isn't much use in a screen saver, as you can save only the portion of the screen where the window or dialog is drawn.

To avoid the GrafPort problem, you could construct your own A5 world, but this approach will quickly transform your "simple screen saver" into a technical nightmare that would have an even greater compatibility risk than your present code does. For more information on JGNEFilter, see Technote 1060, Controlling Apps with Synthesized Events, or jGNEFilter -- the Untold Story.

One approach is to launch an application that creates a window over the entire screen. Since the amount of time it takes to activate a screen saver isn't critical, you could do this when it's time for your screen saver to take control, or you could have it constantly running in the background, and send it to the front. Once your application is in the foreground, you can safely draw anything you want on the screen. To restore the screen, simply close the application, or send it to the background.

-- Pete Gontier
Worldwide Developer Technical Support

Technical Q&As
Previous Question | Contents | Next Question

To contact us, please use the Contact Us page.