From 191ed82104e83c78fa4814922d40d7e6c5e3b4d3 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 28 Oct 2025 08:48:54 -0500 Subject: [PATCH 1/3] feat(input_drivers): Update `pointer_input` to better handle screen rotation --- .../input_drivers/include/pointer_input.hpp | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/components/input_drivers/include/pointer_input.hpp b/components/input_drivers/include/pointer_input.hpp index e273cddee..6624f20c5 100644 --- a/components/input_drivers/include/pointer_input.hpp +++ b/components/input_drivers/include/pointer_input.hpp @@ -153,8 +153,36 @@ class PointerInput : public BaseComponent { return; } read_(x, y, left_pressed, right_pressed); - data->point.x = std::clamp(x, 0, screen_size_x_ - cursor_radius_ * 2); - data->point.y = std::clamp(y, 0, screen_size_y_ - cursor_radius_ * 2); + auto cursor_diameter = cursor_radius_ * 2; + auto disp = lv_display_get_default(); + static int screen_size_x = lv_disp_get_hor_res(disp); + static int screen_size_y = lv_disp_get_ver_res(disp); + auto rotation = lv_disp_get_rotation(disp); + // adjust which side of the clamp we're adjusting by the cursor size based + // on rotation + switch (rotation) { + case LV_DISPLAY_ROTATION_0: + x = std::clamp(x, 0, screen_size_x - cursor_diameter); + y = std::clamp(y, 0, screen_size_y - cursor_diameter); + break; + case LV_DISPLAY_ROTATION_90: + x = std::clamp(x, 0, screen_size_x - cursor_diameter); + y = std::clamp(y, cursor_diameter, screen_size_y); + break; + case LV_DISPLAY_ROTATION_180: + x = std::clamp(x, cursor_diameter, screen_size_x); + y = std::clamp(y, cursor_diameter, screen_size_y); + break; + case LV_DISPLAY_ROTATION_270: + x = std::clamp(x, cursor_diameter, screen_size_x); + y = std::clamp(y, 0, screen_size_y - cursor_diameter); + break; + default: + break; + } + + data->point.x = x; + data->point.y = y; data->state = left_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; } @@ -178,16 +206,10 @@ class PointerInput : public BaseComponent { lv_obj_set_style_bg_color(cursor_obj_, lv_palette_lighten(LV_PALETTE_BLUE, 2), 0); lv_obj_clear_flag(cursor_obj_, LV_OBJ_FLAG_CLICKABLE); lv_indev_set_cursor(indev_pointer_, cursor_obj_); - - auto disp = lv_display_get_default(); - screen_size_x_ = (uint16_t)lv_display_get_horizontal_resolution(disp); - screen_size_y_ = (uint16_t)lv_display_get_vertical_resolution(disp); } read_fn read_; int cursor_radius_{8}; - uint16_t screen_size_x_; - uint16_t screen_size_y_; lv_indev_t *indev_pointer_{nullptr}; lv_obj_t *cursor_obj_{nullptr}; }; From eca60c09112608c87ee50b91dadd1b1fb43477e9 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 28 Oct 2025 08:52:10 -0500 Subject: [PATCH 2/3] add comment for future me --- components/input_drivers/include/pointer_input.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/input_drivers/include/pointer_input.hpp b/components/input_drivers/include/pointer_input.hpp index 6624f20c5..057fa956d 100644 --- a/components/input_drivers/include/pointer_input.hpp +++ b/components/input_drivers/include/pointer_input.hpp @@ -155,6 +155,10 @@ class PointerInput : public BaseComponent { read_(x, y, left_pressed, right_pressed); auto cursor_diameter = cursor_radius_ * 2; auto disp = lv_display_get_default(); + // NOTE: we cache these static values since the screen size is not going to + // change during runtime, and we want the actual screen size (not the + // rotated size) The input driver in lvgl will perform the input + // rotation for us, so we should not rotate the coordinates here. static int screen_size_x = lv_disp_get_hor_res(disp); static int screen_size_y = lv_disp_get_ver_res(disp); auto rotation = lv_disp_get_rotation(disp); From d28917160504074f9b8e8845cfd4cafc281f0734 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 28 Oct 2025 08:52:40 -0500 Subject: [PATCH 3/3] have input be no rotation --- components/input_drivers/include/pointer_input.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/input_drivers/include/pointer_input.hpp b/components/input_drivers/include/pointer_input.hpp index 057fa956d..ac5f4f51e 100644 --- a/components/input_drivers/include/pointer_input.hpp +++ b/components/input_drivers/include/pointer_input.hpp @@ -165,6 +165,7 @@ class PointerInput : public BaseComponent { // adjust which side of the clamp we're adjusting by the cursor size based // on rotation switch (rotation) { + default: case LV_DISPLAY_ROTATION_0: x = std::clamp(x, 0, screen_size_x - cursor_diameter); y = std::clamp(y, 0, screen_size_y - cursor_diameter); @@ -181,8 +182,6 @@ class PointerInput : public BaseComponent { x = std::clamp(x, cursor_diameter, screen_size_x); y = std::clamp(y, 0, screen_size_y - cursor_diameter); break; - default: - break; } data->point.x = x;