void screeninit(void) { int fmt; int dx, dy; ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); fmt = XBGR32; //XRGB32; devRect = max_bounds(); dx = devRect.size.width; dy = devRect.size.height; gscreen = allocmemimage(Rect(0,0,dx,dy), fmt); dataProviderRef = CGDataProviderCreateWithData(0, gscreen->data->bdata, dx * dy * 4, 0); fullScreenImage = CGImageCreate(dx, dy, 8, 32, dx * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipLast, dataProviderRef, 0, 0, kCGRenderingIntentDefault); devRect = CGDisplayBounds(CGMainDisplayID()); kproc("osxscreen", winproc, nil, 0); kproc("osxflush", flushproc, nil, 0); Sleep(&rend, isready, nil); }
// Called before first plot after a set term command. void qt_init() { if (qt_initialized) return; // If we are not connecting to an existing QtGnuplotWidget, start a QtGnuplotApplication if (qt_optionWidget.isEmpty()) execGnuplotQt(); // Create a QApplication without event loop for QObject's that need it, namely font handling // A better strategy would be to transfer the font handling to the QtGnuplotWidget, but it would require // some synchronization between the widget and the gnuplot process. int argc = 0; QApplication* application = new QApplication(argc, (char**)( NULL)); #ifdef Q_WS_MAC // Don't display this application in the MAC OS X dock ProcessSerialNumber psn; if (GetCurrentProcess(&psn) == noErr) TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif // The creation of a QApplication mangled our locale settings #ifdef HAVE_LOCALE_H setlocale(LC_NUMERIC, "C"); setlocale(LC_TIME, current_locale); #endif qt_out.setVersion(QDataStream::Qt_4_4); qt_initialized = true; term_interlock = (void *)qt_init; GP_ATEXIT(qt_atexit); }
bool mmg_app::OnInit() { #ifdef __WXMAC__ ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN, kProcessTransformToForegroundApplication); #endif wxImage::AddHandler(new wxPNGHandler); mtx_common_init("mmg"); wxConfigBase *cfg; uint32_t i; wxString k, v; int index; prepare_mmg_data_folder(); #if defined(SYS_WINDOWS) cfg = new wxConfig(wxT("mkvmergeGUI")); #else cfg = new wxFileConfig(wxT("mkvmergeGUI"), wxEmptyString, get_config_file_name()); #endif cfg->SetExpandEnvVars(false); wxConfigBase::Set(cfg); init_ui_locale(); cfg->SetPath(wxT("/GUI")); cfg->Read(wxT("last_directory"), &last_open_dir, wxEmptyString); for (i = 0; i < 4; i++) { k.Printf(wxT("last_settings %u"), i); if (cfg->Read(k, &v) && wxFile::Exists(v)) last_settings.push_back(v); k.Printf(wxT("last_chapters %u"), i); if (cfg->Read(k, &v) && wxFile::Exists(v)) last_chapters.push_back(v); } cfg->SetPath(wxT("/chapter_editor")); cfg->Read(wxT("default_language"), &k, wxT("und")); g_default_chapter_language = wxMB(k); index = map_to_iso639_2_code(g_default_chapter_language.c_str()); if (-1 == index) g_default_chapter_language = "und"; else g_default_chapter_language = iso639_languages[index].iso639_2_code; if (cfg->Read(wxT("default_country"), &k) && (0 < k.length())) g_default_chapter_country = wxMB(k); if (!is_valid_cctld(g_default_chapter_country.c_str())) g_default_chapter_country = ""; app = this; mdlg = new mmg_dialog(); mdlg->Show(true); handle_command_line_arguments(); return true; }
App::App() { SetAppName( _("launcher") ); #ifdef __MACOSX__ ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); #endif }
/* * On OS X this ensures that the parent process goes to background. * Call TransformProcessType() in the parent process. */ void pyi_parent_to_background() { #if defined(__APPLE__) && defined(WINDOWED) ProcessSerialNumber psn = { 0, kCurrentProcess }; OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif }
int CApp::run(int argc, char** argv) { #if SYSAPI_WIN32 // record window instance for tray icon, etc CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); #endif #if MAC_OS_X_VERSION_10_7 // dock hide only supported on lion :( ProcessSerialNumber psn = { 0, kCurrentProcess }; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif CArch arch; // install application in to arch ARCH->adoptApp(this); // create an instance of log CLOG; // HACK: fail by default (saves us setting result in each catch) int result = kExitFailed; try { result = ARCH->run(argc, argv); } catch (XExitApp& e) { // instead of showing a nasty error, just exit with the error code. // not sure if i like this behaviour, but it's probably better than // using the exit(int) function! result = e.getCode(); } catch (XBase& e) { LOG((CLOG_CRIT "Exception: %s\n", e.what())); } catch (XArch& e) { LOG((CLOG_CRIT "Init failed: %s" BYE, e.what().c_str(), argsBase().m_pname)); } catch (std::exception& e) { LOG((CLOG_CRIT "Exception: %s\n", e.what())); } catch (...) { LOG((CLOG_CRIT "An unexpected exception occurred.\n")); } delete CLOG; ARCH->beforeAppExit(); return result; }
static PyObject *AE_TransformProcessToForegroundApplication(PyObject *_self, PyObject *_args) { OSStatus err = 0; ProcessSerialNumber psn = {0, kCurrentProcess}; if (!PyArg_ParseTuple(_args, "")) return NULL; err = TransformProcessType(& psn, kProcessTransformToForegroundApplication); if (err != noErr) return AE_MacOSError(err); Py_INCREF(Py_None); return Py_None; }
bool Sys_CreateWindow(const char *title, unsigned int w, unsigned int h, bool fs) { OSErr result; ProcessSerialNumber psn; windowRect.top = 100; windowRect.left = 100; windowRect.bottom = windowRect.top + h; windowRect.right = windowRect.left + w; g_Window.height = h; g_Window.width = w; g_Window.fs = fs; result = CreateNewWindow(kDocumentWindowClass, (kWindowStandardDocumentAttributes | kWindowInWindowMenuAttribute | kWindowStandardHandlerAttribute) & ~kWindowResizableAttribute, &windowRect, &g_Window.window); if (result != noErr) return false; SetWindowTitleWithCFString( g_Window.window, CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()) ); result = GetCurrentProcess(&psn); if (result == noErr) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } ShowWindow(g_Window.window); SelectWindow(g_Window.window); g_Window.glctx = createContext(g_Window.window); if (!g_Window.glctx) return false; /* static EventTypeSpec suspendResume[2] = {{kEventClassApplication, kEventAppActivated}, {kEventClassApplication, kEventAppDeactivated}}; InstallApplicationEventHandler(NewEventHandlerUPP(suspendResumeHandler), 2, suspendResume, &g_Window.window, NULL); */ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(quitEventHandler), 0, false); return true; }
//------------------------------------------------------------------------------ bool App::OnInit() { #ifdef __WXMAC__ ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); #endif // Création du Handler pour les images (permet de les ouvrir)... wxInitAllImageHandlers(); // Gestion de la langue // Ajout des préfixes possibles de chemins d'accès aux catalogues wxLocale::AddCatalogLookupPathPrefix(findFile(_T("locale"))); // Mise en place de la langue par défaut du système m_locale.Init(wxLANGUAGE_DEFAULT); { wxLogNull noLog; // Supprime les erreurs si les catalogues n'existent pas // Catalogue de l'application m_locale.AddCatalog(_T("trad")); // Catalogue de wxWidgets m_locale.AddCatalog(_T("wxstd")); } #if USE_LIBNOTIFY == 1 if(!notify_init(StrWxToStd(PROG_FULL_NAME_GETTEXT).c_str())) { std::cerr << "Lib notify not initialised !" << std::endl; return false; } #endif try { wxString frameTitle = PROG_FULL_NAME_GETTEXT; #if DEBUG == 1 frameTitle += _T(" - Debug"); #endif m_frame = new MainFrame(frameTitle, wxDefaultPosition, wxSize(400, 500)); m_frame->SetMinSize(wxSize(300, 300)); m_frame->Show(true); } catch(const std::exception& e) //Rattrape toutes les exceptions { wxMessageBox(_("Error : ") + wxString(e.what(), wxConvUTF8), _("Error..."), wxOK | wxICON_ERROR); exit(1); } return true; }
void pyi_launch_initialize(const char *executable, const char *extractionpath) { #if defined(__APPLE__) && defined(WINDOWED) /* * On OS X this ensures that the application is handled as GUI app. * Call TransformProcessType() in the child process. */ ProcessSerialNumber psn = { 0, kCurrentProcess }; OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication); #elif WIN32 CreateActContext(extractionpath, executable); #endif }
int App::run(int argc, char** argv) { #if MAC_OS_X_VERSION_10_7 // dock hide only supported on lion :( ProcessSerialNumber psn = { 0, kCurrentProcess }; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" GetCurrentProcess(&psn); #pragma GCC diagnostic pop TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif // install application in to arch appUtil().adoptApp(this); // HACK: fail by default (saves us setting result in each catch) int result = kExitFailed; try { result = appUtil().run(argc, argv); } catch (XExitApp& e) { // instead of showing a nasty error, just exit with the error code. // not sure if i like this behaviour, but it's probably better than // using the exit(int) function! result = e.getCode(); } catch (DisplayInvalidException& die) { LOG((CLOG_CRIT "A display invalid exception error occurred: %s\n", die.what())); // display invalid exceptions can occur when going to sleep. When this process exits, the // UI will restart us instantly. We don't really want that behevior, so we quies for a bit ARCH->sleep(10); } catch (std::runtime_error& re) { LOG((CLOG_CRIT "A runtime error occurred: %s\n", re.what())); } catch (std::exception& e) { LOG((CLOG_CRIT "An error occurred: %s\n", e.what())); } catch (...) { LOG((CLOG_CRIT "An unknown error occurred.\n")); } appUtil().beforeAppExit(); return result; }
int main(int argc, const char **argv) { #ifndef NOTRANSFORMPROCESSTYPE ProcessSerialNumber psn = { 0, kCurrentProcess }; OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication); if (returnCode) return 0; #endif if (!mclInitializeApplication( __MCC_lightTest_component_data.runtime_options, __MCC_lightTest_component_data.runtime_option_count)) return 0; return mclRunMain(run_main, argc, argv); }
// ---------------------------------------------------------------------------- bool App::OnInit() { #ifdef __WXMAC__ ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN, kProcessTransformToForegroundApplication); setenv("LC_CTYPE", "UTF-8", 0); #endif //__WXMAC__ setlocale(LC_ALL, ""); GUI_Main *frame = new GUI_Main(argc, argv, wxPoint(50, 50), wxSize(800-100, 600-100)); frame->Show(TRUE); return TRUE; }
//#################### EVENT HANDLERS #################### bool Application::OnInit() { #ifdef __WXMAC__ // Make mast into a foreground application on Mac OS X and bring it to the front. ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN, kProcessTransformToForegroundApplication); SetFrontProcess(&PSN); #endif HelpController::instance().initialize(); MainWindow *window = new MainWindow("MAST - Millipede Automatic Segmentation Tool"); window->Show(); return true; }
/** This chunk of code is heavily based off SDL_macosx.m from SDL. * The CPSEnableForegroundOperation that was here before is private * and should not be used. * Replaced by a call to the 10.3+ TransformProcessType. */ void osx_foreground_hack(void) { #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL) ProcessSerialNumber myProc, frProc; Boolean sameProc; if (GetFrontProcess(&frProc) == noErr && GetCurrentProcess(&myProc) == noErr) { if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) { TransformProcessType(&myProc, kProcessTransformToForegroundApplication); } SetFrontProcess(&myProc); } #endif }
int CApp::run(int argc, char** argv) { #if MAC_OS_X_VERSION_10_7 // dock hide only supported on lion :( ProcessSerialNumber psn = { 0, kCurrentProcess }; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif // install application in to arch appUtil().adoptApp(this); // HACK: fail by default (saves us setting result in each catch) int result = kExitFailed; try { result = appUtil().run(argc, argv); } catch (XExitApp& e) { // instead of showing a nasty error, just exit with the error code. // not sure if i like this behaviour, but it's probably better than // using the exit(int) function! result = e.getCode(); } catch (XBase& e) { LOG((CLOG_CRIT "Exception: %s\n", e.what())); } catch (XArch& e) { LOG((CLOG_CRIT "Init failed: %s" BYE, e.what().c_str(), argsBase().m_pname)); } catch (std::exception& e) { LOG((CLOG_CRIT "Exception: %s\n", e.what())); } catch (...) { LOG((CLOG_CRIT "An unexpected exception occurred.\n")); } appUtil().beforeAppExit(); return result; }
bool SpinEditorApp::OnInit() { spin::spinApp &spin = spin::spinApp::Instance(); // call parent init (mandatory) if (!wxApp::OnInit()) return false; // needs to be called before the MainFrame is constructed (because // wxSpinTreeCtrl needs to set OSC callbacks) this->start(); #ifdef __WXMAC__ // need to give focus to the process (for development; should be fixed when // using an .app bundle): ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN, kProcessTransformToForegroundApplication); #endif // initialize image handlers (for toolbar iconse, etc) // TODO: use only the image handlers required wxInitAllImageHandlers(); // create the main window: MainFrame *frame = new MainFrame( NULL ); // tell the app to exit automatically when the frame closes: wxApp::SetExitOnFrameDelete(true); frame->Show(true); SetTopWindow(frame); // start a timer to act as a periodic polling function (eg, to check that // the spinListener thread is still running spinPollTimer_ = new wxTimer(this, SpinPollTimer_ID); spinPollTimer_->Start(500); // milliseconds return true; }
int CApp::run(int argc, char** argv) { #if MAC_OS_X_VERSION_10_7 // dock hide only supported on lion :( ProcessSerialNumber psn = { 0, kCurrentProcess }; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" GetCurrentProcess(&psn); #pragma GCC diagnostic pop TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif // install application in to arch appUtil().adoptApp(this); // HACK: fail by default (saves us setting result in each catch) int result = kExitFailed; try { result = appUtil().run(argc, argv); } catch (XExitApp& e) { // instead of showing a nasty error, just exit with the error code. // not sure if i like this behaviour, but it's probably better than // using the exit(int) function! result = e.getCode(); } catch (std::exception& e) { LOG((CLOG_CRIT "An error occurred: %s\n", e.what())); } catch (...) { LOG((CLOG_CRIT "An unknown error occurred.\n")); } appUtil().beforeAppExit(); return result; }
void showDockIcon(bool show) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" ProcessSerialNumber psn; windowCounter += show ? 1 : -1; UInt32 transformState = show ? kProcessTransformToForegroundApplication : kProcessTransformToUIElementApplication; const bool shouldHideLastWindow = (transformState == kProcessTransformToUIElementApplication && windowCounter == 0) ? true : false; const bool shouldShowWindow = (transformState == kProcessTransformToForegroundApplication && windowCounter > 0) ? true : false; if (GetCurrentProcess(&psn) == noErr && (shouldShowWindow || shouldHideLastWindow)) { TransformProcessType(&psn, transformState); } #pragma clang diagnostic pop }
int _glfwPlatformOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode, _GLFWhints* hints ) { OSStatus error; ProcessSerialNumber psn; unsigned int windowAttributes; // TO DO: Refactor this function! _glfwWin.WindowFunctions = ( _glfwWin.Fullscreen ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions ); // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( !_glfwWin.Fullscreen ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; if( hints->Stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, hints->AuxBuffers); _setAGLAttribute( AGL_RED_SIZE, redbits ); _setAGLAttribute( AGL_GREEN_SIZE, greenbits ); _setAGLAttribute( AGL_BLUE_SIZE, bluebits ); _setAGLAttribute( AGL_ALPHA_SIZE, alphabits ); _setAGLAttribute( AGL_DEPTH_SIZE, depthbits ); _setAGLAttribute( AGL_STENCIL_SIZE, stencilbits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, hints->AccumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, hints->AccumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, hints->AccumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, hints->AccumAlphaBits ); if( hints->Samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, hints->Samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( pixelFormat == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a pixel format\n" ); return GL_FALSE; } // store pixel format's values for _glfwPlatformGetWindowParam's use _getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated ); _getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits ); _getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits ); _getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits ); _getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits ); _getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits ); _getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits ); _getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits ); _getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits ); _getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits ); _getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits ); _getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers ); _getAGLAttribute( AGL_STEREO, _glfwWin.Stereo ); _getAGLAttribute( AGL_SAMPLES_ARB, _glfwWin.Samples ); _glfwWin.RefreshRate = hints->RefreshRate; // create AGL context _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL ); aglDestroyPixelFormat( pixelFormat ); if( _glfwWin.AGLContext == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create an OpenGL context\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if (_glfwLibrary.Unbundled) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't get its PSN\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } /* Keith Bauer 2007-07-12 - I don't believe this is desirable if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } */ } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute \ | kWindowCollapseBoxAttribute \ | kWindowStandardHandlerAttribute ); if( hints->WindowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.MacWindow ) ); if( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler ); error = InstallWindowEventHandler( _glfwWin.MacWindow, _glfwWin.WindowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't install window event handlers\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.MacWindow, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.AGLContext, GetWindowPort( _glfwWin.MacWindow ) ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't draw to the window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.AGLContext ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't make the OpenGL context current\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // show window ShowWindow( _glfwWin.MacWindow ); return GL_TRUE; } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; CGLPixelFormatObj CGLpfObj; long numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; GLint rgbaAccumDepth = 0; int rgbChannelDepth = 0; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( hints->Stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( hints->Samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)hints->Samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( hints->AccumRedBits \ + hints->AccumGreenBits \ + hints->AccumBlueBits \ + hints->AccumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphabits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)depthbits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)stencilbits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)hints->AuxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &CGLpfObj, &numCGLvs ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( CGLpfObj, NULL, &_glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAColorSize, &rgbColorDepth ); if( rgbColorDepth == 24 || rgbColorDepth == 32 ) { rgbChannelDepth = 8; } if( rgbColorDepth == 16 ) { rgbChannelDepth = 5; } // get pixel depth of accumulator - I haven't got the slightest idea // how this number conforms to any other channel depth than 8 bits, // so this might end up giving completely knackered results... (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAAccumSize, &rgbaAccumDepth ); if( rgbaAccumDepth == 32 ) { rgbaAccumDepth = 8; } // store values of pixel format for _glfwPlatformGetWindowParam's use _getCGLAttribute( kCGLPFAAccelerated, _glfwWin.Accelerated ); _getCGLAttribute( rgbChannelDepth, _glfwWin.RedBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.GreenBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.BlueBits ); _getCGLAttribute( kCGLPFAAlphaSize, _glfwWin.AlphaBits ); _getCGLAttribute( kCGLPFADepthSize, _glfwWin.DepthBits ); _getCGLAttribute( kCGLPFAStencilSize, _glfwWin.StencilBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumRedBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumGreenBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumBlueBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumAlphaBits ); _getCGLAttribute( kCGLPFAAuxBuffers, _glfwWin.AuxBuffers ); _getCGLAttribute( kCGLPFAStereo, _glfwWin.Stereo ); _glfwWin.RefreshRate = hints->RefreshRate; // destroy our pixel format (void)CGLDestroyPixelFormat( CGLpfObj ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, /* Check further to the right -> */ height, hints->RefreshRate, NULL, NULL ); if( optimalMode == NULL ) { return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } return GL_TRUE; } }
SDLWindow::SDLWindow(const GWindow::Settings& settings) { #if defined(G3D_OSX) NSApplicationWrapper wrapper; // Hack to get our window/process to the front... ProcessSerialNumber psn = { 0, kCurrentProcess}; TransformProcessType (&psn, kProcessTransformToForegroundApplication); SetFrontProcess (&psn); _pool = new NSAutoreleasePoolWrapper(); #endif if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); debugPrintf("Unable to initialize SDL: %s\n", SDL_GetError()); Log::common()->printf("Unable to initialize SDL: %s\n", SDL_GetError()); exit(1); } // Set default icon if available if (settings.defaultIconFilename != "nodefault") { try { GImage defaultIcon; defaultIcon.load(settings.defaultIconFilename); setIcon(defaultIcon); } catch (const GImage::Error& e) { // Throw away default icon fprintf(stderr, "GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); debugPrintf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); Log::common()->printf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); } } if (! settings.fullScreen) { // This doesn't really work very well due to SDL bugs so we fix up // the position after the window is created. if (settings.center) { System::setEnv("SDL_VIDEO_CENTERED", ""); } else { System::setEnv("SDL_VIDEO_WINDOW_POS", format("%d,%d", settings.x, settings.y)); } } _mouseVisible = true; _inputCapture = false; // Request various OpenGL parameters SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings.depthBits); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, settings.stencilBits); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, settings.alphaBits); SDL_GL_SetAttribute(SDL_GL_STEREO, settings.stereo); #if SDL_FSAA if (settings.fsaaSamples > 1) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, settings.fsaaSamples); } #endif // Create a width x height OpenGL screen int flags = SDL_HWSURFACE | SDL_OPENGL | (settings.fullScreen ? SDL_FULLSCREEN : 0) | (settings.resizable ? SDL_RESIZABLE : 0) | (settings.framed ? 0 : SDL_NOFRAME); if (SDL_SetVideoMode(settings.width, settings.height, 0, flags) == NULL) { debugAssert(false); Log::common()->printf("Unable to create OpenGL screen: %s\n", SDL_GetError()); error("Critical Error", format("Unable to create OpenGL screen: %s\n", SDL_GetError()).c_str(), true); SDL_Quit(); exit(2); } // See what video mode we really got _settings = settings; int depthBits, stencilBits, redBits, greenBits, blueBits, alphaBits; glGetIntegerv(GL_DEPTH_BITS, &depthBits); glGetIntegerv(GL_STENCIL_BITS, &stencilBits); glGetIntegerv(GL_RED_BITS, &redBits); glGetIntegerv(GL_GREEN_BITS, &greenBits); glGetIntegerv(GL_BLUE_BITS, &blueBits); glGetIntegerv(GL_ALPHA_BITS, &alphaBits); int actualFSAABuffers = 0, actualFSAASamples = 0; #if SDL_FSAA SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &actualFSAABuffers); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualFSAASamples); #else (void)actualFSAABuffers; (void)actualFSAASamples; #endif _settings.rgbBits = iMin(iMin(redBits, greenBits), blueBits); _settings.alphaBits = alphaBits; _settings.stencilBits = stencilBits; _settings.depthBits = depthBits; _settings.fsaaSamples = actualFSAASamples; SDL_version ver; SDL_VERSION(&ver); _version = format("%d,%0d.%0d", ver.major, ver.minor, ver.patch); SDL_EnableUNICODE(1); setCaption("G3D"); SDL_SysWMinfo info; SDL_VERSION(&info.version); SDL_GetWMInfo(&info); _glContext = glGetCurrentContext(); #if defined(G3D_WIN32) // Extract SDL HDC/HWND on Win32 _Win32HWND = info.window; _Win32HDC = wglGetCurrentDC(); #elif defined(G3D_LINUX) // Extract SDL's internal Display pointer on Linux _X11Display = info.info.x11.display; _X11Window = info.info.x11.window; _X11WMWindow = info.info.x11.wmwindow; if (glXGetCurrentDisplay != NULL) { G3D::_internal::x11Display = glXGetCurrentDisplay(); } else { G3D::_internal::x11Display = info.info.x11.display; } if (glXGetCurrentDrawable != NULL) { // A Drawable appears to be either a Window or a Pixmap G3D::_internal::x11Window = glXGetCurrentDrawable(); } else { G3D::_internal::x11Window = info.info.x11.window; } #endif // Adjust window position #ifdef G3D_WIN32 if (! settings.fullScreen) { int W = screenWidth(); int H = screenHeight(); int x = iClamp(settings.x, 0, W); int y = iClamp(settings.y, 0, H); if (settings.center) { x = (W - settings.width) / 2; y = (H - settings.height) / 2; } SetWindowPos(_Win32HWND, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } #endif #ifdef G3D_LINUX if (! settings.fullScreen) { int W = screenWidth(_X11Display); int H = screenHeight(_X11Display); int x = iClamp(settings.x, 0, W); int y = iClamp(settings.y, 0, H); if (settings.center) { x = (W - settings.width) / 2; y = (H - settings.height) / 2; } XMoveWindow(_X11Display, _X11WMWindow, x, y); } #endif // Check for joysticks int j = SDL_NumJoysticks(); if ((j < 0) || (j > 10)) { // If there is no joystick adapter on Win32, // SDL returns ridiculous numbers. j = 0; } if (j > 0) { SDL_JoystickEventState(SDL_ENABLE); // Turn on the joysticks joy.resize(j); for (int i = 0; i < j; ++i) { joy[i] = SDL_JoystickOpen(i); debugAssert(joy[i]); } } GLCaps::init(); // Register this window as the current window makeCurrent(); # if defined(G3D_LINUX) // If G3D is using the default assertion hooks, replace them with our own that use // SDL functions to release the mouse, since we've been unable to implement // a non-SDL way of releasing the mouse using the X11 handle directly. if (assertionHook() == _internal::_handleDebugAssert_) { setFailureHook(SDL_handleDebugAssert_); } if (failureHook() == _internal::_handleErrorCheck_) { setFailureHook(SDL_handleErrorCheck_); } # endif }
CV_IMPL int cvNamedWindow( const char* name, int flags ) { int result = 0; CV_FUNCNAME( "cvNamedWindow" ); if (!wasInitialized) cvInitSystem(0, NULL); // to be able to display a window, we need to be a 'faceful' application // http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html static bool switched_to_faceful = false; if (! switched_to_faceful) { ProcessSerialNumber psn = { 0, kCurrentProcess }; OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication ); if (ret == noErr) { SetFrontProcess( &psn ); switched_to_faceful = true; } else { fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret); fflush (stderr); } } __BEGIN__; WindowRef outWindow = NULL; OSStatus err = noErr; Rect contentBounds = {100,100,320,440}; CvWindow* window; UInt wAttributes = 0; int len; const EventTypeSpec genericWindowEventHandler[] = { { kEventClassMouse, kEventMouseMoved}, { kEventClassMouse, kEventMouseUp}, { kEventClassMouse, kEventMouseDown}, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowBoundsChanged }//FD }; if( !name ) CV_ERROR( CV_StsNullPtr, "NULL name string" ); if( icvFindWindowByName( name ) != 0 ){ result = 1; EXIT; } len = strlen(name); CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1)); memset( window, 0, sizeof(*window)); window->name = (char*)(window + 1); memcpy( window->name, name, len + 1 ); window->flags = flags; window->signature = CV_WINDOW_MAGIC_VAL; window->image = 0; window->last_key = 0; window->on_mouse = 0; window->on_mouse_param = 0; window->next = hg_windows; window->prev = 0; if( hg_windows ) hg_windows->prev = window; hg_windows = window; wAttributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute; err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow); if (err != noErr) fprintf(stderr,"Erreur while creating the window\n"); SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString(NULL,name,kCFStringEncodingASCII)); if (err != noErr) fprintf(stdout,"Erreur SetWindowTitleWithCFString\n"); window->window = outWindow; err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler), GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow, NULL); ShowWindow( outWindow ); result = 1; __END__; return result; }
void unbundled() { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType( &psn, kProcessTransformToForegroundApplication ); SetFrontProcess(&psn); }
bool VisualizerApp::init( int argc, char** argv ) { ROS_INFO( "rviz version %s", get_version().c_str() ); ROS_INFO( "compiled against Qt version " QT_VERSION_STR ); ROS_INFO( "compiled against OGRE version %d.%d.%d%s (%s)", OGRE_VERSION_MAJOR, OGRE_VERSION_MINOR, OGRE_VERSION_PATCH, OGRE_VERSION_SUFFIX, OGRE_VERSION_NAME ); #ifdef Q_OS_MAC ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); SetFrontProcess(&PSN); #endif #if CATCH_EXCEPTIONS try { #endif ros::init( argc, argv, "rviz", ros::init_options::AnonymousName ); startContinueChecker(); po::options_description options; options.add_options() ("help,h", "Produce this help message") ("splash-screen,s", po::value<std::string>(), "A custom splash-screen image to display") ("help-file", po::value<std::string>(), "A custom html file to show as the help screen") ("display-config,d", po::value<std::string>(), "A display config file (.rviz) to load") ("fixed-frame,f", po::value<std::string>(), "Set the fixed frame") ("ogre-log,l", "Enable the Ogre.log file (output in cwd) and console output.") ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper") ("opengl", po::value<int>(), "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)") ("disable-anti-aliasing", "Prevent rviz from trying to use anti-aliasing when rendering.") ("no-stereo", "Disable the use of stereo rendering.") ("verbose,v", "Enable debug visualizations") ("log-level-debug", "Sets the ROS logger level to debug."); po::variables_map vm; std::string display_config, fixed_frame, splash_path, help_path; bool enable_ogre_log = false; bool in_mc_wrapper = false; bool verbose = false; int force_gl_version = 0; bool disable_anti_aliasing = false; bool disable_stereo = false; try { po::store( po::parse_command_line( argc, argv, options ), vm ); po::notify( vm ); if( vm.count( "help" )) { std::cout << "rviz command line options:\n" << options; return false; } if( vm.count( "in-mc-wrapper" )) { in_mc_wrapper = true; } if (vm.count("display-config")) { display_config = vm["display-config"].as<std::string>(); if( display_config.substr( display_config.size() - 4, 4 ) == ".vcg" ) { std::cerr << "ERROR: the config file '" << display_config << "' is a .vcg file, which is the old rviz config format." << std::endl; std::cerr << " New config files have a .rviz extension and use YAML formatting. The format changed" << std::endl; std::cerr << " between Fuerte and Groovy. There is not (yet) an automated conversion program." << std::endl; return false; } } if (vm.count("splash-screen")) { splash_path = vm["splash-screen"].as<std::string>(); } if (vm.count("help-file")) { help_path = vm["help-file"].as<std::string>(); } if (vm.count("fixed-frame")) { fixed_frame = vm["fixed-frame"].as<std::string>(); } if (vm.count("ogre-log")) { enable_ogre_log = true; } if (vm.count("no-stereo")) { disable_stereo = true; } if (vm.count("opengl")) { //std::cout << vm["opengl"].as<std::string>() << std::endl; force_gl_version = vm["opengl"].as<int>(); } if (vm.count("disable-anti-aliasing")) { disable_anti_aliasing = true; } if (vm.count("verbose")) { verbose = true; } if (vm.count("log-level-debug")) { if( ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug) ) { ros::console::notifyLoggerLevelsChanged(); } } } catch (std::exception& e) { ROS_ERROR("Error parsing command line: %s", e.what()); return false; } if( !ros::master::check() ) { WaitForMasterDialog* dialog = new WaitForMasterDialog; if( dialog->exec() != QDialog::Accepted ) { return false; } } nh_.reset( new ros::NodeHandle ); if( enable_ogre_log ) { OgreLogging::useRosLog(); } if ( force_gl_version ) { RenderSystem::forceGlVersion( force_gl_version ); } if (disable_anti_aliasing) { RenderSystem::disableAntiAliasing(); } if ( disable_stereo ) { RenderSystem::forceNoStereo(); } frame_ = new VisualizationFrame(); frame_->setApp( this->app_ ); if( help_path != "" ) { frame_->setHelpPath( QString::fromStdString( help_path )); } frame_->setShowChooseNewMaster( in_mc_wrapper ); if( splash_path != "" ) { frame_->setSplashPath( QString::fromStdString( splash_path )); } frame_->initialize( QString::fromStdString( display_config )); if( !fixed_frame.empty() ) { frame_->getManager()->setFixedFrame( QString::fromStdString( fixed_frame )); } frame_->getManager()->getSelectionManager()->setDebugMode( verbose ); frame_->show(); ros::NodeHandle private_nh("~"); reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders); #if CATCH_EXCEPTIONS } catch (std::exception& e) { ROS_ERROR("Caught exception while loading: %s", e.what()); return false; } #endif return true; }
int _glfwPlatformOpenWindow( int width, int height, const _GLFWwndconfig *wndconfig, const _GLFWfbconfig *fbconfig ) { OSStatus error; unsigned int windowAttributes; ProcessSerialNumber psn; // TODO: Break up this function! _glfwWin.windowUPP = NULL; _glfwWin.mouseUPP = NULL; _glfwWin.keyboardUPP = NULL; _glfwWin.commandUPP = NULL; _glfwWin.window = NULL; _glfwWin.aglContext = NULL; _glfwWin.aglPixelFormat = NULL; _glfwWin.cglContext = NULL; _glfwWin.cglPixelFormat = NULL; _glfwWin.refreshRate = wndconfig->refreshRate; // Fail if OpenGL 3.0 or above was requested if( wndconfig->glMajor > 2 ) { fprintf( stderr, "OpenGL 3.0+ is not yet supported on Mac OS X\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( _glfwLibrary.Unbundled ) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to get the process serial number\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "Failed to become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( wndconfig->mode == GLFW_FULLSCREEN ) { if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } } } if( !installEventHandlers() ) { fprintf( stderr, "Failed to install Carbon application event handlers\n" ); _glfwPlatformTerminate(); return GL_FALSE; } // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( wndconfig->mode == GLFW_WINDOW ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_CLOSEST_POLICY; if( fbconfig->stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, fbconfig->auxBuffers); _setAGLAttribute( AGL_RED_SIZE, fbconfig->redBits ); _setAGLAttribute( AGL_GREEN_SIZE, fbconfig->greenBits ); _setAGLAttribute( AGL_BLUE_SIZE, fbconfig->blueBits ); _setAGLAttribute( AGL_ALPHA_SIZE, fbconfig->alphaBits ); _setAGLAttribute( AGL_DEPTH_SIZE, fbconfig->depthBits ); _setAGLAttribute( AGL_STENCIL_SIZE, fbconfig->stencilBits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, fbconfig->accumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, fbconfig->accumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, fbconfig->accumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, fbconfig->accumAlphaBits ); if( fbconfig->samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, fbconfig->samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); _glfwWin.aglPixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( _glfwWin.aglPixelFormat == NULL ) { fprintf( stderr, "Failed to choose AGL pixel format: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create AGL context _glfwWin.aglContext = aglCreateContext( _glfwWin.aglPixelFormat, NULL ); if( _glfwWin.aglContext == NULL ) { fprintf( stderr, "Failed to create AGL context: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute ); if( wndconfig->windowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.window ) ); if( ( error != noErr ) || ( _glfwWin.window == NULL ) ) { fprintf( stderr, "Failed to create Carbon window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.windowUPP = NewEventHandlerUPP( windowEventHandler ); error = InstallWindowEventHandler( _glfwWin.window, _glfwWin.windowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "Failed to install Carbon window event handler\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.window, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.aglContext, GetWindowPort( _glfwWin.window ) ) ) { fprintf( stderr, "Failed to set the AGL context as the Carbon window drawable: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.aglContext ) ) { fprintf( stderr, "Failed to make AGL context current: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } ShowWindow( _glfwWin.window ); } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; GLint numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( fbconfig->stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( fbconfig->samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)fbconfig->samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( fbconfig->accumRedBits \ + fbconfig->accumGreenBits \ + fbconfig->accumBlueBits \ + fbconfig->accumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)fbconfig->alphaBits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)fbconfig->depthBits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)fbconfig->stencilBits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)fbconfig->auxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &_glfwWin.cglPixelFormat, &numCGLvs ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to choose CGL pixel format: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( _glfwWin.cglPixelFormat, NULL, &_glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to create CGL context: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( _glfwWin.cglPixelFormat, 0, kCGLPFAColorSize, &rgbColorDepth ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to capture Core Graphics displays\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, height, wndconfig->refreshRate, NULL, NULL ); if( optimalMode == NULL ) { fprintf( stderr, "Failed to retrieve Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to switch to Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to make CGL context current: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to set CGL fullscreen mode: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } } return GL_TRUE; }
/* Global functions ---------------- */ #if defined (WX_USER_INTERFACE) bool wxCmguiApp::OnInit() { return (true); } wxAppTraits * wxCmguiApp::CreateTraits() { return new wxGUIAppTraits; } void wxCmguiApp::OnIdle(wxIdleEvent& event) { if (event_dispatcher) { if (Event_dispatcher_process_idle_event(event_dispatcher)) { event.RequestMore(); } } } void wxCmguiApp::SetEventDispatcher(Event_dispatcher *event_dispatcher_in) { event_dispatcher = event_dispatcher_in; } BEGIN_EVENT_TABLE(wxCmguiApp, wxApp) EVT_IDLE(wxCmguiApp::OnIdle) END_EVENT_TABLE() IMPLEMENT_APP_NO_MAIN(wxCmguiApp) #endif /*defined (WX_USER_INTERFACE)*/ #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) int main(int argc,const char *argv[]) #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ int WINAPI WinMain(HINSTANCE current_instance,HINSTANCE previous_instance, LPSTR command_line,int initial_main_window_state) /* using WinMain as the entry point tells Windows that it is a gui and to use the graphics device interface functions for I/O */ /*???DB. WINDOWS a zero return code if WinMain does get into the message loop. Other application interfaces may expect something else. Should this failure code be #define'd ? */ /*???DB. Win32 SDK says that don't have to call it WinMain */ #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /******************************************************************************* LAST MODIFIED : 7 January 2003 DESCRIPTION : Main program for the CMISS Graphical User Interface ==============================================================================*/ { int return_code = 0; #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) int argc = 1, i; const char **argv; char *p, *q; #endif /* defined (WIN32_USER_INTERFACE) */ struct Cmiss_context_app *context = NULL; struct User_interface_module *UI_module = NULL; struct Cmiss_command_data *command_data; #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) ENTER(main); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ ENTER(WinMain); //_CrtSetBreakAlloc(28336); for (p = command_line; p != NULL && *p != 0;) { p = strchr(p, ' '); if (p != NULL) p++; argc++; } argv = (const char **)malloc(sizeof(*argv) * argc); argv[0] = "cmgui"; for (i = 1, p = command_line; p != NULL && *p != 0;) { q = strchr(p, ' '); if (q != NULL) *q++ = 0; if (p != NULL) argv[i++] = p; p = q; } #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /* display the version */ display_message(INFORMATION_MESSAGE, "%s version %s\n%s\n" "Build information: %s %s\n", CMISS_NAME_STRING, CMISS_VERSION_STRING, CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); #if defined (CARBON_USER_INTERFACE) || (defined (WX_USER_INTERFACE) && defined (DARWIN)) ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); #endif context = Cmiss_context_app_create("default"); #if defined (WX_USER_INTERFACE) int wx_entry_started = 0; #endif if (context) { #if defined (WX_USER_INTERFACE) || (!defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)) UI_module = Cmiss_context_create_user_interface(context, argc, argv, NULL); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ UI_module = Cmiss_context_create_user_interface(context, argc, argv, current_instance, previous_instance, command_line, initial_main_window_state, NULL); #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ if (UI_module) { #if defined (WX_USER_INTERFACE) if (UI_module->user_interface) { char **temp_argv = NULL, **cleanup_argv = NULL; int temp_argc = argc, cleanup_argc = argc; if (cleanup_argc > 0) { ALLOCATE(temp_argv, char *, cleanup_argc); ALLOCATE(cleanup_argv, char *, cleanup_argc); for (int i = 0; i < cleanup_argc; i++) { cleanup_argv[i] = temp_argv[i] = duplicate_string(argv[i]); } } if (wxEntryStart(temp_argc, temp_argv)) { wx_entry_started = 1; wxXmlResource::Get()->InitAllHandlers(); wxCmguiApp &app = wxGetApp(); if (&app) { app.SetEventDispatcher(UI_module->event_dispatcher); } else { display_message(ERROR_MESSAGE, "initialiseWxApp. wxCmguiApp not initialised."); } } else { display_message(ERROR_MESSAGE, "initialiseWxApp. Invalid arguments."); } if (cleanup_argv) { for (int i = 0; i < cleanup_argc; i++) { DEALLOCATE(cleanup_argv[i]); } DEALLOCATE(temp_argv); DEALLOCATE(cleanup_argv); } } #endif Cmiss_graphics_module_id graphics_module = NULL; if (NULL != (graphics_module = Cmiss_context_get_default_graphics_module(Cmiss_context_app_get_core_context(context)))) { Cmiss_graphics_module_define_standard_materials(graphics_module); Cmiss_graphics_module_destroy(&graphics_module); } if (NULL != (command_data = Cmiss_context_get_default_command_interpreter(context))) { Cmiss_command_data_set_cmgui_string(command_data, CMISS_NAME_STRING, CMISS_VERSION_STRING, "CMISS_DATE_STRING", CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); Cmiss_command_data_main_loop(command_data); Cmiss_command_data_destroy(&command_data); return_code = 0; } else { return_code = 1; } User_interface_module_destroy(&UI_module); } else { return_code = 1; } Cmiss_context_app_destroy(&context); Context_internal_cleanup(); #if defined (WX_USER_INTERFACE) if (wx_entry_started) wxEntryCleanup(); #endif /* FieldML does not cleanup the global varaibles xmlParser, xmlSchematypes and * xmlCatalog at this moment, so we clean it up here instead*/ xmlCatalogCleanup(); xmlSchemaCleanupTypes(); xmlCleanupParser(); } else { return_code = 1; } #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) free(argv) #endif LEAVE; return (return_code); } /* main */
/** * Actually launch Scilab under Mac OS X. Need to be in a specific thread. * See http://wiki.scilab.org/Compiling_Scilab_5.x_under_MacOSX * @param param The structure containing the missing argument mandatory for realmain * @return the result of the operation (0 if OK ...) */ static int launchMacOSXEnv(ScilabEngineInfo* _pSEI) { #undef JVM_DETECTION #ifdef JVM_DETECTION int ret = -1; { CFStringRef targetJVM = CFSTR("1.5"); CFBundleRef JavaVMBundle; CFURLRef JavaVMBundleURL; CFURLRef JavaVMBundlerVersionsDirURL; CFURLRef TargetJavaVM; UInt8 pathToTargetJVM [PATH_MAX] = "\0"; struct stat sbuf; /* * This piece of code is mandatory because Mac OS X implementation of Java has a bug here. * Cocoa does not know how to handle the new window created this way. * See: http://lists.apple.com/archives/Java-dev/2009/Jan/msg00062.html * Or Mac Os X bug #6484319 * Thanks to Mike Swingler */ ProcessSerialNumber psn; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToForegroundApplication); /* End of the workaround */ // Look for the JavaVM bundle using its identifier JavaVMBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.JavaVM") ); if (JavaVMBundle != NULL) { // Get a path for the JavaVM bundle JavaVMBundleURL = CFBundleCopyBundleURL(JavaVMBundle); CFRelease(JavaVMBundle); if (JavaVMBundleURL != NULL) { // Append to the path the Versions Component JavaVMBundlerVersionsDirURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, JavaVMBundleURL, CFSTR("Versions"), true); CFRelease(JavaVMBundleURL); if (JavaVMBundlerVersionsDirURL != NULL) { // Append to the path the target JVM's Version TargetJavaVM = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, JavaVMBundlerVersionsDirURL, targetJVM, true); CFRelease(JavaVMBundlerVersionsDirURL); if (TargetJavaVM != NULL) { if (CFURLGetFileSystemRepresentation (TargetJavaVM, true, pathToTargetJVM, PATH_MAX )) { // Check to see if the directory, or a sym link for the target JVM directory exists, and if so set the // environment variable JAVA_JVM_VERSION to the target JVM. if (stat((char*)pathToTargetJVM, &sbuf) == 0) { // Ok, the directory exists, so now we need to set the environment var JAVA_JVM_VERSION to the CFSTR targetJVM // We can reuse the pathToTargetJVM buffer to set the environement var. if (CFStringGetCString(targetJVM, (char*)pathToTargetJVM, PATH_MAX, kCFStringEncodingUTF8)) { setenv("JAVA_JVM_VERSION", (char*)pathToTargetJVM, 1); ret = 0; } else { fprintf(stderr, "Could not get the path to the target JVM.\n"); } } else { fprintf(stderr, "Error checking symlink for the target jvm.\n"); } } else { fprintf(stderr, "Error getting file system representation for bundle url.\n"); CFRelease(TargetJavaVM); } } else { fprintf(stderr, "Error appending version component to bundle url.\n"); } } else { fprintf(stderr, "Error appending path component to bundle url.\n"); } } else { fprintf(stderr, "Error copying bundle url.\n"); } } else { fprintf(stderr, "Error: cant find bundle: com.apple.JavaVM.\n"); } } #else int ret = 0; /* * This piece of code is mandatory because Mac OS X implementation of Java has a bug here. * Cocoa does not know how to handle the new window created this way. * See: http://lists.apple.com/archives/Java-dev/2009/Jan/msg00062.html * Or Mac Os X bug #6484319 * Thanks to Mike Swingler */ ProcessSerialNumber psn; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToForegroundApplication); /* End of the workaround */ #endif if (ret == 0) { StartScilabEngine(_pSEI); ret = RunScilabEngine(_pSEI); StopScilabEngine(_pSEI); exit(ret); } return ret; }
int main(int argc, char *argv[]) { // For correct Unicode translation, apply the current system locale: setlocale(LC_ALL, ""); // But use usual conversion for scanf()/sprintf(): setlocale(LC_NUMERIC, "C"); // Finetuning Japanese encoding for corrent DXF/DWG import. // see http://qt-project.org/doc/qt-4.8/codecs-jis.html #ifdef Q_OS_WIN _putenv_s("UNICODEMAP_JP", "cp932"); #else setenv("UNICODEMAP_JP", "cp932", 1); #endif RMainWindow::installMessageHandler(); #ifdef Q_OS_MAC // TODO: make available as script function: QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus); #endif QStringList originalArguments; for (int i=0; i<argc; i++) { QString a = argv[i]; originalArguments.append(a); } RSettings::setOriginalArguments(originalArguments); QString appId = "QCAD"; for (int i=0; i<argc; i++) { QString a = argv[i]; if (a=="-app-id" && i+1<argc) { appId = argv[i+1]; } } bool guiEnabled = true; for (int i=1; i<argc; i++) { if (!strcmp(argv[i], "-no-gui")) { guiEnabled = false; } } RSingleApplication* app = new RSingleApplication(appId, argc, argv, guiEnabled); #if defined(Q_OS_MAC) || defined(Q_OS_LINUX) // note that SIGPIPE is only ignored in release mode, gdb catches SIGPIPE // by default. To disable that behavior in gdb, use: // handle SIGPIPE nostop noprint pass signal(SIGPIPE,catchSigPipe); #endif #ifdef Q_OS_MAC // activate Mac OS X dock icon if desired: if (!app->arguments().contains("-no-dock-icon") && !app->arguments().contains("-help") && !app->arguments().contains("-h") && !app->arguments().contains("-version") && !app->arguments().contains("-v")) { ProcessSerialNumber psn; if (GetCurrentProcess(&psn) == noErr) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); } } #endif if (!app->arguments().contains("-allow-multiple-instances")) { // send arguments to running instance for further processing: if (app->sendMessage(app->arguments().join("\n"), 30000)) { qWarning("Application already running. Aborting..."); return 0; } } #ifdef Q_OS_WIN32 // SVG icons are only rendered if this line is present under windows: QImageReader::supportedImageFormats(); // the SQLite plugin can only be loaded if this line is present under windows: QSqlDatabase::drivers(); #endif qRegisterMetaType<RColor>(); qRegisterMetaTypeStreamOperators<RColor>("RColor"); qRegisterMetaType<RVector>(); qRegisterMetaTypeStreamOperators<RVector>("RVector"); QString cwd = QDir::currentPath(); RSettings::setLaunchPath(cwd); // set current working directory: QDir::setCurrent(RSettings::getApplicationPath()); // disable Qt library paths to avoid plugins for Qt designer from being found: QString pluginPath = RSettings::getPluginPath(); if (pluginPath.isEmpty()) { qWarning() << QString("Folder '%1' does not exist").arg(pluginPath); return -1; } app->setLibraryPaths(QStringList() << pluginPath); RMath::init(); RFontList::init(); RPatternListMetric::init(); RPatternListImperial::init(); // init object properties: RObject::init(); REntity::init(); RArcEntity::init(); RBlockReferenceEntity::init(); RCircleEntity::init(); RDimensionEntity::init(); RDimAlignedEntity::init(); RDimAngularEntity::init(); RDimDiametricEntity::init(); RDimOrdinateEntity::init(); RDimRadialEntity::init(); RDimRotatedEntity::init(); REllipseEntity::init(); RImageEntity::init(); RHatchEntity::init(); RLeaderEntity::init(); RLineEntity::init(); RPointEntity::init(); RPolylineEntity::init(); RSolidEntity::init(); RSplineEntity::init(); RTextBasedEntity::init(); RTextEntity::init(); RAttributeDefinitionEntity::init(); RAttributeEntity::init(); RUcs::init(); RLayer::init(); RLinetype::init(); RBlock::init(); RView::init(); RPluginLoader::loadPlugins(true); // check for autostart option: QString autostartFile; QStringList arguments = app->arguments(); int i = arguments.indexOf("-autostart"); if (i!=-1 && arguments.count()>i+1) { autostartFile = arguments.at(i+1); } RScriptHandlerRegistry::registerScriptHandler(RScriptHandlerEcma::factory, RScriptHandlerEcma::getSupportedFileExtensionsStatic()); RScriptHandler* handler = RScriptHandlerRegistry::getGlobalScriptHandler("js"); Q_ASSERT(handler!=NULL); handler->init(autostartFile, arguments.mid(i+1)); int ret = 0; if (handler->hasUncaughtExceptions()) { ret = 1; } // delete script handler and print uncaught exceptions: delete handler; RSettings::uninit(); RFontList::uninit(); RPatternListMetric::uninit(); RPatternListImperial::uninit(); RSingleton::cleanUp(); RMath::uninit(); return ret; }
// A magic method that allows applications to react to events even // when they are not organized in a bundle static void osx_AllowForeground(void) { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); }
// Note that this function has to be called once. To recreate textures, call the renewTex() member function. int appleMultiContext::init(struct sageDisplayConfig &cfg) { // Make this a "faceful app" that can receive input events: ProcessSerialNumber psn; OSStatus s; s = GetCurrentProcess(&psn); assert(s == noErr); s = TransformProcessType(&psn,kProcessTransformToForegroundApplication); assert(s == noErr); s = SetFrontProcess(&psn); assert(s == noErr); singleContext = false; configStruct = cfg; tileNum = cfg.dimX * cfg.dimY; if (tileNum > MAX_TILES_PER_NODE) { sage::printLog("displayContext::init() : The tile number exceeds the maximum"); return -1; } if (!winCreatFlag) { // // Set up us the OpenGL: // Choose global pixel format: static GLint agl_fmt_list[] = { AGL_RGBA, AGL_RED_SIZE, 8, AGL_GREEN_SIZE, 8, AGL_BLUE_SIZE, 8, AGL_ALPHA_SIZE, 8, AGL_DEPTH_SIZE, 24, AGL_DOUBLEBUFFER, AGL_NONE }; agl_fmt = aglChoosePixelFormat(0,0,agl_fmt_list); if (agl_fmt == 0) { fprintf(stderr,"failed to choose OpenGL pixel format\n"); abort(); } // The critical region object MPCreateCriticalRegion(&cr); // Install event handlers // EventTargetRef target = GetApplicationEventTarget(); EventTypeSpec eventTypes[] = { { kEventClassKeyboard, kEventRawKeyDown } }; InstallEventHandler(target,NewEventHandlerUPP(keyboard_handler), sizeof(eventTypes) / sizeof(EventTypeSpec),eventTypes, 0,0); // Create Windows for (int k = 0; k < tileNum; k++) { int tileX = (k % cfg.dimX) * cfg.tileRect[k].width; int tileY = (k / cfg.dimX) * cfg.tileRect[k].height; Rect wrect; wrect.left = tileX; // cfg.tileRect[k].x; wrect.top = tileY; // cfg.tileRect[k].y; wrect.right = wrect.left + cfg.tileRect[k].width; wrect.bottom = wrect.top + cfg.tileRect[k].height; //fprintf(stderr,"Create window %d at %i,%i,%i,%i\n",k, wrect.left,wrect.top,wrect.right,wrect.bottom); windows[k] = new Window(wrect, configStruct.fullScreenFlag); windows[k]->beginGL(); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); } winCreatFlag = true; } return 0; } // End of appleMultiContext::init()