diff --git a/logic.c b/logic.c index dcfc511..8e50bde 100644 --- a/logic.c +++ b/logic.c @@ -42,6 +42,8 @@ int logic_create(logic_t *const logic) { logic->gamepad_output = GAMEPAD_OUTPUT_DS4; } + logic->restore_to = logic->gamepad_output; + if (queue_init_res < 0) { fprintf(stderr, "Unable to create queue: %d\n", queue_init_res); return queue_init_res; diff --git a/logic.h b/logic.h index c520069..8d3d189 100644 --- a/logic.h +++ b/logic.h @@ -67,6 +67,8 @@ typedef struct logic { // the mutex is not needed if only one thread is writing this and others are checking with equality //pthread_mutex_t gamepad_output_mutex; gamepad_output_t gamepad_output; + + gamepad_output_t restore_to; } logic_t; int logic_create(logic_t *const logic); diff --git a/output_dev.c b/output_dev.c index 0f363a6..5ecdf86 100644 --- a/output_dev.c +++ b/output_dev.c @@ -569,6 +569,7 @@ static void decode_ev(output_dev_t *const out_dev, message_t *const msg) { if (msg->data.event.ev[1].value == 1) { printf("Detected mode switch command, switching mode...\n"); + const int was_mouse_mode = is_mouse_mode(&out_dev->logic->platform); const int new_mode = cycle_mode(&out_dev->logic->platform); if (new_mode < 0) { @@ -577,8 +578,11 @@ static void decode_ev(output_dev_t *const out_dev, message_t *const msg) { printf("Mode correctly switched to %d\n", new_mode); if (new_mode == 1) { + out_dev->logic->restore_to = out_dev->logic->gamepad_output; printf("Mode switched to virtual evdev for lizard mode.\n"); out_dev->logic->gamepad_output = GAMEPAD_OUTPUT_EVDEV; + } else if (was_mouse_mode) { + out_dev->logic->gamepad_output = out_dev->logic->restore_to; } } } else {