Browse Source

More work on integrating new input framework

rdb 9 years ago
parent
commit
fa7f385bb8

+ 13 - 2
panda/src/device/evdevInputDevice.cxx

@@ -346,8 +346,16 @@ init_device() {
     int bi = 0;
     int bi = 0;
     for (int i = 0; i < KEY_CNT; ++i) {
     for (int i = 0; i < KEY_CNT; ++i) {
       if (test_bit(i, keys)) {
       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)) {
         if (test_bit(i, states)) {
           _buttons[bi].state = S_down;
           _buttons[bi].state = S_down;
           all_values_zero = false;
           all_values_zero = false;
@@ -735,6 +743,9 @@ map_button(int code) {
   }
   }
 
 
   switch (code) {
   switch (code) {
+  case BTN_TRIGGER:
+    return GamepadButton::trigger();
+
   case BTN_A:
   case BTN_A:
     return GamepadButton::action_a();
     return GamepadButton::action_a();
 
 

+ 27 - 29
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
  * associated with a ButtonHandle even if their state is unknown.  This number
  * may change as more buttons are discovered.
  * may change as more buttons are discovered.
  */
  */
-INLINE int InputDevice::
+INLINE size_t InputDevice::
 get_num_buttons() const {
 get_num_buttons() const {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
   return _buttons.size();
   return _buttons.size();
@@ -192,10 +192,9 @@ get_num_buttons() const {
  * generate ButtonEvents when the buttons change state.
  * generate ButtonEvents when the buttons change state.
  */
  */
 INLINE void InputDevice::
 INLINE void InputDevice::
-set_button_map(int index, ButtonHandle button) {
+set_button_map(size_t index, ButtonHandle button) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
-  nassertv(index >= 0);
-  if (index >= (int)_buttons.size()) {
+  if (index >= _buttons.size()) {
     _buttons.resize(index + 1, ButtonState());
     _buttons.resize(index + 1, ButtonState());
   }
   }
 
 
@@ -208,8 +207,8 @@ set_button_map(int index, ButtonHandle button) {
  * was associated.
  * was associated.
  */
  */
 INLINE ButtonHandle InputDevice::
 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;
     return _buttons[index].handle;
   } else {
   } else {
     return ButtonHandle::none();
     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.
  * currently known to be down, or false if it is up or unknown.
  */
  */
 INLINE bool InputDevice::
 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);
     return (_buttons[index].state == S_down);
   } else {
   } else {
     return false;
     return false;
@@ -234,8 +233,8 @@ get_button_state(int index) const {
  * have never heard anything about this particular button.
  * have never heard anything about this particular button.
  */
  */
 INLINE bool InputDevice::
 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;
     return _buttons[index].state != S_unknown;
   } else {
   } else {
     return false;
     return false;
@@ -248,12 +247,12 @@ is_button_known(int index) const {
  */
  */
 INLINE InputDevice::ButtonState InputDevice::
 INLINE InputDevice::ButtonState InputDevice::
 get_button(size_t index) const {
 get_button(size_t index) const {
-  if (index >= 0 && index < (int)_buttons.size()) {
+  if (index < _buttons.size()) {
     return _buttons[index];
     return _buttons[index];
   } else {
   } else {
     device_cat.error()
     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::
 INLINE InputDevice::ButtonState InputDevice::
 find_button(ButtonHandle handle) const {
 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) {
     if (_buttons[i].handle == handle) {
       return _buttons[i];
       return _buttons[i];
     }
     }
   }
   }
   device_cat.error()
   device_cat.error()
     << "Handle " << handle.get_name() << " was not found in the controls list\n";
     << "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
  * Returns the number of analog controls known to the InputDevice.  This number
  * may change as more controls are discovered.
  * may change as more controls are discovered.
  */
  */
-INLINE int InputDevice::
+INLINE size_t InputDevice::
 get_num_controls() const {
 get_num_controls() const {
   return _controls.size();
   return _controls.size();
 }
 }
@@ -290,10 +289,9 @@ get_num_controls() const {
  * the various controls by index number.
  * the various controls by index number.
  */
  */
 INLINE void InputDevice::
 INLINE void InputDevice::
-set_control_map(int index, InputDevice::ControlAxis axis) {
+set_control_map(size_t index, InputDevice::ControlAxis axis) {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
-  nassertv(index >= 0);
-  if (index >= (int)_controls.size()) {
+  if (index >= _controls.size()) {
     _controls.resize(index + 1, AnalogState());
     _controls.resize(index + 1, AnalogState());
   }
   }
 
 
@@ -306,8 +304,8 @@ set_control_map(int index, InputDevice::ControlAxis axis) {
  * associated.
  * associated.
  */
  */
 INLINE InputDevice::ControlAxis InputDevice::
 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;
     return _controls[index].axis;
   } else {
   } else {
     return C_none;
     return C_none;
@@ -320,8 +318,8 @@ get_control_map(int index) const {
  * single control is -1.0 to 1.0.
  * single control is -1.0 to 1.0.
  */
  */
 INLINE double InputDevice::
 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;
     return _controls[index].state;
   } else {
   } else {
     return 0.0;
     return 0.0;
@@ -334,12 +332,12 @@ get_control_state(int index) const {
  */
  */
 INLINE InputDevice::AnalogState InputDevice::
 INLINE InputDevice::AnalogState InputDevice::
 get_control(size_t index) const {
 get_control(size_t index) const {
-  if (index >= 0 && index < (int)_controls.size()) {
+  if (index < _controls.size()) {
     return _controls[index];
     return _controls[index];
   } else {
   } else {
     device_cat.error()
     device_cat.error()
       << "Index " << index<< " was not found in the controls list\n";
       << "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::
 INLINE InputDevice::AnalogState InputDevice::
 find_control(InputDevice::ControlAxis axis) const {
 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) {
     if (_controls[i].axis == axis) {
       return _controls[i];
       return _controls[i];
     }
     }
   }
   }
   device_cat.error()
   device_cat.error()
     << "Axis " << axis << " was not found in the controls list\n";
     << "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.
  * if we have never heard anything about this particular control.
  */
  */
 INLINE bool InputDevice::
 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;
     return _controls[index].known;
   } else {
   } else {
     return false;
     return false;

+ 34 - 2
panda/src/device/inputDevice.cxx

@@ -212,8 +212,8 @@ set_control_state(int index, double state) {
     device_cat.spam()
     device_cat.spam()
       << "Changed control " << index;
       << "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";
     device_cat.spam(false) << " to " << state << "\n";
@@ -438,6 +438,14 @@ operator << (ostream &out, InputDevice::DeviceClass dc) {
   case InputDevice::DC_steering_wheel:
   case InputDevice::DC_steering_wheel:
     out << "steering_wheel";
     out << "steering_wheel";
     break;
     break;
+
+  case InputDevice::DC_dance_pad:
+    out << "dance_pad";
+    break;
+
+  case InputDevice::DC_hmd:
+    out << "hmd";
+    break;
   }
   }
   return out;
   return out;
 }
 }
@@ -488,6 +496,30 @@ operator << (ostream &out, InputDevice::ControlAxis axis) {
   case InputDevice::C_throttle:
   case InputDevice::C_throttle:
     out << "throttle";
     out << "throttle";
     break;
     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;
   return out;

+ 11 - 11
panda/src/device/inputDevice.h

@@ -156,17 +156,17 @@ PUBLISHED:
   INLINE short get_battery_level() const;
   INLINE short get_battery_level() const;
   INLINE short get_max_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 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_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 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);
   INLINE void set_vibration(double strong, double weak);
 
 

+ 0 - 5
panda/src/display/graphicsWindow.cxx

@@ -690,11 +690,6 @@ add_input_device(InputDevice *device) {
   LightMutexHolder holder(_input_lock);
   LightMutexHolder holder(_input_lock);
   int index = (int)_input_devices.size();
   int index = (int)_input_devices.size();
   _input_devices.push_back(device);
   _input_devices.push_back(device);
-
-  if (device->is_of_type(GraphicsWindowInputDevice::get_class_type())) {
-    ((GraphicsWindowInputDevice *)device)->set_device_index(index);
-  }
-
   return index;
   return index;
 }
 }
 
 

+ 1 - 11
panda/src/display/graphicsWindowInputDevice.I

@@ -15,17 +15,7 @@
  *
  *
  */
  */
 INLINE GraphicsWindowInputDevice::
 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() {
 }
 }
 
 
 /**
 /**

+ 1 - 3
panda/src/display/graphicsWindowInputDevice.cxx

@@ -28,8 +28,7 @@ TypeHandle GraphicsWindowInputDevice::_type_handle;
  */
  */
 GraphicsWindowInputDevice::
 GraphicsWindowInputDevice::
 GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags) :
 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 &copy) {
  */
  */
 void GraphicsWindowInputDevice::
 void GraphicsWindowInputDevice::
 operator = (const GraphicsWindowInputDevice &copy) {
 operator = (const GraphicsWindowInputDevice &copy) {
-  _host = copy._host;
   InputDevice::operator = (copy);
   InputDevice::operator = (copy);
 }
 }
 
 

+ 0 - 5
panda/src/display/graphicsWindowInputDevice.h

@@ -39,8 +39,6 @@ public:
   void operator = (const GraphicsWindowInputDevice &copy);
   void operator = (const GraphicsWindowInputDevice &copy);
   ~GraphicsWindowInputDevice();
   ~GraphicsWindowInputDevice();
 
 
-  INLINE void set_device_index(int index);
-
 PUBLISHED:
 PUBLISHED:
   // The following interface is for the various kinds of GraphicsWindows to
   // The following interface is for the various kinds of GraphicsWindows to
   // record the data incoming on the device.
   // 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());
   INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time());
 
 
 private:
 private:
-  GraphicsWindow *_host;
-  int _device_index;
-
   typedef pset<ButtonHandle> ButtonsHeld;
   typedef pset<ButtonHandle> ButtonsHeld;
   ButtonsHeld _buttons_held;
   ButtonsHeld _buttons_held;
 
 

+ 0 - 38
panda/src/egldisplay/eglGraphicsWindow.cxx

@@ -55,44 +55,6 @@ eglGraphicsWindow::
 ~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
  * This function will be called within the draw thread before beginning
  * rendering for a given frame.  It should do whatever setup is required, and
  * rendering for a given frame.  It should do whatever setup is required, and

+ 0 - 1
panda/src/egldisplay/eglGraphicsWindow.h

@@ -33,7 +33,6 @@ public:
                     GraphicsOutput *host);
                     GraphicsOutput *host);
   virtual ~eglGraphicsWindow();
   virtual ~eglGraphicsWindow();
 
 
-  virtual bool move_pointer(int device, int x, int y);
   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
   virtual void end_frame(FrameMode mode, Thread *current_thread);
   virtual void end_frame(FrameMode mode, Thread *current_thread);
   virtual void end_flip();
   virtual void end_flip();

+ 4 - 0
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_1)
 DEFINE_GAMEPAD_BUTTON_HANDLE(action_2)
 DEFINE_GAMEPAD_BUTTON_HANDLE(action_2)
 
 
+DEFINE_GAMEPAD_BUTTON_HANDLE(trigger)
+
 /**
 /**
  * This is intended to be called only once, by the static initialization
  * This is intended to be called only once, by the static initialization
  * performed in config_util.cxx.
  * 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_1, "action_1");
   ButtonRegistry::ptr()->register_button(_action_2, "action_2");
   ButtonRegistry::ptr()->register_button(_action_2, "action_2");
+
+  ButtonRegistry::ptr()->register_button(_trigger, "trigger");
 }
 }

+ 2 - 0
panda/src/putil/gamepadButton.h

@@ -53,6 +53,8 @@ PUBLISHED:
   static ButtonHandle action_1();
   static ButtonHandle action_1();
   static ButtonHandle action_2();
   static ButtonHandle action_2();
 
 
+  static ButtonHandle trigger();
+
 public:
 public:
   static void init_gamepad_buttons();
   static void init_gamepad_buttons();
 };
 };

+ 5 - 9
panda/src/x11display/x11GraphicsWindow.cxx

@@ -131,14 +131,13 @@ move_pointer(int device, int x, int y) {
   // Probably not an issue.
   // Probably not an issue.
   if (device == 0) {
   if (device == 0) {
     // Move the system mouse pointer.
     // 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
       // If the window doesn't have input focus, or the mouse isn't currently
       // within the window, forget it.
       // within the window, forget it.
       return false;
       return false;
     }
     }
 
 
-    const MouseData &md = _input->get_pointer();
     if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) {
     if (!md.get_in_window() || md.get_x() != x || md.get_y() != y) {
       if (!_dga_mouse_enabled) {
       if (!_dga_mouse_enabled) {
         XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y);
         XWarpPointer(_display, None, _xwindow, 0, 0, 0, 0, x, y);
@@ -147,12 +146,8 @@ move_pointer(int device, int x, int y) {
     }
     }
     return true;
     return true;
   } else {
   } 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.
  * Adds raw mice to the _input_devices list.
+ * @deprecated obtain raw devices via the device manager instead.
  */
  */
 void x11GraphicsWindow::
 void x11GraphicsWindow::
 open_raw_mice() {
 open_raw_mice() {

+ 0 - 7
panda/src/x11display/x11GraphicsWindow.h

@@ -102,13 +102,6 @@ protected:
   Bool _override_redirect;
   Bool _override_redirect;
   Atom _wm_delete_window;
   Atom _wm_delete_window;
 
 
-  struct MouseDeviceInfo {
-    int    _fd;
-    int    _input_device_index;
-    string _io_buffer;
-  };
-  pvector<MouseDeviceInfo> _mouse_device_info;
-
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
     return _type_handle;
     return _type_handle;