Skip to content

Commit

Permalink
Creating 2.3 brantch
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed Jun 24, 2023
1 parent dd4a524 commit 2a5111a
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 200 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Continuous Integration
on:
push:
branches:
- '2.2'
- '2.3'

pull_request:
branches:
- '2.2'
- '2.3'

release:
types: [ created ]
Expand Down
33 changes: 1 addition & 32 deletions src/main/java/com/github/kwhat/jnativehook/NativeInputEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class NativeInputEvent extends EventObject {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 2306729722565226621L;
private static final long serialVersionUID = 7172837644708242760L;

/** The type of event. */
private final int id;
Expand Down Expand Up @@ -185,37 +185,6 @@ public int getModifiers() {
return this.modifiers;
}

/**
* Sets the modifier flags for this event.
*
* @param modifiers the new modifier flags
* @deprecated
*/
public void setModifiers(int modifiers) {
this.modifiers = modifiers;
}

/**
* Sets the reserved flags for this event.
* <p>
*
* Note the use of this method may not be supported by all native platforms.
* <p>
*
* Event propagation support for X11 cannot be provided due to an oversight
* in the way that XRecord currently operates. No public method will be
* available until a working cross-platform solution can be provided.
*
* @param reserved Non-portable flags for unsupported functionality.
*
* @since 1.1
* @deprecated
*/
@SuppressWarnings("unused")
private void setReserved(short reserved) {
this.reserved = reserved;
}

/**
* Gets a <code>String</code> describing the modifier flags, such as
* "Button1", or "Ctrl+Alt". These strings can be localized by changing the
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class NativeMouseWheelEvent extends NativeMouseEvent {
/**
* The Constant serialVersionUID.
*/
private static final long serialVersionUID = 2112217673594181259L;
private static final long serialVersionUID = 1568146880251274192L;

/**
* Constant representing scrolling by "units" (like scrolling with the arrow keys).
Expand Down Expand Up @@ -111,6 +111,13 @@ public class NativeMouseWheelEvent extends NativeMouseEvent {
*/
private final int wheelDirection;

/**
* Indicates how far the mouse wheel was rotated as a double.
*
* @see #getPreciseWheelRotation()
*/
private final double preciseWheelRotation;

/**
* Instantiates a new <code>NativeMouseWheelEvent</code> object with a vertical direction.
*
Expand All @@ -130,13 +137,12 @@ public class NativeMouseWheelEvent extends NativeMouseEvent {
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>, the number of units to be
* scrolled.
* @param wheelRotation the amount that the mouse wheel was rotated (the number of "clicks")
* @see #NativeMouseWheelEvent(int, int, int, int, int, int, int, int, int)
* @see NativeMouseWheelEvent(int, int, int, int, int, int, int, int, int)
* @see NativeMouseEvent#NativeMouseEvent(int, int, int, int, int)
*/
public NativeMouseWheelEvent(int id, int modifiers, int x, int y, int clickCount,
int scrollType, int scrollAmount, int wheelRotation) {
this(id, modifiers, x, y, clickCount, scrollType, scrollAmount, wheelRotation,
WHEEL_VERTICAL_DIRECTION);
int scrollType, int scrollAmount, int wheelRotation) {
this(id, modifiers, x, y, clickCount, scrollType, scrollAmount, wheelRotation, WHEEL_VERTICAL_DIRECTION);
}

/**
Expand Down Expand Up @@ -165,13 +171,46 @@ public NativeMouseWheelEvent(int id, int modifiers, int x, int y, int clickCount
* @since 2.1
*/
public NativeMouseWheelEvent(int id, int modifiers, int x, int y, int clickCount,
int scrollType, int scrollAmount, int wheelRotation, int wheelDirection) {
int scrollType, int scrollAmount, int wheelRotation, int wheelDirection) {
this(id, modifiers, x, y, clickCount, scrollType, scrollAmount, wheelRotation, wheelDirection, wheelRotation);
}

/**
* Instantiates a new <code>NativeMouseWheelEvent</code> object.
*
* @param id an integer that identifies the native event type.
* @param modifiers a modifier mask describing the modifier keys and mouse buttons active
* for the event.
* <code>NativeInputEvent _MASK</code> modifiers should be used as they
* are
* not compatible with the extended _DOWN_MASK or the old _MASK
* <code>InputEvent</code> modifiers.
* @param x the x coordinate of the native pointer.
* @param y the y coordinate of the native pointer.
* @param clickCount the number of button clicks associated with this event.
* @param scrollType the type of scrolling which should take place in response to this
* event; valid values are <code>WHEEL_UNIT_SCROLL</code> and
* <code>WHEEL_BLOCK_SCROLL</code>.
* @param scrollAmount for scrollType <code>WHEEL_UNIT_SCROLL</code>, the number of units to
* be scrolled.
* @param wheelRotation the amount that the mouse wheel was rotated (the number of "clicks")
* @param wheelDirection the direction of scrolling which should take place in response to this
* event; valid values are <code>WHEEL_VERTICAL_DIRECTION</code> and
* <code>WHEEL_HORIZONTAL_DIRECTION</code>.
* @param preciseWheelRotation the amount that the mouse wheel was rotated (the number of "clicks") as a double.
* @see NativeMouseEvent#NativeMouseEvent(int, int, int, int, int)
* @since 2.3
*/
public NativeMouseWheelEvent(int id, int modifiers, int x, int y, int clickCount,
int scrollType, int scrollAmount, int wheelRotation, int wheelDirection,
double preciseWheelRotation) {
super(id, modifiers, x, y, clickCount);

this.scrollType = scrollType;
this.scrollAmount = scrollAmount;
this.wheelRotation = wheelRotation;
this.wheelDirection = wheelDirection;
this.preciseWheelRotation = preciseWheelRotation;
}

/**
Expand Down Expand Up @@ -212,7 +251,7 @@ public int getScrollType() {
* Returns the number of "clicks" the mouse wheel was rotated.
*
* @return negative values if the mouse wheel was rotated up/away from the user, and positive
* values if the mouse wheel was rotated down/ toward(s) the user.
* values if the mouse wheel was rotated down / toward(s) the user.
*/
public int getWheelRotation() {
return wheelRotation;
Expand All @@ -235,6 +274,15 @@ public int getWheelDirection() {
return wheelDirection;
}

/**
* Returns the number of "clicks" the mouse wheel was rotated as a double.
*
* @return negative values if the mouse wheel was rotated up/away from the user, and positive
* values if the mouse wheel was rotated down / toward(s) the user.
*/
public double getPreciseWheelRotation() {
return this.preciseWheelRotation;
}

/**
* Returns a parameter string identifying the native event. This method is useful for
Expand Down Expand Up @@ -267,6 +315,9 @@ public String paramString() {
param.append(",wheelRotation=");
param.append(getWheelRotation());

param.append(",preciseWheelRotation=");
param.append(getPreciseWheelRotation());

param.append(",wheelDirection=");
switch (getWheelDirection()) {
case WHEEL_VERTICAL_DIRECTION:
Expand Down
12 changes: 7 additions & 5 deletions src/main/jni/jni_EventDispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <jni.h>
#include <stdbool.h>
#include <stdlib.h>
#include <uiohook.h>

#include "jni_Converter.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ static inline void notifyHookThread(JNIEnv *env) {

// NOTE: This function executes on the hook thread! If you need to block
// please do so on another thread via your own event dispatcher.
void jni_EventDispatcher(uiohook_event * const event) {
void jni_EventDispatcher(uiohook_event * const event, void *user_data) {
JNIEnv *env;
if ((*jvm)->GetEnv(jvm, (void **)(&env), jvm_attach_args.version) == JNI_OK) {
jobject NativeInputEvent_obj = NULL;
Expand Down Expand Up @@ -180,11 +181,12 @@ void jni_EventDispatcher(uiohook_event * const event) {
(jint) event->mask,
(jint) event->data.wheel.x,
(jint) event->data.wheel.y,
(jint) event->data.wheel.clicks,
(jint) 1, // clicks
(jint) event->data.wheel.type,
(jint) event->data.wheel.amount,
(jint) event->data.wheel.rotation,
(jint) event->data.wheel.direction);
(jint) abs(event->data.wheel.rotation * -1 / event->data.wheel.delta),
(jint) event->data.wheel.rotation * -1 / event->data.wheel.delta,
(jint) event->data.wheel.direction,
(jdouble) event->data.wheel.rotation * -1 / (float) event->data.wheel.delta);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/main/jni/jni_EventDispathcer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
#include <uiohook.h>

// This is a simple forwarding function to the Java event dispatcher.
extern void jni_EventDispatcher(uiohook_event * const event);
extern void jni_EventDispatcher(uiohook_event * const event, void *user_data);

#endif
6 changes: 5 additions & 1 deletion src/main/jni/jni_Globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int create_NativeMouseWheelEvent(JNIEnv *env) {
jclass NativeMouseWheelEvent_class = (*env)->FindClass(env, "com/github/kwhat/jnativehook/mouse/NativeMouseWheelEvent");
if (NativeMouseWheelEvent_class != NULL) {
// Get the method ID for NativeMouseWheelEvent constructor.
jmethodID init = (*env)->GetMethodID(env, NativeMouseWheelEvent_class, "<init>", "(IIIIIIIII)V");
jmethodID init = (*env)->GetMethodID(env, NativeMouseWheelEvent_class, "<init>", "(IIIIIIIIID)V");

// Get the method ID for NativeMouseWheelEvent.getScrollAmount().
jmethodID getScrollAmount = (*env)->GetMethodID(env, NativeMouseWheelEvent_class, "getScrollAmount", "()I");
Expand All @@ -386,6 +386,9 @@ static int create_NativeMouseWheelEvent(JNIEnv *env) {
// Get the method ID for NativeMouseWheelEvent.getWheelRotation().
jmethodID getWheelRotation = (*env)->GetMethodID(env, NativeMouseWheelEvent_class, "getWheelRotation", "()I");

// Get the method ID for NativeMouseWheelEvent.getPreciseWheelRotation().
jmethodID getPreciseWheelRotation = (*env)->GetMethodID(env, NativeMouseWheelEvent_class, "getPreciseWheelRotation", "()D");

if ((*env)->ExceptionCheck(env) == JNI_FALSE) {
com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent = malloc(sizeof(NativeMouseWheelEvent));
if (com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent != NULL) {
Expand All @@ -396,6 +399,7 @@ static int create_NativeMouseWheelEvent(JNIEnv *env) {
com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent->getScrollAmount = getScrollAmount;
com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent->getScrollType = getScrollType;
com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent->getWheelRotation = getWheelRotation;
com_github_kwhat_jnativehook_mouse_NativeMouseWheelEvent->getPreciseWheelRotation = getPreciseWheelRotation;

status = JNI_OK;
} else {
Expand Down
Loading

0 comments on commit 2a5111a

Please sign in to comment.