changed device_id syntax from 1-BTN_A to now BTN_A@1

This commit is contained in:
Ingo Ruhnke 2011-01-27 05:39:18 +01:00
parent 15772ecfb4
commit b120e5f14c
5 changed files with 84 additions and 53 deletions

1
NEWS
View file

@ -19,6 +19,7 @@ xboxdrv 0.7.0 - (??/Jan/2011)
confusion with X1, Y1
* added --list-all, --list-key, -list-rel, ... to display all
available symbolic name
* changed device_id syntax from 1-BTN_A to now BTN_A@1
xboxdrv 0.6.5 - (22/Jan/2011)

16
TODO
View file

@ -42,31 +42,17 @@ $ dput my-ppa ../xboxdrv_0.7.0-1~lucid1_source.changes
Stuff to do before 0.7.0 release:
=================================
* AxisSensitivity filter has overflow issue
Daemon Related Stuff
====================
* cleanup device_id, don't manually do (slot<<16) | devid
* might need magic to give device-ids in a slot fashion:
from: 1-ABS_X (second uinput device)
to: 2.1-ABS_X (third uinput device for the second slot)
2.mouse-BTN_MIDDLE ?!
1.-BTN_MIDDLE
1.auto-BTN_MIDDLE
auto-BTN_MIDDLE
change syntax: BTN_MIDDLE@mouse, BTN_MIDDLE@2.mouse
must make sure it doesn't conflict with anything
List Output
===========
* update docu on force feedback for multi controller
* rename --list-key to --help-key?
* rename --list-key to --help-key? -> yep
* turn EnumBox into singleton

View file

@ -223,25 +223,28 @@ int str2rel(const std::string& name)
UIEvent str2key_event(const std::string& str)
{
int slot_id;
int device_id;
std::string rest;
split_event_name(str, &rest, &device_id);
split_event_name(str, &rest, &slot_id, &device_id);
return UIEvent::create(device_id, EV_KEY, str2key(rest));
}
UIEvent str2rel_event(const std::string& str)
{
int slot_id;
int device_id;
std::string rest;
split_event_name(str, &rest, &device_id);
split_event_name(str, &rest, &slot_id, &device_id);
return UIEvent::create(device_id, EV_REL, str2rel(rest));
}
UIEvent str2abs_event(const std::string& str)
{
int slot_id;
int device_id;
std::string rest;
split_event_name(str, &rest, &device_id);
split_event_name(str, &rest, &slot_id, &device_id);
return UIEvent::create(device_id, EV_ABS, str2abs(rest));
}

View file

@ -135,39 +135,6 @@ UIEvent::resolve_device_id(int slot, bool extra_devices)
m_device_id_resolved = true;
}
/** Takes "1-BTN_A" splits it into "1", "BTN_A" */
void split_event_name(const std::string& str, std::string* event_str, int* device_id)
{
std::string::size_type p = str.find('-');
if (p == std::string::npos)
{
*event_str = str;
*device_id = DEVICEID_AUTO;
}
else
{
*event_str = str.substr(p+1);
std::string device = str.substr(0, p);
if (device == "auto")
{
*device_id = DEVICEID_AUTO;
}
else if (device == "mouse")
{
*device_id = DEVICEID_MOUSE;
}
else if (device == "keyboard")
{
*device_id = DEVICEID_KEYBOARD;
}
else
{
*device_id = boost::lexical_cast<int>(device);
}
}
}
uint32_t
UIEvent::get_device_id() const
{
@ -176,4 +143,73 @@ UIEvent::get_device_id() const
return (m_slot_id << 16) | m_device_id;
}
namespace {
int str2deviceid(const std::string& device)
{
if (device == "auto" || device.empty())
{
return DEVICEID_AUTO;
}
else if (device == "mouse")
{
return DEVICEID_MOUSE;
}
else if (device == "keyboard")
{
return DEVICEID_KEYBOARD;
}
else if (device == "joystick")
{
return DEVICEID_JOYSTICK;
}
else
{
return boost::lexical_cast<int>(device);
}
}
int str2slotid(const std::string& slot)
{
if (slot == "auto" || slot.empty())
{
return SLOTID_AUTO;
}
else
{
return boost::lexical_cast<int>(slot);
}
}
}
void split_event_name(const std::string& str, std::string* event_str, int* slot_id, int* device_id)
{
std::string::size_type p = str.find('@');
if (p == std::string::npos)
{
*event_str = str;
*slot_id = SLOTID_AUTO;
*device_id = DEVICEID_AUTO;
}
else
{
*event_str = str.substr(0, p);
std::string device = str.substr(p+1);
p = device.find(".");
if (p == std::string::npos)
{
*slot_id = SLOTID_AUTO;
*device_id = str2deviceid(device);
}
else
{
*slot_id = str2slotid(device.substr(p+1));
*device_id = str2deviceid(device.substr(0, p));
}
}
}
/* EOF */

View file

@ -60,8 +60,13 @@ private:
bool m_device_id_resolved;
};
/** Takes "1-BTN_A" splits it into "1", "BTN_A" */
void split_event_name(const std::string& str, std::string* event_str, int* device_id);
/** in: "BTN_A@2"
out: "BTN_A", SLOTID_AUTO, 2
in: "BTN_A@mouse.2"
out: "BTN_A", 3, DEVICEID_MOUSE
*/
void split_event_name(const std::string& str, std::string* event_str, int* slot_id, int* device_id);
#endif