1 /*
2  * Copyright (c) 2020 Jabil Inc.
3  * Copyright (c) 2023 Nordic Semiconductor
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <SDL.h>
9 #include "input_sdl_touch_bottom.h"
10 
sdl_filter(void * arg,SDL_Event * event)11 static int sdl_filter(void *arg, SDL_Event *event)
12 {
13 	struct sdl_input_data *data = arg;
14 
15 	switch (event->type) {
16 	case SDL_MOUSEBUTTONUP:
17 		data->pressed = false;
18 		data->just_released = true;
19 		break;
20 	case SDL_MOUSEBUTTONDOWN:
21 		data->pressed = true;
22 		break;
23 	case SDL_MOUSEMOTION:
24 		data->x = event->button.x;
25 		data->y = event->button.y;
26 		break;
27 	default:
28 		return 1;
29 	}
30 
31 	data->callback(data);
32 
33 	return 1;
34 }
35 
sdl_input_init_bottom(struct sdl_input_data * data)36 void sdl_input_init_bottom(struct sdl_input_data *data)
37 {
38 	SDL_AddEventWatch(sdl_filter, data);
39 }
40