mirror of https://github.com/encounter/SDL.git
Added support for external mouse in Samsung DeX mode
relative mode doesn't work, but absolute coordinates are functional
This commit is contained in:
parent
f1d8f5f7fd
commit
a515853569
|
@ -670,6 +670,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
*/
|
*/
|
||||||
public static boolean supportsRelativeMouse()
|
public static boolean supportsRelativeMouse()
|
||||||
{
|
{
|
||||||
|
// ChromeOS doesn't provide relative mouse motion via the Android 7 APIs
|
||||||
|
if (isChromebook()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Samsung DeX mode doesn't support relative mice properly under Android 7 APIs,
|
||||||
|
// and simply returns no data under Android 8 APIs.
|
||||||
|
if (isDeXMode()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return SDLActivity.getMotionListener().supportsRelativeMouse();
|
return SDLActivity.getMotionListener().supportsRelativeMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,6 +689,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
*/
|
*/
|
||||||
public static boolean setRelativeMouseEnabled(boolean enabled)
|
public static boolean setRelativeMouseEnabled(boolean enabled)
|
||||||
{
|
{
|
||||||
|
if (enabled && !supportsRelativeMouse()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return SDLActivity.getMotionListener().setRelativeMouseEnabled(enabled);
|
return SDLActivity.getMotionListener().setRelativeMouseEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,6 +728,23 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
|
return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called by SDL using JNI.
|
||||||
|
*/
|
||||||
|
public static boolean isDeXMode() {
|
||||||
|
if (Build.VERSION.SDK_INT < 24) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final Configuration config = getContext().getResources().getConfiguration();
|
||||||
|
final Class configClass = config.getClass();
|
||||||
|
return configClass.getField("SEM_DESKTOP_MODE_ENABLED").getInt(configClass)
|
||||||
|
== configClass.getField("semDesktopModeEnabled").getInt(config);
|
||||||
|
} catch(Exception ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called by SDL using JNI.
|
* This method is called by SDL using JNI.
|
||||||
*/
|
*/
|
||||||
|
@ -1313,7 +1345,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
setOnGenericMotionListener(SDLActivity.getMotionListener());
|
setOnGenericMotionListener(SDLActivity.getMotionListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if ((Build.VERSION.SDK_INT >= 26) && !SDLActivity.isDeXMode()) {
|
||||||
setOnCapturedPointerListener(new SDLCapturedPointerListener_API26());
|
setOnCapturedPointerListener(new SDLCapturedPointerListener_API26());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1544,7 +1576,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
float x,y,p;
|
float x,y,p;
|
||||||
|
|
||||||
// !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
|
// !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
|
||||||
if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) {
|
// 12290 = Samsung DeX mode desktop mouse
|
||||||
|
if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == 12290) && SDLActivity.mSeparateMouseAndTouch) {
|
||||||
if (Build.VERSION.SDK_INT < 14) {
|
if (Build.VERSION.SDK_INT < 14) {
|
||||||
mouseButton = 1; // all mouse buttons are the left button
|
mouseButton = 1; // all mouse buttons are the left button
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -692,6 +692,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
|
||||||
return SDLControllerManager.handleJoystickMotionEvent(event);
|
return SDLControllerManager.handleJoystickMotionEvent(event);
|
||||||
|
|
||||||
case InputDevice.SOURCE_MOUSE:
|
case InputDevice.SOURCE_MOUSE:
|
||||||
|
case 12290: // DeX desktop mouse cursor is a separate non-standard input type.
|
||||||
if (!SDLActivity.mSeparateMouseAndTouch) {
|
if (!SDLActivity.mSeparateMouseAndTouch) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,11 @@ extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
|
extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return true is the application is running on a Samsung DeX docking station
|
||||||
|
*/
|
||||||
|
extern DECLSPEC SDL_bool SDLCALL SDL_IsDeXMode(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
See the official Android developer guide for more information:
|
See the official Android developer guide for more information:
|
||||||
http://developer.android.com/guide/topics/data/data-storage.html
|
http://developer.android.com/guide/topics/data/data-storage.html
|
||||||
|
|
|
@ -215,6 +215,7 @@ static jmethodID midSetOrientation;
|
||||||
static jmethodID midGetContext;
|
static jmethodID midGetContext;
|
||||||
static jmethodID midIsAndroidTV;
|
static jmethodID midIsAndroidTV;
|
||||||
static jmethodID midIsChromebook;
|
static jmethodID midIsChromebook;
|
||||||
|
static jmethodID midIsDeXMode;
|
||||||
static jmethodID midInputGetInputDeviceIds;
|
static jmethodID midInputGetInputDeviceIds;
|
||||||
static jmethodID midSendMessage;
|
static jmethodID midSendMessage;
|
||||||
static jmethodID midShowTextInput;
|
static jmethodID midShowTextInput;
|
||||||
|
@ -320,6 +321,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
|
||||||
"isAndroidTV","()Z");
|
"isAndroidTV","()Z");
|
||||||
midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
"isChromebook", "()Z");
|
"isChromebook", "()Z");
|
||||||
|
midIsDeXMode = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"isDeXMode", "()Z");
|
||||||
midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
"inputGetInputDeviceIds", "(I)[I");
|
"inputGetInputDeviceIds", "(I)[I");
|
||||||
midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
@ -354,7 +357,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
|
||||||
!midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
|
!midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
|
||||||
!midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
|
!midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
|
||||||
!midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
|
!midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
|
||||||
!midIsChromebook) {
|
!midIsChromebook || !midIsDeXMode) {
|
||||||
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
|
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2036,6 +2039,12 @@ SDL_bool SDL_IsChromebook(void)
|
||||||
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsChromebook);
|
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsChromebook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_bool SDL_IsDeXMode(void)
|
||||||
|
{
|
||||||
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
|
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsDeXMode);
|
||||||
|
}
|
||||||
|
|
||||||
const char * SDL_AndroidGetInternalStoragePath(void)
|
const char * SDL_AndroidGetInternalStoragePath(void)
|
||||||
{
|
{
|
||||||
static char *s_AndroidInternalFilesPath = NULL;
|
static char *s_AndroidInternalFilesPath = NULL;
|
||||||
|
|
|
@ -673,3 +673,4 @@
|
||||||
#define SDL_LinuxSetThreadPriority SDL_LinuxSetThreadPriority_REAL
|
#define SDL_LinuxSetThreadPriority SDL_LinuxSetThreadPriority_REAL
|
||||||
#define SDL_HasAVX512F SDL_HasAVX512F_REAL
|
#define SDL_HasAVX512F SDL_HasAVX512F_REAL
|
||||||
#define SDL_IsChromebook SDL_IsChromebook_REAL
|
#define SDL_IsChromebook SDL_IsChromebook_REAL
|
||||||
|
#define SDL_IsDeXMode SDL_IsDeXMode_REAL
|
||||||
|
|
|
@ -714,4 +714,5 @@ SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriority,(Sint64 a, int b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX512F,(void),(),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX512F,(void),(),return)
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_IsChromebook,(void),(),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_IsChromebook,(void),(),return)
|
||||||
|
SDL_DYNAPI_PROC(SDL_bool,SDL_IsDeXMode,(void),(),return)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -721,6 +721,9 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
} else if (mouse->SetRelativeMouseMode(enabled) < 0) {
|
} else if (mouse->SetRelativeMouseMode(enabled) < 0) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
/* Fall back to warp mode if native relative mode failed */
|
/* Fall back to warp mode if native relative mode failed */
|
||||||
|
if (!mouse->WarpMouse) {
|
||||||
|
return SDL_SetError("No relative mode implementation available");
|
||||||
|
}
|
||||||
mouse->relative_mode_warp = SDL_TRUE;
|
mouse->relative_mode_warp = SDL_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue