2009-02-09 21:15:56 +00:00
|
|
|
/* ZeroPAD - author: zerofrog(@gmail.com)
|
2009-05-03 12:19:58 +00:00
|
|
|
* Copyright (C) 2006-2007
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
#include "linux.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
Display *GSdsp;
|
|
|
|
static pthread_spinlock_t s_mutexStatus;
|
|
|
|
static u32 s_keyPress[2], s_keyRelease[2]; // thread safe
|
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
static const char* s_pGuiKeyMap[] =
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
"L2", "R2", "L1", "R1",
|
|
|
|
"Triangle", "Circle", "Cross", "Square",
|
|
|
|
"Select", "L3", "R3", "Start",
|
|
|
|
"Up", "Right", "Down", "Left",
|
2009-05-10 05:57:57 +00:00
|
|
|
"Lx", "Rx", "Ly", "Ry",
|
|
|
|
"L_Up", "L_Right", "L_Down", "L_Left",
|
|
|
|
"R_Up", "R_Right", "R_Down", "R_Left"
|
2009-05-03 12:19:58 +00:00
|
|
|
};
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
string GetLabelFromButton(const char* buttonname)
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
string label = "e";
|
|
|
|
label += buttonname;
|
|
|
|
return label;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 _PADopen(void *pDsp)
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
GSdsp = *(Display**)pDsp;
|
|
|
|
pthread_spin_init(&s_mutexStatus, PTHREAD_PROCESS_PRIVATE);
|
|
|
|
s_keyPress[0] = s_keyPress[1] = 0;
|
|
|
|
s_keyRelease[0] = s_keyRelease[1] = 0;
|
|
|
|
XAutoRepeatOff(GSdsp);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
#ifdef JOYSTICK_SUPPORT
|
2009-05-03 12:19:58 +00:00
|
|
|
JoystickInfo::EnumerateJoysticks(s_vjoysticks);
|
2009-05-07 23:37:57 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _PADclose()
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
pthread_spin_destroy(&s_mutexStatus);
|
|
|
|
XAutoRepeatOn(GSdsp);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
vector<JoystickInfo*>::iterator it = s_vjoysticks.begin();
|
|
|
|
|
|
|
|
// Delete everything in the vector vjoysticks.
|
2009-05-07 23:49:12 +00:00
|
|
|
while (it != s_vjoysticks.end())
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it ++;
|
|
|
|
}
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
s_vjoysticks.clear();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _PADupdate(int pad)
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
pthread_spin_lock(&s_mutexStatus);
|
|
|
|
status[pad] |= s_keyRelease[pad];
|
|
|
|
status[pad] &= ~s_keyPress[pad];
|
|
|
|
s_keyRelease[pad] = 0;
|
|
|
|
s_keyPress[pad] = 0;
|
|
|
|
pthread_spin_unlock(&s_mutexStatus);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int _GetJoystickIdFromPAD(int pad)
|
|
|
|
{
|
2009-05-03 11:09:15 +00:00
|
|
|
// select the right joystick id
|
|
|
|
int joyid = -1;
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
for (int p = 0; p < PADSUBKEYS; p++)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < PADKEYS; ++i)
|
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
u32 temp = conf.keys[(PadEnum[pad][p])][i];
|
|
|
|
|
|
|
|
if (IS_JOYSTICK( temp) || IS_JOYBUTTONS(temp))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
joyid = PAD_GETJOYID(temp);
|
2009-05-03 11:09:15 +00:00
|
|
|
return joyid;
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-05-03 11:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-03 19:30:38 +00:00
|
|
|
return joyid;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK PADupdate(int pad)
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
int i;
|
|
|
|
XEvent E;
|
|
|
|
int keyPress = 0, keyRelease = 0;
|
|
|
|
KeySym key;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
// keyboard input
|
|
|
|
while (XPending(GSdsp) > 0)
|
|
|
|
{
|
2009-02-09 21:15:56 +00:00
|
|
|
XNextEvent(GSdsp, &E);
|
2009-05-03 12:19:58 +00:00
|
|
|
switch (E.type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
|
|
|
key = XLookupKeysym((XKeyEvent *) & E, 0);
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
i = FindKey(key, pad);
|
2009-05-03 12:19:58 +00:00
|
|
|
#ifdef ANALOG_CONTROLS_HACK
|
2009-05-10 05:57:57 +00:00
|
|
|
if ((i > PAD_RY) && (i <= PAD_R_LEFT))
|
|
|
|
{
|
|
|
|
switch (i)
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
case PAD_R_LEFT:
|
|
|
|
Analog::ConfigurePad(PAD_RX, pad, DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_R_UP:
|
|
|
|
Analog::ConfigurePad(PAD_RY, pad, DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_L_LEFT:
|
|
|
|
Analog::ConfigurePad(PAD_LX, pad, DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_L_UP:
|
|
|
|
Analog::ConfigurePad(PAD_LY, pad, DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_R_DOWN:
|
|
|
|
Analog::ConfigurePad(PAD_RY, pad, -DEF_VALUE);
|
2009-05-03 12:19:58 +00:00
|
|
|
break;
|
2009-05-10 05:57:57 +00:00
|
|
|
case PAD_R_RIGHT:
|
|
|
|
Analog::ConfigurePad(PAD_RX, pad, -DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_L_DOWN:
|
|
|
|
Analog::ConfigurePad(PAD_LY, pad, -DEF_VALUE);
|
|
|
|
break;
|
|
|
|
case PAD_L_RIGHT:
|
|
|
|
Analog::ConfigurePad(PAD_LX, pad, -DEF_VALUE);
|
2009-05-03 12:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
i += 0xff00;
|
|
|
|
}
|
2009-05-03 11:49:25 +00:00
|
|
|
#endif
|
2009-05-09 20:06:57 +00:00
|
|
|
if (i != -1)
|
|
|
|
{
|
2009-05-03 19:30:38 +00:00
|
|
|
keyPress |= (1 << i);
|
|
|
|
keyRelease &= ~(1 << i);
|
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
//PAD_LOG("Key pressed:%d\n", i);
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
event.evt = KEYPRESS;
|
|
|
|
event.key = key;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyRelease:
|
|
|
|
key = XLookupKeysym((XKeyEvent *) & E, 0);
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
i = FindKey(key, pad);
|
2009-05-03 11:49:25 +00:00
|
|
|
#ifdef ANALOG_CONTROLS_HACK
|
2009-05-10 05:57:57 +00:00
|
|
|
|
|
|
|
if ((i > PAD_RY) && (i <= PAD_R_LEFT))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case PAD_R_LEFT:
|
|
|
|
Analog::ResetPad(PAD_RX, pad);
|
|
|
|
break;
|
|
|
|
case PAD_R_UP:
|
|
|
|
Analog::ResetPad(PAD_RY, pad);
|
|
|
|
break;
|
|
|
|
case PAD_L_LEFT:
|
|
|
|
Analog::ResetPad(PAD_LX, pad);
|
|
|
|
break;
|
|
|
|
case PAD_L_UP:
|
|
|
|
Analog::ResetPad(PAD_LY, pad);
|
|
|
|
break;
|
|
|
|
case PAD_R_DOWN:
|
|
|
|
Analog::ResetPad(PAD_RY, pad);
|
|
|
|
break;
|
|
|
|
case PAD_R_RIGHT:
|
|
|
|
Analog::ResetPad(PAD_RX, pad);
|
|
|
|
break;
|
|
|
|
case PAD_L_DOWN:
|
|
|
|
Analog::ResetPad(PAD_LY, pad);
|
|
|
|
break;
|
|
|
|
case PAD_L_RIGHT:
|
|
|
|
Analog::ResetPad(PAD_LX, pad);
|
2009-05-03 12:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
i += 0xff00;
|
|
|
|
}
|
2009-05-03 11:49:25 +00:00
|
|
|
#endif
|
2009-05-09 20:06:57 +00:00
|
|
|
if (i != -1)
|
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
clear_bit(keyPress, i);
|
|
|
|
set_bit(keyRelease, i);
|
2009-05-03 19:30:38 +00:00
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
event.evt = KEYRELEASE;
|
|
|
|
event.key = key;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusIn:
|
|
|
|
XAutoRepeatOff(GSdsp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusOut:
|
|
|
|
XAutoRepeatOn(GSdsp);
|
|
|
|
break;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
// joystick info
|
2009-02-09 21:15:56 +00:00
|
|
|
#ifdef JOYSTICK_SUPPORT
|
2009-05-03 12:19:58 +00:00
|
|
|
|
2009-05-03 11:09:15 +00:00
|
|
|
SDL_JoystickUpdate();
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < PADKEYS; i++)
|
|
|
|
{
|
|
|
|
int key = conf.keys[PadEnum[pad][0]][i];
|
2009-05-03 11:09:15 +00:00
|
|
|
JoystickInfo* pjoy = NULL;
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
if (IS_JOYBUTTONS(key))
|
|
|
|
{
|
|
|
|
int joyid = PAD_GETJOYID(key);
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
pjoy = s_vjoysticks[joyid];
|
|
|
|
|
|
|
|
if (SDL_JoystickGetButton((pjoy)->GetJoy(), PAD_GETJOYBUTTON(key)))
|
2009-05-10 05:57:57 +00:00
|
|
|
clear_bit(status[(pjoy)->GetPAD()], i); // pressed
|
2009-05-03 12:19:58 +00:00
|
|
|
else
|
2009-05-10 05:57:57 +00:00
|
|
|
set_bit(status[(pjoy)->GetPAD()], i); // pressed
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IS_JOYSTICK(key))
|
|
|
|
{
|
|
|
|
int joyid = PAD_GETJOYID(key);
|
2009-05-10 05:57:57 +00:00
|
|
|
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
pjoy = s_vjoysticks[joyid];
|
|
|
|
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
|
|
|
|
int pad = (pjoy)->GetPAD();
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case PAD_LX:
|
|
|
|
case PAD_LY:
|
|
|
|
case PAD_RX:
|
|
|
|
case PAD_RY:
|
|
|
|
if (abs(value) > (pjoy)->GetDeadzone(value))
|
2009-05-09 20:06:57 +00:00
|
|
|
Analog::ConfigurePad(i, pad, value);
|
2009-05-03 12:19:58 +00:00
|
|
|
else
|
2009-05-09 20:06:57 +00:00
|
|
|
Analog::ResetPad(i, pad);
|
2009-05-03 12:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
#ifdef EXPERAMENTAL_POV_CODE
|
2009-05-03 12:19:58 +00:00
|
|
|
else if (IS_POV(key))
|
|
|
|
{
|
|
|
|
int joyid = PAD_GETJOYID(key);
|
2009-05-10 05:57:57 +00:00
|
|
|
if ((joyid >= 0) && (joyid < (int)s_vjoysticks.size()))
|
|
|
|
{
|
|
|
|
pjoy = s_vjoysticks[joyid];
|
|
|
|
|
|
|
|
int value = SDL_JoystickGetHat((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
|
|
|
|
int pad = (pjoy)->GetPAD();
|
|
|
|
|
|
|
|
//PAD_LOG("Hat = %d for key %d\n", PAD_GETPOVSIGN(key), key);
|
|
|
|
if PAD_GETPOVSIGN(key)
|
|
|
|
set_bit(status[pad], i);
|
|
|
|
else
|
|
|
|
clear_bit(status[pad], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
else if (IS_POV(key))
|
|
|
|
{
|
|
|
|
int joyid = PAD_GETJOYID(key);
|
|
|
|
if (joyid >= 0 && (joyid < (int)s_vjoysticks.size()))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
pjoy = s_vjoysticks[joyid];
|
|
|
|
|
|
|
|
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key));
|
|
|
|
int pad = (pjoy)->GetPAD();
|
2009-05-07 23:49:12 +00:00
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
if (PAD_GETPOVSIGN(key) && (value < -2048))
|
2009-05-10 05:57:57 +00:00
|
|
|
clear_bit(status[pad], i);
|
2009-05-03 12:19:58 +00:00
|
|
|
else if (!PAD_GETPOVSIGN(key) && (value > 2048))
|
2009-05-10 05:57:57 +00:00
|
|
|
clear_bit(status[pad], i);
|
2009-05-03 12:19:58 +00:00
|
|
|
else
|
2009-05-10 05:57:57 +00:00
|
|
|
set_bit(status[pad], i);
|
2009-05-03 11:09:15 +00:00
|
|
|
}
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
#endif
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
#endif
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
pthread_spin_lock(&s_mutexStatus);
|
|
|
|
s_keyPress[pad] |= keyPress;
|
2009-05-10 05:57:57 +00:00
|
|
|
s_keyPress[pad] &= ~keyRelease;
|
2009-05-03 12:19:58 +00:00
|
|
|
s_keyRelease[pad] |= keyRelease;
|
|
|
|
s_keyRelease[pad] &= ~keyPress;
|
|
|
|
pthread_spin_unlock(&s_mutexStatus);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateConf(int pad)
|
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
initLogging();
|
2009-05-03 11:09:15 +00:00
|
|
|
s_selectedpad = pad;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
int i;
|
2009-05-03 11:09:15 +00:00
|
|
|
GtkWidget *Btn;
|
2009-05-03 12:19:58 +00:00
|
|
|
for (i = 0; i < ArraySize(s_pGuiKeyMap); i++)
|
|
|
|
{
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
if (s_pGuiKeyMap[i] == NULL) continue;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
Btn = lookup_widget(Conf, GetLabelFromButton(s_pGuiKeyMap[i]).c_str());
|
2009-05-03 12:19:58 +00:00
|
|
|
if (Btn == NULL)
|
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
PAD_LOG("ZeroPAD: cannot find key %s\n", s_pGuiKeyMap[i]);
|
2009-05-03 12:19:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
string tmp;
|
|
|
|
if (IS_KEYBOARD(conf.keys[pad][i]))
|
|
|
|
{
|
|
|
|
char* pstr = XKeysymToString(PAD_GETKEY(conf.keys[pad][i]));
|
|
|
|
if (pstr != NULL) tmp = pstr;
|
|
|
|
}
|
|
|
|
else if (IS_JOYBUTTONS(conf.keys[pad][i]))
|
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
tmp.resize(28);
|
2009-05-03 12:19:58 +00:00
|
|
|
sprintf(&tmp[0], "JBut %d", PAD_GETJOYBUTTON(conf.keys[pad][i]));
|
|
|
|
}
|
|
|
|
else if (IS_JOYSTICK(conf.keys[pad][i]))
|
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
tmp.resize(28);
|
2009-05-03 12:19:58 +00:00
|
|
|
sprintf(&tmp[0], "JAxis %d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
|
|
|
|
}
|
|
|
|
else if (IS_POV(conf.keys[pad][i]))
|
2009-05-10 05:57:57 +00:00
|
|
|
#ifdef EXPERAMENTAL_POV_CODE
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
2009-05-10 05:57:57 +00:00
|
|
|
tmp.resize(28);
|
|
|
|
switch(PAD_GETPOVSIGN(conf.keys[pad][i]))
|
|
|
|
{
|
|
|
|
case SDL_HAT_UP:
|
|
|
|
sprintf(&tmp[0], "JPOVU-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_HAT_RIGHT:
|
|
|
|
sprintf(&tmp[0], "JPOVR-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_HAT_DOWN:
|
|
|
|
sprintf(&tmp[0], "JPOVD-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_HAT_LEFT:
|
|
|
|
sprintf(&tmp[0], "JPOVL-%d", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
tmp.resize(28);
|
2009-05-03 12:19:58 +00:00
|
|
|
sprintf(&tmp[0], "JPOV %d%s", PAD_GETJOYSTICK_AXIS(conf.keys[pad][i]), PAD_GETPOVSIGN(conf.keys[pad][i]) ? "-" : "+");
|
|
|
|
}
|
2009-05-10 05:57:57 +00:00
|
|
|
#endif
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
if (tmp.size() > 0)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(Btn), tmp.c_str());
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
else
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(Btn), "Unknown");
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
gtk_object_set_user_data(GTK_OBJECT(Btn), (void*)(PADKEYS * pad + i));
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check bounds
|
|
|
|
int joyid = _GetJoystickIdFromPAD(pad);
|
|
|
|
|
2009-05-10 05:57:57 +00:00
|
|
|
if ((joyid < 0) || (joyid >= (int)s_vjoysticks.size()))
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
// get first unused joystick
|
|
|
|
for (joyid = 0; joyid < s_vjoysticks.size(); ++joyid)
|
|
|
|
{
|
|
|
|
if (s_vjoysticks[joyid]->GetPAD() < 0) break;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
if (joyid >= 0 && joyid < (int)s_vjoysticks.size())
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); // select the combo
|
|
|
|
else
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), s_vjoysticks.size()); // no gamepad
|
|
|
|
|
|
|
|
int padopts = conf.options >> (16 * pad);
|
2009-05-10 05:57:57 +00:00
|
|
|
|
|
|
|
set_checked(Conf, "checkbutton_reverselx", padopts & PADOPTION_REVERTLX);
|
|
|
|
set_checked(Conf, "checkbutton_reversely", padopts & PADOPTION_REVERTLY);
|
|
|
|
set_checked(Conf, "checkbutton_reverserx", padopts & PADOPTION_REVERTRX);
|
|
|
|
set_checked(Conf, "checkbutton_reversery", padopts & PADOPTION_REVERTRY);
|
|
|
|
set_checked(Conf, "forcefeedback", padopts & PADOPTION_FORCEFEEDBACK);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnConf_Key(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
2009-05-03 12:19:58 +00:00
|
|
|
GdkEvent *ev;
|
2009-05-10 05:57:57 +00:00
|
|
|
const char* buttonname = gtk_widget_get_name(GTK_WIDGET(button));//gtk_button_get_label(button);
|
|
|
|
const char* labelname = GetLabelFromButton(buttonname).c_str();
|
|
|
|
GtkWidget* label = lookup_widget(Conf, labelname);
|
2009-05-03 12:19:58 +00:00
|
|
|
if (label == NULL)
|
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
PAD_LOG("couldn't find correct label\n");
|
2009-05-03 12:19:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = (int)(uptr)gtk_object_get_user_data(GTK_OBJECT(label));
|
|
|
|
int pad = id / PADKEYS;
|
|
|
|
int key = id % PADKEYS;
|
2009-05-10 05:57:57 +00:00
|
|
|
PAD_LOG("Button = '%s', Label = '%s', id = %d, pad = %d, key = %d\n", buttonname, labelname, id, pad, key);
|
|
|
|
u32 *pkey = &conf.keys[pad][key];
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
// save the states
|
2009-02-09 21:15:56 +00:00
|
|
|
#ifdef JOYSTICK_SUPPORT
|
2009-05-07 23:37:57 +00:00
|
|
|
vector<JoystickInfo*>::iterator itjoy = s_vjoysticks.begin();
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
SDL_JoystickUpdate();
|
2009-05-07 23:37:57 +00:00
|
|
|
|
|
|
|
// Save everything in the vector s_vjoysticks.
|
2009-05-07 23:49:12 +00:00
|
|
|
while (itjoy != s_vjoysticks.end())
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
|
|
|
(*itjoy)->SaveState();
|
|
|
|
itjoy++;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ev = gdk_event_get();
|
|
|
|
if (ev != NULL)
|
|
|
|
{
|
|
|
|
if (ev->type == GDK_KEY_PRESS)
|
|
|
|
{
|
|
|
|
*pkey = ev->key.keyval;
|
|
|
|
|
|
|
|
char* tmp = XKeysymToString(*pkey);
|
|
|
|
if (tmp != NULL)
|
2009-02-09 21:15:56 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), tmp);
|
2009-05-03 12:19:58 +00:00
|
|
|
else
|
2009-02-09 21:15:56 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), "Unknown");
|
|
|
|
return;
|
|
|
|
}
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
#ifdef JOYSTICK_SUPPORT
|
2009-05-07 23:37:57 +00:00
|
|
|
itjoy = s_vjoysticks.begin();
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
SDL_JoystickUpdate();
|
2009-05-07 23:37:57 +00:00
|
|
|
|
2009-05-07 23:49:12 +00:00
|
|
|
while (itjoy != s_vjoysticks.end())
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
// MAKE sure to look for changes in the state!!
|
|
|
|
for (int i = 0; i < (*itjoy)->GetNumButtons(); ++i)
|
|
|
|
{
|
|
|
|
int but = SDL_JoystickGetButton((*itjoy)->GetJoy(), i);
|
|
|
|
if (but != (*itjoy)->GetButtonState(i))
|
|
|
|
{
|
|
|
|
if (!but) // released, we don't really want this
|
|
|
|
{
|
|
|
|
(*itjoy)->SetButtonState(i, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pkey = PAD_JOYBUTTON((*itjoy)->GetId(), i);
|
|
|
|
char str[32];
|
|
|
|
sprintf(str, "JBut %d", i);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (*itjoy)->GetNumAxes(); ++i)
|
|
|
|
{
|
|
|
|
int value = SDL_JoystickGetAxis((*itjoy)->GetJoy(), i);
|
|
|
|
|
|
|
|
if (value != (*itjoy)->GetAxisState(i))
|
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
PAD_LOG("Change in joystick %d: %d.\n", i, value);
|
2009-05-03 12:19:58 +00:00
|
|
|
|
|
|
|
if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this
|
|
|
|
{
|
|
|
|
// released, we don't really want this
|
2009-05-09 22:44:06 +00:00
|
|
|
(*itjoy)->SetAxisState(i, value);
|
2009-05-03 12:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(value) > 0x3fff)
|
|
|
|
{
|
|
|
|
if (key < 16) // POV
|
|
|
|
{
|
|
|
|
*pkey = PAD_POV((*itjoy)->GetId(), value < 0, i);
|
|
|
|
char str[32];
|
|
|
|
sprintf(str, "JPOV %d%s", i, value < 0 ? "-" : "+");
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else // axis
|
|
|
|
{
|
|
|
|
*pkey = PAD_JOYSTICK((*itjoy)->GetId(), i);
|
|
|
|
char str[32];
|
|
|
|
sprintf(str, "JAxis %d", i);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-07 23:37:57 +00:00
|
|
|
|
2009-05-09 22:44:06 +00:00
|
|
|
#ifdef EXPERAMENTAL_POV_CODE
|
|
|
|
for (int i = 0; i < (*itjoy)->GetNumPOV(); ++i)
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
|
|
|
int value = SDL_JoystickGetHat((*itjoy)->GetJoy(), i);
|
|
|
|
|
2009-05-09 20:06:57 +00:00
|
|
|
if (value != (*itjoy)->GetPOVState(i))
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
switch (value)
|
2009-05-09 20:06:57 +00:00
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
char str[32];
|
|
|
|
|
|
|
|
case SDL_HAT_UP:
|
2009-05-10 05:57:57 +00:00
|
|
|
*pkey = PAD_POV((*itjoy)->GetId(), value, i);
|
|
|
|
sprintf(str, "JPOVU-%d", i);
|
2009-05-09 20:06:57 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
2009-05-09 22:44:06 +00:00
|
|
|
case SDL_HAT_RIGHT:
|
2009-05-10 05:57:57 +00:00
|
|
|
*pkey = PAD_POV((*itjoy)->GetId(), value, i);
|
|
|
|
sprintf(str, "JPOVR-%d", i);
|
2009-05-09 20:06:57 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
2009-05-09 22:44:06 +00:00
|
|
|
case SDL_HAT_DOWN:
|
2009-05-10 05:57:57 +00:00
|
|
|
*pkey = PAD_POV((*itjoy)->GetId(), value, i);
|
|
|
|
sprintf(str, "JPOVD-%d", i);
|
2009-05-09 22:44:06 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
|
|
|
case SDL_HAT_LEFT:
|
2009-05-10 05:57:57 +00:00
|
|
|
*pkey = PAD_POV((*itjoy)->GetId(), value, i);
|
|
|
|
sprintf(str, "JPOVL-%d", i);
|
2009-05-09 22:44:06 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(label), str);
|
|
|
|
return;
|
|
|
|
// Not handling SDL_HAT_RIGHTUP, SDL_HAT_RIGHTDOWN,
|
|
|
|
// SDL_HAT_LEFTUP, or SDL_HAT_LEFTDOWN here. They should be
|
|
|
|
// handled in the PADUpdate code, though.
|
2009-05-09 20:06:57 +00:00
|
|
|
}
|
2009-05-07 23:37:57 +00:00
|
|
|
}
|
2009-05-09 22:44:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-05-07 23:37:57 +00:00
|
|
|
itjoy++;
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
#endif
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK PADconfigure()
|
|
|
|
{
|
2009-02-22 12:08:05 +00:00
|
|
|
char strcurdir[256];
|
|
|
|
getcwd(strcurdir, 256);
|
|
|
|
s_strIniPath = strcurdir;
|
|
|
|
s_strIniPath += "/inis/zeropad.ini";
|
2009-05-03 12:19:58 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
Conf = create_Conf();
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
// recreate
|
2009-05-07 23:37:57 +00:00
|
|
|
#ifdef JOYSTICK_SUPPORT
|
2009-05-03 12:19:58 +00:00
|
|
|
JoystickInfo::EnumerateJoysticks(s_vjoysticks);
|
2009-05-07 23:37:57 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
s_devicecombo = lookup_widget(Conf, "joydevicescombo");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
// fill the combo
|
|
|
|
char str[255];
|
2009-05-07 23:37:57 +00:00
|
|
|
vector<JoystickInfo*>::iterator it = s_vjoysticks.begin();
|
2009-05-03 12:19:58 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
// Delete everything in the vector vjoysticks.
|
2009-05-07 23:49:12 +00:00
|
|
|
while (it != s_vjoysticks.end())
|
2009-05-03 12:19:58 +00:00
|
|
|
{
|
|
|
|
sprintf(str, "%d: %s - but: %d, axes: %d, pov: %d", (*it)->GetId(), (*it)->GetName().c_str(),
|
2009-05-09 20:06:57 +00:00
|
|
|
(*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV());
|
2009-05-03 12:19:58 +00:00
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), str);
|
2009-05-07 23:37:57 +00:00
|
|
|
it++;
|
2009-05-03 12:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), "No Gamepad");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
UpdateConf(0);
|
|
|
|
|
2009-05-03 12:19:58 +00:00
|
|
|
gtk_widget_show_all(Conf);
|
2009-02-09 21:15:56 +00:00
|
|
|
gtk_main();
|
|
|
|
}
|