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 <fabianblatz@gmail.com>
This commit is contained in:
Fabian Blatz
2025-03-19 11:08:54 +01:00
committed by Benjamin Cabé
parent fdf9a6172b
commit 9564780564
4 changed files with 44 additions and 3 deletions

View File

@@ -41,7 +41,11 @@ static int sdl_init(const struct device *dev)
return 0;
}
static struct sdl_input_data sdl_data_0;
#define INPUT_SDL_TOUCH_DEFINE(inst) \
static struct sdl_input_data sdl_data_##inst = { \
.display_dev = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, display)), \
}; \
DEVICE_DT_INST_DEFINE(inst, sdl_init, NULL, &sdl_data_##inst, NULL, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
DT_INST_FOREACH_STATUS_OKAY(INPUT_SDL_TOUCH_DEFINE)

View File

@@ -8,10 +8,41 @@
#include <SDL.h>
#include "input_sdl_touch_bottom.h"
static bool event_targets_display(SDL_Event *event, struct sdl_input_data *data)
{
SDL_Window *window = NULL;
const void *display_dev;
if (!data->display_dev) {
return true;
}
if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
window = SDL_GetWindowFromID(event->button.windowID);
} else if (event->type == SDL_MOUSEMOTION) {
window = SDL_GetWindowFromID(event->motion.windowID);
} else {
return false;
}
if (!window) {
return false;
}
/* Get the zephyr display associated with the window */
display_dev = SDL_GetWindowData(window, "zephyr_display");
return !display_dev || display_dev == data->display_dev;
}
static int sdl_filter(void *arg, SDL_Event *event)
{
struct sdl_input_data *data = arg;
if (!event_targets_display(event, data)) {
return 1;
}
switch (event->type) {
case SDL_MOUSEBUTTONUP:
data->pressed = false;

View File

@@ -22,6 +22,7 @@ extern "C" {
struct sdl_input_data {
const void *dev; /* device structure pointer */
const void *display_dev;
void (*callback)(struct sdl_input_data *data);
int x;
int y;

View File

@@ -4,3 +4,8 @@
description: SDL based emulated touch panel
compatible: "zephyr,input-sdl-touch"
properties:
display:
type: phandle
description: Handle to the display that the input events are raised for