提交 f2d4ddfa 编写于 作者: B Benjamin Tissoires 提交者: Jiri Kosina

HID: input: rework spaghetti code with switch statements

Instead of using multiple `if (a == b)`, use the switch statement
which has been done exactly for that.

There should be no functional change (I don't expect moving down
HID_QUIRK_{X|Y}_INVERT having any impact.
Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: NPing Cheng <ping.cheng@wacom.com>
Acked-by: NPeter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 3c2b0dbd
...@@ -1354,12 +1354,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct ...@@ -1354,12 +1354,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
input = field->hidinput->input; input = field->hidinput->input;
if (usage->type == EV_ABS &&
(((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))) {
value = field->logical_maximum - value;
}
if (usage->hat_min < usage->hat_max || usage->hat_dir) { if (usage->hat_min < usage->hat_max || usage->hat_dir) {
int hat_dir = usage->hat_dir; int hat_dir = usage->hat_dir;
if (!hat_dir) if (!hat_dir)
...@@ -1370,12 +1364,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct ...@@ -1370,12 +1364,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
return; return;
} }
if (usage->hid == HID_DG_INVERT) { switch (usage->hid) {
case HID_DG_INVERT:
*quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT); *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
return; return;
}
if (usage->hid == HID_DG_INRANGE) { case HID_DG_INRANGE:
if (value) { if (value) {
input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1); input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
return; return;
...@@ -1383,46 +1377,58 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct ...@@ -1383,46 +1377,58 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
input_event(input, usage->type, usage->code, 0); input_event(input, usage->type, usage->code, 0);
input_event(input, usage->type, BTN_TOOL_RUBBER, 0); input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
return; return;
}
if (usage->hid == HID_DG_TIPPRESSURE && (*quirks & HID_QUIRK_NOTOUCH)) { case HID_DG_TIPPRESSURE:
int a = field->logical_minimum; if (*quirks & HID_QUIRK_NOTOUCH) {
int b = field->logical_maximum; int a = field->logical_minimum;
input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3)); int b = field->logical_maximum;
}
input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
}
break;
if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */ case HID_UP_PID | 0x83UL: /* Simultaneous Effects Max */
dbg_hid("Maximum Effects - %d\n",value); dbg_hid("Maximum Effects - %d\n",value);
return; return;
}
if (usage->hid == (HID_UP_PID | 0x7fUL)) { case HID_UP_PID | 0x7fUL:
dbg_hid("PID Pool Report\n"); dbg_hid("PID Pool Report\n");
return; return;
} }
if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */ switch (usage->type) {
return; case EV_KEY:
if (usage->code == 0) /* Key 0 is "unassigned", not KEY_UNKNOWN */
return;
break;
if ((usage->type == EV_REL) && (usage->code == REL_WHEEL_HI_RES || case EV_REL:
usage->code == REL_HWHEEL_HI_RES)) { if (usage->code == REL_WHEEL_HI_RES ||
hidinput_handle_scroll(usage, input, value); usage->code == REL_HWHEEL_HI_RES) {
return; hidinput_handle_scroll(usage, input, value);
} return;
}
break;
if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) && case EV_ABS:
(usage->code == ABS_VOLUME)) { if ((field->flags & HID_MAIN_ITEM_RELATIVE) &&
int count = abs(value); usage->code == ABS_VOLUME) {
int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN; int count = abs(value);
int i; int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
int i;
for (i = 0; i < count; i++) {
input_event(input, EV_KEY, direction, 1);
input_sync(input);
input_event(input, EV_KEY, direction, 0);
input_sync(input);
}
return;
for (i = 0; i < count; i++) { } else if (((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
input_event(input, EV_KEY, direction, 1); ((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))
input_sync(input); value = field->logical_maximum - value;
input_event(input, EV_KEY, direction, 0); break;
input_sync(input);
}
return;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册