From e57508f29c4122f6b0fb4f88858e8ad63cd7afeb Mon Sep 17 00:00:00 2001 From: pelya Date: Tue, 5 Nov 2013 07:14:07 +0200 Subject: [PATCH] Xserver: print usage help in background --- project/jni/application/xserver/gfx.c | 77 +++++++++++++++++++++++-- project/jni/application/xserver/main.c | 6 +- project/jni/application/xserver/xserver | 2 +- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/project/jni/application/xserver/gfx.c b/project/jni/application/xserver/gfx.c index 5b8a64b74..2fb6c1936 100644 --- a/project/jni/application/xserver/gfx.c +++ b/project/jni/application/xserver/gfx.c @@ -2,6 +2,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -15,7 +22,7 @@ static int unpackProgressMbTotal = 1; static int unpackFinished = 0; static void renderString(const char *c, int x, int y); -static void renderStringColor(const char *c, int x, int y, int r, int g, int b); +static void renderStringColor(const char *c, int x, int y, int r, int g, int b, SDL_Surface * surf); static void * unpackFilesThread(void * unused); static void showErrorMessage(const char *msg); @@ -141,7 +148,7 @@ void XSDL_unpackFiles() } } -void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, int * displayH) +static void showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, int * displayH) { int x, y, i, ii; SDL_Event event; @@ -238,6 +245,64 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i *displayH = *displayH * (dpiScale / fontsVal[dpi]); } +void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, int * displayH) +{ + int sd, addr, ifc_num, i; + struct ifconf ifc; + struct ifreq ifr[20]; + SDL_Surface * surf; + int y = 40; + + showConfigMenu(resolutionW, displayW, resolutionH, displayH); + + surf = SDL_CreateRGBSurface(SDL_SWSURFACE, VID_X, VID_Y, 24, 0x0000ff, 0x00ff00, 0xff0000, 0); + SDL_FillRect(surf, NULL, 0xffffff); + + renderStringColor("Launch these commands on your Linux PC:", VID_X/2, 15, 0, 0, 0, surf); + + sd = socket(PF_INET, SOCK_DGRAM, 0); + if (sd > 0) + { + ifc.ifc_len = sizeof(ifr); + ifc.ifc_ifcu.ifcu_buf = (caddr_t)ifr; + + if (ioctl(sd, SIOCGIFCONF, &ifc) == 0) + { + ifc_num = ifc.ifc_len / sizeof(struct ifreq); + __android_log_print(ANDROID_LOG_INFO, "XSDL", "%d network interfaces found", ifc_num); + + for (i = 0; i < ifc_num; ++i) + { + int addr = 0; + char saddr[32]; + char msg[128]; + if (ifr[i].ifr_addr.sa_family != AF_INET) + continue; + + if (ioctl(sd, SIOCGIFADDR, &ifr[i]) == 0) + addr = ((struct sockaddr_in *)(&ifr[i].ifr_addr))->sin_addr.s_addr; + if (addr == 0) + continue; + sprintf (saddr, "%d.%d.%d.%d", (addr & 0xFF), (addr >> 8 & 0xFF), (addr >> 16 & 0xFF), (addr >> 24 & 0xFF)); + __android_log_print(ANDROID_LOG_INFO, "XSDL", "interface: %s address: %s\n", ifr[i].ifr_name, saddr); + if (strcmp(saddr, "127.0.0.1") == 0) + continue; + sprintf (msg, "env DISPLAY=%s:1111 metacity &", saddr); + renderStringColor(msg, VID_X/2, y, 0, 0, 0, surf); + y += 15; + sprintf (msg, "env DISPLAY=%s:1111 gimp", saddr); + renderStringColor(msg, VID_X/2, y, 0, 0, 0, surf); + y += 20; + } + } + + close(sd); + } + + SDL_SaveBMP(surf, "help.bmp"); + SDL_FreeSurface(surf); +} + void showErrorMessage(const char *msg) { SDL_Event event; @@ -264,7 +329,7 @@ void XSDL_initSDL() SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(VID_X, VID_Y, 24, SDL_SWSURFACE); TTF_Init(); - sFont = TTF_OpenFont("DroidSansMono.ttf", 10); + sFont = TTF_OpenFont("DroidSansMono.ttf", 12); if (!sFont) { __android_log_print(ANDROID_LOG_INFO, "XSDL", "Error: cannot open font file, please reinstall the app"); @@ -280,7 +345,7 @@ void XSDL_deinitSDL() // Do NOT call SDL_Quit(), it crashes! } -void renderStringColor(const char *c, int x, int y, int r, int g, int b) +void renderStringColor(const char *c, int x, int y, int r, int g, int b, SDL_Surface * surf) { SDL_Color fColor = {r, g, b}; SDL_Rect fontRect = {0, 0, 0, 0}; @@ -289,12 +354,12 @@ void renderStringColor(const char *c, int x, int y, int r, int g, int b) fontRect.h = fontSurface->h; fontRect.x = x - fontRect.w / 2; fontRect.y = y - fontRect.h / 2; - SDL_BlitSurface(fontSurface, NULL, SDL_GetVideoSurface(), &fontRect); + SDL_BlitSurface(fontSurface, NULL, surf, &fontRect); SDL_FreeSurface(fontSurface); } void renderString(const char *c, int x, int y) { - renderStringColor(c, x, y, 255, 255, 255); + renderStringColor(c, x, y, 255, 255, 255, SDL_GetVideoSurface()); } diff --git a/project/jni/application/xserver/main.c b/project/jni/application/xserver/main.c index fd8db92b5..8b253482e 100644 --- a/project/jni/application/xserver/main.c +++ b/project/jni/application/xserver/main.c @@ -11,7 +11,7 @@ extern int android_main( int argc, char *argv[], char *envp[] ); int main( int argc, char* argv[] ) { char screenres[128] = "640x480x24"; - char clientcmd[PATH_MAX*2] = "xhost +"; + char clientcmd[PATH_MAX*3] = "xhost +"; char * cmd = ""; char* args[] = { "XSDL", @@ -44,8 +44,8 @@ int main( int argc, char* argv[] ) if( argc >= 2 ) cmd = argv[2]; - sprintf( clientcmd, "%s/usr/bin/xhost + ; %s", - getenv("SECURE_STORAGE_DIR"), cmd ); + sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xli -onroot -fullscreen help.bmp ; %s", + getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), cmd ); __android_log_print(ANDROID_LOG_INFO, "XSDL", "XSDL video resolution %s", screenres); diff --git a/project/jni/application/xserver/xserver b/project/jni/application/xserver/xserver index f1a52cb49..0c842ff9a 160000 --- a/project/jni/application/xserver/xserver +++ b/project/jni/application/xserver/xserver @@ -1 +1 @@ -Subproject commit f1a52cb49bd4b869d6ce94f65156bdfb95b042a8 +Subproject commit 0c842ff9a78db8c1578c1670ac45f9c514729abe