mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-28 01:28:51 +01:00
add correct VT cleaning after game
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
parent
e9070675b9
commit
1c72c76c59
@ -155,7 +155,6 @@ bool UserInput::initialize()
|
||||
MapKey("addPlaylist", KeyCodeAddPlaylist, false);
|
||||
MapKey("removePlaylist", KeyCodeRemovePlaylist, false);
|
||||
MapKey("random", KeyCodeRandom, false);
|
||||
MapKey("menu", KeyCodeMenu, false);
|
||||
|
||||
bool retVal = true;
|
||||
|
||||
@ -181,6 +180,7 @@ bool UserInput::initialize()
|
||||
retVal = MapKey("select", KeyCodeSelect) && retVal;
|
||||
retVal = MapKey("back", KeyCodeBack) && retVal;
|
||||
retVal = MapKey("quit", KeyCodeQuit) && retVal;
|
||||
retVal = MapKey("menu", KeyCodeMenu) && retVal;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@ -119,9 +119,34 @@ bool Launcher::run(std::string collection, Item *collectionItem)
|
||||
if(!execute(executablePath, args, currentDirectory))
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "Launcher", "Failed to launch.");
|
||||
|
||||
/// Clean VT
|
||||
int current_VT = Utils::getVTid();
|
||||
if(current_VT >= 0){
|
||||
printf("ERROR Cleaning VT %d\n", current_VT);
|
||||
Utils::termfix(current_VT);
|
||||
}
|
||||
else{
|
||||
for(int i=0; i<=12; i++){
|
||||
Utils::termfix(i);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Clean VT
|
||||
int current_VT = Utils::getVTid();
|
||||
if(current_VT >= 0){
|
||||
printf("Cleaning VT %d\n", current_VT);
|
||||
Utils::termfix(current_VT);
|
||||
}
|
||||
else{
|
||||
for(int i=0; i<=12; i++){
|
||||
Utils::termfix(i);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,13 @@
|
||||
|
||||
#define FPS 30 // TODO: set in conf file
|
||||
|
||||
//#define DEBUG_FPS
|
||||
#ifdef DEBUG_FPS
|
||||
#define DEBUG_FPS_PRINTF(...) printf(__VA_ARGS__);
|
||||
#else
|
||||
#define DEBUG_FPS_PRINTF(...)
|
||||
#endif //MENU_DEBUG
|
||||
|
||||
|
||||
RetroFE::RetroFE( Configuration &c )
|
||||
: initialized(false)
|
||||
@ -110,7 +117,7 @@ void RetroFE::render( )
|
||||
avg_draw_time += draw_time;
|
||||
avg_draw_time_nb_vals++;
|
||||
if(avg_draw_time_nb_vals >= FPS*5){
|
||||
printf("Average draw time: %dms\n", avg_draw_time/avg_draw_time_nb_vals);
|
||||
DEBUG_FPS_PRINTF("Average draw time: %dms\n", avg_draw_time/avg_draw_time_nb_vals);
|
||||
avg_draw_time=0;
|
||||
avg_draw_time_nb_vals=0;
|
||||
}
|
||||
|
||||
@ -32,6 +32,13 @@
|
||||
#include <linux/keyboard.h>
|
||||
|
||||
|
||||
/* The following devices are the same on all systems. */
|
||||
#define CURRENT_TTY "/dev/tty"
|
||||
#define DEV_CONSOLE "/dev/console"
|
||||
/*Linux, normal names */
|
||||
# define CURRENT_VC "/dev/tty0"
|
||||
|
||||
|
||||
Utils::Utils()
|
||||
{
|
||||
}
|
||||
@ -287,3 +294,67 @@ int Utils::termfix(uint32_t ttyId){
|
||||
//printf("Success\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
int Utils::open_a_console(const char *fnam)
|
||||
{
|
||||
int fd;
|
||||
|
||||
/* try read-write */
|
||||
fd = open(fnam, O_RDWR);
|
||||
|
||||
/* if failed, try read-only */
|
||||
if (fd < 0 && errno == EACCES)
|
||||
fd = open(fnam, O_RDONLY);
|
||||
|
||||
/* if failed, try write-only */
|
||||
if (fd < 0 && errno == EACCES)
|
||||
fd = open(fnam, O_WRONLY);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get an fd for use with kbd/console ioctls.
|
||||
* We try several things because opening /dev/console will fail
|
||||
* if someone else used X (which does a chown on /dev/console).
|
||||
*/
|
||||
int Utils::get_console_fd_or_die(void)
|
||||
{
|
||||
static const char *const console_names[] = {
|
||||
DEV_CONSOLE, CURRENT_VC, CURRENT_TTY
|
||||
};
|
||||
|
||||
int fd;
|
||||
|
||||
for (fd = 2; fd >= 0; fd--) {
|
||||
int fd4name;
|
||||
int choice_fd;
|
||||
char arg;
|
||||
|
||||
fd4name = open_a_console(console_names[fd]);
|
||||
chk_std:
|
||||
choice_fd = (fd4name >= 0 ? fd4name : fd);
|
||||
|
||||
arg = 0;
|
||||
if (ioctl(choice_fd, KDGKBTYPE, &arg) == 0)
|
||||
return choice_fd;
|
||||
if (fd4name >= 0) {
|
||||
fd4name = -1;
|
||||
goto chk_std;
|
||||
}
|
||||
}
|
||||
|
||||
printf("can't open console");
|
||||
/*return fd; - total failure */
|
||||
}
|
||||
|
||||
|
||||
int Utils::getVTid(){
|
||||
struct vt_stat vtstat;
|
||||
|
||||
vtstat.v_active = 0;
|
||||
ioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
|
||||
//printf("Active VT: %d\n", vtstat.v_active);
|
||||
|
||||
return vtstat.v_active;
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ public:
|
||||
static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4, std::string path5);
|
||||
|
||||
static int termfix(uint32_t ttyId);
|
||||
static int getVTid();
|
||||
|
||||
#ifdef WIN32
|
||||
static const char pathSeparator = '\\';
|
||||
@ -55,5 +56,7 @@ public:
|
||||
private:
|
||||
Utils();
|
||||
virtual ~Utils();
|
||||
static int open_a_console(const char *fnam);
|
||||
static int get_console_fd_or_die(void);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user