Skip to contentSkip to conversation

Input: make input_report_slot_state() return boolean

RFC/PATCH Dmitry Torokhov 3 participants 3 messages Jun 5, 2018 – Jun 6, 2018

Subsystems (3)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

Let's make input_report_slot_state() return boolean representing whether the contact is active or not. This will allow writing code like:

	if (input_mt_report_slot_state(input, obj->mt_tool,
					obj->type != RMI_2D_OBJECT_NONE) {

		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
		...
	}

instead of:

	input_mt_report_slot_state(input, obj->mt_tool,
				   obj->type != RMI_2D_OBJECT_NONE);
	if (obj->type != RMI_2D_OBJECT_NONE) {
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
		...
	}
---
 drivers/input/input-mt.c | 10 +++++++---
 include/linux/input/mt.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/input/input-mt.c +7 -3
index 7ca4b318ed419..4a69716e54614 100644
@@ -131,8 +131,10 @@ EXPORT_SYMBOL(input_mt_destroy_slots);
  * inactive, or if the tool type is changed, a new tracking id is
  * assigned to the slot. The tool type is only reported if the
  * corresponding absbit field is set.
+ *
+ * Returns true if contact is active.
  */
-void input_mt_report_slot_state(struct input_dev *dev,
+bool input_mt_report_slot_state(struct input_dev *dev,
 				unsigned int tool_type, bool active)
 {
 	struct input_mt *mt = dev->mt;
@@ -140,14 +142,14 @@ void input_mt_report_slot_state(struct input_dev *dev,
 	int id;
 
 	if (!mt)
-		return;
+		return false;
 
 	slot = &mt->slots[mt->slot];
 	slot->frame = mt->frame;
 
 	if (!active) {
 		input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
-		return;
+		return false;
 	}
 
 	id = input_mt_get_value(slot, ABS_MT_TRACKING_ID);
@@ -156,6 +158,8 @@ void input_mt_report_slot_state(struct input_dev *dev,
 
 	input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id);
 	input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type);
+
+	return true;
 }
 EXPORT_SYMBOL(input_mt_report_slot_state);
 
include/linux/input/mt.h +1 -1
index d7188de4db968..3f4bf60b0bb55 100644
@@ -100,7 +100,7 @@ static inline bool input_is_mt_axis(int axis)
 	return axis == ABS_MT_SLOT || input_is_mt_value(axis);
 }
 
-void input_mt_report_slot_state(struct input_dev *dev,
+bool input_mt_report_slot_state(struct input_dev *dev,
 				unsigned int tool_type, bool active);
 
 void input_mt_report_finger_count(struct input_dev *dev, int count);
Signature · 5 lines
2.17.1.1185.g55be947832-goog


-- 
Dmitry
maintainer Reviewed-by
#1 lore raw
Quoted 74 lines · Dmitry Torokhov

Let's make input_report_slot_state() return boolean representing whether the contact is active or not. This will allow writing code like:

	if (input_mt_report_slot_state(input, obj->mt_tool,
					obj->type != RMI_2D_OBJECT_NONE) {

		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
		...
	}

instead of:

	input_mt_report_slot_state(input, obj->mt_tool,
				   obj->type != RMI_2D_OBJECT_NONE);
	if (obj->type != RMI_2D_OBJECT_NONE) {
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
		input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
		...
	}
---
  drivers/input/input-mt.c | 10 +++++++---
  include/linux/input/mt.h |  2 +-
  2 files changed, 8 insertions(+), 4 deletions(-)
drivers/input/input-mt.c +7 -3
index 7ca4b318ed419..4a69716e54614 100644
@@ -131,8 +131,10 @@ EXPORT_SYMBOL(input_mt_destroy_slots);
   * inactive, or if the tool type is changed, a new tracking id is
   * assigned to the slot. The tool type is only reported if the
   * corresponding absbit field is set.
+ *
+ * Returns true if contact is active.
   */
-void input_mt_report_slot_state(struct input_dev *dev,
+bool input_mt_report_slot_state(struct input_dev *dev,
  				unsigned int tool_type, bool active)
  {
  	struct input_mt *mt = dev->mt;
@@ -140,14 +142,14 @@ void input_mt_report_slot_state(struct input_dev *dev,
  	int id;
 
  	if (!mt)
-		return;
+		return false;
 
  	slot = &mt->slots[mt->slot];
  	slot->frame = mt->frame;
 
  	if (!active) {
  		input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
-		return;
+		return false;
  	}
 
  	id = input_mt_get_value(slot, ABS_MT_TRACKING_ID);
@@ -156,6 +158,8 @@ void input_mt_report_slot_state(struct input_dev *dev,
 
  	input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id);
  	input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type);
+
+	return true;
  }
  EXPORT_SYMBOL(input_mt_report_slot_state);
 
include/linux/input/mt.h +0 -0
index d7188de4db968..3f4bf60b0bb55 100644

include/linux/input/mt.h static inline bool input_is_mt_axis(int axis) · line 106

Quoted 8 lines
include/linux/input/mt.h +1 -1
@@ -100,7 +100,7 @@ static inline bool input_is_mt_axis(int axis)
  	return axis == ABS_MT_SLOT || input_is_mt_value(axis);
  }
 
-void input_mt_report_slot_state(struct input_dev *dev,
+bool input_mt_report_slot_state(struct input_dev *dev,
  				unsigned int tool_type, bool active);
 
  void input_mt_report_finger_count(struct input_dev *dev, int count);

Thanks, Dmitry.

Henrik

#2 lore raw
In reply to Dmitry Torokhov
Quoted 21 lines · Dmitry Torokhov

Let's make input_report_slot_state() return boolean representing whether the contact is active or not. This will allow writing code like:

        if (input_mt_report_slot_state(input, obj->mt_tool,
                                        obj->type != RMI_2D_OBJECT_NONE) {

                input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
                input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
                ...
        }

instead of:

        input_mt_report_slot_state(input, obj->mt_tool,
                                   obj->type != RMI_2D_OBJECT_NONE);
        if (obj->type != RMI_2D_OBJECT_NONE) {
                input_event(sensor->input, EV_ABS, ABS_MT_POSITION_X, obj->x);
                input_event(sensor->input, EV_ABS, ABS_MT_POSITION_Y, obj->y);
                ...
        }
Quoted 2 lines

---

Looks good to me as well.

In case you still need it:

Cheers,
Benjamin