Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Android: remove SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH
java layer runs as if separate mouse and touch was 1,
Use SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS
for generating synthetic touch/mouse events
  • Loading branch information
1bsyl committed Apr 4, 2019
1 parent e415761 commit bfdd0b2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 68 deletions.
Expand Up @@ -73,10 +73,6 @@ public enum NativeState {
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
public static boolean mBrokenLibraries;

// If we want to separate mouse and touch events.
// This is only toggled in native code when a hint is set!
public static boolean mSeparateMouseAndTouch;

// Main components
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
Expand Down Expand Up @@ -1772,8 +1768,7 @@ public boolean onTouch(View v, MotionEvent event) {
// 12290 = Samsung DeX mode desktop mouse
// 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
// 0x2 = SOURCE_CLASS_POINTER
if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN))
&& SDLActivity.mSeparateMouseAndTouch) {
if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
try {
mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
} catch(Exception e) {
Expand Down
Expand Up @@ -555,9 +555,6 @@ public boolean onGenericMotion(View v, MotionEvent event) {
return SDLControllerManager.handleJoystickMotionEvent(event);

case InputDevice.SOURCE_MOUSE:
if (!SDLActivity.mSeparateMouseAndTouch) {
break;
}
action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_SCROLL:
Expand Down Expand Up @@ -624,14 +621,12 @@ public boolean onGenericMotion(View v, MotionEvent event) {
// Handle relative mouse mode
if (mRelativeModeEnabled) {
if (event.getSource() == InputDevice.SOURCE_MOUSE) {
if (SDLActivity.mSeparateMouseAndTouch) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_HOVER_MOVE) {
float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
SDLActivity.onNativeMouse(0, action, x, y, true);
return true;
}
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_HOVER_MOVE) {
float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
SDLActivity.onNativeMouse(0, action, x, y, true);
return true;
}
}
}
Expand Down Expand Up @@ -696,10 +691,6 @@ public boolean onGenericMotion(View v, MotionEvent event) {
case InputDevice.SOURCE_MOUSE:
// DeX desktop mouse cursor is a separate non-standard input type.
case InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN:
if (!SDLActivity.mSeparateMouseAndTouch) {
break;
}

action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_SCROLL:
Expand All @@ -720,9 +711,6 @@ public boolean onGenericMotion(View v, MotionEvent event) {
break;

case InputDevice.SOURCE_MOUSE_RELATIVE:
if (!SDLActivity.mSeparateMouseAndTouch) {
break;
}
action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_SCROLL:
Expand Down
14 changes: 1 addition & 13 deletions include/SDL_hints.h
Expand Up @@ -869,19 +869,7 @@ extern "C" {
*/
#define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"

/**
* \brief A variable to control whether mouse and touch events are to be treated together or separately
*
* The variable can be set to the following values:
* "0" - Mouse events will be handled as touch events, and touch will raise fake mouse
* events. This is the behaviour of SDL <= 2.0.3. (default)
* "1" - Mouse events will be handled separately from pure touch events.
*
* The value of this hint is used at runtime, so it can be changed at any time.
*/
#define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"

/**
/**
* \brief A variable to control whether we trap the Android back button to handle it manually.
* This is necessary for the right mouse button to work on some Android devices, or
* to be able to trap the back button for use in your code reliably. If set to true,
Expand Down
16 changes: 0 additions & 16 deletions src/core/android/SDL_android.c
Expand Up @@ -280,9 +280,6 @@ static jmethodID midPollHapticDevices;
static jmethodID midHapticRun;
static jmethodID midHapticStop;

/* static fields */
static jfieldID fidSeparateMouseAndTouch;

/* Accelerometer data storage */
static SDL_DisplayOrientation displayOrientation;
static float fLastAccelerometer[3];
Expand Down Expand Up @@ -537,12 +534,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
}

fidSeparateMouseAndTouch = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");

if (!fidSeparateMouseAndTouch) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?");
}

checkJNIReady();
}

Expand Down Expand Up @@ -2206,13 +2197,6 @@ void Android_JNI_InitTouch() {
(*env)->CallStaticVoidMethod(env, mActivityClass, midInitTouch);
}

/* sets the mSeparateMouseAndTouch field */
void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
{
JNIEnv *env = Android_JNI_GetEnv();
(*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
}

void Android_JNI_PollInputDevices(void)
{
JNIEnv *env = Android_JNI_GetEnv();
Expand Down
1 change: 0 additions & 1 deletion src/core/android/SDL_android.h
Expand Up @@ -96,7 +96,6 @@ void Android_JNI_SuspendScreenSaver(SDL_bool suspend);

/* Touch support */
void Android_JNI_InitTouch(void);
void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);

/* Threads */
#include <jni.h>
Expand Down
15 changes: 1 addition & 14 deletions src/video/android/SDL_androidtouch.c
Expand Up @@ -40,28 +40,15 @@
#define ACTION_POINTER_DOWN 5
#define ACTION_POINTER_UP 6

static void SDLCALL
SeparateEventsHintWatcher(void *userdata, const char *name,
const char *oldValue, const char *newValue)
{
SDL_bool separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));

Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
}

void Android_InitTouch(void)
{
SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
SeparateEventsHintWatcher, NULL);

/* Add all touch devices */
Android_JNI_InitTouch();
}

void Android_QuitTouch(void)
{
SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
SeparateEventsHintWatcher, NULL);
return;
}

void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
Expand Down

0 comments on commit bfdd0b2

Please sign in to comment.