From 3618f30f0d32e0fae4815f912afb9c02c14a6154 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Thu, 13 Aug 2020 21:08:02 -0400 Subject: [PATCH] Minor code cleanup in SDL game pad config. Small logic change to joystick init. --- src/drivers/Qt/GamePadConf.cpp | 1 + src/drivers/Qt/fceuWrapper.cpp | 4 +-- src/drivers/sdl/GamePadConf.cpp | 56 +++++++++++++++++++++++++++------ src/drivers/sdl/sdl.cpp | 4 +-- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index 41bc3460..03df69bb 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -56,6 +56,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) std::string prefix; char stmp[256]; + // Ensure that joysticks are enabled, no harm calling init again. InitJoysticks(); portNum = 0; diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 886e08d4..cfbbb98b 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -196,8 +196,8 @@ DriverKill() if (!noconfig) g_config->save(); - if(inited&2) - KillJoysticks(); + KillJoysticks(); + if(inited&4) KillVideo(); if(inited&1) diff --git a/src/drivers/sdl/GamePadConf.cpp b/src/drivers/sdl/GamePadConf.cpp index ea292b84..e359bad7 100644 --- a/src/drivers/sdl/GamePadConf.cpp +++ b/src/drivers/sdl/GamePadConf.cpp @@ -127,7 +127,7 @@ static void loadMapList(void) path = std::string(baseDir) + "/input/" + std::string(guid); - sprintf( stmp, "SDL.Input.GamePad.%u.", padNo ); + sprintf( stmp, "SDL.Input.GamePad.%i.", padNo ); prefix = stmp; g_config->getOption(prefix + "Profile", &mapName ); @@ -182,9 +182,15 @@ static void loadMapList(void) static void selPortChanged( GtkWidget * w, gpointer p ) { - padNo = - atoi (gtk_combo_box_text_get_active_text - (GTK_COMBO_BOX_TEXT (padNoCombo))) - 1; + const char *txt; + + txt = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT (padNoCombo)); + + if ( txt == NULL ) + { + return; + } + padNo = atoi(txt) - 1; GtkTreeModel *treeModel = gtk_combo_box_get_model( GTK_COMBO_BOX (devSelCombo) ); GtkTreeIter iter; @@ -270,12 +276,19 @@ static void saveConfig(void) { int i; char stmp[256]; + const char *txt; std::string prefix, mapName; - sprintf( stmp, "SDL.Input.GamePad.%u.", padNo ); + sprintf( stmp, "SDL.Input.GamePad.%i.", padNo ); prefix = stmp; - mapName.assign( gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ) ); + txt = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ); + + if ( txt == NULL ) + { + return; + } + mapName.assign( txt ); g_config->setOption(prefix + "DeviceGUID", GamePad[padNo].getGUID() ); g_config->setOption(prefix + "Profile" , mapName.c_str() ); @@ -312,10 +325,17 @@ static void loadProfileCB (GtkButton * button, gpointer p) char stmp[256]; int devIdx, ret; std::string mapName; + const char *txt; devIdx = getDeviceIndex(); - mapName.assign( gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ) ); + txt = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ); + + if ( txt == NULL ) + { + return; + } + mapName.assign( txt ); GamePad[padNo].setDeviceIndex( devIdx ); @@ -347,8 +367,15 @@ static void saveProfileCB (GtkButton * button, gpointer p) int ret; std::string mapName; char stmp[256]; + const char *txt; - mapName.assign( gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ) ); + txt = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ); + + if ( txt == NULL ) + { + return; + } + mapName.assign( txt ); ret = GamePad[padNo].saveCurrentMapToFile( mapName.c_str() ); @@ -402,8 +429,15 @@ static void deleteProfileCB (GtkButton * button, gpointer p) int ret; std::string mapName; char stmp[256]; + const char *txt; - mapName.assign( gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ) ); + txt = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(mapProfCombo) ); + + if ( txt == NULL ) + { + return; + } + mapName.assign( txt ); ret = GamePad[padNo].deleteMapping( mapName.c_str() ); @@ -570,6 +604,10 @@ void openGamepadConfig (void) { return; } + + // Ensure that joysticks are enabled, no harm calling init again. + InitJoysticks(); + padNo = 0; win = gtk_dialog_new_with_buttons ("Controller Configuration", diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 59d2e6c1..25f7f0aa 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -337,8 +337,8 @@ DriverKill() if (!noconfig) g_config->save(); - if(inited&2) - KillJoysticks(); + KillJoysticks(); + if(inited&4) KillVideo(); if(inited&1)