Added SDL_GetDisplayOrientation() to get the display orientation, and added a new event SDL_DISPLAYEVENT to notify the application when the orientation changes.
authorSam Lantinga <slouken@libsdl.org>
Wed, 22 Aug 2018 21:48:28 -0700
changeset 12143673ec0369266
parent 12142 b2123abf97e0
child 12144 c48e1ae67968
Added SDL_GetDisplayOrientation() to get the display orientation, and added a new event SDL_DISPLAYEVENT to notify the application when the orientation changes.
Documented the values returned by the accelerometer and gyroscope sensors
Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
include/SDL_events.h
include/SDL_sensor.h
include/SDL_video.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/events/SDL_displayevents.c
src/events/SDL_displayevents_c.h
src/events/SDL_events_c.h
src/sensor/coremotion/SDL_coremotionsensor.m
src/test/SDL_test_common.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Wed Aug 22 17:44:28 2018 -0700
     1.2 +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Wed Aug 22 21:48:28 2018 -0700
     1.3 @@ -113,6 +113,9 @@
     1.4  		93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; };
     1.5  		A704172E20F7E74800A82227 /* controller_type.h in Headers */ = {isa = PBXBuildFile; fileRef = A704172D20F7E74800A82227 /* controller_type.h */; };
     1.6  		A704172F20F7E76000A82227 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; };
     1.7 +		A7C19D29212E552C00DF2152 /* SDL_displayevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */; };
     1.8 +		A7C19D2A212E552C00DF2152 /* SDL_displayevents.c in Sources */ = {isa = PBXBuildFile; fileRef = A7C19D28212E552B00DF2152 /* SDL_displayevents.c */; };
     1.9 +		A7C19D2B212E552C00DF2152 /* SDL_displayevents.c in Sources */ = {isa = PBXBuildFile; fileRef = A7C19D28212E552B00DF2152 /* SDL_displayevents.c */; };
    1.10  		A7F629241FE06523002F9CC9 /* SDL_uikitmetalview.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D7516F81EE1C28A00820EEA /* SDL_uikitmetalview.m */; };
    1.11  		AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; };
    1.12  		AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */; };
    1.13 @@ -454,6 +457,8 @@
    1.14  		93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = "<group>"; };
    1.15  		93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = "<group>"; };
    1.16  		A704172D20F7E74800A82227 /* controller_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = controller_type.h; sourceTree = "<group>"; };
    1.17 +		A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_displayevents_c.h; sourceTree = "<group>"; };
    1.18 +		A7C19D28212E552B00DF2152 /* SDL_displayevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_displayevents.c; sourceTree = "<group>"; };
    1.19  		AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gamecontroller.c; sourceTree = "<group>"; };
    1.20  		AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamecontroller.h; sourceTree = "<group>"; };
    1.21  		AA0F8494178D5F1A00823F9D /* SDL_systls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systls.c; sourceTree = "<group>"; };
    1.22 @@ -1109,6 +1114,8 @@
    1.23  				FD99B9920DD52EDC00FB1D6B /* scancodes_xfree86.h */,
    1.24  				0420496F11E6F03D007E7EC9 /* SDL_clipboardevents.c */,
    1.25  				0420496E11E6F03D007E7EC9 /* SDL_clipboardevents_c.h */,
    1.26 +				A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */,
    1.27 +				A7C19D28212E552B00DF2152 /* SDL_displayevents.c */,
    1.28  				AA704DD5162AA90A0076D1C1 /* SDL_dropevents.c */,
    1.29  				AA704DD4162AA90A0076D1C1 /* SDL_dropevents_c.h */,
    1.30  				FD99B9930DD52EDC00FB1D6B /* SDL_events.c */,
    1.31 @@ -1326,6 +1333,7 @@
    1.32  				F30D9CA7212CD0BF0047DF2E /* SDL_coremotionsensor.h in Headers */,
    1.33  				AA7558AF1595D55500BBD41B /* SDL_main.h in Headers */,
    1.34  				AA7558B01595D55500BBD41B /* SDL_mouse.h in Headers */,
    1.35 +				A7C19D29212E552C00DF2152 /* SDL_displayevents_c.h in Headers */,
    1.36  				AA7558B11595D55500BBD41B /* SDL_mutex.h in Headers */,
    1.37  				AA7558B21595D55500BBD41B /* SDL_name.h in Headers */,
    1.38  				AA7558B31595D55500BBD41B /* SDL_opengl.h in Headers */,
    1.39 @@ -1557,6 +1565,7 @@
    1.40  				FAB598731BB5C31600BE72C5 /* SDL_iconv.c in Sources */,
    1.41  				FAB598741BB5C31600BE72C5 /* SDL_malloc.c in Sources */,
    1.42  				FAB598751BB5C31600BE72C5 /* SDL_qsort.c in Sources */,
    1.43 +				A7C19D2B212E552C00DF2152 /* SDL_displayevents.c in Sources */,
    1.44  				FAB598761BB5C31600BE72C5 /* SDL_stdlib.c in Sources */,
    1.45  				FAB598771BB5C31600BE72C5 /* SDL_string.c in Sources */,
    1.46  				FAB598781BB5C31600BE72C5 /* SDL_syscond.c in Sources */,
    1.47 @@ -1677,6 +1686,7 @@
    1.48  				FD689F1F0E26E5D900F90B21 /* SDL_uikitopengles.m in Sources */,
    1.49  				FD689F210E26E5D900F90B21 /* SDL_uikitvideo.m in Sources */,
    1.50  				FD689F230E26E5D900F90B21 /* SDL_uikitview.m in Sources */,
    1.51 +				A7C19D2A212E552C00DF2152 /* SDL_displayevents.c in Sources */,
    1.52  				FD689F250E26E5D900F90B21 /* SDL_uikitwindow.m in Sources */,
    1.53  				FD689F270E26E5D900F90B21 /* SDL_uikitopenglview.m in Sources */,
    1.54  				FD689FCE0E26E9D400F90B21 /* SDL_uikitappdelegate.m in Sources */,
     2.1 --- a/include/SDL_events.h	Wed Aug 22 17:44:28 2018 -0700
     2.2 +++ b/include/SDL_events.h	Wed Aug 22 21:48:28 2018 -0700
     2.3 @@ -85,6 +85,9 @@
     2.4                                       Called on Android in onResume()
     2.5                                  */
     2.6  
     2.7 +    /* Display events */
     2.8 +    SDL_DISPLAYEVENT   = 0x150,  /**< Display state change */
     2.9 +
    2.10      /* Window events */
    2.11      SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    2.12      SDL_SYSWMEVENT,             /**< System specific event */
    2.13 @@ -172,6 +175,21 @@
    2.14  } SDL_CommonEvent;
    2.15  
    2.16  /**
    2.17 + *  \brief Display state change event data (event.display.*)
    2.18 + */
    2.19 +typedef struct SDL_DisplayEvent
    2.20 +{
    2.21 +    Uint32 type;        /**< ::SDL_DISPLAYEVENT */
    2.22 +    Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
    2.23 +    Uint32 display;     /**< The associated display index */
    2.24 +    Uint8 event;        /**< ::SDL_DisplayEventID */
    2.25 +    Uint8 padding1;
    2.26 +    Uint8 padding2;
    2.27 +    Uint8 padding3;
    2.28 +    Sint32 data1;       /**< event dependent data */
    2.29 +} SDL_DisplayEvent;
    2.30 +
    2.31 +/**
    2.32   *  \brief Window state change event data (event.window.*)
    2.33   */
    2.34  typedef struct SDL_WindowEvent
    2.35 @@ -540,6 +558,7 @@
    2.36  {
    2.37      Uint32 type;                    /**< Event type, shared with all events */
    2.38      SDL_CommonEvent common;         /**< Common event data */
    2.39 +    SDL_DisplayEvent display;       /**< Window event data */
    2.40      SDL_WindowEvent window;         /**< Window event data */
    2.41      SDL_KeyboardEvent key;          /**< Keyboard event data */
    2.42      SDL_TextEditingEvent edit;      /**< Text editing event data */
     3.1 --- a/include/SDL_sensor.h	Wed Aug 22 17:44:28 2018 -0700
     3.2 +++ b/include/SDL_sensor.h	Wed Aug 22 21:48:28 2018 -0700
     3.3 @@ -68,6 +68,51 @@
     3.4      SDL_SENSOR_GYRO,            /**< Gyroscope */
     3.5  } SDL_SensorType;
     3.6  
     3.7 +/**
     3.8 + * Accelerometer sensor
     3.9 + *
    3.10 + * The accelerometer returns the current acceleration in SI meters per
    3.11 + * second squared. This includes gravity, so a device at rest will have
    3.12 + * an acceleration of SDL_STANDARD_GRAVITY straight down.
    3.13 + *
    3.14 + * values[0]: Acceleration on the x axis
    3.15 + * values[1]: Acceleration on the y axis
    3.16 + * values[2]: Acceleration on the z axis
    3.17 + *
    3.18 + * For phones held in portrait mode, the axes are defined as follows:
    3.19 + * -X ... +X : left ... right
    3.20 + * -Y ... +Y : bottom ... top
    3.21 + * -Z ... +Z : farther ... closer
    3.22 + * 
    3.23 + * The axis data is not changed when the phone is rotated.
    3.24 + *
    3.25 + * \sa SDL_GetDisplayOrientation()
    3.26 + */
    3.27 +#define SDL_STANDARD_GRAVITY    9.80665f
    3.28 +
    3.29 +/**
    3.30 + * Gyroscope sensor
    3.31 + *
    3.32 + * The gyroscope returns the current rate of rotation in radians per second.
    3.33 + * The rotation is positive in the counter-clockwise direction. That is,
    3.34 + * an observer looking from a positive location on one of the axes would
    3.35 + * see positive rotation on that axis when it appeared to be rotating
    3.36 + * counter-clockwise.
    3.37 + *
    3.38 + * values[0]: Angular speed around the x axis
    3.39 + * values[1]: Angular speed around the y axis
    3.40 + * values[2]: Angular speed around the z axis
    3.41 + *
    3.42 + * For phones held in portrait mode, the axes are defined as follows:
    3.43 + * -X ... +X : left ... right
    3.44 + * -Y ... +Y : bottom ... top
    3.45 + * -Z ... +Z : farther ... closer
    3.46 + * 
    3.47 + * The axis data is not changed when the phone is rotated.
    3.48 + *
    3.49 + * \sa SDL_GetDisplayOrientation()
    3.50 + */
    3.51 +
    3.52  /* Function prototypes */
    3.53  
    3.54  /**
     4.1 --- a/include/SDL_video.h	Wed Aug 22 17:44:28 2018 -0700
     4.2 +++ b/include/SDL_video.h	Wed Aug 22 21:48:28 2018 -0700
     4.3 @@ -170,6 +170,24 @@
     4.4  } SDL_WindowEventID;
     4.5  
     4.6  /**
     4.7 + *  \brief Event subtype for display events
     4.8 + */
     4.9 +typedef enum
    4.10 +{
    4.11 +    SDL_DISPLAYEVENT_NONE,          /**< Never used */
    4.12 +    SDL_DISPLAYEVENT_ORIENTATION,   /**< Display orientation has changed to data1 */
    4.13 +} SDL_DisplayEventID;
    4.14 +
    4.15 +typedef enum
    4.16 +{
    4.17 +    SDL_ORIENTATION_UNKNOWN,            /**< The display orientation can't be determined */
    4.18 +    SDL_ORIENTATION_LANDSCAPE,          /**< The display is in landscape mode, with the right side up, relative to portrait mode */
    4.19 +    SDL_ORIENTATION_LANDSCAPE_FLIPPED,  /**< The display is in landscape mode, with the left side up, relative to portrait mode */
    4.20 +    SDL_ORIENTATION_PORTRAIT,           /**< The display is in portrait mode */
    4.21 +    SDL_ORIENTATION_PORTRAIT_FLIPPED,   /**< The display is in portrait mode, upside down */
    4.22 +} SDL_DisplayOrientation;
    4.23 +
    4.24 +/**
    4.25   *  \brief An opaque handle to an OpenGL context.
    4.26   */
    4.27  typedef void *SDL_GLContext;
    4.28 @@ -317,18 +335,6 @@
    4.29  extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);
    4.30  
    4.31  /**
    4.32 - *  \brief Get the dots/pixels-per-inch for a display
    4.33 - *
    4.34 - *  \note Diagonal, horizontal and vertical DPI can all be optionally
    4.35 - *        returned if the parameter is non-NULL.
    4.36 - *
    4.37 - *  \return 0 on success, or -1 if no DPI information is available or the index is out of range.
    4.38 - *
    4.39 - *  \sa SDL_GetNumVideoDisplays()
    4.40 - */
    4.41 -extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi);
    4.42 -
    4.43 -/**
    4.44   *  \brief Get the usable desktop area represented by a display, with the
    4.45   *         primary display located at 0,0
    4.46   *
    4.47 @@ -348,6 +354,27 @@
    4.48  extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect);
    4.49  
    4.50  /**
    4.51 + *  \brief Get the dots/pixels-per-inch for a display
    4.52 + *
    4.53 + *  \note Diagonal, horizontal and vertical DPI can all be optionally
    4.54 + *        returned if the parameter is non-NULL.
    4.55 + *
    4.56 + *  \return 0 on success, or -1 if no DPI information is available or the index is out of range.
    4.57 + *
    4.58 + *  \sa SDL_GetNumVideoDisplays()
    4.59 + */
    4.60 +extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi);
    4.61 +
    4.62 +/**
    4.63 + *  \brief Get the orientation of a display
    4.64 + *
    4.65 + *  \return The orientation of the display, or SDL_ORIENTATION_UNKNOWN if it isn't available.
    4.66 + *
    4.67 + *  \sa SDL_GetNumVideoDisplays()
    4.68 + */
    4.69 +extern DECLSPEC SDL_DisplayOrientation SDLCALL SDL_GetDisplayOrientation(int displayIndex);
    4.70 +
    4.71 +/**
    4.72   *  \brief Returns the number of available display modes.
    4.73   *
    4.74   *  \sa SDL_GetDisplayMode()
     5.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Wed Aug 22 17:44:28 2018 -0700
     5.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Wed Aug 22 21:48:28 2018 -0700
     5.3 @@ -695,3 +695,4 @@
     5.4  #define SDL_SensorClose SDL_SensorClose_REAL
     5.5  #define SDL_SensorUpdate SDL_SensorUpdate_REAL
     5.6  #define SDL_IsTablet SDL_IsTablet_REAL
     5.7 +#define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
     6.1 --- a/src/dynapi/SDL_dynapi_procs.h	Wed Aug 22 17:44:28 2018 -0700
     6.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Wed Aug 22 21:48:28 2018 -0700
     6.3 @@ -737,3 +737,4 @@
     6.4  SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),)
     6.5  SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),)
     6.6  SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
     6.7 +SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return)
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/events/SDL_displayevents.c	Wed Aug 22 21:48:28 2018 -0700
     7.3 @@ -0,0 +1,61 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +#include "../SDL_internal.h"
    7.25 +
    7.26 +/* Display event handling code for SDL */
    7.27 +
    7.28 +#include "SDL_events.h"
    7.29 +#include "SDL_events_c.h"
    7.30 +#include "../video/SDL_sysvideo.h"
    7.31 +
    7.32 +
    7.33 +int
    7.34 +SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
    7.35 +{
    7.36 +    int posted;
    7.37 +
    7.38 +    if (!display) {
    7.39 +        return 0;
    7.40 +    }
    7.41 +    switch (displayevent) {
    7.42 +    case SDL_DISPLAYEVENT_ORIENTATION:
    7.43 +        if (data1 == SDL_ORIENTATION_UNKNOWN || data1 == display->orientation) {
    7.44 +            return 0;
    7.45 +        }
    7.46 +        display->orientation = (SDL_DisplayOrientation)data1;
    7.47 +        break;
    7.48 +    }
    7.49 +
    7.50 +    /* Post the event, if desired */
    7.51 +    posted = 0;
    7.52 +    if (SDL_GetEventState(SDL_DISPLAYEVENT) == SDL_ENABLE) {
    7.53 +        SDL_Event event;
    7.54 +        event.type = SDL_DISPLAYEVENT;
    7.55 +        event.display.event = displayevent;
    7.56 +        event.display.display = SDL_GetIndexOfDisplay(display);
    7.57 +        event.display.data1 = data1;
    7.58 +        posted = (SDL_PushEvent(&event) > 0);
    7.59 +    }
    7.60 +
    7.61 +    return (posted);
    7.62 +}
    7.63 +
    7.64 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/events/SDL_displayevents_c.h	Wed Aug 22 21:48:28 2018 -0700
     8.3 @@ -0,0 +1,32 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +#include "../SDL_internal.h"
    8.25 +
    8.26 +#ifndef SDL_displayevents_c_h_
    8.27 +#define SDL_displayevents_c_h_
    8.28 +
    8.29 +typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    8.30 +
    8.31 +extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1);
    8.32 +
    8.33 +#endif /* SDL_displayevents_c_h_ */
    8.34 +
    8.35 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/events/SDL_events_c.h	Wed Aug 22 17:44:28 2018 -0700
     9.2 +++ b/src/events/SDL_events_c.h	Wed Aug 22 21:48:28 2018 -0700
     9.3 @@ -24,6 +24,7 @@
     9.4  #include "SDL_events.h"
     9.5  #include "SDL_thread.h"
     9.6  #include "SDL_clipboardevents_c.h"
     9.7 +#include "SDL_displayevents_c.h"
     9.8  #include "SDL_dropevents_c.h"
     9.9  #include "SDL_gesture_c.h"
    9.10  #include "SDL_keyboard_c.h"
    10.1 --- a/src/sensor/coremotion/SDL_coremotionsensor.m	Wed Aug 22 17:44:28 2018 -0700
    10.2 +++ b/src/sensor/coremotion/SDL_coremotionsensor.m	Wed Aug 22 21:48:28 2018 -0700
    10.3 @@ -32,8 +32,6 @@
    10.4  #include "../SDL_syssensor.h"
    10.5  #include "../SDL_sensor_c.h"
    10.6  
    10.7 -#define STANDARD_GRAVITY    9.80665f
    10.8 -
    10.9  typedef struct
   10.10  {
   10.11      SDL_SensorType type;
   10.12 @@ -160,9 +158,9 @@
   10.13              if (accelerometerData) {
   10.14                  CMAcceleration acceleration = accelerometerData.acceleration;
   10.15                  float data[3];
   10.16 -                data[0] = acceleration.x * STANDARD_GRAVITY;
   10.17 -                data[1] = acceleration.y * STANDARD_GRAVITY;
   10.18 -                data[2] = acceleration.z * STANDARD_GRAVITY;
   10.19 +                data[0] = acceleration.x * SDL_STANDARD_GRAVITY;
   10.20 +                data[1] = acceleration.y * SDL_STANDARD_GRAVITY;
   10.21 +                data[2] = acceleration.z * SDL_STANDARD_GRAVITY;
   10.22                  if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
   10.23                      SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
   10.24                      SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
    11.1 --- a/src/test/SDL_test_common.c	Wed Aug 22 17:44:28 2018 -0700
    11.2 +++ b/src/test/SDL_test_common.c	Wed Aug 22 21:48:28 2018 -0700
    11.3 @@ -1049,6 +1049,22 @@
    11.4  }
    11.5  
    11.6  static const char *
    11.7 +DisplayOrientationName(int orientation)
    11.8 +{
    11.9 +    switch (orientation)
   11.10 +    {
   11.11 +#define CASE(X) case SDL_ORIENTATION_##X: return #X
   11.12 +        CASE(UNKNOWN);
   11.13 +        CASE(LANDSCAPE);
   11.14 +        CASE(LANDSCAPE_FLIPPED);
   11.15 +        CASE(PORTRAIT);
   11.16 +        CASE(PORTRAIT_FLIPPED);
   11.17 +#undef CASE
   11.18 +default: return "???";
   11.19 +    }
   11.20 +}
   11.21 +
   11.22 +static const char *
   11.23  ControllerAxisName(const SDL_GameControllerAxis axis)
   11.24  {
   11.25      switch (axis)
   11.26 @@ -1102,6 +1118,17 @@
   11.27      }
   11.28  
   11.29      switch (event->type) {
   11.30 +    case SDL_DISPLAYEVENT:
   11.31 +        switch (event->display.event) {
   11.32 +        case SDL_DISPLAYEVENT_ORIENTATION:
   11.33 +            SDL_Log("SDL EVENT: Display %d changed orientation to %s", event->display.display, DisplayOrientationName(event->display.data1));
   11.34 +            break;
   11.35 +        default:
   11.36 +            SDL_Log("SDL EVENT: Display %d got unknown event 0x%4.4x",
   11.37 +                    event->display.display, event->display.event);
   11.38 +            break;
   11.39 +        }
   11.40 +        break;
   11.41      case SDL_WINDOWEVENT:
   11.42          switch (event->window.event) {
   11.43          case SDL_WINDOWEVENT_SHOWN:
    12.1 --- a/src/video/SDL_sysvideo.h	Wed Aug 22 17:44:28 2018 -0700
    12.2 +++ b/src/video/SDL_sysvideo.h	Wed Aug 22 21:48:28 2018 -0700
    12.3 @@ -119,8 +119,8 @@
    12.4       !((W)->flags & SDL_WINDOW_MINIMIZED))
    12.5  
    12.6  /*
    12.7 - * Define the SDL display structure This corresponds to physical monitors
    12.8 - * attached to the system.
    12.9 + * Define the SDL display structure.
   12.10 + * This corresponds to physical monitors attached to the system.
   12.11   */
   12.12  struct SDL_VideoDisplay
   12.13  {
   12.14 @@ -130,6 +130,7 @@
   12.15      SDL_DisplayMode *display_modes;
   12.16      SDL_DisplayMode desktop_mode;
   12.17      SDL_DisplayMode current_mode;
   12.18 +    SDL_DisplayOrientation orientation;
   12.19  
   12.20      SDL_Window *fullscreen_window;
   12.21  
   12.22 @@ -181,16 +182,16 @@
   12.23      int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   12.24  
   12.25      /*
   12.26 +     * Get the usable bounds of a display (bounds minus menubar or whatever)
   12.27 +     */
   12.28 +    int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   12.29 +
   12.30 +    /*
   12.31       * Get the dots/pixels-per-inch of a display
   12.32       */
   12.33      int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
   12.34  
   12.35      /*
   12.36 -     * Get the usable bounds of a display (bounds minus menubar or whatever)
   12.37 -     */
   12.38 -    int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   12.39 -
   12.40 -    /*
   12.41       * Get a list of the available display modes for a display.
   12.42       */
   12.43      void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   12.44 @@ -426,6 +427,8 @@
   12.45  extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   12.46  extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   12.47  extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   12.48 +extern int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display);
   12.49 +extern SDL_VideoDisplay *SDL_GetDisplay(int displayIndex);
   12.50  extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   12.51  extern void *SDL_GetDisplayDriverData( int displayIndex );
   12.52  
    13.1 --- a/src/video/SDL_video.c	Wed Aug 22 17:44:28 2018 -0700
    13.2 +++ b/src/video/SDL_video.c	Wed Aug 22 21:48:28 2018 -0700
    13.3 @@ -641,7 +641,7 @@
    13.4      return _this->num_displays;
    13.5  }
    13.6  
    13.7 -static int
    13.8 +int
    13.9  SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
   13.10  {
   13.11      int displayIndex;
   13.12 @@ -739,6 +739,17 @@
   13.13      return -1;
   13.14  }
   13.15  
   13.16 +SDL_DisplayOrientation
   13.17 +SDL_GetDisplayOrientation(int displayIndex)
   13.18 +{
   13.19 +    SDL_VideoDisplay *display;
   13.20 +
   13.21 +    CHECK_DISPLAY_INDEX(displayIndex, SDL_ORIENTATION_UNKNOWN);
   13.22 +
   13.23 +    display = &_this->displays[displayIndex];
   13.24 +    return display->orientation;
   13.25 +}
   13.26 +
   13.27  SDL_bool
   13.28  SDL_AddDisplayMode(SDL_VideoDisplay * display,  const SDL_DisplayMode * mode)
   13.29  {
   13.30 @@ -1009,6 +1020,14 @@
   13.31      return 0;
   13.32  }
   13.33  
   13.34 +SDL_VideoDisplay *
   13.35 +SDL_GetDisplay(int displayIndex)
   13.36 +{
   13.37 +    CHECK_DISPLAY_INDEX(displayIndex, NULL);
   13.38 +
   13.39 +    return &_this->displays[displayIndex];
   13.40 +}
   13.41 +
   13.42  int
   13.43  SDL_GetWindowDisplayIndex(SDL_Window * window)
   13.44  {
    14.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Wed Aug 22 17:44:28 2018 -0700
    14.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Wed Aug 22 21:48:28 2018 -0700
    14.3 @@ -451,6 +451,7 @@
    14.4      if (_this && _this->num_displays > 0) {
    14.5          SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
    14.6          SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
    14.7 +        SDL_DisplayOrientation orientation = SDL_ORIENTATION_UNKNOWN;
    14.8  
    14.9          /* The desktop display mode should be kept in sync with the screen
   14.10           * orientation so that updating a window's fullscreen state to
   14.11 @@ -468,6 +469,26 @@
   14.12              currentmode->w = currentmode->h;
   14.13              currentmode->h = height;
   14.14          }
   14.15 +
   14.16 +        switch (application.statusBarOrientation) {
   14.17 +        case UIInterfaceOrientationPortrait:
   14.18 +            orientation = SDL_ORIENTATION_PORTRAIT;
   14.19 +            break;
   14.20 +        case UIInterfaceOrientationPortraitUpsideDown:
   14.21 +            orientation = SDL_ORIENTATION_PORTRAIT_FLIPPED;
   14.22 +            break;
   14.23 +        case UIInterfaceOrientationLandscapeLeft:
   14.24 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
   14.25 +            orientation = SDL_ORIENTATION_LANDSCAPE_FLIPPED;
   14.26 +            break;
   14.27 +        case UIInterfaceOrientationLandscapeRight:
   14.28 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
   14.29 +            orientation = SDL_ORIENTATION_LANDSCAPE;
   14.30 +            break;
   14.31 +        default:
   14.32 +            break;
   14.33 +        }
   14.34 +        SDL_SendDisplayEvent(&_this->displays[0], SDL_DISPLAYEVENT_ORIENTATION, orientation);
   14.35      }
   14.36  }
   14.37  #endif