2009-07-10 06:07:32 +00:00
|
|
|
/* OnePAD - author: arcum42(@gmail.com)
|
|
|
|
* Copyright (C) 2009
|
|
|
|
*
|
|
|
|
* Based on ZeroPAD, author zerofrog@gmail.com
|
|
|
|
* Copyright (C) 2006-2007
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-07-10 06:07:32 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-05 11:03:12 +00:00
|
|
|
#include <string.h>
|
2009-07-10 06:07:32 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
#include "GamePad.h"
|
2011-06-12 14:48:36 +00:00
|
|
|
#include "keyboard.h"
|
2009-07-10 06:07:32 +00:00
|
|
|
#include "onepad.h"
|
|
|
|
#include "linux.h"
|
|
|
|
|
2010-05-22 02:52:47 +00:00
|
|
|
extern std::string s_strIniPath;
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
string KeyName(int pad, int key, int keysym)
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
|
|
|
string tmp;
|
2011-06-12 14:48:36 +00:00
|
|
|
tmp.resize(28);
|
|
|
|
|
|
|
|
if (keysym) {
|
|
|
|
if (keysym < 10) {
|
|
|
|
// mouse
|
|
|
|
switch (keysym) {
|
|
|
|
case 1: sprintf(&tmp[0], "Mouse Left"); break;
|
|
|
|
case 2: sprintf(&tmp[0], "Mouse Middle"); break;
|
|
|
|
case 3: sprintf(&tmp[0], "Mouse Right"); break;
|
|
|
|
default: // Use only number for extra button
|
|
|
|
sprintf(&tmp[0], "Mouse %d", keysym);
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
} else {
|
|
|
|
// keyboard
|
|
|
|
char* pstr = XKeysymToString(keysym);
|
|
|
|
if (pstr != NULL) tmp = pstr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// joystick
|
|
|
|
KeyType k = type_of_joykey(pad, key);
|
|
|
|
switch (k)
|
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
case PAD_JOYBUTTONS:
|
2011-06-12 14:48:36 +00:00
|
|
|
{
|
|
|
|
int button = key_to_button(pad, key);
|
|
|
|
sprintf(&tmp[0], "JBut %d", button);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_AXIS:
|
|
|
|
{
|
|
|
|
if (key_to_axis_type(pad,key))
|
2011-06-17 20:44:46 +00:00
|
|
|
sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key));
|
2011-06-12 14:48:36 +00:00
|
|
|
else
|
|
|
|
sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+");
|
|
|
|
break;
|
|
|
|
}
|
2009-07-10 06:07:32 +00:00
|
|
|
case PAD_HAT:
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
int axis = key_to_axis(pad, key);
|
|
|
|
switch(key_to_hat_dir(pad, key))
|
|
|
|
{
|
2015-10-14 13:05:02 +00:00
|
|
|
case HAT_UP:
|
2011-06-12 14:48:36 +00:00
|
|
|
sprintf(&tmp[0], "JPOVU-%d", axis);
|
|
|
|
break;
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
case HAT_RIGHT:
|
2011-06-12 14:48:36 +00:00
|
|
|
sprintf(&tmp[0], "JPOVR-%d", axis);
|
|
|
|
break;
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
case HAT_DOWN:
|
2011-06-12 14:48:36 +00:00
|
|
|
sprintf(&tmp[0], "JPOVD-%d", axis);
|
|
|
|
break;
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
case HAT_LEFT:
|
2011-06-12 14:48:36 +00:00
|
|
|
sprintf(&tmp[0], "JPOVL-%d", axis);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void DefaultKeyboardValues()
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
set_keyboad_key(0, XK_a, PAD_L2);
|
|
|
|
set_keyboad_key(0, XK_semicolon, PAD_R2);
|
|
|
|
set_keyboad_key(0, XK_w, PAD_L1);
|
|
|
|
set_keyboad_key(0, XK_p, PAD_R1);
|
|
|
|
set_keyboad_key(0, XK_i, PAD_TRIANGLE);
|
|
|
|
set_keyboad_key(0, XK_l, PAD_CIRCLE);
|
|
|
|
set_keyboad_key(0, XK_k, PAD_CROSS);
|
|
|
|
set_keyboad_key(0, XK_j, PAD_SQUARE);
|
|
|
|
set_keyboad_key(0, XK_v, PAD_SELECT);
|
|
|
|
set_keyboad_key(0, XK_n, PAD_START);
|
|
|
|
set_keyboad_key(0, XK_e, PAD_UP);
|
|
|
|
set_keyboad_key(0, XK_f, PAD_RIGHT);
|
|
|
|
set_keyboad_key(0, XK_d, PAD_DOWN);
|
|
|
|
set_keyboad_key(0, XK_s, PAD_LEFT);
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveConfig()
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
2010-05-22 02:52:47 +00:00
|
|
|
const std::string iniFile(s_strIniPath + "OnePAD.ini");
|
|
|
|
f = fopen(iniFile.c_str(), "w");
|
2009-07-10 06:07:32 +00:00
|
|
|
if (f == NULL)
|
|
|
|
{
|
2011-05-14 20:03:29 +00:00
|
|
|
printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
|
2009-07-10 06:07:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
fprintf(f, "log = %d\n", conf->log);
|
2015-10-14 11:11:09 +00:00
|
|
|
fprintf(f, "options = %d\n", conf->packed_options);
|
|
|
|
fprintf(f, "mouse_sensibility = %d\n", conf->get_sensibility());
|
2011-06-12 14:48:36 +00:00
|
|
|
fprintf(f, "joy_pad_map = %d\n", conf->joyid_map);
|
2015-10-14 11:11:09 +00:00
|
|
|
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
for (int pad = 0; pad < 2; pad++)
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
|
|
|
for (int key = 0; key < MAX_KEYS; key++)
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad,key));
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
map<u32,u32>::iterator it;
|
|
|
|
for (int pad = 0; pad < 2 ; pad++)
|
|
|
|
for (it = conf->keysym_map[pad].begin(); it != conf->keysym_map[pad].end(); ++it)
|
|
|
|
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it->first, it->second);
|
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadConfig()
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char str[256];
|
2011-06-12 14:48:36 +00:00
|
|
|
bool have_user_setting = false;
|
|
|
|
|
|
|
|
if (!conf)
|
|
|
|
conf = new PADconf;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
conf->init();
|
2009-07-10 06:07:32 +00:00
|
|
|
|
2010-05-22 02:52:47 +00:00
|
|
|
const std::string iniFile(s_strIniPath + "OnePAD.ini");
|
|
|
|
f = fopen(iniFile.c_str(), "r");
|
2009-07-10 06:07:32 +00:00
|
|
|
if (f == NULL)
|
|
|
|
{
|
2010-05-22 02:52:47 +00:00
|
|
|
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
|
2009-07-10 06:07:32 +00:00
|
|
|
SaveConfig(); //save and return
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-17 20:44:46 +00:00
|
|
|
u32 value;
|
2015-09-10 12:21:27 +00:00
|
|
|
if (fscanf(f, "log = %d\n", &value) == 0) goto error;
|
2011-06-17 20:44:46 +00:00
|
|
|
conf->log = value;
|
2015-09-10 12:21:27 +00:00
|
|
|
if (fscanf(f, "options = %d\n", &value) == 0) goto error;
|
2015-10-14 11:11:09 +00:00
|
|
|
conf->packed_options = value;
|
2015-09-10 12:21:27 +00:00
|
|
|
if (fscanf(f, "mouse_sensibility = %d\n", &value) == 0) goto error;
|
2015-10-14 11:11:09 +00:00
|
|
|
conf->set_sensibility(value);
|
2015-09-10 12:21:27 +00:00
|
|
|
if (fscanf(f, "joy_pad_map = %d\n", &value) == 0) goto error;
|
2011-06-17 20:44:46 +00:00
|
|
|
conf->joyid_map = value;
|
2015-09-10 12:21:27 +00:00
|
|
|
if (fscanf(f, "ff_intensity = %d\n", &value) == 0) goto error;
|
2015-10-14 11:11:09 +00:00
|
|
|
conf->set_ff_intensity(value);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2011-06-17 20:44:46 +00:00
|
|
|
for (int pad = 0; pad < 2; pad++)
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
|
|
|
for (int key = 0; key < MAX_KEYS; key++)
|
|
|
|
{
|
|
|
|
sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
|
2011-06-12 14:48:36 +00:00
|
|
|
u32 temp = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
if (fscanf(f, str, &temp) == 0) temp = 0;
|
|
|
|
set_key(pad, key, temp);
|
2011-06-12 14:48:36 +00:00
|
|
|
if (temp && pad == 0) have_user_setting = true;
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
u32 pad;
|
|
|
|
u32 keysym;
|
|
|
|
u32 index;
|
|
|
|
while( fscanf(f, "PAD %d:KEYSYM 0x%x = %d\n", &pad, &keysym, &index) != EOF ) {
|
2015-09-11 07:18:49 +00:00
|
|
|
set_keyboad_key(pad & 1, keysym, index);
|
2011-06-12 14:48:36 +00:00
|
|
|
if(pad == 0) have_user_setting = true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 12:21:27 +00:00
|
|
|
if (!have_user_setting) DefaultKeyboardValues();
|
|
|
|
|
|
|
|
error:
|
2009-07-10 06:07:32 +00:00
|
|
|
fclose(f);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|