Refactor app loading and window management (#609)
This commit is contained in:
committed by
GitHub
parent
dc3f6104b8
commit
37c507544b
@@ -50,11 +50,10 @@ void lvgl_keyboard_enable(lv_indev_t* indev);
|
||||
void lvgl_keyboard_disable(lv_indev_t* indev);
|
||||
|
||||
/**
|
||||
* @brief Wires a textarea up to the on-screen keyboard: shows it on focus, hides it on
|
||||
* defocus/ready, and adds the textarea to the keyboard's navigation group.
|
||||
*
|
||||
* No-op if lvgl_software_keyboard_is_enabled() is false (i.e. a hardware keyboard is present).
|
||||
*
|
||||
* @brief Adds the textarea to the shared keyboard navigation group (so any keypad indev -
|
||||
* hardware or on-screen - can type into it once it's focused), and, only when
|
||||
* lvgl_software_keyboard_is_enabled() is true (i.e. no hardware keyboard is present), wires it
|
||||
* up to show/hide the on-screen keyboard on focus/defocus/ready.
|
||||
* @warning Caller must hold the LVGL lock.
|
||||
* @param[in] keyboard the on-screen keyboard to associate with the textarea
|
||||
* @param[in] textarea the lv_textarea_t object to wire up
|
||||
|
||||
@@ -19,6 +19,10 @@ void lvgl_keyboard_on_start_lvgl() {
|
||||
lvgl_lock();
|
||||
keyboard_group = lv_group_create();
|
||||
check(keyboard_group);
|
||||
// We currently set this group as the default, so it doesn't only get (manually added) textareas,
|
||||
// but gets all widgets by default. This is a temporary work-around until a proper default group is
|
||||
// created to fix the trackball issue (see trackball.cpp and ideas.md, search for "group")
|
||||
lv_group_set_default(keyboard_group);
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
@@ -77,6 +81,8 @@ error_t lvgl_keyboard_add(struct Device* device, lv_display_t* display, lv_indev
|
||||
lv_indev_set_display(indev, display);
|
||||
}
|
||||
|
||||
lvgl_keyboard_enable(indev);
|
||||
|
||||
*out_indev = indev;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -106,8 +112,11 @@ bool lvgl_hardware_keyboard_is_available() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Refactor the driver subsystem to so it does proper probing/releasing of such devices
|
||||
// This work-around exists for the Tab5 keyboard driver.
|
||||
bool present = keyboard_is_present(keyboard_device);
|
||||
device_put(keyboard_device);
|
||||
return true;
|
||||
return present;
|
||||
}
|
||||
|
||||
void lvgl_hardware_keyboard_add_custom(lv_indev_t* indev) {
|
||||
@@ -137,9 +146,15 @@ static void textarea_show_keyboard(lv_event_t* event) {
|
||||
}
|
||||
|
||||
static void textarea_hide_keyboard(lv_event_t* event) {
|
||||
if (last_software_keyboard.object != nullptr) {
|
||||
lvgl_software_keyboard_hide(&last_software_keyboard);
|
||||
if (last_software_keyboard.object == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Only hide if the keyboard is actually bound to the textarea that triggered this
|
||||
lv_obj_t* target = lv_event_get_current_target_obj(event);
|
||||
if (lv_keyboard_get_textarea(last_software_keyboard.object) != target) {
|
||||
return;
|
||||
}
|
||||
lvgl_software_keyboard_hide(&last_software_keyboard);
|
||||
}
|
||||
|
||||
void lvgl_software_keyboard_construct(LvglSoftwareKeyboard* keyboard, lv_obj_t* parent) {
|
||||
@@ -177,16 +192,23 @@ LvglSoftwareKeyboard* lvgl_software_keyboard_get_last() {
|
||||
}
|
||||
|
||||
void lvgl_keyboard_add_textarea(LvglSoftwareKeyboard* keyboard, lv_obj_t* textarea) {
|
||||
// Only the on-screen keyboard's show/hide wiring is specific to "no hardware keyboard"
|
||||
// mode. Group membership must NOT be gated on it: a hardware keypad indev (see
|
||||
// lvgl_keyboard_enable()/lvgl_software_keyboard_activate()) is bound to keyboard_group
|
||||
// regardless of whether a software keyboard is in use, so skipping lv_group_add_obj()
|
||||
// here left every textarea unreachable from a hardware keyboard - it was never a member
|
||||
// of the group its indev delivers key events through.
|
||||
if (lvgl_software_keyboard_is_enabled()) {
|
||||
lv_obj_add_event_cb(textarea, textarea_show_keyboard, LV_EVENT_FOCUSED, nullptr);
|
||||
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_DEFOCUSED, nullptr);
|
||||
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_READY, nullptr);
|
||||
|
||||
// lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3)
|
||||
lv_group_add_obj(keyboard_group, textarea);
|
||||
|
||||
lvgl_software_keyboard_activate(keyboard);
|
||||
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_DELETE, nullptr);
|
||||
}
|
||||
|
||||
// lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3)
|
||||
lv_group_add_obj(keyboard_group, textarea);
|
||||
|
||||
lvgl_software_keyboard_activate(keyboard);
|
||||
}
|
||||
|
||||
void lvgl_software_keyboard_activate(LvglSoftwareKeyboard* keyboard) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <lvgl/devices/trackball.h>
|
||||
#include <lvgl/devices/device_context.h>
|
||||
#include <lvgl/devices/keyboard.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include <tactility/drivers/trackball.h>
|
||||
@@ -154,6 +155,13 @@ error_t lvgl_trackball_add(struct Device* device, lv_display_t* display, lv_inde
|
||||
}
|
||||
recenter_cursor(ctx, indev);
|
||||
|
||||
// Encoder indevs are useless without a group (LVGL dispatch bails out immediately if indev->group is NULL)
|
||||
// Use the keyboard group for now, until it's refactored into a proper global/shared group. See ideas.md
|
||||
// When refactoring this, you probably want to remove the calls to lvgl_keyboard_* below.
|
||||
if (ctx->settings.mode == LVGL_TRACKBALL_MODE_ENCODER) {
|
||||
lvgl_keyboard_enable(indev);
|
||||
}
|
||||
|
||||
*out_indev = indev;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -196,12 +204,14 @@ error_t lvgl_trackball_set_settings(lv_indev_t* indev, const struct LvglTrackbal
|
||||
|
||||
if (mode_changed) {
|
||||
if (settings->mode == LVGL_TRACKBALL_MODE_POINTER) {
|
||||
lvgl_keyboard_disable(indev);
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||||
recenter_cursor(ctx, indev);
|
||||
show_cursor(ctx, indev);
|
||||
} else {
|
||||
hide_cursor(ctx);
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_ENCODER);
|
||||
lvgl_keyboard_enable(indev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user