mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-06 15:04:41 +00:00
Added closeRequested support to linux
This commit is contained in:
parent
36d8f34e86
commit
c022100cab
4 changed files with 99 additions and 78 deletions
|
|
@ -55,6 +55,7 @@ Display * disp;
|
|||
int screen;
|
||||
Window win;
|
||||
|
||||
static jfieldID fid_close;
|
||||
static bool current_fullscreen;
|
||||
static bool current_focused;
|
||||
static bool current_minimized;
|
||||
|
|
@ -62,7 +63,15 @@ static int win_width;
|
|||
static int win_height;
|
||||
static XF86VidModeModeInfo **avail_modes;
|
||||
static XVisualInfo * vis_info;
|
||||
static Atom delete_atom;
|
||||
static bool gl_loaded = false;
|
||||
static JNIEnv *saved_env;
|
||||
static jclass saved_clazz;
|
||||
|
||||
extern void handlePointerMotion(XMotionEvent *);
|
||||
extern void handleButtonPress(XButtonEvent *);
|
||||
extern void handleButtonRelease(XButtonEvent *);
|
||||
extern void handleKeyEvent(XKeyEvent *);
|
||||
|
||||
struct pixelformat {
|
||||
int bpp;
|
||||
|
|
@ -192,8 +201,13 @@ void waitMapped(Display *disp, Window win) {
|
|||
|
||||
void handleMessages(void) {
|
||||
XEvent event;
|
||||
while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask | StructureNotifyMask, &event)) {
|
||||
while (XPending(disp) > 0) {
|
||||
XNextEvent(disp, &event);
|
||||
switch (event.type) {
|
||||
case ClientMessage:
|
||||
if ((event.xclient.format == 32) && (event.xclient.data.l[0] == delete_atom))
|
||||
saved_env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE);
|
||||
break;
|
||||
case EnterNotify:
|
||||
current_focused = true;
|
||||
break;
|
||||
|
|
@ -206,6 +220,19 @@ void handleMessages(void) {
|
|||
case UnmapNotify:
|
||||
current_minimized = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -249,12 +276,12 @@ bool isFullscreen(void) {
|
|||
return current_fullscreen;
|
||||
}
|
||||
|
||||
bool isFocused(void) {
|
||||
bool isFocused() {
|
||||
handleMessages();
|
||||
return current_focused;
|
||||
}
|
||||
|
||||
bool isMinimized(void) {
|
||||
bool isMinimized() {
|
||||
handleMessages();
|
||||
return current_minimized;
|
||||
}
|
||||
|
|
@ -281,6 +308,10 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized(JNIEnv *env, jclas
|
|||
}
|
||||
|
||||
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) {
|
||||
saved_env = env;
|
||||
saved_clazz = clazz;
|
||||
fid_close = env->GetStaticFieldID(clazz, "closeRequested", "Z");
|
||||
|
||||
Window root_win;
|
||||
XSetWindowAttributes attribs;
|
||||
Colormap cmap;
|
||||
|
|
@ -350,6 +381,8 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c
|
|||
size_hints->max_height = height;
|
||||
XSetWMNormalHints(disp, win, size_hints);
|
||||
XFree(size_hints);
|
||||
delete_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(disp, win, &delete_atom, 1);
|
||||
XMapRaised(disp, win);
|
||||
waitMapped(disp, win);
|
||||
if (fullscreen) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue