diff --git a/panda/src/device/evdevInputDevice.cxx b/panda/src/device/evdevInputDevice.cxx index 39ba47b236..7a71e5f222 100644 --- a/panda/src/device/evdevInputDevice.cxx +++ b/panda/src/device/evdevInputDevice.cxx @@ -346,8 +346,16 @@ init_device() { int bi = 0; for (int i = 0; i < KEY_CNT; ++i) { if (test_bit(i, keys)) { - set_button_map(bi, map_button(i)); - //cerr << "Button " << bi << " is mapped by the driver to " << i << "\n"; + ButtonHandle mapped = map_button(i); + set_button_map(bi, mapped); + + if (mapped == ButtonHandle::none()) { + if (device_cat.is_debug()) { + device_cat.debug() << "Unmapped /dev/input/event" << _index + << " button " << bi << ": 0x" << hex << i << dec << "\n"; + } + } + if (test_bit(i, states)) { _buttons[bi].state = S_down; all_values_zero = false; @@ -735,6 +743,9 @@ map_button(int code) { } switch (code) { + case BTN_TRIGGER: + return GamepadButton::trigger(); + case BTN_A: return GamepadButton::action_a(); diff --git a/panda/src/device/inputDevice.I b/panda/src/device/inputDevice.I index a6094c8c69..b512b973a8 100644 --- a/panda/src/device/inputDevice.I +++ b/panda/src/device/inputDevice.I @@ -175,7 +175,7 @@ get_max_battery_level() const { * associated with a ButtonHandle even if their state is unknown. This number * may change as more buttons are discovered. */ -INLINE int InputDevice:: +INLINE size_t InputDevice:: get_num_buttons() const { LightMutexHolder holder(_lock); return _buttons.size(); @@ -192,10 +192,9 @@ get_num_buttons() const { * generate ButtonEvents when the buttons change state. */ INLINE void InputDevice:: -set_button_map(int index, ButtonHandle button) { +set_button_map(size_t index, ButtonHandle button) { LightMutexHolder holder(_lock); - nassertv(index >= 0); - if (index >= (int)_buttons.size()) { + if (index >= _buttons.size()) { _buttons.resize(index + 1, ButtonState()); } @@ -208,8 +207,8 @@ set_button_map(int index, ButtonHandle button) { * was associated. */ INLINE ButtonHandle InputDevice:: -get_button_map(int index) const { - if (index >= 0 && index < (int)_buttons.size()) { +get_button_map(size_t index) const { + if (index < _buttons.size()) { return _buttons[index].handle; } else { return ButtonHandle::none(); @@ -221,8 +220,8 @@ get_button_map(int index) const { * currently known to be down, or false if it is up or unknown. */ INLINE bool InputDevice:: -get_button_state(int index) const { - if (index >= 0 && index < (int)_buttons.size()) { +get_button_state(size_t index) const { + if (index < _buttons.size()) { return (_buttons[index].state == S_down); } else { return false; @@ -234,8 +233,8 @@ get_button_state(int index) const { * have never heard anything about this particular button. */ INLINE bool InputDevice:: -is_button_known(int index) const { - if (index >= 0 && index < (int)_buttons.size()) { +is_button_known(size_t index) const { + if (index < _buttons.size()) { return _buttons[index].state != S_unknown; } else { return false; @@ -248,12 +247,12 @@ is_button_known(int index) const { */ INLINE InputDevice::ButtonState InputDevice:: get_button(size_t index) const { - if (index >= 0 && index < (int)_buttons.size()) { + if (index < _buttons.size()) { return _buttons[index]; } else { device_cat.error() - << "Index " << index<< " was not found in the controls list\n"; - nassertr(false, ButtonState()); + << "Index " << index << " was not found in the controls list\n"; + return ButtonState(); } } @@ -263,21 +262,21 @@ get_button(size_t index) const { */ INLINE InputDevice::ButtonState InputDevice:: find_button(ButtonHandle handle) const { - for (int i; i < (int)_buttons.size(); i++) { + for (size_t i = 0; i < _buttons.size(); ++i) { if (_buttons[i].handle == handle) { return _buttons[i]; } } device_cat.error() << "Handle " << handle.get_name() << " was not found in the controls list\n"; - nassertr(false, ButtonState()); + return ButtonState(); } /** * Returns the number of analog controls known to the InputDevice. This number * may change as more controls are discovered. */ -INLINE int InputDevice:: +INLINE size_t InputDevice:: get_num_controls() const { return _controls.size(); } @@ -290,10 +289,9 @@ get_num_controls() const { * the various controls by index number. */ INLINE void InputDevice:: -set_control_map(int index, InputDevice::ControlAxis axis) { +set_control_map(size_t index, InputDevice::ControlAxis axis) { LightMutexHolder holder(_lock); - nassertv(index >= 0); - if (index >= (int)_controls.size()) { + if (index >= _controls.size()) { _controls.resize(index + 1, AnalogState()); } @@ -306,8 +304,8 @@ set_control_map(int index, InputDevice::ControlAxis axis) { * associated. */ INLINE InputDevice::ControlAxis InputDevice:: -get_control_map(int index) const { - if (index >= 0 && index < (int)_controls.size()) { +get_control_map(size_t index) const { + if (index < _controls.size()) { return _controls[index].axis; } else { return C_none; @@ -320,8 +318,8 @@ get_control_map(int index) const { * single control is -1.0 to 1.0. */ INLINE double InputDevice:: -get_control_state(int index) const { - if (index >= 0 && index < (int)_controls.size()) { +get_control_state(size_t index) const { + if (index < _controls.size()) { return _controls[index].state; } else { return 0.0; @@ -334,12 +332,12 @@ get_control_state(int index) const { */ INLINE InputDevice::AnalogState InputDevice:: get_control(size_t index) const { - if (index >= 0 && index < (int)_controls.size()) { + if (index < _controls.size()) { return _controls[index]; } else { device_cat.error() << "Index " << index<< " was not found in the controls list\n"; - nassertr(false, AnalogState()); + return AnalogState(); } } @@ -349,14 +347,14 @@ get_control(size_t index) const { */ INLINE InputDevice::AnalogState InputDevice:: find_control(InputDevice::ControlAxis axis) const { - for (int i; i < (int)_controls.size(); i++) { + for (size_t i = 0; i < _controls.size(); ++i) { if (_controls[i].axis == axis) { return _controls[i]; } } device_cat.error() << "Axis " << axis << " was not found in the controls list\n"; - nassertr(false, AnalogState()); + return AnalogState(); } /** @@ -364,8 +362,8 @@ find_control(InputDevice::ControlAxis axis) const { * if we have never heard anything about this particular control. */ INLINE bool InputDevice:: -is_control_known(int index) const { - if (index >= 0 && index < (int)_controls.size()) { +is_control_known(size_t index) const { + if (index < _controls.size()) { return _controls[index].known; } else { return false; diff --git a/panda/src/device/inputDevice.cxx b/panda/src/device/inputDevice.cxx index 956a821bef..6a910de566 100644 --- a/panda/src/device/inputDevice.cxx +++ b/panda/src/device/inputDevice.cxx @@ -212,8 +212,8 @@ set_control_state(int index, double state) { device_cat.spam() << "Changed control " << index; - if (_controls[index].known != C_none) { - device_cat.spam(false) << " (" << _controls[index].known << ")"; + if (_controls[index].axis != C_none) { + device_cat.spam(false) << " (" << _controls[index].axis << ")"; } device_cat.spam(false) << " to " << state << "\n"; @@ -438,6 +438,14 @@ operator << (ostream &out, InputDevice::DeviceClass dc) { case InputDevice::DC_steering_wheel: out << "steering_wheel"; break; + + case InputDevice::DC_dance_pad: + out << "dance_pad"; + break; + + case InputDevice::DC_hmd: + out << "hmd"; + break; } return out; } @@ -488,6 +496,30 @@ operator << (ostream &out, InputDevice::ControlAxis axis) { case InputDevice::C_throttle: out << "throttle"; break; + + case InputDevice::C_rudder: + out << "rudder"; + break; + + case InputDevice::C_hat_x: + out << "hat_x"; + break; + + case InputDevice::C_hat_y: + out << "hat_y"; + break; + + case InputDevice::C_wheel: + out << "wheel"; + break; + + case InputDevice::C_accelerator: + out << "accelerator"; + break; + + case InputDevice::C_brake: + out << "brake"; + break; } return out; diff --git a/panda/src/device/inputDevice.h b/panda/src/device/inputDevice.h index a007fbb081..d964b80781 100644 --- a/panda/src/device/inputDevice.h +++ b/panda/src/device/inputDevice.h @@ -156,17 +156,17 @@ PUBLISHED: INLINE short get_battery_level() const; INLINE short get_max_battery_level() const; - INLINE int get_num_buttons() const; - INLINE void set_button_map(int index, ButtonHandle button); - INLINE ButtonHandle get_button_map(int index) const; - INLINE bool get_button_state(int index) const; - INLINE bool is_button_known(int index) const; + INLINE size_t get_num_buttons() const; + INLINE void set_button_map(size_t index, ButtonHandle button); + INLINE ButtonHandle get_button_map(size_t index) const; + INLINE bool get_button_state(size_t index) const; + INLINE bool is_button_known(size_t index) const; - INLINE int get_num_controls() const; - INLINE void set_control_map(int index, ControlAxis axis); - INLINE ControlAxis get_control_map(int index) const; - INLINE double get_control_state(int index) const; - INLINE bool is_control_known(int index) const; + INLINE size_t get_num_controls() const; + INLINE void set_control_map(size_t index, ControlAxis axis); + INLINE ControlAxis get_control_map(size_t index) const; + INLINE double get_control_state(size_t index) const; + INLINE bool is_control_known(size_t index) const; INLINE void set_vibration(double strong, double weak); diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index cb7960313e..d37d765d91 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -690,11 +690,6 @@ add_input_device(InputDevice *device) { LightMutexHolder holder(_input_lock); int index = (int)_input_devices.size(); _input_devices.push_back(device); - - if (device->is_of_type(GraphicsWindowInputDevice::get_class_type())) { - ((GraphicsWindowInputDevice *)device)->set_device_index(index); - } - return index; } diff --git a/panda/src/display/graphicsWindowInputDevice.I b/panda/src/display/graphicsWindowInputDevice.I index 9d89dc308e..ef97c1f974 100644 --- a/panda/src/display/graphicsWindowInputDevice.I +++ b/panda/src/display/graphicsWindowInputDevice.I @@ -15,17 +15,7 @@ * */ INLINE GraphicsWindowInputDevice:: -GraphicsWindowInputDevice() : _host(NULL) { -} - -/** - * Set the device index. This is reported in pointer events. The device - * index will be equal to the position of the GraphicsWindowInputDevice in the - * window's list. - */ -INLINE void GraphicsWindowInputDevice:: -set_device_index(int index) { - _device_index = index; +GraphicsWindowInputDevice() { } /** diff --git a/panda/src/display/graphicsWindowInputDevice.cxx b/panda/src/display/graphicsWindowInputDevice.cxx index 4f30561112..6e0a5a7dfe 100644 --- a/panda/src/display/graphicsWindowInputDevice.cxx +++ b/panda/src/display/graphicsWindowInputDevice.cxx @@ -28,8 +28,7 @@ TypeHandle GraphicsWindowInputDevice::_type_handle; */ GraphicsWindowInputDevice:: GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags) : - InputDevice(name, DC_virtual, flags), - _host(host) + InputDevice(name, DC_virtual, flags) { } @@ -74,7 +73,6 @@ GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©) { */ void GraphicsWindowInputDevice:: operator = (const GraphicsWindowInputDevice ©) { - _host = copy._host; InputDevice::operator = (copy); } diff --git a/panda/src/display/graphicsWindowInputDevice.h b/panda/src/display/graphicsWindowInputDevice.h index 50bd03e01f..b5b6a98a46 100644 --- a/panda/src/display/graphicsWindowInputDevice.h +++ b/panda/src/display/graphicsWindowInputDevice.h @@ -39,8 +39,6 @@ public: void operator = (const GraphicsWindowInputDevice ©); ~GraphicsWindowInputDevice(); - INLINE void set_device_index(int index); - PUBLISHED: // The following interface is for the various kinds of GraphicsWindows to // record the data incoming on the device. @@ -61,9 +59,6 @@ PUBLISHED: INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time()); private: - GraphicsWindow *_host; - int _device_index; - typedef pset ButtonsHeld; ButtonsHeld _buttons_held; diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index b7e7d5dccf..b9118a3f93 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -55,44 +55,6 @@ eglGraphicsWindow:: ~eglGraphicsWindow() { } -/** - * Forces the pointer to the indicated position within the window, if - * possible. - * - * Returns true if successful, false on failure. This may fail if the mouse - * is not currently within the window, or if the API doesn't support this - * operation. - */ -bool eglGraphicsWindow:: -move_pointer(int device, int x, int y) { - // Note: this is not thread-safe; it should be called only from App. - // Probably not an issue. - if (device == 0) { - // Move the system mouse pointer. - if (!_properties.get_foreground() || - !_input_devices[0].get_pointer().get_in_window()) { - // If the window doesn't have input focus, or the mouse isn't currently - // within the window, forget it. - return false; - } - - const MouseData &md = _input_devices[0].get_pointer(); - if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) { - XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y); - _input_devices[0].set_pointer_in_window(x, y); - } - return true; - } else { - // Move a raw mouse. - if ((device < 1)||(device >= _input_devices.size())) { - return false; - } - _input_devices[device].set_pointer_in_window(x, y); - return true; - } -} - - /** * This function will be called within the draw thread before beginning * rendering for a given frame. It should do whatever setup is required, and diff --git a/panda/src/egldisplay/eglGraphicsWindow.h b/panda/src/egldisplay/eglGraphicsWindow.h index 508365cc65..e936a97cef 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.h +++ b/panda/src/egldisplay/eglGraphicsWindow.h @@ -33,7 +33,6 @@ public: GraphicsOutput *host); virtual ~eglGraphicsWindow(); - virtual bool move_pointer(int device, int x, int y); virtual bool begin_frame(FrameMode mode, Thread *current_thread); virtual void end_frame(FrameMode mode, Thread *current_thread); virtual void end_flip(); diff --git a/panda/src/putil/gamepadButton.cxx b/panda/src/putil/gamepadButton.cxx index ba7fe41b5a..7ddbc33b17 100644 --- a/panda/src/putil/gamepadButton.cxx +++ b/panda/src/putil/gamepadButton.cxx @@ -47,6 +47,8 @@ DEFINE_GAMEPAD_BUTTON_HANDLE(action_z) DEFINE_GAMEPAD_BUTTON_HANDLE(action_1) DEFINE_GAMEPAD_BUTTON_HANDLE(action_2) +DEFINE_GAMEPAD_BUTTON_HANDLE(trigger) + /** * This is intended to be called only once, by the static initialization * performed in config_util.cxx. @@ -81,4 +83,6 @@ init_gamepad_buttons() { ButtonRegistry::ptr()->register_button(_action_1, "action_1"); ButtonRegistry::ptr()->register_button(_action_2, "action_2"); + + ButtonRegistry::ptr()->register_button(_trigger, "trigger"); } diff --git a/panda/src/putil/gamepadButton.h b/panda/src/putil/gamepadButton.h index 9a8597a6b9..0edbbad99b 100644 --- a/panda/src/putil/gamepadButton.h +++ b/panda/src/putil/gamepadButton.h @@ -53,6 +53,8 @@ PUBLISHED: static ButtonHandle action_1(); static ButtonHandle action_2(); + static ButtonHandle trigger(); + public: static void init_gamepad_buttons(); }; diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index 43cff8e061..949d4841d0 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -131,14 +131,13 @@ move_pointer(int device, int x, int y) { // Probably not an issue. if (device == 0) { // Move the system mouse pointer. - if (!_properties.get_foreground() || - !_input->get_pointer().get_in_window()) { + PointerData md = _input->get_pointer(); + if (!_properties.get_foreground() || !md.get_in_window()) { // If the window doesn't have input focus, or the mouse isn't currently // within the window, forget it. return false; } - const MouseData &md = _input->get_pointer(); if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) { if (!_dga_mouse_enabled) { XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y); @@ -147,12 +146,8 @@ move_pointer(int device, int x, int y) { } return true; } else { - // Move a raw mouse. - if (device < 1 || device >= _input_devices.size()) { - return false; - } - //_input_devices[device]->set_pointer_in_window(x, y); - return true; + // Can't move a raw mouse. + return false; } } @@ -1236,6 +1231,7 @@ setup_colormap(XVisualInfo *visual) { /** * Adds raw mice to the _input_devices list. + * @deprecated obtain raw devices via the device manager instead. */ void x11GraphicsWindow:: open_raw_mice() { diff --git a/panda/src/x11display/x11GraphicsWindow.h b/panda/src/x11display/x11GraphicsWindow.h index 1400456d3b..c452622d03 100644 --- a/panda/src/x11display/x11GraphicsWindow.h +++ b/panda/src/x11display/x11GraphicsWindow.h @@ -102,13 +102,6 @@ protected: Bool _override_redirect; Atom _wm_delete_window; - struct MouseDeviceInfo { - int _fd; - int _input_device_index; - string _io_buffer; - }; - pvector _mouse_device_info; - public: static TypeHandle get_class_type() { return _type_handle;