PDA

View Full Version : Dual purpose ScreenSaver




nunyabeezwax
Jul 19, 2007, 03:52 PM
I wish to write a Mac screensaver and I have looked at some tutorials and it looks doable for me but I have an issue coming from the Win32(hiss boo) world. In Win32 there is no real difference between a screensaver and a normal application except it just behaves differently based on user input and a couple of command line switches.

I have written a Win32 screensaver that can be run, as a screensaver if it's name is scrnsvr.scr and run, as a normal application if it's name is scrnsvr.exe. I "need" to port this application to Mac (because the boss says so) and I was wondering if it is possible to do the same thing for a Mac.

Thanks from a soon to be convert,

John



kainjow
Jul 19, 2007, 05:47 PM
Screensavers in Mac OS X are just Cocoa bundles (plugins), that draw into an NSView subclass.

Once you figure out how to make the screensaver work normally, it probably wouldn't be hard to make a wrapper application that loads the screensaver on its own, into its own view.

There are several applications that load screensavers independently from System Preferences, and I'm sure some are open source. Search around on macupdate.com or versiontracker.com.

nunyabeezwax
Jul 20, 2007, 08:47 AM
Thanks for the fast reply but I don't want to call the screensaver from my app I want my app to be both a screensaver and a normal application. Sorry but I have to go back to Win32 (hiss boo) to explain, in Win32 I can make an app named foo.exe and it draws a box on the screen. If I take that exact same app and rename it foo.scr and copy it to my system32 directory it will run as a screensaver. If I wish to take full advantage of the screensaver functionality I do have to support more methods that the normal app does but it is possible. I am sorry I am asking these silly questions but I don't even have my Mac yet to just shotgun the approach and prove it myself.

Thanks again,
John

kainjow
Jul 20, 2007, 09:21 AM
You can't do that on Mac OS X. That was what I was explaining in my post above. It is not a matter of renaming the file, it is a matter of what the API supports. Win32 supports screensavers as executables, Cocoa does not.

MongoTheGeek
Jul 20, 2007, 09:26 AM
Thanks for the fast reply but I don't want to call the screensaver from my app I want my app to be both a screensaver and a normal application. Sorry but I have to go back to Win32 (hiss boo) to explain, in Win32 I can make an app named foo.exe and it draws a box on the screen. If I take that exact same app and rename it foo.scr and copy it to my system32 directory it will run as a screensaver. If I wish to take full advantage of the screensaver functionality I do have to support more methods that the normal app does but it is possible. I am sorry I am asking these silly questions but I don't even have my Mac yet to just shotgun the approach and prove it myself.


The problem is that on the mac screen savers aren't applications. They are code bundles. To use the win32 metaphor think of them as DLLs. Even if you were to bulk them up with application infrastructure changing the extension wouldn't be enough. You would also have to hack the bundle identifier, change the main class.

Writing the two off of a shared code base is easy though and you could distribute them together. Or you could even have the app carry around the screen saver inside of itself and give the user the option to install it.