Added isMinimized to linux
This commit is contained in:
parent
e96c1322eb
commit
f2f829483b
|
@ -47,20 +47,22 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "org_lwjgl_Display.h"
|
#include "org_lwjgl_Display.h"
|
||||||
|
|
||||||
|
|
||||||
Display * disp;
|
Display * disp;
|
||||||
int screen;
|
int screen;
|
||||||
int current_fullscreen;
|
|
||||||
int current_focused;
|
|
||||||
Window win;
|
Window win;
|
||||||
int win_width;
|
|
||||||
int win_height;
|
static bool current_fullscreen;
|
||||||
XF86VidModeModeInfo **avail_modes;
|
static bool current_focused;
|
||||||
XVisualInfo * vis_info;
|
static bool current_minimized;
|
||||||
int gl_loaded = 0;
|
static int win_width;
|
||||||
|
static int win_height;
|
||||||
|
static XF86VidModeModeInfo **avail_modes;
|
||||||
|
static XVisualInfo * vis_info;
|
||||||
|
static bool gl_loaded = false;
|
||||||
|
|
||||||
struct pixelformat {
|
struct pixelformat {
|
||||||
int bpp;
|
int bpp;
|
||||||
|
@ -188,32 +190,41 @@ void waitMapped(Display *disp, Window win) {
|
||||||
} while ((event.type != MapNotify) || (event.xmap.event != win));
|
} while ((event.type != MapNotify) || (event.xmap.event != win));
|
||||||
}
|
}
|
||||||
|
|
||||||
int isFocused(void) {
|
void handleMessages(void) {
|
||||||
XEvent event;
|
XEvent event;
|
||||||
while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask, &event)) {
|
while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask | StructureNotifyMask, &event)) {
|
||||||
if (event.type == EnterNotify)
|
switch (event.type) {
|
||||||
current_focused = 1;
|
case EnterNotify:
|
||||||
else if (event.type == LeaveNotify)
|
current_focused = true;
|
||||||
current_focused = 0;
|
break;
|
||||||
|
case LeaveNotify:
|
||||||
|
current_focused = false;
|
||||||
|
break;
|
||||||
|
case MapNotify:
|
||||||
|
current_minimized = false;
|
||||||
|
break;
|
||||||
|
case UnmapNotify:
|
||||||
|
current_minimized = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return current_focused;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadGL(Display *disp, int screen) {
|
bool loadGL(Display *disp, int screen) {
|
||||||
if (gl_loaded == 1)
|
if (gl_loaded == true)
|
||||||
return JNI_TRUE;
|
return true;
|
||||||
if (extgl_Open(disp, screen) != 0) {
|
if (extgl_Open(disp, screen) != 0) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Could not load gl libs\n");
|
printf("Could not load gl libs\n");
|
||||||
#endif
|
#endif
|
||||||
return JNI_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
gl_loaded = 1;
|
gl_loaded = true;
|
||||||
return JNI_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeGL(void) {
|
void closeGL(void) {
|
||||||
gl_loaded = 0;
|
gl_loaded = false;
|
||||||
extgl_Close();
|
extgl_Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +245,41 @@ int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeIn
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isFullscreen(void) {
|
||||||
|
return current_fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFocused(void) {
|
||||||
|
handleMessages();
|
||||||
|
return current_focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMinimized(void) {
|
||||||
|
handleMessages();
|
||||||
|
return current_minimized;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getWindowHeight(void) {
|
||||||
|
return win_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getWindowWidth(void) {
|
||||||
|
return win_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
XVisualInfo *getVisualInfo(void) {
|
||||||
|
return vis_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_lwjgl_Display
|
||||||
|
* Method: isMinimized
|
||||||
|
* Signature: ()Z
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized(JNIEnv *env, jclass clazz) {
|
||||||
|
return isMinimized() ? JNI_TRUE : JNI_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alpha_bits, jint depth_bits, jint stencil_bits, jboolean fullscreen, jstring title) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alpha_bits, jint depth_bits, jint stencil_bits, jboolean fullscreen, jstring title) {
|
||||||
Window root_win;
|
Window root_win;
|
||||||
XSetWindowAttributes attribs;
|
XSetWindowAttributes attribs;
|
||||||
|
@ -243,8 +289,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
|
||||||
|
|
||||||
win_width = width;
|
win_width = width;
|
||||||
win_height = height;
|
win_height = height;
|
||||||
current_fullscreen = fullscreen;
|
if (fullscreen == JNI_TRUE)
|
||||||
current_focused = 0;
|
current_fullscreen = true;
|
||||||
|
else
|
||||||
|
current_fullscreen = false;
|
||||||
|
current_minimized = false;
|
||||||
|
current_focused = false;
|
||||||
disp = XOpenDisplay(NULL);
|
disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -253,7 +303,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
screen = DefaultScreen(disp);
|
screen = DefaultScreen(disp);
|
||||||
if (loadGL(disp, screen) != JNI_TRUE) {
|
if (!loadGL(disp, screen)) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Could not load GL libs\n");
|
printf("Could not load GL libs\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -278,7 +328,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
|
||||||
|
|
||||||
cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone);
|
cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone);
|
||||||
attribs.colormap = cmap;
|
attribs.colormap = cmap;
|
||||||
attribs.event_mask = StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
|
attribs.event_mask = VisibilityChangeMask| StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
|
||||||
attribs.background_pixel = 0xFF000000;
|
attribs.background_pixel = 0xFF000000;
|
||||||
attribmask = CWColormap | CWBackPixel | CWEventMask;
|
attribmask = CWColormap | CWBackPixel | CWEventMask;
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
|
@ -359,7 +409,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (loadGL(disp, screen) != JNI_TRUE) {
|
if (!loadGL(disp, screen)) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Could not load GL\n");
|
printf("Could not load GL\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,24 +50,25 @@
|
||||||
#define KEYBOARD_SIZE 256
|
#define KEYBOARD_SIZE 256
|
||||||
#define KEY_EVENT_BACKLOG 20
|
#define KEY_EVENT_BACKLOG 20
|
||||||
|
|
||||||
unsigned char readBuffer[KEYBOARD_BUFFER_SIZE * 2];
|
static unsigned char readBuffer[KEYBOARD_BUFFER_SIZE * 2];
|
||||||
jfieldID fid_readBuffer;
|
static jfieldID fid_readBuffer;
|
||||||
unsigned char key_buf[KEYBOARD_SIZE];
|
static unsigned char key_buf[KEYBOARD_SIZE];
|
||||||
unsigned char key_map[KEYBOARD_SIZE];
|
static unsigned char key_map[KEYBOARD_SIZE];
|
||||||
|
|
||||||
XKeyEvent saved_key_events[KEY_EVENT_BACKLOG];
|
static XKeyEvent saved_key_events[KEY_EVENT_BACKLOG];
|
||||||
int list_start = 0;
|
static int list_start = 0;
|
||||||
int list_end = 0;
|
static int list_end = 0;
|
||||||
|
|
||||||
bool keyboard_grabbed;
|
static bool keyboard_grabbed;
|
||||||
bool buffer_enabled;
|
static bool buffer_enabled;
|
||||||
bool translation_enabled;
|
static bool translation_enabled;
|
||||||
|
|
||||||
extern Display *disp;
|
extern Display *disp;
|
||||||
extern Window win;
|
extern Window win;
|
||||||
extern int current_fullscreen;
|
|
||||||
|
|
||||||
extern int isFocused(void);
|
extern bool isFullscreen(void);
|
||||||
|
|
||||||
|
extern bool isFocused(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_input_Keyboard
|
* Class: org_lwjgl_input_Keyboard
|
||||||
|
@ -100,7 +101,7 @@ void ungrabKeyboard(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateKeyboardGrab(void) {
|
int updateKeyboardGrab(void) {
|
||||||
if (current_fullscreen) {
|
if (isFullscreen()) {
|
||||||
if (!keyboard_grabbed)
|
if (!keyboard_grabbed)
|
||||||
return grabKeyboard();
|
return grabKeyboard();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,28 +55,27 @@
|
||||||
extern Display *disp;
|
extern Display *disp;
|
||||||
extern Window win;
|
extern Window win;
|
||||||
extern int screen;
|
extern int screen;
|
||||||
extern int current_fullscreen;
|
extern bool isFullscreen(void);
|
||||||
extern int win_width;
|
extern bool isFocused(void);
|
||||||
extern int win_height;
|
extern int getWindowWidth(void);
|
||||||
|
extern int getWindowHeight(void);
|
||||||
|
|
||||||
bool pointer_grabbed;
|
static bool pointer_grabbed;
|
||||||
|
|
||||||
jfieldID fid_button;
|
static jfieldID fid_button;
|
||||||
jfieldID fid_dx;
|
static jfieldID fid_dx;
|
||||||
jfieldID fid_dy;
|
static jfieldID fid_dy;
|
||||||
jfieldID fid_dz;
|
static jfieldID fid_dz;
|
||||||
|
|
||||||
int last_x;
|
static int last_x;
|
||||||
int last_y;
|
static int last_y;
|
||||||
int last_z;
|
static int last_z;
|
||||||
int current_x;
|
static int current_x;
|
||||||
int current_y;
|
static int current_y;
|
||||||
int current_z;
|
static int current_z;
|
||||||
unsigned char buttons[NUM_BUTTONS];
|
static unsigned char buttons[NUM_BUTTONS];
|
||||||
|
|
||||||
Cursor blank_cursor;
|
static Cursor blank_cursor;
|
||||||
|
|
||||||
extern int isFocused(void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_input_Mouse
|
* Class: org_lwjgl_input_Mouse
|
||||||
|
@ -131,7 +130,7 @@ int blankCursor(void) {
|
||||||
int grabPointer(void) {
|
int grabPointer(void) {
|
||||||
int result;
|
int result;
|
||||||
int mask = EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
int mask = EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
||||||
if (current_fullscreen) {
|
if (isFullscreen()) {
|
||||||
result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime);
|
result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime);
|
||||||
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
|
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
|
||||||
XF86VidModeSetViewPort(disp, screen, 0, 0); // make sure we have a centered window
|
XF86VidModeSetViewPort(disp, screen, 0, 0); // make sure we have a centered window
|
||||||
|
@ -148,7 +147,7 @@ void ungrabPointer(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int updatePointerGrab(void) {
|
int updatePointerGrab(void) {
|
||||||
if (current_fullscreen) {
|
if (isFullscreen()) {
|
||||||
if (!pointer_grabbed)
|
if (!pointer_grabbed)
|
||||||
return grabPointer();
|
return grabPointer();
|
||||||
} else {
|
} else {
|
||||||
|
@ -281,9 +280,9 @@ void warpPointer(void) {
|
||||||
int i;
|
int i;
|
||||||
// Reset pointer to middle of screen if inside a certain inner border
|
// Reset pointer to middle of screen if inside a certain inner border
|
||||||
if (current_x < POINTER_WARP_BORDER || current_y < POINTER_WARP_BORDER ||
|
if (current_x < POINTER_WARP_BORDER || current_y < POINTER_WARP_BORDER ||
|
||||||
current_x > win_width - POINTER_WARP_BORDER || current_y > win_height - POINTER_WARP_BORDER) {
|
current_x > getWindowWidth() - POINTER_WARP_BORDER || current_y > getWindowHeight() - POINTER_WARP_BORDER) {
|
||||||
current_x = last_x = win_width/2;
|
current_x = last_x = getWindowWidth()/2;
|
||||||
current_y = last_y = win_height/2;
|
current_y = last_y = getWindowHeight()/2;
|
||||||
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
|
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
|
||||||
XEvent event;
|
XEvent event;
|
||||||
// Try to catch the warp pointer event
|
// Try to catch the warp pointer event
|
||||||
|
@ -325,7 +324,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll
|
||||||
last_z = current_z;
|
last_z = current_z;
|
||||||
jbooleanArray buttonsArray = (jbooleanArray) env->GetStaticObjectField(clazz, fid_button);
|
jbooleanArray buttonsArray = (jbooleanArray) env->GetStaticObjectField(clazz, fid_button);
|
||||||
env->SetBooleanArrayRegion(buttonsArray, 0, NUM_BUTTONS, buttons);
|
env->SetBooleanArrayRegion(buttonsArray, 0, NUM_BUTTONS, buttons);
|
||||||
if (current_fullscreen)
|
if (isFullscreen())
|
||||||
warpPointer();
|
warpPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
#include "org_lwjgl_opengl_BaseGL.h"
|
#include "org_lwjgl_opengl_BaseGL.h"
|
||||||
|
|
||||||
GLXContext context = NULL; // OpenGL rendering context
|
GLXContext context = NULL; // OpenGL rendering context
|
||||||
extern XVisualInfo * vis_info;
|
extern XVisualInfo * getVisualInfo(void);
|
||||||
extern Window win;
|
extern Window win;
|
||||||
extern Display * disp;
|
extern Display * disp;
|
||||||
|
|
||||||
|
@ -64,13 +64,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
|
||||||
(JNIEnv * env, jobject obj)
|
(JNIEnv * env, jobject obj)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!vis_info) {
|
if (!getVisualInfo()) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("No visual info\n");
|
printf("No visual info\n");
|
||||||
#endif
|
#endif
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
context = glXCreateContext(disp, vis_info, NULL, True);
|
context = glXCreateContext(disp, getVisualInfo(), NULL, True);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Could not create context\n");
|
printf("Could not create context\n");
|
||||||
|
|
Loading…
Reference in New Issue