Moved DEVICEID_AUTO resolving to UIEvent, code compiles again
This commit is contained in:
parent
3e9e0c5507
commit
7daeb8cd1b
8 changed files with 34 additions and 99 deletions
|
@ -49,6 +49,7 @@ env = conf.Finish()
|
|||
env.Program('xboxdrv', ['src/xboxdrv.cpp',
|
||||
'src/xboxmsg.cpp',
|
||||
'src/uinput.cpp',
|
||||
'src/uinput_deviceid.cpp',
|
||||
'src/uinput_cfg.cpp',
|
||||
'src/button_event.cpp',
|
||||
'src/axis_event.cpp',
|
||||
|
|
|
@ -39,7 +39,8 @@ AxisEvent
|
|||
AxisEvent::create_abs(int device_id, int code, int fuzz, int flat)
|
||||
{
|
||||
AxisEvent ev;
|
||||
ev.type = EV_REL;
|
||||
ev.type = EV_ABS;
|
||||
ev.abs.code = UIEvent::create(device_id, EV_ABS, code);
|
||||
ev.abs.fuzz = fuzz;
|
||||
ev.abs.flat = flat;
|
||||
return ev;
|
||||
|
@ -50,6 +51,7 @@ AxisEvent::create_rel(int device_id, int code, int repeat, float value)
|
|||
{
|
||||
AxisEvent ev;
|
||||
ev.type = EV_REL;
|
||||
ev.rel.code = UIEvent::create(device_id, EV_REL, code);
|
||||
ev.rel.repeat = repeat;
|
||||
ev.rel.value = value;
|
||||
return ev;
|
||||
|
@ -60,6 +62,9 @@ AxisEvent::create_key()
|
|||
{
|
||||
AxisEvent ev;
|
||||
ev.type = EV_KEY;
|
||||
std::fill_n(ev.key.up_codes, MAX_MODIFIER+1, UIEvent::invalid());
|
||||
std::fill_n(ev.key.down_codes, MAX_MODIFIER+1, UIEvent::invalid());
|
||||
ev.key.threshold = 8000;
|
||||
return ev;
|
||||
}
|
||||
|
||||
|
@ -251,7 +256,7 @@ AxisEvent::is_valid() const
|
|||
}
|
||||
|
||||
void
|
||||
AxisEvent::init(uInput& uinput)
|
||||
AxisEvent::init(uInput& uinput) const
|
||||
{
|
||||
if (is_valid())
|
||||
{
|
||||
|
@ -260,43 +265,24 @@ AxisEvent::init(uInput& uinput)
|
|||
case EV_KEY:
|
||||
for(int i = 0; key.up_codes[i].is_valid(); ++i)
|
||||
{
|
||||
if (uinput.is_mouse_button(key.up_codes[i].code))
|
||||
key.up_codes[i].device_id = uinput.create_uinput_device(DEVICEID_MOUSE);
|
||||
else if (uinput.is_keyboard_button(key.up_codes[i].code))
|
||||
key.up_codes[i].device_id = uinput.create_uinput_device(DEVICEID_KEYBOARD);
|
||||
else
|
||||
key.up_codes[i].device_id = uinput.create_uinput_device(DEVICEID_JOYSTICK);
|
||||
|
||||
uinput.create_uinput_device(key.up_codes[i].device_id);
|
||||
uinput.add_key(key.up_codes[i].device_id, key.up_codes[i].code);
|
||||
}
|
||||
|
||||
for(int i = 0; key.down_codes[i].is_valid(); ++i)
|
||||
{
|
||||
if (uinput.is_mouse_button(key.down_codes[i].code))
|
||||
key.down_codes[i].device_id = uinput.create_uinput_device(DEVICEID_MOUSE);
|
||||
else if (uinput.is_keyboard_button(key.down_codes[i].code))
|
||||
key.down_codes[i].device_id = uinput.create_uinput_device(DEVICEID_KEYBOARD);
|
||||
else
|
||||
key.down_codes[i].device_id = uinput.create_uinput_device(DEVICEID_JOYSTICK);
|
||||
|
||||
uinput.create_uinput_device(key.down_codes[i].device_id);
|
||||
uinput.add_key(key.down_codes[i].device_id, key.down_codes[i].code);
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_REL:
|
||||
rel.code.device_id = uinput.create_uinput_device(DEVICEID_MOUSE);
|
||||
uinput.create_uinput_device(rel.code.device_id);
|
||||
uinput.add_rel(rel.code.device_id, rel.code.code);
|
||||
|
||||
// RelAxisState rel_axis_state;
|
||||
// rel_axis_state.axis = code;
|
||||
// rel_axis_state.time = 0;
|
||||
// rel_axis_state.next_time = 0;
|
||||
|
||||
// rel_axis.push_back(rel_axis_state);
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
rel.code.device_id = uinput.create_uinput_device(DEVICEID_JOYSTICK);
|
||||
uinput.create_uinput_device(abs.code.device_id);
|
||||
uinput.add_abs(abs.code.device_id, abs.code.code,
|
||||
abs.min, abs.max, abs.fuzz, abs.flat);
|
||||
break;
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
} key;
|
||||
};
|
||||
|
||||
void init(uInput& uinput);
|
||||
void init(uInput& uinput) const;
|
||||
void send(uInput& uinput, int old_value, int value) const;
|
||||
|
||||
bool is_valid() const;
|
||||
|
|
|
@ -66,7 +66,7 @@ ButtonEvent::create_btn(int code)
|
|||
{
|
||||
ButtonEvent ev = create(EV_KEY);
|
||||
std::fill_n(ev.key.codes, MAX_MODIFIER + 1, UIEvent::invalid());
|
||||
ev.key.codes[0] = UIEvent::create(DEVICEID_AUTO, code);
|
||||
ev.key.codes[0] = UIEvent::create(DEVICEID_AUTO, EV_KEY, code);
|
||||
return ev;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ ButtonEvent
|
|||
ButtonEvent::create_rel(int code)
|
||||
{
|
||||
ButtonEvent ev = create(EV_REL);
|
||||
ev.rel.code = UIEvent::create(DEVICEID_AUTO, code);
|
||||
ev.rel.code = UIEvent::create(DEVICEID_AUTO, EV_REL, code);
|
||||
ev.rel.repeat = 100;
|
||||
ev.rel.value = 3;
|
||||
return ev;
|
||||
|
@ -144,7 +144,7 @@ ButtonEvent::from_string(const std::string& str)
|
|||
}
|
||||
|
||||
void
|
||||
ButtonEvent::init(uInput& uinput)
|
||||
ButtonEvent::init(uInput& uinput) const
|
||||
{
|
||||
if (is_valid())
|
||||
{
|
||||
|
@ -153,39 +153,22 @@ ButtonEvent::init(uInput& uinput)
|
|||
case EV_KEY:
|
||||
for(int i = 0; key.codes[i].is_valid(); ++i)
|
||||
{
|
||||
if (uinput.is_mouse_button(key.codes[i].code))
|
||||
{
|
||||
key.codes[i].device_id = uinput.create_uinput_device(DEVICEID_MOUSE);
|
||||
}
|
||||
else if (uinput.is_keyboard_button(key.codes[i].code))
|
||||
{
|
||||
key.codes[i].device_id = uinput.create_uinput_device(DEVICEID_KEYBOARD);
|
||||
}
|
||||
else
|
||||
{
|
||||
key.codes[i].device_id = uinput.create_uinput_device(DEVICEID_JOYSTICK);
|
||||
}
|
||||
|
||||
uinput.create_uinput_device(key.codes[i].device_id);
|
||||
uinput.add_key(key.codes[i].device_id, key.codes[i].code);
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_REL:
|
||||
if (rel.code.device_id == DEVICEID_AUTO)
|
||||
{
|
||||
rel.code.device_id = uinput.create_uinput_device(DEVICEID_MOUSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
rel.code.device_id = uinput.create_uinput_device(rel.code.device_id);
|
||||
}
|
||||
|
||||
uinput.create_uinput_device(rel.code.device_id);
|
||||
uinput.get_uinput(rel.code.device_id)->add_rel(rel.code.code);
|
||||
break;
|
||||
|
||||
default:
|
||||
abs.code.device_id = uinput.create_uinput_device(DEVICEID_JOYSTICK);
|
||||
case EV_ABS:
|
||||
uinput.create_uinput_device(abs.code.device_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"ButtonEvent::init(): never reached");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ struct ButtonEvent
|
|||
} key;
|
||||
};
|
||||
|
||||
void init(uInput& uinput);
|
||||
void init(uInput& uinput) const;
|
||||
void send(uInput& uinput, bool value) const;
|
||||
|
||||
bool is_valid() const;
|
||||
|
|
|
@ -85,20 +85,18 @@ uInput::uInput(const XPadDevice& dev, uInputCfg config_) :
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
uInput::create_uinput_device(int device_id)
|
||||
{
|
||||
assert(device_id != DEVICEID_AUTO);
|
||||
|
||||
uInputDevs::iterator it = uinput_devs.find(device_id);
|
||||
if (it != uinput_devs.end())
|
||||
{
|
||||
// device already exist, which is fine
|
||||
return device_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cfg.extra_devices)
|
||||
device_id = DEVICEID_JOYSTICK;
|
||||
|
||||
std::ostringstream dev_name;
|
||||
dev_name << cfg.device_name;
|
||||
|
||||
|
@ -142,8 +140,6 @@ uInput::create_uinput_device(int device_id)
|
|||
}
|
||||
|
||||
std::cout << "Creating uinput device: device_id: " << device_id << ", dev_name: " << dev_name.str() << std::endl;
|
||||
|
||||
return device_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
LinuxUinput* get_force_feedback_uinput() const;
|
||||
|
||||
public:
|
||||
int create_uinput_device(int device_id);
|
||||
void create_uinput_device(int device_id);
|
||||
|
||||
public:
|
||||
static bool is_mouse_button(int ev_code);
|
||||
|
|
|
@ -31,46 +31,15 @@ enum {
|
|||
|
||||
struct UIEvent
|
||||
{
|
||||
static UIEvent create(int device_id, int code)
|
||||
{
|
||||
UIEvent ev;
|
||||
ev.device_id = device_id;
|
||||
ev.code = code;
|
||||
return ev;
|
||||
}
|
||||
static UIEvent create(int device_id, int type, int code);
|
||||
static UIEvent invalid();
|
||||
|
||||
static UIEvent invalid()
|
||||
{
|
||||
UIEvent ev;
|
||||
ev.device_id = DEVICEID_INVALID;
|
||||
ev.code = -1;
|
||||
return ev;
|
||||
}
|
||||
|
||||
bool is_valid() const
|
||||
{
|
||||
return
|
||||
device_id == DEVICEID_INVALID ||
|
||||
code == -1;
|
||||
}
|
||||
|
||||
bool operator<(const UIEvent& rhs) const
|
||||
{
|
||||
if (device_id == rhs.device_id)
|
||||
{
|
||||
return code < rhs.code;
|
||||
}
|
||||
else if (device_id > rhs.device_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else // (device_id < rhs.device_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
void resolve_device_id();
|
||||
bool is_valid() const;
|
||||
bool operator<(const UIEvent& rhs) const;
|
||||
|
||||
int device_id;
|
||||
int type;
|
||||
int code;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue