PsychError SCREENCloseAll(void) { //all subfunctions should have these two lines. PsychPushHelp(useString, synopsisString, seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; PsychErrorExit(PsychCapNumInputArgs(0)); //The maximum number of inputs PsychErrorExit(PsychCapNumOutputArgs(0)); //The maximum number of outputs // Close all windows: ScreenCloseAllWindows(); return(PsychError_none); }
PsychError ScreenExitFunction(void) { //The timing array holds time values set by Screen internal diagnostics. It allocates memory with //malloc to hold the array of times. This call frees the memory prior to unloading Screen ClearTimingArray(); // Close all open onscreen windows and release their resources, // -> Perform exactly the same cleanup that Screen('CloseAll') would do. ScreenCloseAllWindows(); CloseWindowBank(); // Shutdown low-level display glue (Screens, displays, kernel-drivers et al.): PsychCleanupDisplayGlue(); // Cleanup internal data structures of SCREEN('FillPoly'); // This is defined in Common/Screen/SCREENFillPoly.c PsychCleanupSCREENFillPoly(); // Release our internal locale object for character <-> unicode conversion: PsychSetUnicodeTextConversionLocale(NULL); return(PsychError_none); }
PsychError ScreenExitFunction(void) { CGDirectDisplayID dpy, last_dpy; int i; //The timing array holds time values set by Screen internal diagnostics. It allocates memory with //malloc to hold the array of times. This call frees the memory prior to unloading Screen ClearTimingArray(); // Close all open onscreen windows and release their resources, // -> Perform exactly the same cleanup that Screen('CloseAll') would do. ScreenCloseAllWindows(); CloseWindowBank(); #if PSYCH_SYSTEM == PSYCH_LINUX // Linux specific hack. Close display connection(s) to X-Server(s). This is a bit unclean. last_dpy = NULL; // Go trough full screen list: for (i=0; i < PsychGetNumDisplays(); i++) { // Get display-ptr for this screen: PsychGetCGDisplayIDFromScreenNumber(&dpy, i); // Did we close this connection already (dpy==last_dpy)? if (dpy != last_dpy) { // Nope. Keep track of it... last_dpy=dpy; // ...and close display connection to X-Server: XCloseDisplay(dpy); } } // All connections should be closed now. We can't NULL-out the display list, but // Matlab will flush the Screen - Mexfile anyway... #endif return(PsychError_none); }
// Callback handler for Window manager: Handles some events LONG FAR PASCAL WndProc(HWND hWnd, unsigned uMsg, unsigned wParam, LONG lParam) { static PAINTSTRUCT ps; PsychWindowRecordType **windowRecordArray; int i, numWindows; // What event happened? switch(uMsg) { case WM_SYSCOMMAND: // System command received: We intercept system commands that would start // the screensaver or put the display into powersaving sleep-mode: switch(wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return(0); } break; case WM_LBUTTONDOWN: // Left mouse button depressed: mousebutton_l = TRUE; break; case WM_LBUTTONUP: // Left mouse button released: mousebutton_l = FALSE; break; case WM_MBUTTONDOWN: // Middle mouse button depressed: mousebutton_m = TRUE; break; case WM_MBUTTONUP: // Middle mouse button released: mousebutton_m = FALSE; break; case WM_RBUTTONDOWN: // Right mouse button depressed: mousebutton_r = TRUE; break; case WM_RBUTTONUP: // Right mouse button released: mousebutton_r = FALSE; break; case WM_PAINT: // Repaint event: This happens if a previously covered non-fullscreen window // got uncovered, so part of it needs to be redrawn. PTB's rendering model // doesn't have a concept of redrawing a stimulus. As this is mostly useful // for debugging, we just do a double doublebuffer swap in the hope that this // will restore the frontbuffer... BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); // Scan the list of windows to find onscreen window with handle hWnd: PsychCreateVolatileWindowRecordPointerList(&numWindows, &windowRecordArray); for(i = 0; i < numWindows; i++) { if (PsychIsOnscreenWindow(windowRecordArray[i]) && windowRecordArray[i]->targetSpecific.windowHandle == hWnd && windowRecordArray[i]->stereomode == 0) { // This is it! Initiate bufferswap twice: PsychOSFlipWindowBuffers(windowRecordArray[i]); PsychOSFlipWindowBuffers(windowRecordArray[i]); } } PsychDestroyVolatileWindowRecordPointerList(windowRecordArray); // Done. return 0; case WM_SIZE: // Window resize event: Only happens in debug-mode (non-fullscreen). // We resize the viewport accordingly and then trigger a repaint-op. glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); PostMessage(hWnd, WM_PAINT, 0, 0); // printf("\nPTB-INFO: Onscreen window resized to: %i x %i.\n", (int) LOWORD(lParam), (int) HIWORD(lParam)); return 0; case WM_CLOSE: // WM_CLOSE falls through to WM_CHAR and emulates an Abort-key press. // -> Manually closing an onscreen window does the same as pressing the Abort-key. wParam='@'; case WM_CHAR: // Character received. We only care about one key, the '@' key. // Pressing '@' will immediately close all onscreen windows, show // the cursor and such. It is the emergency stop key. if (wParam=='@') { // Emergency shutdown: printf("\nPTB-INFO: Master-Abort key '@' pressed by user.\n"); printf("PTB-INFO: Enforcing script abortion and restoring desktop by executing Screen('CloseAll') now!\n"); printf("PTB-INFO: Please ignore the false error message (INTERNAL PSYCHTOOLBOX ERROR) caused by this...\n"); ScreenCloseAllWindows(); return(0); } break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); }