Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:30:36+00:00 2026-05-29T13:30:36+00:00

First time I’m writing something here. I have a question that i hope someone

  • 0

First time I’m writing something here. I have a question that i hope someone can give me an answer to.

I’m developing a screen saver for Mac OS X Lion using Objective-C. I have read some tutorials on how to do using a ScreenSaverView. Everything works perfect until I plug in another monitor. The program then run all the methods twice (loads the xml-file twice) and stuff like that. Whats the solution to this?

Should I use something else than ScreenSaverView?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:30:37+00:00Added an answer on May 29, 2026 at 1:30 pm

    I usually solve this by using a singleton (global variable initialed to true):

    static BOOL gFirst = YES;
    

    Then in the class initialization method I save it’s value to an ivar & then set the global false:

    - (id) initWithFrame: (NSRect) frameRect isPreview: (BOOL) isPreview {
    
        preview = first = NO;     // assume failure (pessimist!)
        if ( isPreview ) {
            preview = YES;        // remember this is the preview instance
        } else if ( gFirst ) {    // if the singleton is still true
            gFirst = NO;          // clear the singleton
            first = YES;          // and set the ivar
        }
    

    Note: I also save the isPreview flag to an ivar and don’t clear/set the first global/ivar when it’s true. So the logic here will set preview to true when isPreview is true otherwise will set first true the first time this class is instantiated (when isPreview is false) and false otherwise.

    Now in the drawRect I use the preview & first ivar’s to affect what get’s drawn…:

    - (void) drawRect: (NSRect) inRect {
        if ( preview || first ) {
            // ADD THE DRAWING CODE FOR THE 1ST MONITOR (or preview view) HERE
        } else {
            // ADD THE DRAWING CODE FOR THE NTH MONITOR(S) HERE
            [super drawRect:inRect];    // draw the default black background
        }
    }
    

    Note: Some screen savers do their drawing in their animateOneFrame method so you may need to move the above preview/first logic there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time asking a question here. Usually I can find my answer without having
first time poster - semi-newb to Rails. Here is my question. Suppose you have
First time asking a question here. I have a question, I have a UIImageView
first time SO user :) I know that I can format a number like
First time poster here. A quick question about setting up a loop here. I
First time posting here, will try to be succinct. This is a classic 'can't
First time I post a question, so here it goes. I want to push
First time using this service for a question. I hope I am not asking
First time poster, long time lurker :) I have a form setup that posts
first time using Asp.Net MVC here. I have a model class defined with 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.