Merge pull request #162 from mjbudd77/master

Minor code cleanup in SDL game pad config. Small logic change to joys…
This commit is contained in:
mjbudd77 2020-08-13 22:35:16 -04:00 committed by GitHub
commit 267377a367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 13 deletions

View File

@ -56,6 +56,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
std::string prefix; std::string prefix;
char stmp[256]; char stmp[256];
// Ensure that joysticks are enabled, no harm calling init again.
InitJoysticks(); InitJoysticks();
portNum = 0; portNum = 0;

View File

@ -196,8 +196,8 @@ DriverKill()
if (!noconfig) if (!noconfig)
g_config->save(); g_config->save();
if(inited&2) KillJoysticks();
KillJoysticks();
if(inited&4) if(inited&4)
KillVideo(); KillVideo();
if(inited&1) if(inited&1)

View File

@ -127,7 +127,7 @@ static void loadMapList(void)
path = std::string(baseDir) + "/input/" + std::string(guid); path = std::string(baseDir) + "/input/" + std::string(guid);
sprintf( stmp, "SDL.Input.GamePad.%u.", padNo ); sprintf( stmp, "SDL.Input.GamePad.%i.", padNo );
prefix = stmp; prefix = stmp;
g_config->getOption(prefix + "Profile", &mapName ); g_config->getOption(prefix + "Profile", &mapName );
@ -182,9 +182,15 @@ static void loadMapList(void)
static void selPortChanged( GtkWidget * w, gpointer p ) static void selPortChanged( GtkWidget * w, gpointer p )
{ {
padNo = const char *txt;
atoi (gtk_combo_box_text_get_active_text
(GTK_COMBO_BOX_TEXT (padNoCombo))) - 1; 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) ); GtkTreeModel *treeModel = gtk_combo_box_get_model( GTK_COMBO_BOX (devSelCombo) );
GtkTreeIter iter; GtkTreeIter iter;
@ -270,12 +276,19 @@ static void saveConfig(void)
{ {
int i; int i;
char stmp[256]; char stmp[256];
const char *txt;
std::string prefix, mapName; std::string prefix, mapName;
sprintf( stmp, "SDL.Input.GamePad.%u.", padNo ); sprintf( stmp, "SDL.Input.GamePad.%i.", padNo );
prefix = stmp; 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 + "DeviceGUID", GamePad[padNo].getGUID() );
g_config->setOption(prefix + "Profile" , mapName.c_str() ); g_config->setOption(prefix + "Profile" , mapName.c_str() );
@ -312,10 +325,17 @@ static void loadProfileCB (GtkButton * button, gpointer p)
char stmp[256]; char stmp[256];
int devIdx, ret; int devIdx, ret;
std::string mapName; std::string mapName;
const char *txt;
devIdx = getDeviceIndex(); 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 ); GamePad[padNo].setDeviceIndex( devIdx );
@ -347,8 +367,15 @@ static void saveProfileCB (GtkButton * button, gpointer p)
int ret; int ret;
std::string mapName; std::string mapName;
char stmp[256]; 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() ); ret = GamePad[padNo].saveCurrentMapToFile( mapName.c_str() );
@ -402,8 +429,15 @@ static void deleteProfileCB (GtkButton * button, gpointer p)
int ret; int ret;
std::string mapName; std::string mapName;
char stmp[256]; 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() ); ret = GamePad[padNo].deleteMapping( mapName.c_str() );
@ -570,6 +604,10 @@ void openGamepadConfig (void)
{ {
return; return;
} }
// Ensure that joysticks are enabled, no harm calling init again.
InitJoysticks();
padNo = 0; padNo = 0;
win = gtk_dialog_new_with_buttons ("Controller Configuration", win = gtk_dialog_new_with_buttons ("Controller Configuration",

View File

@ -337,8 +337,8 @@ DriverKill()
if (!noconfig) if (!noconfig)
g_config->save(); g_config->save();
if(inited&2) KillJoysticks();
KillJoysticks();
if(inited&4) if(inited&4)
KillVideo(); KillVideo();
if(inited&1) if(inited&1)