Skip to content

Commit 9564780

Browse files
faxe1008kartben
authored andcommitted
drivers: input: sdl_touch: Associate display with instance
Make the zephyr,input-sdl-touch driver be multi instance and add the possibility to associate it with a display. The input events are only emitted if the events occured on this display. Signed-off-by: Fabian Blatz <[email protected]>
1 parent fdf9a61 commit 9564780

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

drivers/input/input_sdl_touch.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ static int sdl_init(const struct device *dev)
4141
return 0;
4242
}
4343

44-
static struct sdl_input_data sdl_data_0;
45-
46-
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
47-
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
44+
#define INPUT_SDL_TOUCH_DEFINE(inst) \
45+
static struct sdl_input_data sdl_data_##inst = { \
46+
.display_dev = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, display)), \
47+
}; \
48+
DEVICE_DT_INST_DEFINE(inst, sdl_init, NULL, &sdl_data_##inst, NULL, POST_KERNEL, \
49+
CONFIG_INPUT_INIT_PRIORITY, NULL);
50+
51+
DT_INST_FOREACH_STATUS_OKAY(INPUT_SDL_TOUCH_DEFINE)

drivers/input/input_sdl_touch_bottom.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,41 @@
88
#include <SDL.h>
99
#include "input_sdl_touch_bottom.h"
1010

11+
static bool event_targets_display(SDL_Event *event, struct sdl_input_data *data)
12+
{
13+
SDL_Window *window = NULL;
14+
const void *display_dev;
15+
16+
if (!data->display_dev) {
17+
return true;
18+
}
19+
20+
if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
21+
window = SDL_GetWindowFromID(event->button.windowID);
22+
} else if (event->type == SDL_MOUSEMOTION) {
23+
window = SDL_GetWindowFromID(event->motion.windowID);
24+
} else {
25+
return false;
26+
}
27+
28+
if (!window) {
29+
return false;
30+
}
31+
32+
/* Get the zephyr display associated with the window */
33+
display_dev = SDL_GetWindowData(window, "zephyr_display");
34+
35+
return !display_dev || display_dev == data->display_dev;
36+
}
37+
1138
static int sdl_filter(void *arg, SDL_Event *event)
1239
{
1340
struct sdl_input_data *data = arg;
1441

42+
if (!event_targets_display(event, data)) {
43+
return 1;
44+
}
45+
1546
switch (event->type) {
1647
case SDL_MOUSEBUTTONUP:
1748
data->pressed = false;

drivers/input/input_sdl_touch_bottom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222

2323
struct sdl_input_data {
2424
const void *dev; /* device structure pointer */
25+
const void *display_dev;
2526
void (*callback)(struct sdl_input_data *data);
2627
int x;
2728
int y;

dts/bindings/input/zephyr,input-sdl-touch.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
description: SDL based emulated touch panel
55

66
compatible: "zephyr,input-sdl-touch"
7+
8+
properties:
9+
display:
10+
type: phandle
11+
description: Handle to the display that the input events are raised for

0 commit comments

Comments
 (0)