lvgl-demo: add patch to discover input device and draw mouse cursor

https://onedigi.atlassian.net/browse/DEL-9750

Signed-off-by: Mike Engel <Mike.Engel@digi.com>
This commit is contained in:
Mike Engel 2025-08-20 13:22:09 +02:00
parent 7afc4a67de
commit a81298940f
2 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,76 @@
From d7696f869a014d6fa15e25cf7818e43f3c110acb Mon Sep 17 00:00:00 2001
From: Mike Engel <Mike.Engel@digi.com>
Date: Tue, 2 Sep 2025 11:49:32 +0200
Subject: [PATCH] lvgl-demo: add input device discovery support to LVGL-demo
This commit adds input device discovery support to the demo.
When input device is a mouse it will create the cursor.
Signed-off-by: Mike Engel <Mike.Engel@digi.com>
---
main.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/main.c b/main.c
index ba03f23..f821936 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
+#include "lvgl/src/core/lv_global.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
@@ -11,6 +12,30 @@ static const char *getenv_default(const char *name, const char *dflt)
return getenv(name) ? : dflt;
}
+static void indev_deleted_cb(lv_event_t * e)
+{
+ if(LV_GLOBAL_DEFAULT()->deinit_in_progress)
+ return;
+ lv_obj_t * cursor_obj = lv_event_get_user_data(e);
+ lv_obj_delete(cursor_obj);
+}
+
+static void discovery_cb(lv_indev_t * indev, lv_evdev_type_t type, void * user_data)
+{
+ LV_LOG_USER("new '%s' device discovered", type == LV_EVDEV_TYPE_REL ? "REL" :
+ type == LV_EVDEV_TYPE_ABS ? "ABS" :
+ type == LV_EVDEV_TYPE_KEY ? "KEY" :
+ "unknown");
+ /* if input device is mouse add cursor */
+ if(type == LV_EVDEV_TYPE_REL) {
+ LV_IMAGE_DECLARE(mouse_cursor_icon);
+ lv_obj_t * cursor_obj = lv_image_create(lv_screen_active());
+ lv_image_set_src(cursor_obj, &mouse_cursor_icon);
+ lv_indev_set_cursor(indev, cursor_obj);
+ lv_indev_add_event_cb(indev, indev_deleted_cb, LV_EVENT_DELETE, cursor_obj);
+ }
+}
+
#if LV_USE_LINUX_FBDEV
static void lv_linux_disp_init(void)
{
@@ -18,6 +43,8 @@ static void lv_linux_disp_init(void)
lv_display_t * disp = lv_linux_fbdev_create();
lv_linux_fbdev_set_file(disp, device);
+ /* search for input devices */
+ lv_evdev_discovery_start(discovery_cb, NULL);
}
#elif LV_USE_LINUX_DRM
static void lv_linux_disp_init(void)
@@ -26,6 +53,8 @@ static void lv_linux_disp_init(void)
lv_display_t * disp = lv_linux_drm_create();
lv_linux_drm_set_file(disp, device, -1);
+ /* search for input devices */
+ lv_evdev_discovery_start(discovery_cb, NULL);
}
#elif LV_USE_SDL
static void lv_linux_disp_init(void)
--
2.51.0

View File

@ -8,11 +8,16 @@ SRC_URI = "\
git://github.com/lvgl/lv_port_linux_frame_buffer.git;protocol=https;branch=release/v9.3;name=demo \
git://github.com/lvgl/lvgl;protocol=https;branch=release/v9.3;name=lvgl;subdir=git/lvgl \
file://0001-lvgl-demo-remove-demo-slideshow.patch \
file://0004-lvgl-demo-add-input-device-discovery-support-to-LVGL.patch \
file://lvgl-demo-init \
file://lvgl-demo-init.service \
"
SRC_URI:append:ccimx6ul += "\
SRC_URI:append:ccimx6ul = "\
file://0003-CMakefile-remove-libdrm-dependency-when-building-fbd.patch \
"
SRC_URI:append:ccimx6 = "\
file://0003-CMakefile-remove-libdrm-dependency-when-building-fbd.patch \
"