2004-11-02 07:49:41 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Linux specific display functions.
|
|
|
|
*
|
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <jni.h>
|
2005-01-11 10:22:12 -05:00
|
|
|
#include <jawt.h>
|
2004-11-02 07:49:41 -05:00
|
|
|
#include "common_tools.h"
|
|
|
|
#include "extgl.h"
|
|
|
|
#include "extgl_glx.h"
|
|
|
|
#include "Window.h"
|
2005-02-20 06:24:22 -05:00
|
|
|
#include "context.h"
|
2004-11-02 07:49:41 -05:00
|
|
|
#include "display.h"
|
|
|
|
#include "org_lwjgl_opengl_LinuxDisplay.h"
|
2005-02-20 06:24:22 -05:00
|
|
|
#include "org_lwjgl_opengl_LinuxDisplayPeerInfo.h"
|
2004-11-02 07:49:41 -05:00
|
|
|
|
|
|
|
#define ERR_MSG_SIZE 1024
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long functions;
|
|
|
|
unsigned long decorations;
|
|
|
|
long input_mode;
|
|
|
|
unsigned long status;
|
|
|
|
} MotifWmHints;
|
|
|
|
|
|
|
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
|
|
|
|
|
|
|
typedef enum {FULLSCREEN_LEGACY, FULLSCREEN_NETWM, WINDOWED} window_mode;
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
static GLXWindow glx_window = None;
|
2004-11-02 07:49:41 -05:00
|
|
|
|
|
|
|
static Atom delete_atom;
|
|
|
|
static Colormap cmap;
|
|
|
|
static Window current_win;
|
|
|
|
static window_mode current_window_mode;
|
|
|
|
static int current_height;
|
|
|
|
static int current_width;
|
2005-07-06 15:46:35 -04:00
|
|
|
static int current_depth;
|
|
|
|
|
|
|
|
static Visual *current_visual;
|
2004-11-02 07:49:41 -05:00
|
|
|
|
|
|
|
static bool input_released;
|
|
|
|
|
|
|
|
static bool dirty;
|
|
|
|
static bool vsync_enabled;
|
|
|
|
static bool minimized;
|
|
|
|
static bool focused;
|
|
|
|
static bool closerequested;
|
|
|
|
static bool grab;
|
|
|
|
|
|
|
|
static int current_screen;
|
|
|
|
static Display *display_connection = NULL;
|
|
|
|
static bool async_x_error;
|
|
|
|
static char error_message[ERR_MSG_SIZE];
|
|
|
|
static Atom warp_atom;
|
|
|
|
|
|
|
|
int getCurrentScreen(void) {
|
|
|
|
return current_screen;
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
bool checkXError(JNIEnv *env, Display *disp) {
|
|
|
|
XSync(disp, False);
|
2004-11-02 07:49:41 -05:00
|
|
|
if (async_x_error) {
|
|
|
|
async_x_error = false;
|
|
|
|
if (env != NULL)
|
|
|
|
throwException(env, error_message);
|
|
|
|
else
|
2005-01-06 09:03:48 -05:00
|
|
|
printfDebug(error_message);
|
2004-11-02 07:49:41 -05:00
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int errorHandler(Display *disp, XErrorEvent *error) {
|
|
|
|
char err_msg_buffer[ERR_MSG_SIZE];
|
|
|
|
XGetErrorText(disp, error->error_code, err_msg_buffer, ERR_MSG_SIZE);
|
|
|
|
err_msg_buffer[ERR_MSG_SIZE - 1] = '\0';
|
|
|
|
snprintf(error_message, ERR_MSG_SIZE, "X Error - serial: %d, error_code: %s, request_code: %d, minor_code: %d", (int)error->serial, err_msg_buffer, (int)error->request_code, (int)error->minor_code);
|
|
|
|
error_message[ERR_MSG_SIZE - 1] = '\0';
|
|
|
|
async_x_error = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Display *getDisplay(void) {
|
|
|
|
return display_connection;
|
|
|
|
}
|
|
|
|
|
2005-03-29 06:31:22 -05:00
|
|
|
static void openDisplay(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
async_x_error = false;
|
2005-03-29 06:31:22 -05:00
|
|
|
XSetErrorHandler(errorHandler);
|
|
|
|
display_connection = XOpenDisplay(NULL);
|
|
|
|
if (display_connection == NULL) {
|
|
|
|
throwException(env, "Could not open X display connection");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current_screen = XDefaultScreen(getDisplay());
|
|
|
|
warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Atom getWarpAtom(void) {
|
|
|
|
return warp_atom;
|
|
|
|
}
|
|
|
|
|
2005-03-29 06:31:22 -05:00
|
|
|
static void closeDisplay(void) {
|
|
|
|
XCloseDisplay(display_connection);
|
|
|
|
display_connection = NULL;
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void waitMapped(Window win) {
|
|
|
|
XEvent event;
|
|
|
|
do {
|
|
|
|
XMaskEvent(getDisplay(), StructureNotifyMask, &event);
|
|
|
|
} while ((event.type != MapNotify) || (event.xmap.event != win));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void updateInputGrab(void) {
|
|
|
|
updatePointerGrab();
|
|
|
|
updateKeyboardGrab();
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:18:18 -05:00
|
|
|
static void setRepeatMode(JNIEnv *env, int mode) {
|
2004-11-02 07:49:41 -05:00
|
|
|
XKeyboardControl repeat_mode;
|
|
|
|
repeat_mode.auto_repeat_mode = mode;
|
|
|
|
Display *disp = XOpenDisplay(NULL);
|
2005-06-28 11:19:32 -04:00
|
|
|
if (disp == NULL && env != NULL) {
|
2004-12-11 15:18:18 -05:00
|
|
|
printfDebugJava(env, "Could not open display to set repeat mode");
|
2004-11-02 07:49:41 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode);
|
|
|
|
XCloseDisplay(disp);
|
|
|
|
}
|
|
|
|
|
2005-06-28 11:19:32 -04:00
|
|
|
void __attribute__ ((destructor)) my_fini(void) {
|
|
|
|
setRepeatMode(NULL, AutoRepeatModeDefault);
|
|
|
|
}
|
|
|
|
|
2004-11-02 07:49:41 -05:00
|
|
|
static void setDecorations(int dec) {
|
|
|
|
Atom motif_hints_atom = XInternAtom(getDisplay(), "_MOTIF_WM_HINTS", False);
|
|
|
|
MotifWmHints motif_hints;
|
|
|
|
motif_hints.flags = MWM_HINTS_DECORATIONS;
|
|
|
|
motif_hints.decorations = dec;
|
|
|
|
XChangeProperty (getDisplay(), getCurrentWindow(), motif_hints_atom, motif_hints_atom, 32, PropModeReplace, (unsigned char *)&motif_hints, sizeof(MotifWmHints)/sizeof(long));
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:09:04 -05:00
|
|
|
static bool releaseInput(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
if (isLegacyFullscreen() || input_released)
|
|
|
|
return false;
|
|
|
|
input_released = true;
|
2004-12-11 15:18:18 -05:00
|
|
|
setRepeatMode(env, AutoRepeatModeDefault);
|
2004-11-02 07:49:41 -05:00
|
|
|
updateInputGrab();
|
|
|
|
if (current_window_mode == FULLSCREEN_NETWM) {
|
|
|
|
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
2004-12-11 15:09:04 -05:00
|
|
|
resetDisplayMode(env, getCurrentScreen(), true);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:09:04 -05:00
|
|
|
static void acquireInput(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
if (isLegacyFullscreen() || !input_released)
|
|
|
|
return;
|
|
|
|
input_released = false;
|
2004-12-11 15:18:18 -05:00
|
|
|
setRepeatMode(env, AutoRepeatModeOff);
|
2004-11-02 07:49:41 -05:00
|
|
|
updateInputGrab();
|
|
|
|
if (current_window_mode == FULLSCREEN_NETWM) {
|
2004-12-11 15:09:04 -05:00
|
|
|
temporaryRestoreMode(env, getCurrentScreen());
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-10 14:49:11 -05:00
|
|
|
bool isFullscreen(void) {
|
|
|
|
return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM;
|
|
|
|
}
|
|
|
|
|
2004-11-02 07:49:41 -05:00
|
|
|
bool isLegacyFullscreen(void) {
|
|
|
|
return current_window_mode == FULLSCREEN_LEGACY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldGrab(void) {
|
|
|
|
return !input_released && grab;
|
|
|
|
}
|
|
|
|
|
2004-12-11 06:21:01 -05:00
|
|
|
bool isGrabbed(void) {
|
|
|
|
return grab;
|
|
|
|
}
|
|
|
|
|
2004-11-02 07:49:41 -05:00
|
|
|
void setGrab(bool new_grab) {
|
|
|
|
if (new_grab != grab) {
|
|
|
|
grab = new_grab;
|
|
|
|
updateInputGrab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:09:04 -05:00
|
|
|
static void checkInput(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
Window win;
|
|
|
|
int revert_mode;
|
|
|
|
XGetInputFocus(getDisplay(), &win, &revert_mode);
|
|
|
|
if (win == current_win) {
|
2004-12-11 15:09:04 -05:00
|
|
|
acquireInput(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
focused = true;
|
2004-11-06 04:41:02 -05:00
|
|
|
} else {
|
2004-12-11 15:09:04 -05:00
|
|
|
releaseInput(env);
|
2004-11-06 04:41:02 -05:00
|
|
|
focused = false;
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:09:04 -05:00
|
|
|
void handleMessages(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
XEvent event;
|
2004-11-06 04:41:02 -05:00
|
|
|
/* Window win;
|
|
|
|
int revert_mode;*/
|
2004-11-02 07:49:41 -05:00
|
|
|
while (XPending(getDisplay()) > 0) {
|
|
|
|
XNextEvent(getDisplay(), &event);
|
|
|
|
if (XFilterEvent(&event, None) == True)
|
|
|
|
continue;
|
|
|
|
switch (event.type) {
|
|
|
|
case ClientMessage:
|
|
|
|
if (event.xclient.message_type == warp_atom) {
|
|
|
|
handleWarpEvent(&(event.xclient));
|
|
|
|
} else if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom))
|
|
|
|
closerequested = true;
|
|
|
|
break;
|
2004-11-06 04:41:02 -05:00
|
|
|
/* case FocusOut:
|
2004-11-02 07:49:41 -05:00
|
|
|
XGetInputFocus(getDisplay(), &win, &revert_mode);
|
|
|
|
if (win != current_win) {
|
|
|
|
releaseInput();
|
|
|
|
focused = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FocusIn:
|
|
|
|
checkInput();
|
2004-11-06 04:41:02 -05:00
|
|
|
break;*/
|
2004-11-02 07:49:41 -05:00
|
|
|
case MapNotify:
|
|
|
|
dirty = true;
|
|
|
|
minimized = false;
|
|
|
|
break;
|
|
|
|
case UnmapNotify:
|
|
|
|
dirty = true;
|
|
|
|
minimized = true;
|
|
|
|
break;
|
|
|
|
case Expose:
|
|
|
|
dirty = true;
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
handleButtonPress(&(event.xbutton));
|
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
|
|
|
handleButtonRelease(&(event.xbutton));
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
handlePointerMotion(&(event.xmotion));
|
|
|
|
break;
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
handleKeyEvent(&(event.xkey));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-11 15:09:04 -05:00
|
|
|
checkInput(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setWindowTitle(const char *title) {
|
|
|
|
XStoreName(getDisplay(), current_win, title);
|
|
|
|
}
|
|
|
|
|
2005-03-29 06:31:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_openDisplay(JNIEnv *env, jclass clazz) {
|
|
|
|
openDisplay(env);
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
|
2005-03-29 06:31:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_closeDisplay(JNIEnv *env, jclass clazz) {
|
|
|
|
closeDisplay();
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplayPeerInfo_initDrawable(JNIEnv *env, jclass clazz, jobject peer_info_handle) {
|
|
|
|
X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_info_handle);
|
|
|
|
if (peer_info->glx13)
|
|
|
|
peer_info->drawable = glx_window;
|
|
|
|
else
|
|
|
|
peer_info->drawable = getCurrentWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplayPeerInfo_initDefaultPeerInfo(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject pixel_format) {
|
|
|
|
initPeerInfo(env, peer_info_handle, getDisplay(), getCurrentScreen(), pixel_format, true, GLX_WINDOW_BIT, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetTitle(JNIEnv * env, jclass clazz, jstring title_obj) {
|
2004-11-13 16:06:38 -05:00
|
|
|
char * title = GetStringNativeChars(env, title_obj);
|
2004-11-02 07:49:41 -05:00
|
|
|
setWindowTitle(title);
|
2004-11-13 16:06:38 -05:00
|
|
|
free(title);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2004-12-11 15:18:18 -05:00
|
|
|
static void destroyWindow(JNIEnv *env) {
|
2005-02-20 06:24:22 -05:00
|
|
|
if (glx_window != None) {
|
2005-02-24 05:44:34 -05:00
|
|
|
_glXDestroyWindow(getDisplay(), glx_window);
|
2005-02-20 06:24:22 -05:00
|
|
|
glx_window = None;
|
|
|
|
}
|
2004-11-02 07:49:41 -05:00
|
|
|
XDestroyWindow(getDisplay(), current_win);
|
|
|
|
XFreeColormap(getDisplay(), cmap);
|
2004-12-11 15:18:18 -05:00
|
|
|
setRepeatMode(env, AutoRepeatModeDefault);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-04-14 06:10:46 -04:00
|
|
|
static bool isNetWMForceDisabled() {
|
|
|
|
char *supported_env = getenv("LWJGL_DISABLE_NETWM");
|
|
|
|
return supported_env != NULL;
|
|
|
|
}
|
|
|
|
|
2004-12-11 15:18:18 -05:00
|
|
|
static bool isNetWMFullscreenSupported(JNIEnv *env) {
|
2004-11-02 07:49:41 -05:00
|
|
|
unsigned long nitems;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long bytes_after;
|
|
|
|
Atom *supported_list;
|
2005-04-14 06:10:46 -04:00
|
|
|
if (isNetWMForceDisabled())
|
|
|
|
return false;
|
2004-11-02 07:49:41 -05:00
|
|
|
Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False);
|
|
|
|
int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list);
|
|
|
|
if (result != Success) {
|
2004-12-11 15:18:18 -05:00
|
|
|
printfDebugJava(env, "Unable to query _NET_SUPPORTED window property");
|
2004-11-02 07:49:41 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
bool supported = false;
|
|
|
|
unsigned long i;
|
|
|
|
for (i = 0; i < nitems; i++) {
|
|
|
|
if (fullscreen_atom == supported_list[i]) {
|
|
|
|
supported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(supported_list);
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nReshape(JNIEnv *env, jclass clazz, jint x, jint y, jint width, jint height) {
|
2004-11-02 07:49:41 -05:00
|
|
|
XMoveWindow(getDisplay(), getCurrentWindow(), x, y);
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
static bool createWindow(JNIEnv* env, X11PeerInfo *peer_info, int x, int y, int width, int height) {
|
2004-11-02 07:49:41 -05:00
|
|
|
bool undecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
|
|
|
|
dirty = true;
|
|
|
|
focused = true;
|
|
|
|
minimized = false;
|
|
|
|
closerequested = false;
|
|
|
|
vsync_enabled = false;
|
|
|
|
grab = false;
|
|
|
|
Window root_win;
|
|
|
|
Window win;
|
|
|
|
XSetWindowAttributes attribs;
|
|
|
|
int attribmask;
|
|
|
|
|
|
|
|
input_released = false;
|
|
|
|
current_width = width;
|
|
|
|
current_height = height;
|
|
|
|
root_win = RootWindow(getDisplay(), getCurrentScreen());
|
2005-02-20 06:24:22 -05:00
|
|
|
XVisualInfo *vis_info = getVisualInfoFromPeerInfo(env, peer_info);
|
|
|
|
if (vis_info == NULL)
|
|
|
|
return false;
|
2004-11-02 07:49:41 -05:00
|
|
|
cmap = XCreateColormap(getDisplay(), root_win, vis_info->visual, AllocNone);
|
|
|
|
attribs.colormap = cmap;
|
2004-11-06 04:41:02 -05:00
|
|
|
attribs.event_mask = ExposureMask | /*FocusChangeMask | */VisibilityChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
|
2004-11-02 07:49:41 -05:00
|
|
|
attribs.background_pixel = 0xFF000000;
|
|
|
|
attribs.win_gravity = NorthWestGravity;
|
|
|
|
attribmask = CWColormap | CWBackPixel | CWEventMask | CWWinGravity;
|
|
|
|
if (isLegacyFullscreen()) {
|
|
|
|
attribmask |= CWOverrideRedirect;
|
|
|
|
attribs.override_redirect = True;
|
|
|
|
}
|
|
|
|
win = XCreateWindow(getDisplay(), root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
|
2005-07-06 15:46:35 -04:00
|
|
|
|
|
|
|
current_depth = vis_info->depth;
|
|
|
|
current_visual = vis_info->visual;
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
XFree(vis_info);
|
|
|
|
if (!checkXError(env, getDisplay())) {
|
2004-11-02 07:49:41 -05:00
|
|
|
XFreeColormap(getDisplay(), cmap);
|
|
|
|
return false;
|
|
|
|
}
|
2004-12-11 15:18:18 -05:00
|
|
|
printfDebugJava(env, "Created window");
|
2004-11-02 07:49:41 -05:00
|
|
|
current_win = win;
|
|
|
|
if (current_window_mode != WINDOWED || undecorated) {
|
|
|
|
// Use Motif decoration hint property and hope the window manager respects them
|
|
|
|
setDecorations(0);
|
|
|
|
}
|
|
|
|
XSizeHints * size_hints = XAllocSizeHints();
|
|
|
|
size_hints->flags = PMinSize | PMaxSize;
|
|
|
|
size_hints->min_width = width;
|
|
|
|
size_hints->max_width = width;
|
|
|
|
size_hints->min_height = height;
|
|
|
|
size_hints->max_height = height;
|
|
|
|
XSetWMNormalHints(getDisplay(), win, size_hints);
|
|
|
|
XFree(size_hints);
|
|
|
|
delete_atom = XInternAtom(getDisplay(), "WM_DELETE_WINDOW", False);
|
|
|
|
XSetWMProtocols(getDisplay(), win, &delete_atom, 1);
|
|
|
|
if (current_window_mode == FULLSCREEN_NETWM) {
|
|
|
|
Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
XChangeProperty(getDisplay(), getCurrentWindow(), XInternAtom(getDisplay(), "_NET_WM_STATE", False),
|
|
|
|
XInternAtom(getDisplay(), "ATOM", False), 32, PropModeReplace, (const unsigned char*)&fullscreen_atom, 1);
|
|
|
|
}
|
|
|
|
XMapRaised(getDisplay(), win);
|
|
|
|
waitMapped(win);
|
|
|
|
XClearWindow(getDisplay(), win);
|
2004-12-11 15:18:18 -05:00
|
|
|
setRepeatMode(env, AutoRepeatModeOff);
|
2005-02-20 06:24:22 -05:00
|
|
|
if (!checkXError(env, getDisplay())) {
|
2004-12-11 15:18:18 -05:00
|
|
|
destroyWindow(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window getCurrentWindow(void) {
|
|
|
|
return current_win;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getWindowWidth(void) {
|
|
|
|
return current_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getWindowHeight(void) {
|
|
|
|
return current_height;
|
|
|
|
}
|
|
|
|
|
2005-01-11 10:22:12 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate
|
2005-02-20 06:24:22 -05:00
|
|
|
(JNIEnv *env, jclass clazz)
|
2004-11-02 07:49:41 -05:00
|
|
|
{
|
2004-12-11 15:09:04 -05:00
|
|
|
handleMessages(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz) {
|
2004-11-02 07:49:41 -05:00
|
|
|
return getAvailableDisplayModes(env, getCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
|
2004-11-02 07:49:41 -05:00
|
|
|
switchDisplayMode(env, mode, getCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz) {
|
2004-12-11 15:09:04 -05:00
|
|
|
resetDisplayMode(env, getCurrentScreen(), false);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
|
2004-12-11 15:09:04 -05:00
|
|
|
return (jint)getGammaRampLength(env, getCurrentScreen());
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
|
2004-11-02 07:49:41 -05:00
|
|
|
setGammaRamp(env, gamma_buffer, getCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nInit(JNIEnv *env, jclass clazz) {
|
2004-11-02 07:49:41 -05:00
|
|
|
return initDisplay(env, getCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jboolean fullscreen, jint x, jint y) {
|
2004-11-02 07:49:41 -05:00
|
|
|
bool current_fullscreen = fullscreen == JNI_TRUE;
|
|
|
|
if (current_fullscreen) {
|
2004-12-12 14:02:43 -05:00
|
|
|
if (getCurrentDisplayModeExtension() == XRANDR && isNetWMFullscreenSupported(env)) {
|
|
|
|
printfDebugJava(env, "Using NetWM for fullscreen window");
|
2004-11-02 07:49:41 -05:00
|
|
|
current_window_mode = FULLSCREEN_NETWM;
|
2004-12-12 14:02:43 -05:00
|
|
|
} else {
|
|
|
|
printfDebugJava(env, "Using legacy mode for fullscreen window");
|
2004-11-02 07:49:41 -05:00
|
|
|
current_window_mode = FULLSCREEN_LEGACY;
|
2004-12-12 14:02:43 -05:00
|
|
|
}
|
2004-11-02 07:49:41 -05:00
|
|
|
} else
|
|
|
|
current_window_mode = WINDOWED;
|
2005-02-20 06:24:22 -05:00
|
|
|
X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_info_handle);
|
|
|
|
GLXFBConfig *fb_config = NULL;
|
|
|
|
if (peer_info->glx13) {
|
|
|
|
fb_config = getFBConfigFromPeerInfo(env, peer_info);
|
|
|
|
if (fb_config == NULL)
|
|
|
|
return;
|
|
|
|
}
|
2004-11-02 07:49:41 -05:00
|
|
|
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
|
|
|
|
jfieldID fid_width = (*env)->GetFieldID(env, cls_displayMode, "width", "I");
|
|
|
|
jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I");
|
|
|
|
int width = (*env)->GetIntField(env, mode, fid_width);
|
|
|
|
int height = (*env)->GetIntField(env, mode, fid_height);
|
2005-02-20 06:24:22 -05:00
|
|
|
bool window_created = createWindow(env, peer_info, x, y, width, height);
|
2004-11-02 07:49:41 -05:00
|
|
|
if (!window_created) {
|
|
|
|
return;
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
if (peer_info->glx13) {
|
2005-02-24 05:44:34 -05:00
|
|
|
glx_window = _glXCreateWindow(getDisplay(), *fb_config, getCurrentWindow(), NULL);
|
2005-02-20 06:24:22 -05:00
|
|
|
XFree(fb_config);
|
|
|
|
}
|
|
|
|
if (!checkXError(env, getDisplay())) {
|
2005-02-24 05:44:34 -05:00
|
|
|
_glXDestroyWindow(getDisplay(), glx_window);
|
2004-12-11 15:18:18 -05:00
|
|
|
destroyWindow(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyWindow(JNIEnv *env, jclass clazz) {
|
2004-12-11 15:18:18 -05:00
|
|
|
destroyWindow(env);
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-01-11 10:22:12 -05:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsDirty
|
2005-02-20 06:24:22 -05:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-11-02 07:49:41 -05:00
|
|
|
bool result = dirty;
|
|
|
|
dirty = false;
|
|
|
|
return result ? JNI_TRUE : JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-01-11 10:22:12 -05:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsVisible
|
2005-02-20 06:24:22 -05:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-11-02 07:49:41 -05:00
|
|
|
return minimized ? JNI_FALSE : JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-11 10:22:12 -05:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsCloseRequested
|
2005-02-20 06:24:22 -05:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-11-02 07:49:41 -05:00
|
|
|
bool saved = closerequested;
|
|
|
|
closerequested = false;
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2005-01-11 10:22:12 -05:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsActive
|
2005-02-20 06:24:22 -05:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-12-11 14:44:53 -05:00
|
|
|
return focused || isLegacyFullscreen() ? JNI_TRUE : JNI_FALSE;
|
2004-11-02 07:49:41 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_lockAWT(JNIEnv *env, jclass clazz) {
|
2005-01-11 10:22:12 -05:00
|
|
|
JAWT jawt;
|
|
|
|
jawt.version = JAWT_VERSION_1_4;
|
|
|
|
if (JAWT_GetAWT(env, &jawt) != JNI_TRUE) {
|
|
|
|
throwGeneralException(env, "java/lang/RuntimeException", "GetAWT failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
jawt.Lock(env);
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_unlockAWT(JNIEnv *env, jclass clazz) {
|
2005-01-11 10:22:12 -05:00
|
|
|
JAWT jawt;
|
|
|
|
jawt.version = JAWT_VERSION_1_4;
|
|
|
|
if (JAWT_GetAWT(env, &jawt) != JNI_TRUE) {
|
|
|
|
throwGeneralException(env, "java/lang/RuntimeException", "GetAWT failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
jawt.Unlock(env);
|
|
|
|
}
|
2005-07-05 17:46:27 -04:00
|
|
|
|
2005-07-06 15:46:35 -04:00
|
|
|
int setIcon(char *data,int width,int height) {
|
|
|
|
XWMHints* win_hints;
|
|
|
|
int x = 0;
|
|
|
|
int y = 5;
|
|
|
|
char r,g,b,a;
|
|
|
|
|
|
|
|
int depth = 4;
|
|
|
|
|
|
|
|
for (y=0;y<height;y++) {
|
|
|
|
for (x=0;x<width;x++) {
|
|
|
|
r = data[(x*4)+(y*width*4)];
|
|
|
|
g = data[(x*4)+(y*width*4)+1];
|
|
|
|
b = data[(x*4)+(y*width*4)+2];
|
|
|
|
a = data[(x*4)+(y*width*4)+3];
|
|
|
|
|
|
|
|
data[(x*depth)+(y*width*depth)] = b; // blue
|
|
|
|
data[(x*depth)+(y*width*depth)+1] = g; // green
|
|
|
|
data[(x*depth)+(y*width*depth)+2] = r;
|
|
|
|
data[(x*depth)+(y*width*depth)+3] = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pixmap icon_pixmap = XCreatePixmap(getDisplay(), getCurrentWindow(), width, height, current_depth);
|
|
|
|
|
|
|
|
XImage *image = XCreateImage(getDisplay(), current_visual, current_depth, ZPixmap, 0, data, width, height, 32, 0);
|
|
|
|
|
|
|
|
GC gc = XCreateGC(getDisplay(), icon_pixmap, 0, NULL);
|
|
|
|
|
|
|
|
XPutImage(getDisplay(), icon_pixmap, gc, image, 0, 0, 0, 0, width, height);
|
|
|
|
|
|
|
|
win_hints = XAllocWMHints();
|
|
|
|
if (!win_hints) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
win_hints->flags = IconPixmapHint;
|
|
|
|
win_hints->icon_pixmap = icon_pixmap;
|
|
|
|
|
|
|
|
XSetWMHints(getDisplay(), getCurrentWindow(), win_hints);
|
|
|
|
XFree(win_hints);
|
|
|
|
XFlush(getDisplay());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-05 17:46:27 -04:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetWindowIcon
|
|
|
|
(JNIEnv *env, jclass clazz, jobject iconBuffer)
|
|
|
|
{
|
2005-07-06 15:46:35 -04:00
|
|
|
char *imgData = (char *)(*env)->GetDirectBufferAddress(env, iconBuffer);
|
2005-07-05 17:46:27 -04:00
|
|
|
|
2005-07-06 15:46:35 -04:00
|
|
|
if (setIcon(imgData,32,32) == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-07-05 17:46:27 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|