Skip to content

Commit 3a498b6

Browse files
committed
Merge pull request kwhat#12 from kwhat/hook_events
Merging hook events upstream changes.
2 parents 4c0294e + 3a49faf commit 3a498b6

9 files changed

+242
-207
lines changed

src/java/org/jnativehook/GlobalScreen.java

+2
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ private static void loadNativeLibrary() {
525525
if (manInputStream != null) {
526526
// Try and extract a version string from the Manifest.
527527
Manifest manifest = new Manifest(manInputStream);
528+
529+
// FIXME More OS X JRE Bugs! This returns NULL but only for Apple!
528530
Attributes attributes = manifest.getAttributes(basePackage);
529531

530532
if (attributes != null) {

src/jni/jni_Converter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jint jni_ConvertToJavaType(event_type nativeType, jint *javaType) {
3333
case EVENT_KEY_TYPED:
3434
case EVENT_KEY_PRESSED:
3535
case EVENT_KEY_RELEASED:
36-
*javaType = (nativeType + org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_FIRST) - 1;
36+
*javaType = (nativeType + org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_FIRST) + 1;
3737
break;
3838

3939
case EVENT_MOUSE_CLICKED:
@@ -43,7 +43,7 @@ jint jni_ConvertToJavaType(event_type nativeType, jint *javaType) {
4343
case EVENT_MOUSE_DRAGGED:
4444
case EVENT_MOUSE_WHEEL:
4545
*javaType = (nativeType + org_jnativehook_mouse_NativeMouseEvent_NATIVE_MOUSE_FIRST) -
46-
(org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_LAST - org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_FIRST) - 1;
46+
(org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_LAST - org_jnativehook_keyboard_NativeKeyEvent_NATIVE_KEY_FIRST) + 1;
4747
break;
4848

4949
default:

src/jni/jni_Errors.c

+21-27
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,42 @@
2222
#include "jni_Errors.h"
2323
#include "jni_Globals.h"
2424

25-
void ThrowFatalError(const char *message) {
25+
void jni_ThrowFatalError(JNIEnv *env, const char *message) {
2626
#ifdef USE_DEBUG
2727
fprintf(stderr, "Fatal Error: %s\n", message);
2828
#endif
2929

30-
JNIEnv *env = NULL;
31-
if ((*jvm)->GetEnv(jvm, (void **)(&env), jni_version) == JNI_OK) {
32-
(*env)->FatalError(env, message);
33-
}
30+
(*env)->FatalError(env, message);
3431

3532
exit(EXIT_FAILURE);
3633
}
3734

38-
void ThrowException(const char *classname, const char *message) {
39-
JNIEnv *env = NULL;
40-
if ((*jvm)->GetEnv(jvm, (void **)(&env), jni_version) == JNI_OK) {
41-
// Locate our exception class.
42-
// FIXME This needs to be relocated to a jni_Global.
43-
jclass Exception_class = (*env)->FindClass(env, classname);
35+
void jni_ThrowException(JNIEnv *env, const char *classname, const char *message) {
36+
// Locate our exception class.
37+
// FIXME This needs to be relocated to a jni_Global.
38+
jclass Exception_class = (*env)->FindClass(env, classname);
39+
40+
if (Exception_class != NULL) {
41+
(*env)->ThrowNew(env, Exception_class, message);
42+
#ifdef USE_DEBUG
43+
fprintf(stderr, "%s: %s\n", classname, message);
44+
#endif
45+
(*env)->DeleteLocalRef(env, Exception_class);
46+
}
47+
else {
48+
Exception_class = (*env)->FindClass(env, java_lang_NoClassDefFoundError);
4449

4550
if (Exception_class != NULL) {
46-
(*env)->ThrowNew(env, Exception_class, message);
4751
#ifdef USE_DEBUG
48-
fprintf(stderr, "ThrowException(): %s: %s\n", classname, message);
52+
fprintf(stderr, "%s: %s\n", java_lang_NoClassDefFoundError, classname);
4953
#endif
54+
55+
(*env)->ThrowNew(env, Exception_class, classname);
5056
(*env)->DeleteLocalRef(env, Exception_class);
5157
}
5258
else {
53-
Exception_class = (*env)->FindClass(env, java_lang_NoClassDefFoundError);
54-
55-
if (Exception_class != NULL) {
56-
#ifdef USE_DEBUG
57-
fprintf(stderr, "ThrowException(): %s: %s\n", java_lang_NoClassDefFoundError, classname);
58-
#endif
59-
60-
(*env)->ThrowNew(env, Exception_class, classname);
61-
(*env)->DeleteLocalRef(env, Exception_class);
62-
}
63-
else {
64-
// Unable to find exception class, Terminate with error.
65-
ThrowFatalError("Unable to locate exception class.");
66-
}
59+
// Unable to find exception class, Terminate with error.
60+
jni_ThrowFatalError(env, "Unable to locate exception class.");
6761
}
6862
}
6963
}

src/jni/jni_Errors.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
/* Produces a hard error in the virtual machine. This error is unrecoverable
3030
* and Program execution will terminate immediately.
3131
*/
32-
extern void ThrowFatalError(const char *message);
32+
extern void jni_ThrowFatalError(JNIEnv *env, const char *message);
3333

3434
/* Produces a recoverable error in the virtual machine. This error should be
3535
* recoverable outside of the native library.
3636
*/
37-
extern void ThrowException(const char *classname, const char *message);
37+
extern void jni_ThrowException(JNIEnv *env, const char *classname, const char *message);
3838

3939
#endif

0 commit comments

Comments
 (0)