2005-04-19 00:34:41 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
//
|
|
|
|
// macglutfix.m
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "boinc_api.h"
|
|
|
|
|
|
|
|
void MacGLUTFix(bool isScreenSaver);
|
|
|
|
void BringAppToFront(void);
|
|
|
|
|
2005-04-24 12:31:55 +00:00
|
|
|
// The standard ScreenSaverView class actually sets the window
|
|
|
|
// level to 2002, not the 1000 defined by NSScreenSaverWindowLevel
|
|
|
|
// and kCGScreenSaverWindowLevel
|
|
|
|
#define RealSaverLevel 2002
|
|
|
|
|
2005-04-25 11:09:40 +00:00
|
|
|
// Delay when switching to screensaver mode to reduce annoying flashes
|
|
|
|
#define SAVERDELAY 30
|
|
|
|
|
2005-04-19 00:34:41 +00:00
|
|
|
void MacGLUTFix(bool isScreenSaver) {
|
|
|
|
static NSMenu * emptyMenu;
|
2005-04-24 12:31:55 +00:00
|
|
|
NSOpenGLContext * myContext = nil;
|
|
|
|
NSView *myView = nil;
|
2005-04-19 00:34:41 +00:00
|
|
|
NSWindow* myWindow = nil;
|
2005-04-24 12:31:55 +00:00
|
|
|
int newWindowLevel;
|
2005-04-25 11:09:40 +00:00
|
|
|
static int stabilizationDelay = 0;
|
2005-04-19 00:34:41 +00:00
|
|
|
|
|
|
|
if (! boinc_is_standalone()) {
|
|
|
|
if (emptyMenu == nil) {
|
|
|
|
emptyMenu = [ NSMenu alloc ];
|
|
|
|
[ NSApp setMainMenu:emptyMenu ];
|
|
|
|
}
|
|
|
|
}
|
2005-04-24 12:31:55 +00:00
|
|
|
|
|
|
|
// In screensaver mode, set our window's level just above
|
|
|
|
// our BOINC screensaver's window level so it can appear
|
|
|
|
// over it. This doesn't interfere with the screensaver
|
|
|
|
// password dialog because the dialog appears only after
|
|
|
|
// our screensaver is closed.
|
|
|
|
myContext = [ NSOpenGLContext currentContext ];
|
|
|
|
if (myContext)
|
|
|
|
myView = [ myContext view ];
|
|
|
|
if (myView)
|
|
|
|
myWindow = [ myView window ];
|
2005-04-19 00:34:41 +00:00
|
|
|
if (myWindow == nil)
|
|
|
|
return;
|
2005-04-24 12:31:55 +00:00
|
|
|
|
|
|
|
newWindowLevel = isScreenSaver ? RealSaverLevel+20 : NSNormalWindowLevel;
|
2005-04-19 00:34:41 +00:00
|
|
|
if ([ myWindow level ] == newWindowLevel)
|
2005-04-25 11:09:40 +00:00
|
|
|
{
|
|
|
|
stabilizationDelay = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++stabilizationDelay < SAVERDELAY)
|
2005-04-19 00:34:41 +00:00
|
|
|
return;
|
2005-04-25 11:09:40 +00:00
|
|
|
|
2005-04-19 00:34:41 +00:00
|
|
|
[ myWindow setLevel:newWindowLevel ];
|
|
|
|
}
|
|
|
|
|
|
|
|
void BringAppToFront() {
|
|
|
|
[ NSApp activateIgnoringOtherApps:YES ];
|
|
|
|
}
|