More backports of stuff from the wxwidgets branch

This commit is contained in:
Ilari Liusvaara 2011-11-04 01:19:00 +02:00
parent 9e8ba1f68c
commit f73a2debd3
3 changed files with 34 additions and 0 deletions

View file

@ -116,6 +116,12 @@ modifier::modifier(const std::string& name, const std::string& linkgroup) throw(
modifier_linkages()[name] = linkgroup;
}
modifier::~modifier() throw()
{
known_modifiers().erase(modname);
modifier_linkages().erase(modname);
}
modifier& modifier::lookup(const std::string& name) throw(std::bad_alloc, std::runtime_error)
{
if(!known_modifiers().count(name)) {
@ -275,6 +281,11 @@ keygroup::keygroup(const std::string& name, enum type t) throw(std::bad_alloc)
cal_tolerance = 0.5;
}
keygroup::~keygroup() throw()
{
keygroups().erase(keyname);
}
void keygroup::change_type(enum type t) throw()
{
ktype = t;

View file

@ -51,6 +51,10 @@ public:
* throws std::bad_alloc: Not enough memory.
*/
modifier(const std::string& name, const std::string& linkgroup) throw(std::bad_alloc);
/**
* Destructor
*/
~modifier() throw();
/**
* Look up a modifier.
*
@ -198,6 +202,10 @@ public:
* throws std::bad_alloc: Not enough memory.
*/
keygroup(const std::string& name, enum type t) throw(std::bad_alloc);
/**
* Destructor
*/
~keygroup() throw();
/**
* Change type of key group.
*

View file

@ -55,6 +55,7 @@ namespace
NULL //No associated key group.
};
std::set<keygroup*> keygroups;
std::map<uint64_t, struct event_mapping> event_map;
std::map<int, uint16_t> joystick_map;
std::set<int> joysticks;
@ -89,6 +90,7 @@ namespace
_name << "joystick" << joynum << "button" << buttonnum;
std::string name = _name.str();
keygroup* grp = new keygroup(name, keygroup::KT_KEY);
keygroups.insert(grp);
struct event_mapping evmap;
evmap.joystick = joynum;
evmap.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcode);
@ -112,6 +114,7 @@ namespace
grp = new keygroup(name, keygroup::KT_AXIS_PAIR);
else
grp = new keygroup(name, keygroup::KT_PRESSURE_MP);
keygroups.insert(grp);
struct event_mapping evmap;
evmap.joystick = joynum;
evmap.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcode);
@ -132,6 +135,7 @@ namespace
_name << "joystick" << joynum << "hat" << hatnum;
std::string name = _name.str();
keygroup* grp = new keygroup(name, keygroup::KT_HAT);
keygroups.insert(grp);
struct event_mapping evmap1;
evmap1.joystick = joynum;
evmap1.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcodeX);
@ -408,6 +412,17 @@ void joystick_quit()
{
for(int fd : joysticks)
close(fd);
for(auto i : keygroups)
delete i;
keygroups.clear();
joystick_map.clear();
joysticks.clear();
joystick_names.clear();
std::map<uint64_t, struct event_mapping> event_map;
std::map<int, uint16_t> joystick_map;
std::set<int> joysticks;
std::map<uint16_t, std::string> joystick_names;
}
const char* joystick_plugin_name = "Evdev joystick plugin";