build-scripts/androidbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 17 Aug 2014 14:57:52 -0700
changeset 9086 c5e33f9a0d03
parent 7974 8af2b2344e9e
child 9823 9fb8a612dd7c
permissions -rwxr-xr-x
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different

Tim McDaniel

On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.

I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.

If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
     1 #!/bin/bash
     2 
     3 SOURCES=()
     4 MKSOURCES=""
     5 CURDIR=`pwd -P`
     6 
     7 # Fetch sources
     8 if [[ $# -ge 2 ]]; then
     9     for src in ${@:2}
    10     do
    11         SOURCES+=($src)
    12         MKSOURCES="$MKSOURCES $(basename $src)"
    13     done
    14 else
    15     if [ -n "$1" ]; then
    16         while read src
    17         do
    18             SOURCES+=($src)
    19             MKSOURCES="$MKSOURCES $(basename $src)"
    20         done
    21     fi
    22 fi
    23 
    24 if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    25     echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    26     echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    27     echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
    28     echo "You can pass additional arguments to ndk-build with the NDKARGS variable: NDKARGS=\"-s\" androidbuild.sh ..."
    29     exit 1
    30 fi
    31 
    32 
    33 
    34 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    35 
    36 NDKBUILD=`which ndk-build`
    37 if [ -z "$NDKBUILD" ];then
    38     echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    39     exit 1
    40 fi
    41 
    42 ANDROID=`which android`
    43 if [ -z "$ANDROID" ];then
    44     echo "Could not find the android utility, install Android's SDK and add it to the path"
    45     exit 1
    46 fi
    47 
    48 ANT=`which ant`
    49 
    50 if [ -z "$ANT" ];then
    51     echo "Could not find the ant utility, install Android's SDK and add it to the path"
    52     exit 1
    53 fi
    54 
    55 NCPUS="1"
    56 case "$OSTYPE" in
    57     darwin*)
    58         NCPU=`sysctl -n hw.ncpu`
    59         ;; 
    60     linux*)
    61         if [ -n `which nproc` ]; then
    62             NCPUS=`nproc`
    63         fi  
    64         ;;
    65   *);;
    66 esac
    67 
    68 APP="$1"
    69 APPARR=(${APP//./ })
    70 BUILDPATH="$SDLPATH/build/$APP"
    71 
    72 # Start Building
    73 
    74 rm -rf $BUILDPATH
    75 mkdir -p $BUILDPATH
    76 
    77 cp -r $SDLPATH/android-project/* $BUILDPATH
    78 
    79 # Copy SDL sources
    80 mkdir -p $BUILDPATH/jni/SDL
    81 if [ -z "$COPYSOURCE" ]; then
    82     ln -s $SDLPATH/src $BUILDPATH/jni/SDL
    83     ln -s $SDLPATH/include $BUILDPATH/jni/SDL
    84 else
    85     cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    86     cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    87 fi
    88 
    89 cp -r $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    90 sed -i "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    91 sed -i "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    92 
    93 # Copy user sources
    94 for src in "${SOURCES[@]}"
    95 do
    96     cp $src $BUILDPATH/jni/src
    97 done
    98 
    99 # Create an inherited Activity
   100 cd $BUILDPATH/src
   101 for folder in "${APPARR[@]}"
   102 do
   103     mkdir -p $folder
   104     cd $folder
   105 done
   106 
   107 ACTIVITY="${folder}Activity"
   108 sed -i "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
   109 sed -i "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
   110 
   111 # Fill in a default Activity
   112 echo "package $APP;" >  "$ACTIVITY.java"
   113 echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
   114 echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
   115 
   116 # Update project and build
   117 cd $BUILDPATH
   118 android update project --path $BUILDPATH
   119 $NDKBUILD -j $NCPUS $NDKARGS
   120 $ANT debug
   121 
   122 cd $CURDIR
   123 
   124 APK="$BUILDPATH/bin/$APP-debug.apk"
   125 
   126 if [ -f "$APK" ]; then
   127     echo "Your APK is ready at $APK"
   128     echo "To install to your device: "
   129     echo "cd  $BUILDPATH"
   130     echo "ant debug install"
   131     exit 0
   132 fi
   133 
   134 echo "There was an error building the APK"
   135 exit 1