From 3c5a231ec7e3e645195a280a5870ceca5dafa6c7 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 22 Sep 2004 18:21:28 +0000 Subject: [PATCH] Win32: reset/restore display mode when activated/deactivated --- src/native/common/org_lwjgl_input_Keyboard.h | 4 +- src/native/common/org_lwjgl_input_Mouse.h | 7 +- src/native/win32/display.cpp | 71 +++++++------------ src/native/win32/display.h | 1 + src/native/win32/org_lwjgl_opengl_Display.cpp | 3 + 5 files changed, 38 insertions(+), 48 deletions(-) diff --git a/src/native/common/org_lwjgl_input_Keyboard.h b/src/native/common/org_lwjgl_input_Keyboard.h index ecc63273..6bd4079d 100644 --- a/src/native/common/org_lwjgl_input_Keyboard.h +++ b/src/native/common/org_lwjgl_input_Keyboard.h @@ -265,6 +265,8 @@ extern "C" { #define org_lwjgl_input_Keyboard_STATE_UNKNOWN 2L #undef org_lwjgl_input_Keyboard_BUFFER_SIZE #define org_lwjgl_input_Keyboard_BUFFER_SIZE 50L +#undef org_lwjgl_input_Keyboard_EVENT_SIZE +#define org_lwjgl_input_Keyboard_EVENT_SIZE 3L /* Inaccessible static: keyName */ /* Inaccessible static: keyMap */ /* Inaccessible static: counter */ @@ -305,7 +307,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll /* * Class: org_lwjgl_input_Keyboard * Method: nRead - * Signature: (Ljava/nio/ByteBuffer;I)I + * Signature: (Ljava/nio/IntBuffer;I)I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead (JNIEnv *, jclass, jobject, jint); diff --git a/src/native/common/org_lwjgl_input_Mouse.h b/src/native/common/org_lwjgl_input_Mouse.h index 26a9636e..c6c604bd 100644 --- a/src/native/common/org_lwjgl_input_Mouse.h +++ b/src/native/common/org_lwjgl_input_Mouse.h @@ -39,8 +39,13 @@ extern "C" { /* Inaccessible static: readBuffer */ /* Inaccessible static: eventButton */ /* Inaccessible static: eventState */ +/* Inaccessible static: event_dx */ +/* Inaccessible static: event_dy */ +/* Inaccessible static: event_dwheel */ #undef org_lwjgl_input_Mouse_BUFFER_SIZE #define org_lwjgl_input_Mouse_BUFFER_SIZE 50L +#undef org_lwjgl_input_Mouse_EVENT_SIZE +#define org_lwjgl_input_Mouse_EVENT_SIZE 5L /* Inaccessible static: isGrabbed */ /* Inaccessible static: trackingEnabled */ /* @@ -126,7 +131,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer /* * Class: org_lwjgl_input_Mouse * Method: nRead - * Signature: (Ljava/nio/ByteBuffer;I)I + * Signature: (Ljava/nio/IntBuffer;I)I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead (JNIEnv *, jclass, jobject, jint); diff --git a/src/native/win32/display.cpp b/src/native/win32/display.cpp index da2c13b5..2e3b058b 100644 --- a/src/native/win32/display.cpp +++ b/src/native/win32/display.cpp @@ -232,48 +232,6 @@ void switchDisplayMode(JNIEnv * env, jobject mode) modeSet = true; } -/* - * Temporarily reset display settings. This is called when the window is minimized. - */ -/*static void tempResetDisplayMode() { - // Return device gamma to normal - HDC screenDC = GetDC(NULL); - if (!SetDeviceGammaRamp(screenDC, originalGamma)) { - printfDebug("Could not reset device gamma\n"); - } - ReleaseDC(NULL, screenDC); - - if (modeSet) { - printfDebug("Attempting to temporarily reset the display mode\n"); - modeSet = false; - // Under Win32, all we have to do is: - ChangeDisplaySettings(NULL, 0); - } -} -*/ -/* - * Put display settings back to what they were when the window is maximized. - */ -/*static void tempRestoreDisplayMode() { - // Restore gamma - HDC screenDC = GetDC(NULL); - if (!SetDeviceGammaRamp(screenDC, currentGamma)) { - printfDebug("Could not restore device gamma\n"); - } - ReleaseDC(NULL, screenDC); - - if (!modeSet) { - printfDebug("Attempting to restore the display mode\n"); - modeSet = true; - LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN); - - if (cdsret != DISP_CHANGE_SUCCESSFUL) { - printfDebug("Failed to restore display mode\n"); - } - } -} -*/ - int getGammaRampLength(void) { return 256; @@ -328,9 +286,7 @@ jobject initDisplay(JNIEnv * env) return newMode; } -void resetDisplayMode(JNIEnv * env) -{ - +void resetDisplayMode(JNIEnv * env) { // Return device gamma to normal HDC screenDC = GetDC(NULL); if (!SetDeviceGammaRamp(screenDC, originalGamma)) { @@ -344,7 +300,30 @@ void resetDisplayMode(JNIEnv * env) ChangeDisplaySettings(NULL, 0); // And we'll call init() again to put the correct mode back in Display - initDisplay(env); + if (env != NULL) + initDisplay(env); + } +} + +/* + * Put display settings back to what they were when the window is maximized. + */ +void restoreDisplayMode(void) { + // Restore gamma + HDC screenDC = GetDC(NULL); + if (!SetDeviceGammaRamp(screenDC, currentGamma)) { + printfDebug("Could not restore device gamma\n"); + } + ReleaseDC(NULL, screenDC); + + if (!modeSet) { + printfDebug("Attempting to restore the display mode\n"); + modeSet = true; + LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN); + + if (cdsret != DISP_CHANGE_SUCCESSFUL) { + printfDebug("Failed to restore display mode\n"); + } } } diff --git a/src/native/win32/display.h b/src/native/win32/display.h index bfcaf446..691d61a1 100644 --- a/src/native/win32/display.h +++ b/src/native/win32/display.h @@ -47,6 +47,7 @@ extern jobjectArray getAvailableDisplayModes(JNIEnv *env); extern void switchDisplayMode(JNIEnv * env, jobject mode); extern void resetDisplayMode(JNIEnv * env); +extern void restoreDisplayMode(void); extern int getGammaRampLength(void); extern void setGammaRamp(JNIEnv * env, jobject gammaRampBuffer); extern jobject initDisplay(JNIEnv * env); diff --git a/src/native/win32/org_lwjgl_opengl_Display.cpp b/src/native/win32/org_lwjgl_opengl_Display.cpp index e9cf7fbf..e728b613 100644 --- a/src/native/win32/org_lwjgl_opengl_Display.cpp +++ b/src/native/win32/org_lwjgl_opengl_Display.cpp @@ -284,10 +284,13 @@ void closeWindow(HWND hwnd, HDC hdc) static void appActivate(bool active) { if (active) { + if (isFullScreen) + restoreDisplayMode(); SetForegroundWindow(display_hwnd); ShowWindow(display_hwnd, SW_RESTORE); } else if (isFullScreen) { ShowWindow(display_hwnd, SW_MINIMIZE); + resetDisplayMode(NULL); } }