Skip to content

Commit

Permalink
Moved SDL_IsTablet() to a cross-platform API function
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 22, 2018
1 parent e9f6805 commit 6f758ad
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
14 changes: 5 additions & 9 deletions include/SDL_system.h
Expand Up @@ -174,15 +174,6 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);

#endif /* __ANDROID__ */

#if defined(__ANDROID__) || defined(__IPHONEOS__)

/**
\brief Return true if the current device is a tablet.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);

#endif

/* Platform specific functions for WinRT */
#if defined(__WINRT__) && __WINRT__

Expand Down Expand Up @@ -272,6 +263,11 @@ extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();

#endif /* __WINRT__ */

/**
\brief Return true if the current device is a tablet.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down
14 changes: 14 additions & 0 deletions src/SDL.c
Expand Up @@ -475,6 +475,20 @@ SDL_GetPlatform()
#endif
}

SDL_bool
SDL_IsTablet()
{
#if __ANDROID__
extern SDL_bool SDL_IsAndroidTablet(void);
return SDL_IsAndroidTablet();
#elif __IPHONEOS__
extern SDL_bool SDL_IsIPad(void);
return SDL_IsIPad();
#else
return SDL_FALSE;
#endif
}

#if defined(__WIN32__)

#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
Expand Down
21 changes: 11 additions & 10 deletions src/core/android/SDL_android.c
Expand Up @@ -213,6 +213,7 @@ static jmethodID midSetActivityTitle;
static jmethodID midSetWindowStyle;
static jmethodID midSetOrientation;
static jmethodID midGetContext;
static jmethodID midIsTablet;
static jmethodID midIsAndroidTV;
static jmethodID midIsChromebook;
static jmethodID midIsDeXMode;
Expand All @@ -232,7 +233,6 @@ static jmethodID midSetCustomCursor;
static jmethodID midSetSystemCursor;
static jmethodID midSupportsRelativeMouse;
static jmethodID midSetRelativeMouseEnabled;
static jmethodID midIsTablet;

/* audio manager */
static jclass mAudioManagerClass;
Expand Down Expand Up @@ -319,6 +319,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
"setOrientation","(IIZLjava/lang/String;)V");
midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"getContext","()Landroid/content/Context;");
midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"isTablet", "()Z");
midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"isAndroidTV","()Z");
midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
Expand Down Expand Up @@ -355,15 +357,14 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
midSupportsRelativeMouse = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "supportsRelativeMouse", "()Z");
midSetRelativeMouseEnabled = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");

midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "isTablet", "()Z");

if (!midGetNativeSurface ||
!midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
!midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInputGetInputDeviceIds ||
!midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
!midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
!midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
!midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
!midIsChromebook || !midIsDeXMode || !midManualBackButton || !midIsTablet) {
!midIsChromebook || !midIsDeXMode || !midManualBackButton) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
}

Expand Down Expand Up @@ -2033,6 +2034,12 @@ void *SDL_AndroidGetActivity(void)
return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
}

SDL_bool SDL_IsAndroidTablet(void)
{
JNIEnv *env = Android_JNI_GetEnv();
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsTablet);
}

SDL_bool SDL_IsAndroidTV(void)
{
JNIEnv *env = Android_JNI_GetEnv();
Expand All @@ -2051,12 +2058,6 @@ SDL_bool SDL_IsDeXMode(void)
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsDeXMode);
}

SDL_bool SDL_IsTablet(void)
{
JNIEnv *env = Android_JNI_GetEnv();
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsTablet);
}

void SDL_AndroidBackButton(void)
{
JNIEnv *env = Android_JNI_GetEnv();
Expand Down
3 changes: 1 addition & 2 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -680,8 +680,6 @@
#define SDL_wcsdup SDL_wcsdup_REAL
#define SDL_GameControllerRumble SDL_GameControllerRumble_REAL
#define SDL_JoystickRumble SDL_JoystickRumble_REAL
#define SDL_IsTablet SDL_IsTablet_REAL
#define SDL_IsTablet SDL_IsTablet_REAL
#define SDL_NumSensors SDL_NumSensors_REAL
#define SDL_SensorGetDeviceName SDL_SensorGetDeviceName_REAL
#define SDL_SensorGetDeviceType SDL_SensorGetDeviceType_REAL
Expand All @@ -696,3 +694,4 @@
#define SDL_SensorGetData SDL_SensorGetData_REAL
#define SDL_SensorClose SDL_SensorClose_REAL
#define SDL_SensorUpdate SDL_SensorUpdate_REAL
#define SDL_IsTablet SDL_IsTablet_REAL
4 changes: 1 addition & 3 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -722,9 +722,6 @@ SDL_DYNAPI_PROC(float,SDL_expf,(float a),(a),return)
SDL_DYNAPI_PROC(wchar_t*,SDL_wcsdup,(const wchar_t *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GameControllerRumble,(SDL_GameController *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_JoystickRumble,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
#if defined(__ANDROID__) || defined(__IPHONEOS__)
SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
#endif
SDL_DYNAPI_PROC(int,SDL_NumSensors,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_SensorGetDeviceName,(int a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorType,SDL_SensorGetDeviceType,(int a),(a),return)
Expand All @@ -739,3 +736,4 @@ SDL_DYNAPI_PROC(SDL_SensorID,SDL_SensorGetInstanceID,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SensorGetData,(SDL_Sensor *a, float *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),)
SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
4 changes: 2 additions & 2 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -237,9 +237,9 @@ void SDL_NSLog(const char *text)
* iOS Tablet detection
*
* This doesn't really have aything to do with the interfaces of the SDL video
* subsystem, but we need to stuff this into an Objective-C source code file.
* subsystem, but we need to stuff this into an Objective-C source code file.
*/
SDL_bool SDL_IsTablet(void)
SDL_bool SDL_IsIPad(void)
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
Expand Down

0 comments on commit 6f758ad

Please sign in to comment.