Skip to content
Permalink
Browse files

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 bfdd0b228a7d629ef621ab0449783e5851d8611f
@@ -73,10 +73,6 @@
/** 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;
@@ -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) {
@@ -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:
@@ -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;
}
}
}
@@ -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:
@@ -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:
@@ -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,
@@ -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];
@@ -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();
}

@@ -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();
@@ -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>
@@ -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)

0 comments on commit bfdd0b2

Please sign in to comment.