Skip to content

Commit

Permalink
HID: apple: Add missing scan code event for keys handled by hid-apple
Browse files Browse the repository at this point in the history
When an EV_KEY event is generated by hid-apple due to special key
mapping, the usual associated scan code event (EV_MSC) is missing.
This issue can be seen with the evtest utility.

Add the scan code event for these special keys.

BugLink: https://bugs.debian.org/757356
Co-developed-by: Daniel Lin <ephemient@gmail.com>
Signed-off-by: Daniel Lin <ephemient@gmail.com>
Signed-off-by: Vincent Lefevre <vincent@vinc17.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Vincent Lefevre authored and Jiri Kosina committed Jul 28, 2021
1 parent df04fbe commit 3b41fb4
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions drivers/hid/hid-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ static const struct apple_key_translation *apple_find_translation(
return NULL;
}

static void input_event_with_scancode(struct input_dev *input,
__u8 type, __u16 code, unsigned int hid, __s32 value)
{
if (type == EV_KEY &&
(!test_bit(code, input->key)) == value)
input_event(input, EV_MSC, MSC_SCAN, hid);
input_event(input, type, code, value);
}

static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
struct hid_usage *usage, __s32 value)
{
Expand All @@ -199,7 +208,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,

if (usage->code == fn_keycode) {
asc->fn_on = !!value;
input_event(input, usage->type, KEY_FN, value);
input_event_with_scancode(input, usage->type, KEY_FN,
usage->hid, value);
return 1;
}

Expand Down Expand Up @@ -240,7 +250,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
code = do_translate ? trans->to : trans->from;
}

input_event(input, usage->type, code, value);
input_event_with_scancode(input, usage->type, code,
usage->hid, value);
return 1;
}

Expand All @@ -258,8 +269,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
clear_bit(usage->code,
asc->pressed_numlock);

input_event(input, usage->type, trans->to,
value);
input_event_with_scancode(input, usage->type,
trans->to, usage->hid, value);
}

return 1;
Expand All @@ -270,7 +281,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
if (hid->country == HID_COUNTRY_INTERNATIONAL_ISO) {
trans = apple_find_translation(apple_iso_keyboard, usage->code);
if (trans) {
input_event(input, usage->type, trans->to, value);
input_event_with_scancode(input, usage->type,
trans->to, usage->hid, value);
return 1;
}
}
Expand All @@ -279,15 +291,17 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
if (swap_opt_cmd) {
trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
if (trans) {
input_event(input, usage->type, trans->to, value);
input_event_with_scancode(input, usage->type,
trans->to, usage->hid, value);
return 1;
}
}

if (swap_fn_leftctrl) {
trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
if (trans) {
input_event(input, usage->type, trans->to, value);
input_event_with_scancode(input, usage->type,
trans->to, usage->hid, value);
return 1;
}
}
Expand All @@ -306,8 +320,8 @@ static int apple_event(struct hid_device *hdev, struct hid_field *field,

if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
usage->code == REL_HWHEEL) {
input_event(field->hidinput->input, usage->type, usage->code,
-value);
input_event_with_scancode(field->hidinput->input, usage->type,
usage->code, usage->hid, -value);
return 1;
}

Expand Down

0 comments on commit 3b41fb4

Please sign in to comment.