From a967016781c780c2bd5ad42f82891bd83fc394eb Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Tue, 8 Oct 2019 18:39:36 +0300 Subject: [PATCH] XSDL: fixed help message --- .../ballfield/AndroidAppSettings.cfg | 12 ++-- .../ballfield/{ballfield.cpp => ballfield.c} | 21 ++----- project/jni/application/ballfield/socket.c | 58 +++++++++++++++++++ .../xserver/AndroidAppSettings.cfg | 2 +- .../jni/application/xserver/AndroidBuild.sh | 2 +- project/jni/application/xserver/gfx.c | 14 +++-- project/jni/application/xserver/main.c | 13 +++-- project/jni/application/xserver/xserver | 2 +- 8 files changed, 90 insertions(+), 34 deletions(-) rename project/jni/application/ballfield/{ballfield.cpp => ballfield.c} (98%) create mode 100644 project/jni/application/ballfield/socket.c diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index 56ad0e328..e9ac3fc67 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -262,19 +262,19 @@ AppMinimumRAM=0 NDK_TOOLCHAIN_VERSION=clang # Android platform version. -# android-16 = Android 4.1, the earliest supported version for NDK r18. +# android-16 = Android 4.1, the earliest supported version in NDK r18. # android-18 = Android 4.3, the first version supporting GLES3. # android-21 = Android 5.1, the first version with SO_REUSEPORT defined. APP_PLATFORM= # Specify architectures to compile, 'all' or 'y' to compile for all architectures. -# Available architectures: armeabi-v7a x86 arm64-v8a x86_64 -MultiABI='arm64-v8a' # armeabi-v7a x86 x86_64 +# Available architectures: armeabi-v7a arm64-v8a x86 x86_64 +MultiABI='arm64-v8a' # Optional shared libraries to compile - removing some of them will save space -# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed +# MP3 patents are expired, but libmad license is GPL, not LGPL # Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2 -CompiledLibraries="sdl_image icui18n iculx icu-le-hb harfbuzz icudata icuuc iconv charset" +CompiledLibraries="sdl_image c++_shared" # Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n) CustomBuildScript=n @@ -283,7 +283,7 @@ CustomBuildScript=n AppCflags='' # Aditional C++-specific compiler flags for application, added after AppCflags -AppCppflags='-fexceptions' +AppCppflags='' # Additional LDFLAGS for application AppLdflags='' diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.c similarity index 98% rename from project/jni/application/ballfield/ballfield.cpp rename to project/jni/application/ballfield/ballfield.c index 2a4c359c0..858833471 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -24,6 +23,9 @@ #define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__) #define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__) +extern int create_server_socket(int portno); + + /*---------------------------------------------------------- Definitions... ----------------------------------------------------------*/ @@ -411,16 +413,6 @@ void tiled_back(SDL_Surface *back, SDL_Surface *screen, int xo, int yo) SDL_BlitSurface(back, NULL, screen, &r); } -void throw_something_more() -{ - throw std::runtime_error("Exception: whoops"); -} - -void throw_something() -{ - throw_something_more(); -} - /*---------------------------------------------------------- main() ----------------------------------------------------------*/ @@ -594,6 +586,8 @@ int main(int argc, char* argv[]) } //SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, 1); //SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, 1); + + create_server_socket(6000); while(1) { @@ -700,11 +694,6 @@ int main(int argc, char* argv[]) { SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 1); SDL_ANDROID_SetMouseEmulationMode(0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1); - try { - throw_something(); - } catch (const std::exception & e) { - __android_log_print(ANDROID_LOG_INFO, "Ballfield", "Got exception: %s", e.what()); - } } if(evt.key.keysym.sym == SDLK_1) { diff --git a/project/jni/application/ballfield/socket.c b/project/jni/application/ballfield/socket.c new file mode 100644 index 000000000..6a83f1040 --- /dev/null +++ b/project/jni/application/ballfield/socket.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__) +#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__) + + + +void error(const char *msg) +{ + perror(msg); + __android_log_print(ANDROID_LOG_ERROR, "Ballfield", "%s", msg); + exit(1); +} + +int create_server_socket(int portno) +{ + int sockfd, newsockfd; + socklen_t clilen; + char buffer[256]; + struct sockaddr_in serv_addr, cli_addr; + int n; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) error("ERROR opening socket"); + bzero((char *) &serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(portno); + if (bind(sockfd, (struct sockaddr *) &serv_addr, + sizeof(serv_addr)) < 0) error("ERROR on binding"); + listen(sockfd,5); + __android_log_print(ANDROID_LOG_INFO, "Ballfield", "Opened TCP socket %d port %d", sockfd, portno); + return 0; + /* + clilen = sizeof(cli_addr); + newsockfd = accept(sockfd, + (struct sockaddr *) &cli_addr, + &clilen); + if (newsockfd < 0) + error("ERROR on accept"); + bzero(buffer,256); + n = read(newsockfd,buffer,255); + if (n < 0) error("ERROR reading from socket"); + printf("Here is the message: %s\n",buffer); + n = write(newsockfd,"I got your message",18); + if (n < 0) error("ERROR writing to socket"); + close(newsockfd); + close(sockfd); + return 0; + */ +} diff --git a/project/jni/application/xserver/AndroidAppSettings.cfg b/project/jni/application/xserver/AndroidAppSettings.cfg index 1e903f301..89b4b25d4 100644 --- a/project/jni/application/xserver/AndroidAppSettings.cfg +++ b/project/jni/application/xserver/AndroidAppSettings.cfg @@ -275,7 +275,7 @@ MultiABI='arm64-v8a' # Optional shared libraries to compile - removing some of them will save space # MP3 patents are expired, but libmad license is GPL, not LGPL # Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2 -CompiledLibraries="jpeg png freetype sdl_ttf crypto" +CompiledLibraries="freetype sdl_ttf crypto sdl_savepng jpeg png" # Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n) CustomBuildScript=y diff --git a/project/jni/application/xserver/AndroidBuild.sh b/project/jni/application/xserver/AndroidBuild.sh index d1c04c414..03c66f9a0 100755 --- a/project/jni/application/xserver/AndroidBuild.sh +++ b/project/jni/application/xserver/AndroidBuild.sh @@ -70,7 +70,7 @@ xkb/.libs/libxkbstubs.a \ composite/.libs/libcomposite.a \ os/.libs/libos.a \ -L$CURDIR/../../../libs/'"$1"' \ --lpixman-1 -lXfont2 -lXau -lxshmfence -lXdmcp -lfontenc -lfreetype \ +-lpixman-1 -lXfont2 -lXau -lxshmfence -lXdmcp -lfontenc -lfreetype -lsdl_savepng -lpng \ -llog -lsdl-1.2 -lsdl_native_helpers -lGLESv1_CM -landroid-shmem -l:libcrypto.so.sdl.1.so -lz -lm -ldl' \ || exit 1 diff --git a/project/jni/application/xserver/gfx.c b/project/jni/application/xserver/gfx.c index edfc31410..b8824e5ee 100644 --- a/project/jni/application/xserver/gfx.c +++ b/project/jni/application/xserver/gfx.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "gfx.h" @@ -767,13 +768,13 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i { surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 16, 16, 24, 0x0000ff, 0x00ff00, 0xff0000, 0); SDL_FillRect(surf, NULL, 0x00002f); - SDL_SaveBMP(surf, "background.bmp"); + SDL_SavePNG(surf, "background.png"); SDL_FreeSurface(surf); return; } surf = SDL_CreateRGBSurface(SDL_SWSURFACE, resolutionW, resolutionH, 24, 0x0000ff, 0x00ff00, 0xff0000, 0); - SDL_FillRect(surf, NULL, 0x00002f); + SDL_FillRect(surf, NULL, 0x7f0000); renderStringScaled("Launch these commands on your Linux PC:", 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf); y += resolutionH * 30 / VID_Y; @@ -810,7 +811,7 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i sprintf (msg, "export PULSE_SERVER=tcp:%s:4712", saddr); renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf); y += resolutionH * 15 / VID_Y; - sprintf (msg, "gnome-session & gimp"); + sprintf (msg, "x-window-manager & gimp"); renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf); y += resolutionH * 20 / VID_Y; } @@ -833,7 +834,7 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i sprintf (msg, "export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4712"); renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf); - SDL_SaveBMP(surf, "background.bmp"); + SDL_SavePNG(surf, "background.png"); SDL_FreeSurface(surf); } @@ -928,11 +929,14 @@ void renderString(const char *c, int x, int y) void renderStringScaled(const char *c, int size, int x, int y, int r, int g, int b, SDL_Surface * surf) { + char fontpath[PATH_MAX]; if (!c || !c[0]) return; SDL_Color fColor = {r, g, b}; SDL_Rect fontRect = {0, 0, 0, 0}; - TTF_Font* font = TTF_OpenFont("DroidSansMono.ttf", size); + strcpy( fontpath, getenv("UNSECURE_STORAGE_DIR") ); + strcat( fontpath, "/DroidSansMono.ttf" ); + TTF_Font* font = TTF_OpenFont(fontpath, size); SDL_Surface* fontSurface = TTF_RenderUTF8_Solid(font, c, fColor); TTF_CloseFont(font); fontRect.w = fontSurface->w; diff --git a/project/jni/application/xserver/main.c b/project/jni/application/xserver/main.c index 8e6c56757..7364d9f19 100644 --- a/project/jni/application/xserver/main.c +++ b/project/jni/application/xserver/main.c @@ -34,7 +34,11 @@ int main( int argc, char* argv[] ) port, "-nolock", "-noreset", - "-pn", + "-nopn", + "-listen", + "inet", + "-listen", + "inet6", "-nolisten", "unix", "-fp", @@ -42,7 +46,7 @@ int main( int argc, char* argv[] ) "-screen", screenres, }; - int argnum = 11; + int argnum = 15; char * envp[] = { NULL }; int printHelp = 1; int screenResOverride = 0; @@ -123,14 +127,15 @@ int main( int argc, char* argv[] ) sprintf( screenres, "%d/%dx%d/%dx%d", resolutionW, displayW, resolutionH, displayH, SDL_GetVideoInfo()->vfmt->BitsPerPixel ); } - XSDL_generateBackground( port, printHelp, 800, 600 ); + XSDL_generateBackground( port, printHelp, 600 * resolutionW / resolutionH, 600 ); XSDL_deinitSDL(); if( printHelp ) { - sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xloadimage -onroot -fullscreen %s/background.bmp", + sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xloadimage -onroot -fullscreen %s/background.png", getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("UNSECURE_STORAGE_DIR") ); + args[argnum] = "-exec"; args[argnum+1] = clientcmd; argnum += 2; diff --git a/project/jni/application/xserver/xserver b/project/jni/application/xserver/xserver index 084e48f43..6473d4669 160000 --- a/project/jni/application/xserver/xserver +++ b/project/jni/application/xserver/xserver @@ -1 +1 @@ -Subproject commit 084e48f430dd0a58d58eb2391c4353019f7a3693 +Subproject commit 6473d46696c31779c986b77f3fb36078553c631b