Added isMinimized to linux

This commit is contained in:
Elias Naur 2003-02-08 19:55:07 +00:00
parent e96c1322eb
commit f2f829483b
4 changed files with 117 additions and 67 deletions

View File

@ -47,20 +47,22 @@
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <jni.h>
#include "org_lwjgl_Display.h"
Display * disp;
int screen;
int current_fullscreen;
int current_focused;
Window win;
int win_width;
int win_height;
XF86VidModeModeInfo **avail_modes;
XVisualInfo * vis_info;
int gl_loaded = 0;
static bool current_fullscreen;
static bool current_focused;
static bool current_minimized;
static int win_width;
static int win_height;
static XF86VidModeModeInfo **avail_modes;
static XVisualInfo * vis_info;
static bool gl_loaded = false;
struct pixelformat {
int bpp;
@ -188,32 +190,41 @@ void waitMapped(Display *disp, Window win) {
} while ((event.type != MapNotify) || (event.xmap.event != win));
}
int isFocused(void) {
void handleMessages(void) {
XEvent event;
while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask, &event)) {
if (event.type == EnterNotify)
current_focused = 1;
else if (event.type == LeaveNotify)
current_focused = 0;
while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask | StructureNotifyMask, &event)) {
switch (event.type) {
case EnterNotify:
current_focused = true;
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) {
if (gl_loaded == 1)
return JNI_TRUE;
bool loadGL(Display *disp, int screen) {
if (gl_loaded == true)
return true;
if (extgl_Open(disp, screen) != 0) {
#ifdef _DEBUG
printf("Could not load gl libs\n");
#endif
return JNI_FALSE;
return false;
}
gl_loaded = 1;
return JNI_TRUE;
gl_loaded = true;
return true;
}
void closeGL(void) {
gl_loaded = 0;
gl_loaded = false;
extgl_Close();
}
@ -234,6 +245,41 @@ int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeIn
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) {
Window root_win;
XSetWindowAttributes attribs;
@ -243,8 +289,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
win_width = width;
win_height = height;
current_fullscreen = fullscreen;
current_focused = 0;
if (fullscreen == JNI_TRUE)
current_fullscreen = true;
else
current_fullscreen = false;
current_minimized = false;
current_focused = false;
disp = XOpenDisplay(NULL);
if (disp == NULL) {
#ifdef _DEBUG
@ -253,7 +303,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
return JNI_FALSE;
}
screen = DefaultScreen(disp);
if (loadGL(disp, screen) != JNI_TRUE) {
if (!loadGL(disp, screen)) {
#ifdef _DEBUG
printf("Could not load GL libs\n");
#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);
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;
attribmask = CWColormap | CWBackPixel | CWEventMask;
if (fullscreen) {
@ -359,7 +409,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes
XCloseDisplay(disp);
return NULL;
}
if (loadGL(disp, screen) != JNI_TRUE) {
if (!loadGL(disp, screen)) {
#ifdef _DEBUG
printf("Could not load GL\n");
#endif

View File

@ -50,24 +50,25 @@
#define KEYBOARD_SIZE 256
#define KEY_EVENT_BACKLOG 20
unsigned char readBuffer[KEYBOARD_BUFFER_SIZE * 2];
jfieldID fid_readBuffer;
unsigned char key_buf[KEYBOARD_SIZE];
unsigned char key_map[KEYBOARD_SIZE];
static unsigned char readBuffer[KEYBOARD_BUFFER_SIZE * 2];
static jfieldID fid_readBuffer;
static unsigned char key_buf[KEYBOARD_SIZE];
static unsigned char key_map[KEYBOARD_SIZE];
XKeyEvent saved_key_events[KEY_EVENT_BACKLOG];
int list_start = 0;
int list_end = 0;
static XKeyEvent saved_key_events[KEY_EVENT_BACKLOG];
static int list_start = 0;
static int list_end = 0;
bool keyboard_grabbed;
bool buffer_enabled;
bool translation_enabled;
static bool keyboard_grabbed;
static bool buffer_enabled;
static bool translation_enabled;
extern Display *disp;
extern Window win;
extern int current_fullscreen;
extern int isFocused(void);
extern bool isFullscreen(void);
extern bool isFocused(void);
/*
* Class: org_lwjgl_input_Keyboard
@ -100,7 +101,7 @@ void ungrabKeyboard(void) {
}
int updateKeyboardGrab(void) {
if (current_fullscreen) {
if (isFullscreen()) {
if (!keyboard_grabbed)
return grabKeyboard();
} else {

View File

@ -55,28 +55,27 @@
extern Display *disp;
extern Window win;
extern int screen;
extern int current_fullscreen;
extern int win_width;
extern int win_height;
extern bool isFullscreen(void);
extern bool isFocused(void);
extern int getWindowWidth(void);
extern int getWindowHeight(void);
bool pointer_grabbed;
static bool pointer_grabbed;
jfieldID fid_button;
jfieldID fid_dx;
jfieldID fid_dy;
jfieldID fid_dz;
static jfieldID fid_button;
static jfieldID fid_dx;
static jfieldID fid_dy;
static jfieldID fid_dz;
int last_x;
int last_y;
int last_z;
int current_x;
int current_y;
int current_z;
unsigned char buttons[NUM_BUTTONS];
static int last_x;
static int last_y;
static int last_z;
static int current_x;
static int current_y;
static int current_z;
static unsigned char buttons[NUM_BUTTONS];
Cursor blank_cursor;
extern int isFocused(void);
static Cursor blank_cursor;
/*
* Class: org_lwjgl_input_Mouse
@ -131,7 +130,7 @@ int blankCursor(void) {
int grabPointer(void) {
int result;
int mask = EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
if (current_fullscreen) {
if (isFullscreen()) {
result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime);
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
XF86VidModeSetViewPort(disp, screen, 0, 0); // make sure we have a centered window
@ -148,7 +147,7 @@ void ungrabPointer(void) {
}
int updatePointerGrab(void) {
if (current_fullscreen) {
if (isFullscreen()) {
if (!pointer_grabbed)
return grabPointer();
} else {
@ -281,9 +280,9 @@ void warpPointer(void) {
int i;
// Reset pointer to middle of screen if inside a certain inner 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 = last_x = win_width/2;
current_y = last_y = win_height/2;
current_x > getWindowWidth() - POINTER_WARP_BORDER || current_y > getWindowHeight() - POINTER_WARP_BORDER) {
current_x = last_x = getWindowWidth()/2;
current_y = last_y = getWindowHeight()/2;
XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
XEvent 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;
jbooleanArray buttonsArray = (jbooleanArray) env->GetStaticObjectField(clazz, fid_button);
env->SetBooleanArrayRegion(buttonsArray, 0, NUM_BUTTONS, buttons);
if (current_fullscreen)
if (isFullscreen())
warpPointer();
}

View File

@ -43,7 +43,7 @@
#include "org_lwjgl_opengl_BaseGL.h"
GLXContext context = NULL; // OpenGL rendering context
extern XVisualInfo * vis_info;
extern XVisualInfo * getVisualInfo(void);
extern Window win;
extern Display * disp;
@ -64,13 +64,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
(JNIEnv * env, jobject obj)
{
if (!vis_info) {
if (!getVisualInfo()) {
#ifdef _DEBUG
printf("No visual info\n");
#endif
return JNI_FALSE;
}
context = glXCreateContext(disp, vis_info, NULL, True);
context = glXCreateContext(disp, getVisualInfo(), NULL, True);
if (!context) {
#ifdef _DEBUG
printf("Could not create context\n");