Skip to content

Commit

Permalink
xpadneo, consumer: Move buttons to keyboard device
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed May 26, 2022
1 parent ef38514 commit cdea040
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h
/* combine triggers to form a rudder, use ABS_MISC to order after dpad */
input_set_abs_params(xdata->gamepad, ABS_MISC, -1023, 1023, 3, 63);

/* do not report the consumer control buttons as part of the gamepad */
/* do not report the keyboard buttons as part of the gamepad */
__clear_bit(BTN_XBOX, xdata->gamepad->keybit);
__clear_bit(BTN_SHARE, xdata->gamepad->keybit);

Expand All @@ -884,7 +884,7 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
{
struct xpadneo_devdata *xdata = hid_get_drvdata(hdev);
struct input_dev *gamepad = xdata->gamepad;
struct input_dev *consumer = xdata->consumer;
struct input_dev *keyboard = xdata->keyboard;

if ((usage->type == EV_KEY) && (usage->code == BTN_PADDLES(0))) {
if (gamepad && xdata->profile == 0) {
Expand Down Expand Up @@ -929,24 +929,24 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
xdata->xbox_button_down = false;
if (xdata->profile_switched) {
xdata->profile_switched = false;
} else if (consumer) {
} else if (keyboard) {
/* replay cached event */
input_report_key(consumer, BTN_XBOX, 1);
input_sync(consumer);
input_report_key(keyboard, BTN_XBOX, 1);
input_sync(keyboard);
/* synthesize the release to remove the scan code */
input_report_key(consumer, BTN_XBOX, 0);
input_sync(consumer);
input_report_key(keyboard, BTN_XBOX, 0);
input_sync(keyboard);
}
}
if (!consumer)
goto consumer_missing;
if (!keyboard)
goto keyboard_missing;
goto stop_processing;
} else if ((usage->type == EV_KEY) && (usage->code == BTN_SHARE)) {
/* move the Share button to the consumer control device */
if (!consumer)
goto consumer_missing;
input_report_key(consumer, BTN_SHARE, value);
input_sync(consumer);
/* move the Share button to the keyboard device */
if (!keyboard)
goto keyboard_missing;
input_report_key(keyboard, BTN_SHARE, value);
input_sync(keyboard);
goto stop_processing;
} else if (xdata->xbox_button_down && (usage->type == EV_KEY)) {
if (!(xdata->quirks & XPADNEO_QUIRK_USE_HW_PROFILES)) {
Expand Down Expand Up @@ -985,10 +985,10 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
}
return 0;

consumer_missing:
if ((xdata->missing_reported && XPADNEO_MISSING_CONSUMER) == 0) {
xdata->missing_reported |= XPADNEO_MISSING_CONSUMER;
hid_err(hdev, "consumer control not detected\n");
keyboard_missing:
if ((xdata->missing_reported && XPADNEO_MISSING_KEYBOARD) == 0) {
xdata->missing_reported |= XPADNEO_MISSING_KEYBOARD;
hid_err(hdev, "keyboard not detected\n");
}

stop_processing:
Expand Down
4 changes: 0 additions & 4 deletions hid-xpadneo/src/xpadneo/consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ extern int xpadneo_init_consumer(struct xpadneo_devdata *xdata)
return ret;
}

/* enable key events for consumer control */
input_set_capability(xdata->consumer, EV_KEY, BTN_XBOX);
input_set_capability(xdata->consumer, EV_KEY, BTN_SHARE);

if (synth) {
ret = input_register_device(xdata->consumer);
if (ret) {
Expand Down
4 changes: 4 additions & 0 deletions hid-xpadneo/src/xpadneo/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ extern int xpadneo_init_keyboard(struct xpadneo_devdata *xdata)
return ret;
}

/* enable key events for keyboard */
input_set_capability(xdata->keyboard, EV_KEY, BTN_XBOX);
input_set_capability(xdata->keyboard, EV_KEY, BTN_SHARE);

if (synth) {
ret = input_register_device(xdata->keyboard);
if (ret) {
Expand Down

0 comments on commit cdea040

Please sign in to comment.