2009-07-03 11:45:47 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linux.h"
|
2009-12-26 00:01:30 +00:00
|
|
|
#include <gdk/gdkx.h>
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
Display *GSdsp;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
const char* s_pGuiKeyMap[] =
|
|
|
|
{
|
2009-07-03 11:45:47 +00:00
|
|
|
"L2", "R2", "L1", "R1",
|
|
|
|
"Triangle", "Circle", "Cross", "Square",
|
|
|
|
"Select", "L3", "R3", "Start",
|
|
|
|
"Up", "Right", "Down", "Left",
|
|
|
|
"Lx", "Rx", "Ly", "Ry",
|
|
|
|
"L_Up", "L_Right", "L_Down", "L_Left",
|
|
|
|
"R_Up", "R_Right", "R_Down", "R_Left"
|
|
|
|
};
|
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
extern string KeyName(int pad, int key);
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
s32 _PADopen(void *pDsp)
|
|
|
|
{
|
2009-12-26 00:01:30 +00:00
|
|
|
GtkScrolledWindow *win;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-12-26 00:01:30 +00:00
|
|
|
win = *(GtkScrolledWindow**) pDsp;
|
|
|
|
PAD_LOG("It is a '%s'", GTK_OBJECT_TYPE_NAME(&win));
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2009-12-26 00:01:30 +00:00
|
|
|
if (GTK_IS_WIDGET(win))
|
|
|
|
{
|
|
|
|
// Since we have a GtkScrolledWindow, for now we'll grab whatever display
|
|
|
|
// comes along instead. Later, we can fiddle with this, but I'm not sure the
|
2010-04-25 00:31:27 +00:00
|
|
|
// best way to get a Display* out of a GtkScrolledWindow. A GtkWindow I might
|
2009-12-26 00:01:30 +00:00
|
|
|
// be able to manage... --arcum42
|
|
|
|
GSdsp = GDK_DISPLAY();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSdsp = *(Display**)pDsp;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-12-26 00:01:30 +00:00
|
|
|
SetAutoRepeat(false);
|
2009-07-03 11:45:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _PADclose()
|
|
|
|
{
|
|
|
|
SetAutoRepeat(true);
|
|
|
|
|
|
|
|
vector<JoystickInfo*>::iterator it = s_vjoysticks.begin();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
// Delete everything in the vector vjoysticks.
|
|
|
|
while (it != s_vjoysticks.end())
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it ++;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
s_vjoysticks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
int _GetJoystickIdFromPAD(int pad)
|
|
|
|
{
|
|
|
|
// select the right joystick id
|
2009-11-14 09:02:10 +00:00
|
|
|
u32 joyid = -1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
for (int p = 0; p < MAX_SUB_KEYS; p++)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; ++i)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
KeyType k = type_of_key(PadEnum[pad][p],i);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
if (k == PAD_JOYSTICK || k == PAD_JOYBUTTONS)
|
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
joyid = key_to_joystick_id(PadEnum[pad][p],i);
|
2009-07-03 11:45:47 +00:00
|
|
|
return joyid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
if (!JoystickIdWithinBounds(joyid))
|
|
|
|
{
|
|
|
|
// get first unused joystick
|
|
|
|
for (joyid = 0; joyid < s_vjoysticks.size(); ++joyid)
|
|
|
|
{
|
|
|
|
if (s_vjoysticks[joyid]->GetPAD() < 0) break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
return joyid;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) PADupdate(int pad)
|
|
|
|
{
|
|
|
|
// Poll keyboard.
|
|
|
|
PollForKeyboardInput(pad);
|
|
|
|
|
|
|
|
// joystick info
|
|
|
|
SDL_JoystickUpdate();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; i++)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
int cpad = PadEnum[pad][0];
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 00:05:05 +00:00
|
|
|
if (JoystickIdWithinBounds(key_to_joystick_id(cpad, i)))
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
JoystickInfo* pjoy = s_vjoysticks[key_to_joystick_id(cpad, i)];
|
2009-07-03 11:45:47 +00:00
|
|
|
int pad = (pjoy)->GetPAD();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 00:05:05 +00:00
|
|
|
switch (type_of_key(cpad, i))
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_JOYBUTTONS:
|
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
int value = SDL_JoystickGetButton((pjoy)->GetJoy(), key_to_button(cpad, i));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
if (value)
|
|
|
|
clear_bit(status[pad], i); // released
|
|
|
|
else
|
|
|
|
set_bit(status[pad], i); // pressed
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_HAT:
|
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
int value = SDL_JoystickGetHat((pjoy)->GetJoy(), key_to_axis(cpad, i));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
if (key_to_hat_dir(cpad, i) == value)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
clear_bit(status[pad], i);
|
|
|
|
//PAD_LOG("Registered %s\n", HatName(value), i);
|
|
|
|
//PAD_LOG("%s\n", KeyName(cpad, i).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
set_bit(status[pad], i);
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_POV:
|
|
|
|
{
|
2009-07-10 00:05:05 +00:00
|
|
|
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), key_to_axis(cpad, i));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
PAD_LOG("%s: %d (%d)\n", KeyName(cpad, i).c_str(), value, key_to_pov_sign(cpad, i));
|
2009-07-10 00:05:05 +00:00
|
|
|
if (key_to_pov_sign(cpad, i) && (value < -2048))
|
2009-07-11 17:21:23 +00:00
|
|
|
{
|
|
|
|
//PAD_LOG("%s Released+.\n", KeyName(cpad, i).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
clear_bit(status[pad], i);
|
2009-07-11 17:21:23 +00:00
|
|
|
}
|
2009-07-10 00:05:05 +00:00
|
|
|
else if (!key_to_pov_sign(cpad, i) && (value > 2048))
|
2009-07-11 17:21:23 +00:00
|
|
|
{
|
|
|
|
//PAD_LOG("%s Released-\n", KeyName(cpad, i).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
clear_bit(status[pad], i);
|
2009-07-11 17:21:23 +00:00
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
else
|
2009-07-11 17:21:23 +00:00
|
|
|
{
|
|
|
|
//PAD_LOG("%s Pressed.\n", KeyName(cpad, i).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
set_bit(status[pad], i);
|
2009-07-11 17:21:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_JOYSTICK:
|
|
|
|
{
|
|
|
|
int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), key_to_axis(cpad, i));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case PAD_LX:
|
|
|
|
case PAD_LY:
|
|
|
|
case PAD_RX:
|
|
|
|
case PAD_RY:
|
|
|
|
if (abs(value) > (pjoy)->GetDeadzone(value))
|
|
|
|
Analog::ConfigurePad(pad, i, value);
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-07-11 17:21:23 +00:00
|
|
|
Analog::ResetPad(pad, i);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateConf(int pad)
|
|
|
|
{
|
|
|
|
initLogging();
|
|
|
|
s_selectedpad = pad;
|
|
|
|
init_tree_view();
|
|
|
|
int i;
|
|
|
|
GtkWidget *Btn;
|
|
|
|
for (i = 0; i < ArraySize(s_pGuiKeyMap); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (s_pGuiKeyMap[i] == NULL) continue;
|
|
|
|
|
|
|
|
Btn = lookup_widget(Conf, s_pGuiKeyMap[i]);
|
|
|
|
if (Btn == NULL)
|
|
|
|
{
|
|
|
|
PAD_LOG("OnePAD: cannot find key %s\n", s_pGuiKeyMap[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
gtk_object_set_user_data(GTK_OBJECT(Btn), (void*)(MAX_KEYS * pad + i));
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check bounds
|
|
|
|
int joyid = _GetJoystickIdFromPAD(pad);
|
|
|
|
|
|
|
|
if (JoystickIdWithinBounds(joyid))
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); // select the combo
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-07-03 11:45:47 +00:00
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), s_vjoysticks.size()); // no gamepad
|
|
|
|
|
|
|
|
int padopts = conf.options >> (16 * pad);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetLabelId(GtkWidget *label)
|
|
|
|
{
|
|
|
|
if (label == NULL)
|
|
|
|
{
|
|
|
|
PAD_LOG("couldn't find correct label\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
return (int)(uptr)gtk_object_get_user_data(GTK_OBJECT(label));
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnConf_Key(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
|
|
|
bool captured = false;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
const char* buttonname = gtk_widget_get_name(GTK_WIDGET(button));
|
|
|
|
GtkWidget* label = lookup_widget(Conf, buttonname);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int id = GetLabelId(label);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
if (id == -1) return;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
int pad = id / MAX_KEYS;
|
|
|
|
int key = id % MAX_KEYS;
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
// save the joystick states
|
|
|
|
UpdateJoysticks();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
while (!captured)
|
|
|
|
{
|
|
|
|
vector<JoystickInfo*>::iterator itjoy;
|
|
|
|
char *tmp;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
u32 pkey = get_key(pad, key);
|
|
|
|
if (PollX11Keyboard(tmp, pkey))
|
|
|
|
{
|
|
|
|
set_key(pad, key, pkey);
|
2009-07-10 06:07:32 +00:00
|
|
|
PAD_LOG("%s\n", KeyName(pad, key).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
captured = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
SDL_JoystickUpdate();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
itjoy = s_vjoysticks.begin();
|
|
|
|
while ((itjoy != s_vjoysticks.end()) && (!captured))
|
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
int button_id, direction;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
pkey = get_key(pad, key);
|
2009-07-10 06:07:32 +00:00
|
|
|
if ((*itjoy)->PollButtons(button_id, pkey))
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
set_key(pad, key, pkey);
|
2009-07-10 06:07:32 +00:00
|
|
|
PAD_LOG("%s\n", KeyName(pad, key).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
captured = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
bool sign = false;
|
2009-07-03 11:45:47 +00:00
|
|
|
bool pov = (!((key == PAD_RY) || (key == PAD_LY) || (key == PAD_RX) || (key == PAD_LX)));
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
int axis_id;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
if (pov)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-10 06:07:32 +00:00
|
|
|
if ((*itjoy)->PollPOV(axis_id, sign, pkey))
|
|
|
|
{
|
|
|
|
set_key(pad, key, pkey);
|
|
|
|
PAD_LOG("%s\n", KeyName(pad, key).c_str());
|
|
|
|
captured = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((*itjoy)->PollAxes(axis_id, pkey))
|
|
|
|
{
|
|
|
|
set_key(pad, key, pkey);
|
|
|
|
PAD_LOG("%s\n", KeyName(pad, key).c_str());
|
|
|
|
captured = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-10 06:07:32 +00:00
|
|
|
if ((*itjoy)->PollHats(axis_id, direction, pkey))
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
set_key(pad, key, pkey);
|
2009-07-10 06:07:32 +00:00
|
|
|
PAD_LOG("%s\n", KeyName(pad, key).c_str());
|
2009-07-03 11:45:47 +00:00
|
|
|
captured = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
itjoy++;
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
init_tree_view();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) PADconfigure()
|
|
|
|
{
|
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
Conf = create_Conf();
|
|
|
|
|
|
|
|
// recreate
|
|
|
|
JoystickInfo::EnumerateJoysticks(s_vjoysticks);
|
|
|
|
|
|
|
|
s_devicecombo = lookup_widget(Conf, "joydevicescombo");
|
|
|
|
|
|
|
|
// fill the combo
|
|
|
|
char str[255];
|
|
|
|
vector<JoystickInfo*>::iterator it = s_vjoysticks.begin();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
// Delete everything in the vector vjoysticks.
|
|
|
|
while (it != s_vjoysticks.end())
|
|
|
|
{
|
|
|
|
sprintf(str, "%d: %s - but: %d, axes: %d, hats: %d", (*it)->GetId(), (*it)->GetName().c_str(),
|
|
|
|
(*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumHats());
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), str);
|
|
|
|
it++;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), "No Gamepad");
|
|
|
|
|
|
|
|
UpdateConf(0);
|
|
|
|
|
|
|
|
gtk_widget_show_all(Conf);
|
|
|
|
gtk_main();
|
|
|
|
}
|