Moved SDL_IsTablet() to a cross-platform API function
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Aug 2018 20:03:54 -0700
changeset 12137161f67f4a7c6
parent 12136 ec2cee693e4b
child 12138 220ce1ab98d6
Moved SDL_IsTablet() to a cross-platform API function
include/SDL_system.h
src/SDL.c
src/core/android/SDL_android.c
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/video/uikit/SDL_uikitvideo.m
     1.1 --- a/include/SDL_system.h	Tue Aug 21 19:42:19 2018 -0700
     1.2 +++ b/include/SDL_system.h	Tue Aug 21 20:03:54 2018 -0700
     1.3 @@ -174,15 +174,6 @@
     1.4  
     1.5  #endif /* __ANDROID__ */
     1.6  
     1.7 -#if defined(__ANDROID__) || defined(__IPHONEOS__)
     1.8 -
     1.9 -/**
    1.10 - \brief Return true if the current device is a tablet.
    1.11 - */
    1.12 -extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
    1.13 -
    1.14 -#endif
    1.15 -
    1.16  /* Platform specific functions for WinRT */
    1.17  #if defined(__WINRT__) && __WINRT__
    1.18  
    1.19 @@ -272,6 +263,11 @@
    1.20  
    1.21  #endif /* __WINRT__ */
    1.22  
    1.23 +/**
    1.24 + \brief Return true if the current device is a tablet.
    1.25 + */
    1.26 +extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
    1.27 +
    1.28  /* Ends C function definitions when using C++ */
    1.29  #ifdef __cplusplus
    1.30  }
     2.1 --- a/src/SDL.c	Tue Aug 21 19:42:19 2018 -0700
     2.2 +++ b/src/SDL.c	Tue Aug 21 20:03:54 2018 -0700
     2.3 @@ -475,6 +475,20 @@
     2.4  #endif
     2.5  }
     2.6  
     2.7 +SDL_bool
     2.8 +SDL_IsTablet()
     2.9 +{
    2.10 +#if __ANDROID__
    2.11 +    extern SDL_bool SDL_IsAndroidTablet(void);
    2.12 +    return SDL_IsAndroidTablet();
    2.13 +#elif __IPHONEOS__
    2.14 +    extern SDL_bool SDL_IsIPad(void);
    2.15 +    return SDL_IsIPad();
    2.16 +#else
    2.17 +    return SDL_FALSE;
    2.18 +#endif
    2.19 +}
    2.20 +
    2.21  #if defined(__WIN32__)
    2.22  
    2.23  #if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
     3.1 --- a/src/core/android/SDL_android.c	Tue Aug 21 19:42:19 2018 -0700
     3.2 +++ b/src/core/android/SDL_android.c	Tue Aug 21 20:03:54 2018 -0700
     3.3 @@ -213,6 +213,7 @@
     3.4  static jmethodID midSetWindowStyle;
     3.5  static jmethodID midSetOrientation;
     3.6  static jmethodID midGetContext;
     3.7 +static jmethodID midIsTablet;
     3.8  static jmethodID midIsAndroidTV;
     3.9  static jmethodID midIsChromebook;
    3.10  static jmethodID midIsDeXMode;
    3.11 @@ -232,7 +233,6 @@
    3.12  static jmethodID midSetSystemCursor;
    3.13  static jmethodID midSupportsRelativeMouse;
    3.14  static jmethodID midSetRelativeMouseEnabled;
    3.15 -static jmethodID midIsTablet;
    3.16  
    3.17  /* audio manager */
    3.18  static jclass mAudioManagerClass;
    3.19 @@ -319,6 +319,8 @@
    3.20                                  "setOrientation","(IIZLjava/lang/String;)V");
    3.21      midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.22                                  "getContext","()Landroid/content/Context;");
    3.23 +    midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.24 +                                "isTablet", "()Z");
    3.25      midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.26                                  "isAndroidTV","()Z");
    3.27      midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    3.28 @@ -355,15 +357,14 @@
    3.29      midSupportsRelativeMouse = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "supportsRelativeMouse", "()Z");
    3.30      midSetRelativeMouseEnabled = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
    3.31  
    3.32 -    midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "isTablet", "()Z");
    3.33  
    3.34      if (!midGetNativeSurface ||
    3.35 -       !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
    3.36 +       !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInputGetInputDeviceIds ||
    3.37         !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
    3.38         !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
    3.39         !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
    3.40         !midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
    3.41 -       !midIsChromebook || !midIsDeXMode || !midManualBackButton || !midIsTablet) {
    3.42 +       !midIsChromebook || !midIsDeXMode || !midManualBackButton) {
    3.43          __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
    3.44      }
    3.45  
    3.46 @@ -2033,6 +2034,12 @@
    3.47      return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
    3.48  }
    3.49  
    3.50 +SDL_bool SDL_IsAndroidTablet(void)
    3.51 +{
    3.52 +    JNIEnv *env = Android_JNI_GetEnv();
    3.53 +    return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsTablet);
    3.54 +}
    3.55 +
    3.56  SDL_bool SDL_IsAndroidTV(void)
    3.57  {
    3.58      JNIEnv *env = Android_JNI_GetEnv();
    3.59 @@ -2051,12 +2058,6 @@
    3.60      return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsDeXMode);
    3.61  }
    3.62  
    3.63 -SDL_bool SDL_IsTablet(void)
    3.64 -{
    3.65 -    JNIEnv *env = Android_JNI_GetEnv();
    3.66 -    return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsTablet);
    3.67 -}
    3.68 -
    3.69  void SDL_AndroidBackButton(void)
    3.70  {
    3.71      JNIEnv *env = Android_JNI_GetEnv();
     4.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Tue Aug 21 19:42:19 2018 -0700
     4.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Tue Aug 21 20:03:54 2018 -0700
     4.3 @@ -680,8 +680,6 @@
     4.4  #define SDL_wcsdup SDL_wcsdup_REAL
     4.5  #define SDL_GameControllerRumble SDL_GameControllerRumble_REAL
     4.6  #define SDL_JoystickRumble SDL_JoystickRumble_REAL
     4.7 -#define SDL_IsTablet SDL_IsTablet_REAL
     4.8 -#define SDL_IsTablet SDL_IsTablet_REAL
     4.9  #define SDL_NumSensors SDL_NumSensors_REAL
    4.10  #define SDL_SensorGetDeviceName SDL_SensorGetDeviceName_REAL
    4.11  #define SDL_SensorGetDeviceType SDL_SensorGetDeviceType_REAL
    4.12 @@ -696,3 +694,4 @@
    4.13  #define SDL_SensorGetData SDL_SensorGetData_REAL
    4.14  #define SDL_SensorClose SDL_SensorClose_REAL
    4.15  #define SDL_SensorUpdate SDL_SensorUpdate_REAL
    4.16 +#define SDL_IsTablet SDL_IsTablet_REAL
     5.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Aug 21 19:42:19 2018 -0700
     5.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Tue Aug 21 20:03:54 2018 -0700
     5.3 @@ -722,9 +722,6 @@
     5.4  SDL_DYNAPI_PROC(wchar_t*,SDL_wcsdup,(const wchar_t *a),(a),return)
     5.5  SDL_DYNAPI_PROC(int,SDL_GameControllerRumble,(SDL_GameController *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
     5.6  SDL_DYNAPI_PROC(int,SDL_JoystickRumble,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
     5.7 -#if defined(__ANDROID__) || defined(__IPHONEOS__)
     5.8 -SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
     5.9 -#endif
    5.10  SDL_DYNAPI_PROC(int,SDL_NumSensors,(void),(),return)
    5.11  SDL_DYNAPI_PROC(const char*,SDL_SensorGetDeviceName,(int a),(a),return)
    5.12  SDL_DYNAPI_PROC(SDL_SensorType,SDL_SensorGetDeviceType,(int a),(a),return)
    5.13 @@ -739,3 +736,4 @@
    5.14  SDL_DYNAPI_PROC(int,SDL_SensorGetData,(SDL_Sensor *a, float *b, int c),(a,b,c),return)
    5.15  SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),)
    5.16  SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
    5.17 +SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
     6.1 --- a/src/video/uikit/SDL_uikitvideo.m	Tue Aug 21 19:42:19 2018 -0700
     6.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Tue Aug 21 20:03:54 2018 -0700
     6.3 @@ -237,9 +237,9 @@
     6.4   * iOS Tablet detection
     6.5   *
     6.6   * This doesn't really have aything to do with the interfaces of the SDL video
     6.7 - *  subsystem, but we need to stuff this into an Objective-C source code file.
     6.8 + * subsystem, but we need to stuff this into an Objective-C source code file.
     6.9   */
    6.10 -SDL_bool SDL_IsTablet(void)
    6.11 +SDL_bool SDL_IsIPad(void)
    6.12  {
    6.13      return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
    6.14  }