X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2FXScreenSaverView.m;h=528c4f6c5b0a36e3032445aea201d4a230a35957;hb=f0261d8acab611f3433160e4f07367b870439739;hp=2d60982d4e69b6355084b79ab12f11b9bb3a2c7b;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/OSX/XScreenSaverView.m b/OSX/XScreenSaverView.m index 2d60982d..528c4f6c 100644 --- a/OSX/XScreenSaverView.m +++ b/OSX/XScreenSaverView.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 2006, 2007 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -81,7 +81,7 @@ int mono_p = 0; perror ("putenv"); abort(); } - free (npath); +// free (npath); // Oops, don't free this! putenv() does not copy it! } @@ -126,9 +126,12 @@ add_default_options (const XrmOptionDescRec *opts, { "-choose-random-images", ".chooseRandomImages",XrmoptionNoArg, "True" }, { "-no-choose-random-images",".chooseRandomImages",XrmoptionNoArg, "False"}, { "-image-directory", ".imageDirectory", XrmoptionSepArg, 0 }, + { "-fps", ".doFPS", XrmoptionNoArg, "True" }, + { "-no-fps", ".doFPS", XrmoptionNoArg, "False"}, { 0, 0, 0, 0 } }; static const char *default_defaults [] = { + ".doFPS: False", ".textMode: date", // ".textLiteral: ", // ".textFile: ", @@ -262,6 +265,13 @@ add_default_options (const XrmOptionDescRec *opts, [self lockFocus]; // in case something tries to draw from here [self prepareContext]; + + /* I considered just not even calling the free callback at all... + But webcollage-cocoa needs it, to kill the inferior webcollage + processes (since the screen saver framework never generates a + SIGPIPE for them...) Instead, I turned off the free call in + xlockmore.c, which is where all of the bogus calls are anyway. + */ xsft->free_cb (xdpy, xwindow, xdata); [self unlockFocus]; @@ -286,6 +296,15 @@ add_default_options (const XrmOptionDescRec *opts, { } + +static void +screenhack_do_fps (Display *dpy, Window w, fps_state *fpst, void *closure) +{ + fps_compute (fpst, 0); + fps_draw (fpst); +} + + - (void) animateOneFrame { if (!initted_p) { @@ -313,7 +332,18 @@ add_default_options (const XrmOptionDescRec *opts, XClearWindow (xdpy, xwindow); [[self window] setAcceptsMouseMovedEvents:YES]; - + + /* In MacOS 10.5, this enables "QuartzGL", meaning that the Quartz + drawing primitives will run on the GPU instead of the CPU. + It seems like it might make things worse rather than better, + though... Plus it makes us binary-incompatible with 10.4. + +# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + [[self window] setPreferredBackingLocation: + NSWindowBackingLocationVideoMemory]; +# endif + */ + /* Kludge: even though the init_cb functions are declared to take 2 args, actually call them with 3, for the benefit of xlockmore_init() and xlockmore_setup(). @@ -322,6 +352,11 @@ add_default_options (const XrmOptionDescRec *opts, (void *(*) (Display *, Window, void *)) xsft->init_cb; xdata = init_cb (xdpy, xwindow, xsft->setup_arg); + + if (get_boolean_resource (xdpy, "doFPS", "DoFPS")) { + fpst = fps_init (xdpy, xwindow); + if (! xsft->fps_cb) xsft->fps_cb = screenhack_do_fps; + } } /* I don't understand why we have to do this *every frame*, but we do, @@ -330,6 +365,18 @@ add_default_options (const XrmOptionDescRec *opts, if (![self isPreview]) [NSCursor setHiddenUntilMouseMoves:YES]; + + if (fpst) + { + /* This is just a guess, but the -fps code wants to know how long + we were sleeping between frames. + */ + unsigned long usecs = 1000000 * [self animationTimeInterval]; + usecs -= 200; // caller apparently sleeps for slightly less sometimes... + fps_slept (fpst, usecs); + } + + /* It turns out that [ScreenSaverView setAnimationTimeInterval] does nothing. This is bad, because some of the screen hacks want to delay for long periods (like 5 seconds or a minute!) between frames, and running them @@ -373,10 +420,12 @@ add_default_options (const XrmOptionDescRec *opts, // And finally: // + NSDisableScreenUpdates(); unsigned long delay = xsft->draw_cb (xdpy, xwindow, xdata); - + if (fpst) xsft->fps_cb (xdpy, xwindow, fpst, xdata); XSync (xdpy, 0); - + NSEnableScreenUpdates(); + gettimeofday (&tv, 0); now = tv.tv_sec + (tv.tv_usec / 1000000.0); next_frame_time = now + (delay / 1000000.0); @@ -488,7 +537,11 @@ add_default_options (const XrmOptionDescRec *opts, xe.xbutton.y = y; xe.xbutton.state = state; if ([e type] == NSScrollWheel) - xe.xbutton.button = ([e deltaY] > 0 ? Button4 : Button5); + xe.xbutton.button = ([e deltaY] > 0 ? Button4 : + [e deltaY] < 0 ? Button5 : + [e deltaX] > 0 ? Button6 : + [e deltaX] < 0 ? Button7 : + 0); else xe.xbutton.button = [e buttonNumber] + 1; break; @@ -501,7 +554,7 @@ add_default_options (const XrmOptionDescRec *opts, case KeyRelease: { NSString *nss = [e characters]; - const char *s = [nss cStringUsingEncoding:NSUTF8StringEncoding]; + const char *s = [nss cStringUsingEncoding:NSISOLatin1StringEncoding]; xe.xkey.keycode = (s && *s ? *s : 0); xe.xkey.state = state; break;