Add pausing

This commit is contained in:
Camden Dixie O'Brien
2025-10-16 14:22:10 +01:00
parent 07553feef1
commit 03f1bedc61
4 changed files with 76 additions and 10 deletions

11
input.c
View File

@@ -19,6 +19,7 @@ static int input_fd;
static input_callback_t restart;
static input_callback_t quit;
static input_callback_t shoot;
static input_callback_t pause_;
static void key_press(int key)
{
@@ -46,6 +47,9 @@ static void key_press(int key)
if (shoot != nullptr)
shoot();
break;
case KEY_P:
if (pause_ != nullptr)
pause_();
}
}
@@ -74,7 +78,7 @@ static void key_repeat(int key)
int input_init()
{
memset(&input, 0, sizeof(input));
shoot = nullptr;
shoot = restart = quit = pause_ = nullptr;
input_fd = open("/dev/input/event0", O_RDONLY);
assert(input_fd != -1);
@@ -105,6 +109,11 @@ void input_on_quit(input_callback_t cb)
quit = cb;
}
void input_on_pause(input_callback_t cb)
{
pause_ = cb;
}
void input_handle()
{
struct input_event ev;