build-scripts/androidbuild.sh
author Ryan C. Gordon
Mon, 21 Aug 2017 00:42:06 -0400
changeset 11334 749cb40916f2
parent 10200 c678dcec4f44
child 11647 5816b27073a4
permissions -rwxr-xr-x
x11: specify event mask for buttons when grabbing pointer (thanks, Stas!).

This fixes a strange corner case (notes appended below), and should be
safe to do anyhow.

Fixes Bugzilla #3674.

"I did more tests.
It appears the bug only happens if there is
another window on the screen that has "always
on top" property. For me it is xawtv - it is
always opened in a screen corner. Closing
xawtv or removing "always on top" property
from it makes the problem to go away.
Plus, it doesn't appear like the buttons are
not delivered at all. It appears that instead
the button presses are delivered on some mouse
positions, but not delivered when you move the
mouse to other part of the window... So this is
really weird and is likely somewhere deep in the
Xorg.
Maybe somehow it happens that the cursor is
actually above the xawtv window, but, because
my app uses grab, it is not visible there, and
in that case the events are not delivered to
my app?
But with my patch the button events are
always delivered flawlessly, it seems.

Hmm, and that indeed seems to explain my problem:
if the mask is set properly and my app uses
grab, then, even if the mouse is above some
other window, the events would still be delivered
to the grabbing app, which is what actually wanted
because my app uses relative mouse mode, so it
doesn't know the pointer can cross some other window
(my app draws the pointer itself).
So my current theory is that my patch only enforces
the mouse grab, which otherwise can be tricked by
some other window preventing the button events
delivery (but motion events are still delivered
via xinput2, which makes it all look very obscure)."
     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 -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    91 sed -i -e "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 -e "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
   109 sed -i -e "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