Linux: Removed current_* mode cache from display.c
This commit is contained in:
parent
f548d581ce
commit
7469d59dbf
|
@ -85,6 +85,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
/** Saved mode to restore with */
|
/** Saved mode to restore with */
|
||||||
private static DisplayMode saved_mode;
|
private static DisplayMode saved_mode;
|
||||||
|
private static DisplayMode current_mode;
|
||||||
|
|
||||||
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
|
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
|
@ -249,7 +250,8 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
nSwitchDisplayMode(current_displaymode_extension, mode);
|
current_mode = mode;
|
||||||
|
nSwitchDisplayMode(current_displaymode_extension, current_mode);
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
|
@ -329,6 +331,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
if (modes == null || modes.length == 0)
|
if (modes == null || modes.length == 0)
|
||||||
throw new LWJGLException("No modes available");
|
throw new LWJGLException("No modes available");
|
||||||
saved_mode = modes[0];
|
saved_mode = modes[0];
|
||||||
|
current_mode = saved_mode;
|
||||||
saved_gamma = getCurrentGammaRamp();
|
saved_gamma = getCurrentGammaRamp();
|
||||||
current_gamma = saved_gamma;
|
current_gamma = saved_gamma;
|
||||||
return saved_mode;
|
return saved_mode;
|
||||||
|
@ -386,13 +389,13 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void update() {
|
public void update() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode);
|
nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
LWJGLUtil.log("Caught exception while processing messages: " + e);
|
LWJGLUtil.log("Caught exception while processing messages: " + e);
|
||||||
}
|
}
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode) throws LWJGLException;
|
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode, DisplayMode current_mode) throws LWJGLException;
|
||||||
|
|
||||||
public void reshape(int x, int y, int width, int height) {
|
public void reshape(int x, int y, int width, int height) {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
|
|
|
@ -64,10 +64,6 @@ typedef struct {
|
||||||
} mode_data;
|
} mode_data;
|
||||||
} mode_info;
|
} mode_info;
|
||||||
|
|
||||||
static int current_width;
|
|
||||||
static int current_height;
|
|
||||||
static int current_freq;
|
|
||||||
|
|
||||||
static bool getXF86VidModeVersion(JNIEnv *env, Display *disp, int *major, int *minor) {
|
static bool getXF86VidModeVersion(JNIEnv *env, Display *disp, int *major, int *minor) {
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
|
|
||||||
|
@ -226,7 +222,7 @@ static bool setXrandrMode(Display *disp, int screen, mode_info *mode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int width, int height, int freq, bool temporary) {
|
static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int width, int height, int freq) {
|
||||||
int num_modes, i;
|
int num_modes, i;
|
||||||
mode_info *avail_modes = getDisplayModes(disp, screen, extension, &num_modes);
|
mode_info *avail_modes = getDisplayModes(disp, screen, extension, &num_modes);
|
||||||
if (avail_modes == NULL) {
|
if (avail_modes == NULL) {
|
||||||
|
@ -255,11 +251,6 @@ static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result = true;
|
result = true;
|
||||||
if (!temporary) {
|
|
||||||
current_width = width;
|
|
||||||
current_height = height;
|
|
||||||
current_freq = freq;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +314,7 @@ static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
|
static void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer) {
|
||||||
Display * disp = XOpenDisplay(NULL);
|
Display * disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
throwException(env, "Could not open display");
|
throwException(env, "Could not open display");
|
||||||
|
@ -333,20 +324,7 @@ static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject saved_gamma_ramp) {
|
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) {
|
||||||
Display *disp = XOpenDisplay(NULL);
|
|
||||||
if (disp == NULL) {
|
|
||||||
printfDebugJava(env, "Could not open display");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!setMode(env, disp, screen, extension, current_width, current_height, current_freq, false))
|
|
||||||
printfDebugJava(env, "Could not restore mode");
|
|
||||||
XCloseDisplay(disp);
|
|
||||||
// Don't propagate error to caller
|
|
||||||
setGammaRamp(env, saved_gamma_ramp, screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode, bool temporary) {
|
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
throwException(env, "mode must be non-null");
|
throwException(env, "mode must be non-null");
|
||||||
return false;
|
return false;
|
||||||
|
@ -363,7 +341,7 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
|
||||||
throwException(env, "Could not open display");
|
throwException(env, "Could not open display");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!setMode(env, disp, screen, extension, width, height, freq, temporary)) {
|
if (!setMode(env, disp, screen, extension, width, height, freq)) {
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
throwException(env, "Could not switch mode.");
|
throwException(env, "Could not switch mode.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -372,10 +350,16 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary) {
|
void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject current_gamma_ramp, jobject current_mode) {
|
||||||
if (!switchDisplayMode(env, screen, extension, saved_mode, temporary))
|
switchDisplayMode(env, screen, extension, current_mode);
|
||||||
|
// Don't propagate error to caller
|
||||||
|
setGammaRamp(env, screen, current_gamma_ramp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject saved_gamma_ramp, jobject saved_mode) {
|
||||||
|
if (!switchDisplayMode(env, screen, extension, saved_mode))
|
||||||
return;
|
return;
|
||||||
setGammaRamp(env, gamma_ramp, screen);
|
setGammaRamp(env, screen, saved_gamma_ramp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
||||||
|
@ -406,11 +390,11 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableD
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject mode) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject mode) {
|
||||||
switchDisplayMode(env, getCurrentScreen(), extension, mode, false);
|
switchDisplayMode(env, getCurrentScreen(), extension, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
|
||||||
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode, false);
|
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
|
||||||
|
@ -418,6 +402,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JN
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
|
||||||
setGammaRamp(env, gamma_buffer, getCurrentScreen());
|
setGammaRamp(env, getCurrentScreen(), gamma_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
|
|
||||||
extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary);
|
extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
|
||||||
extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp);
|
extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -190,19 +190,19 @@ static bool releaseInput(JNIEnv *env, jint extension, jint window_mode, jobject
|
||||||
updateInputGrab(window_mode);
|
updateInputGrab(window_mode);
|
||||||
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
||||||
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
||||||
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode, true);
|
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void acquireInput(JNIEnv *env, jint extension, jint window_mode, jobject gamma_ramp) {
|
static void acquireInput(JNIEnv *env, jint extension, jint window_mode, jobject gamma_ramp, jobject mode) {
|
||||||
if (isLegacyFullscreen(window_mode) || !input_released)
|
if (isLegacyFullscreen(window_mode) || !input_released)
|
||||||
return;
|
return;
|
||||||
input_released = false;
|
input_released = false;
|
||||||
setRepeatMode(env, AutoRepeatModeOff);
|
setRepeatMode(env, AutoRepeatModeOff);
|
||||||
updateInputGrab(window_mode);
|
updateInputGrab(window_mode);
|
||||||
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
||||||
temporaryRestoreMode(env, getCurrentScreen(), extension, gamma_ramp);
|
temporaryRestoreMode(env, getCurrentScreen(), extension, gamma_ramp, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,12 +229,12 @@ void setGrab(jint window_mode, bool new_grab) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode) {
|
static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) {
|
||||||
Window win;
|
Window win;
|
||||||
int revert_mode;
|
int revert_mode;
|
||||||
XGetInputFocus(getDisplay(), &win, &revert_mode);
|
XGetInputFocus(getDisplay(), &win, &revert_mode);
|
||||||
if (win == current_win) {
|
if (win == current_win) {
|
||||||
acquireInput(env, extension, window_mode, current_gamma);
|
acquireInput(env, extension, window_mode, current_gamma, current_mode);
|
||||||
focused = true;
|
focused = true;
|
||||||
} else {
|
} else {
|
||||||
releaseInput(env, extension, window_mode, saved_gamma, saved_mode);
|
releaseInput(env, extension, window_mode, saved_gamma, saved_mode);
|
||||||
|
@ -242,7 +242,7 @@ static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject sa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode) {
|
void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) {
|
||||||
XEvent event;
|
XEvent event;
|
||||||
/* Window win;
|
/* Window win;
|
||||||
int revert_mode;*/
|
int revert_mode;*/
|
||||||
|
@ -293,7 +293,7 @@ void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkInput(env, extension, window_mode, saved_gamma, current_gamma, saved_mode);
|
checkInput(env, extension, window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWindowTitle(const char *title) {
|
static void setWindowTitle(const char *title) {
|
||||||
|
@ -446,9 +446,9 @@ Window getCurrentWindow(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate
|
||||||
(JNIEnv *env, jclass clazz, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode)
|
(JNIEnv *env, jclass clazz, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode)
|
||||||
{
|
{
|
||||||
handleMessages(env, extension, window_mode, saved_gamma, current_gamma, saved_mode);
|
handleMessages(env, extension, window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) {
|
||||||
|
|
Loading…
Reference in New Issue