*** empty log message ***
This commit is contained in:
parent
a55e3b2ade
commit
e62178a8df
|
@ -47,6 +47,29 @@
|
||||||
#define KEYBOARD_SIZE 256
|
#define KEYBOARD_SIZE 256
|
||||||
#define KEY_EVENT_BACKLOG 40
|
#define KEY_EVENT_BACKLOG 40
|
||||||
|
|
||||||
|
static unsigned char key_buf[KEYBOARD_SIZE];
|
||||||
|
static unsigned char key_map[KEYBOARD_SIZE];
|
||||||
|
|
||||||
|
static void handleKey(UInt32 key_code, unsigned char state) {
|
||||||
|
if (key_code >= KEYBOARD_SIZE) {
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("Key code too large %x\n", (unsigned int)key_code);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lock();
|
||||||
|
unsigned char mapped_code = key_map[key_code];
|
||||||
|
unsigned char old_state = key_buf[mapped_code];
|
||||||
|
if (old_state != state) {
|
||||||
|
if (state == 1)
|
||||||
|
printf("key down, key %x\n", key_code);
|
||||||
|
else
|
||||||
|
printf("key up, key %x\n", key_code);
|
||||||
|
key_buf[mapped_code] = state;
|
||||||
|
}
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
static pascal OSStatus doKeyDown(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
|
static pascal OSStatus doKeyDown(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
|
||||||
UInt32 key_code;
|
UInt32 key_code;
|
||||||
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
||||||
|
@ -56,7 +79,7 @@ static pascal OSStatus doKeyDown(EventHandlerCallRef next_handler, EventRef even
|
||||||
#endif
|
#endif
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
}
|
||||||
printf("key down, key %d\n", key_code);
|
handleKey(key_code, 1);
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,109 +92,85 @@ static pascal OSStatus doKeyUp(EventHandlerCallRef next_handler, EventRef event,
|
||||||
#endif
|
#endif
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
}
|
||||||
printf("key up, key %d\n", key_code);
|
handleKey(key_code, 0);
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleModifier(UInt32 modifier_bit_mask, UInt32 modifier_bit, unsigned char key_code) {
|
||||||
|
bool key_down = (modifier_bit_mask & modifier_bit) == modifier_bit;
|
||||||
|
unsigned char key_state = key_down ? 1 : 0;
|
||||||
|
handleKey(key_code, key_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static pascal OSStatus doKeyModifier(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
|
||||||
|
UInt32 modifier_bits;
|
||||||
|
OSStatus err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifier_bits), NULL, &modifier_bits);
|
||||||
|
if (err != noErr) {
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("Could not get event key code\n");
|
||||||
|
#endif
|
||||||
|
return eventNotHandledErr;
|
||||||
|
}
|
||||||
|
handleModifier(modifier_bits, controlKey, 0x1d);
|
||||||
|
handleModifier(modifier_bits, rightControlKey, 0x9d);
|
||||||
|
handleModifier(modifier_bits, shiftKey, 0x2a);
|
||||||
|
handleModifier(modifier_bits, rightShiftKey, 0x36);
|
||||||
|
handleModifier(modifier_bits, optionKey, 0x38);
|
||||||
|
handleModifier(modifier_bits, rightOptionKey, 0xb8);
|
||||||
|
handleModifier(modifier_bits, cmdKey, 0xdb);
|
||||||
|
handleModifier(modifier_bits, alphaLock, 0x3a);
|
||||||
|
handleModifier(modifier_bits, kEventKeyModifierNumLockMask, 0x45);
|
||||||
|
//handleModifier(modifier_bits, rightCmdKey, 0xdc);
|
||||||
|
return noErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool registerHandler(JNIEnv* env, WindowRef win_ref, EventHandlerProcPtr func, UInt32 event_kind) {
|
||||||
|
EventTypeSpec event_type;
|
||||||
|
EventHandlerUPP handler_upp = NewEventHandlerUPP(func);
|
||||||
|
event_type.eventClass = kEventClassKeyboard;
|
||||||
|
event_type.eventKind = event_kind;
|
||||||
|
OSStatus err = InstallWindowEventHandler(win_ref, handler_upp, 1, &event_type, NULL, NULL);
|
||||||
|
DisposeEventHandlerUPP(handler_upp);
|
||||||
|
if (noErr != err) {
|
||||||
|
throwException(env, "Could not register window event handler");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool registerKeyboardHandler(JNIEnv* env, WindowRef win_ref) {
|
bool registerKeyboardHandler(JNIEnv* env, WindowRef win_ref) {
|
||||||
EventTypeSpec event_types[1];
|
bool error = registerHandler(env, win_ref, doKeyUp, kEventRawKeyUp);
|
||||||
EventHandlerUPP handler_upp = NewEventHandlerUPP(doKeyUp);
|
error = error || registerHandler(env, win_ref, doKeyDown, kEventRawKeyDown);
|
||||||
event_types[0].eventClass = kEventClassKeyboard;
|
error = error || registerHandler(env, win_ref, doKeyModifier, kEventRawKeyModifiersChanged);
|
||||||
event_types[0].eventKind = kEventRawKeyUp;
|
return !error;
|
||||||
OSStatus err = InstallWindowEventHandler(win_ref, handler_upp, 1, event_types, NULL, NULL);
|
|
||||||
DisposeEventHandlerUPP(handler_upp);
|
|
||||||
if (noErr != err) {
|
|
||||||
throwException(env, "Could not register window event handler");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
handler_upp = NewEventHandlerUPP(doKeyDown);
|
|
||||||
event_types[0].eventClass = kEventClassKeyboard;
|
|
||||||
event_types[0].eventKind = kEventRawKeyDown;
|
|
||||||
err = InstallWindowEventHandler(win_ref, handler_upp, 1, event_types, NULL, NULL);
|
|
||||||
DisposeEventHandlerUPP(handler_upp);
|
|
||||||
if (noErr != err) {
|
|
||||||
throwException(env, "Could not register window event handler");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
|
||||||
* Method: initIDs
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
memset(key_buf, 0, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||||
* Method: nCreate
|
|
||||||
* Signature: ()Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
|
||||||
* Method: nDestroy
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll(JNIEnv * env, jclass clazz, jobject buffer) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
unsigned char *new_keyboard_buffer = (unsigned char *)env->GetDirectBufferAddress(buffer);
|
||||||
* Method: nPoll
|
lock();
|
||||||
* Signature: (I)V
|
memcpy(new_keyboard_buffer, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||||
*/
|
unlock();
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
|
|
||||||
(JNIEnv * env, jclass clazz, jobject buffer)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
|
||||||
* Method: nRead
|
|
||||||
* Signature: (I)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation(JNIEnv *env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
|
||||||
* Method: nEnableTranslation
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation
|
|
||||||
(JNIEnv *env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
|
||||||
* Method: nEnableBuffer
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key) {
|
||||||
* Class: org_lwjgl_input_Keyboard
|
return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
|
||||||
* Method: nisStateKeySet
|
|
||||||
* Signature: (I)I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key)
|
|
||||||
{
|
|
||||||
return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event,
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool registerWindowHandler(JNIEnv* env, EventHandlerProcPtr func, UInt32 event_kind) {
|
static bool registerWindowHandler(JNIEnv* env, WindowRef win_ref, EventHandlerProcPtr func, UInt32 event_kind) {
|
||||||
EventTypeSpec event_type;
|
EventTypeSpec event_type;
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
EventHandlerUPP handler_upp = NewEventHandlerUPP(func);
|
EventHandlerUPP handler_upp = NewEventHandlerUPP(func);
|
||||||
|
@ -124,11 +124,11 @@ static bool registerWindowHandler(JNIEnv* env, EventHandlerProcPtr func, UInt32
|
||||||
|
|
||||||
static bool registerEventHandlers(JNIEnv *env) {
|
static bool registerEventHandlers(JNIEnv *env) {
|
||||||
bool error;
|
bool error;
|
||||||
error = registerWindowHandler(env, doQuit, kEventWindowClose);
|
error = registerWindowHandler(env, win_ref, doQuit, kEventWindowClose);
|
||||||
error = error || registerWindowHandler(env, doActivate, kEventWindowActivated);
|
error = error || registerWindowHandler(env, win_ref, doActivate, kEventWindowActivated);
|
||||||
error = error || registerWindowHandler(env, doDeactivate, kEventWindowDeactivated);
|
error = error || registerWindowHandler(env, win_ref, doDeactivate, kEventWindowDeactivated);
|
||||||
error = error || registerWindowHandler(env, doMiniaturized, kEventWindowCollapsed);
|
error = error || registerWindowHandler(env, win_ref, doMiniaturized, kEventWindowCollapsed);
|
||||||
error = error || registerWindowHandler(env, doMaximize, kEventWindowExpanded);
|
error = error || registerWindowHandler(env, win_ref, doMaximize, kEventWindowExpanded);
|
||||||
if (error)
|
if (error)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
@ -143,11 +143,11 @@ static void destroyWindow(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(void) {
|
static void destroy(void) {
|
||||||
destroyLock();
|
|
||||||
aglSetCurrentContext(NULL);
|
aglSetCurrentContext(NULL);
|
||||||
aglDestroyContext(context);
|
aglDestroyContext(context);
|
||||||
destroyWindow();
|
destroyWindow();
|
||||||
extgl_Close();
|
extgl_Close();
|
||||||
|
destroyLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
|
static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
|
||||||
|
|
Loading…
Reference in New Issue