From 0993a48eca2f67869ea95cde0418a5ad8fcb286a Mon Sep 17 00:00:00 2001 From: Ayla Date: Mon, 11 Jul 2011 11:27:38 +0200 Subject: [PATCH] Add a function which unlocks the virtual terminal before and after each execution of a binary. It ensures that GMenu2X can restart after a SDL program segfaulted or crashed. It also allow GMenu2X to exit without clearing the screen, so that the "loading" screen appears until the launched binary starts using the framebuffer. --- src/gmenu2x.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 7c58b32..c46a949 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -35,6 +35,13 @@ #include "gp2x.h" #include //for battery +#ifdef PLATFORM_DINGUX +# define UNLOCK_VT +# include +# include +# include +#endif + //for browsing the filesystem #include #include @@ -121,6 +128,52 @@ static void quit_all(int err) { exit(err); } +#ifdef UNLOCK_VT + +#define FB_TTY "/dev/tty%i" +static void unlockVT() +{ + int i; + int fd; + char tty[10]; + + for (i=0; i < 10; i++) { + int mode; + + sprintf(tty, FB_TTY, i); + fd = open(tty, O_RDWR); + if (fd < 0) + continue; + + if (ioctl(fd, KDGETMODE, &mode) < 0) { + WARNING("Unable to get mode for tty %i.\n", i); + close(fd); + return; + } + + if (mode != KD_TEXT) + break; + + close(fd); + } + + if (i==10) { + DEBUG("No graphic tty found.\n"); + return; + } + + DEBUG("Graphic tty found on %s.\n", tty); + + if (ioctl(fd, KDSETMODE, KD_TEXT) < 0) + WARNING("unable to set keyboard mode.\n"); + + if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) + WARNING("unable to unlock terminal.\n"); + + close(fd); +} +#endif + const string GMenu2X::getHome(void) { return gmenu2x_home; @@ -291,6 +344,10 @@ GMenu2X::GMenu2X() { }*/ #endif +#ifdef UNLOCK_VT + unlockVT(); +#endif + //Screen if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK|SDL_INIT_TIMER)<0 ) { ERROR("Could not initialize SDL: %s\n", SDL_GetError()); @@ -352,7 +409,14 @@ void GMenu2X::quit() { fflush(NULL); sc.clear(); free(s); + +#ifdef UNLOCK_VT + SDL_QuitSubSystem(SDL_INIT_EVERYTHING & ~SDL_INIT_VIDEO); + unlockVT(); +#else SDL_Quit(); +#endif + #ifdef TARGET_GP2X /* if (gp2x_mem!=0) { //Fix tv-out