input: use events instead of threads

This commit is contained in:
Vladimir Stoiakin 2025-10-21 17:51:58 +00:00 committed by Johannes Marbach
parent a22b192e23
commit 8ddc3d448e
22 changed files with 1027 additions and 597 deletions

View file

@ -88,6 +88,23 @@ static int parsing_handler(void* user_data, const char* section, const char* key
return 1;
}
}
} else if (strcmp(section, "hardware keyboard") == 0) {
if (strcmp(key, "rules") == 0) {
opts->hw_keyboard.rules = strdup(value);
return 1;
} else if (strcmp(key, "model") == 0) {
opts->hw_keyboard.model = strdup(value);
return 1;
} else if (strcmp(key, "layout") == 0) {
opts->hw_keyboard.layout = strdup(value);
return 1;
} else if (strcmp(key, "variant") == 0) {
opts->hw_keyboard.variant = strdup(value);
return 1;
} else if (strcmp(key, "options") == 0) {
opts->hw_keyboard.options = strdup(value);
return 1;
}
} else if (strcmp(section, "quirks") == 0) {
if (strcmp(key, "fbdev_force_refresh") == 0) {
if (bbx_config_parse_bool(value, &(opts->quirks.fbdev_force_refresh))) {
@ -178,6 +195,11 @@ void f0_config_init_opts(f0_config_opts *opts) {
opts->input.keyboard = true;
opts->input.pointer = true;
opts->input.touchscreen = true;
opts->hw_keyboard.rules = NULL;
opts->hw_keyboard.model = NULL;
opts->hw_keyboard.layout = NULL;
opts->hw_keyboard.variant = NULL;
opts->hw_keyboard.options = NULL;
opts->quirks.fbdev_force_refresh = false;
opts->quirks.terminal_prevent_graphics_mode = false;
opts->quirks.terminal_allow_keyboard_input = false;

View file

@ -7,13 +7,13 @@
#define F0_CONFIG_H
#include "../shared/backends.h"
#include "../shared/config.h"
#include "../shared/themes.h"
#include "sq2lv_layouts.h"
#include <stdbool.h>
#include <stdint.h>
#include <xkbcommon/xkbcommon.h>
/**
* General options
@ -122,6 +122,8 @@ typedef struct {
f0_config_opts_textarea textarea;
/* Options related to input devices */
f0_config_opts_input input;
/* Options to create a keymap for hardware keyboards */
struct xkb_rule_names hw_keyboard;
/* Options related to (normally unneeded) quirks */
f0_config_opts_quirks quirks;
/* Intro section */

View file

@ -109,9 +109,9 @@ LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL
LV_USE_LINUX_DRM 0
LV_USE_LIBINPUT 1
LV_USE_LIBINPUT 0
LV_LIBINPUT_BSD 0
LV_LIBINPUT_XKB 1
LV_LIBINPUT_XKB 0
LV_BUILD_EXAMPLES 0
LV_BUILD_DEMOS 0

View file

@ -1249,13 +1249,13 @@
#define LV_USE_EVDEV 0
/** Driver for libinput input devices */
#define LV_USE_LIBINPUT 1
#define LV_USE_LIBINPUT 0
#if LV_USE_LIBINPUT
#define LV_LIBINPUT_BSD 0
/** Full keyboard support */
#define LV_LIBINPUT_XKB 1
#define LV_LIBINPUT_XKB 0
#if LV_LIBINPUT_XKB
/** "setxkbmap -query" can help find the right values for your keyboard */
#define LV_LIBINPUT_XKB_KEY_MAP { .rules = NULL, .model = "pc101", .layout = "us", .variant = NULL, .options = NULL }

View file

@ -19,13 +19,15 @@
#include "lvgl/lvgl.h"
#include <sys/epoll.h>
#include <sys/reboot.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/reboot.h>
#define F0_PASSWORD_HIDDEN_DOTS "••••••••"
/**
@ -584,9 +586,8 @@ static void show_intro_screen(void) {
lv_obj_add_event_cb(btn, get_started_btn_clicked_cb, LV_EVENT_CLICKED, NULL);
/* Set up keyboard input for intro screen */
lv_group_t *intro_input_group = lv_group_create();
bbx_indev_set_keyboard_input_group(intro_input_group);
lv_group_add_obj(intro_input_group, btn);
lv_group_remove_all_objs(keyboard_input_group);
lv_group_add_obj(keyboard_input_group, btn);
lv_obj_add_event_cb(btn, intro_key_cb, LV_EVENT_KEY, NULL);
}
@ -734,8 +735,7 @@ static void show_form_screen(void) {
keyboard = bbx_keyboard_create(lv_screen_active(), form_textarea, &keyboard_config);
/* Configuring routing for physical keyboard input into the textarea */
lv_group_t *keyboard_input_group = lv_group_create();
bbx_indev_set_keyboard_input_group(keyboard_input_group);
lv_group_remove_all_objs(keyboard_input_group);
lv_group_add_obj(keyboard_input_group, form_textarea);
}
@ -831,9 +831,8 @@ static void show_summary_screen(void) {
lv_obj_add_event_cb(finish_btn, finish_cb, LV_EVENT_CLICKED, NULL);
/* Set up keyboard input for summary screen */
lv_group_t *summary_input_group = lv_group_create();
bbx_indev_set_keyboard_input_group(summary_input_group);
lv_group_add_obj(summary_input_group, finish_btn);
lv_group_remove_all_objs(keyboard_input_group);
lv_group_add_obj(keyboard_input_group, finish_btn);
}
int main(int argc, char *argv[]) {
@ -879,12 +878,23 @@ int main(int argc, char *argv[]) {
exit_failure();
}
/* Prepare for routing physical keyboard input into the textarea */
lv_group_t *keyboard_input_group = lv_group_create();
bbx_indev_set_keyboard_input_group(keyboard_input_group);
int fd_epoll = epoll_create1(EPOLL_CLOEXEC);
if (fd_epoll == -1) {
bbx_log(BBX_LOG_LEVEL_ERROR, "epoll_create1() is failed");
exit_failure();
}
/* Start input device monitor and auto-connect available devices */
bbx_indev_start_monitor_and_autoconnect(conf_opts.input.keyboard, conf_opts.input.pointer, conf_opts.input.touchscreen);
/* Attach input devices and start monitoring for new ones */
struct bbx_indev_opts input_config = {
.keymap = &conf_opts.hw_keyboard,
.keyboard = conf_opts.input.keyboard,
.pointer = conf_opts.input.pointer,
.touchscreen = conf_opts.input.touchscreen
};
if (bbx_indev_init(fd_epoll, &input_config) == 0)
exit_failure();
bbx_indev_set_key_power_cb(shutdown);
/* Hide the on-screen keyboard by default if a physical keyboard is connected */
if (conf_opts.keyboard.autohide && bbx_indev_is_keyboard_connected()) {
@ -906,7 +916,21 @@ int main(int argc, char *argv[]) {
/* Main loop */
while(1) {
uint32_t time_till_next = lv_timer_handler();
usleep(time_till_next * 1000);
struct epoll_event event;
int r = epoll_wait(fd_epoll, &event, 1, time_till_next);
if (r == 0)
continue;
if (r > 0) {
__extension__ void (*handler)() = event.data.ptr;
handler();
continue;
}
if (errno == EINTR)
continue;
bbx_log(BBX_LOG_LEVEL_ERROR, "epoll_wait() is failed");
exit_failure();
}
return 0;

View file

@ -10,7 +10,6 @@ f0rmz_sources = files(
f0rmz_dependencies = [
common_dependencies,
depinih,
depxkbcommon
]
@ -26,7 +25,7 @@ endif
executable('f0rmz',
include_directories: common_include_dirs,
sources: f0rmz_sources + shared_sources + squeek2lvgl_sources + lvgl_sources + header_sources,
sources: f0rmz_sources + shared_sources + shared_sources_ul_f0 + squeek2lvgl_sources + lvgl_sources,
dependencies: f0rmz_dependencies,
c_args: f0rmz_args,
install: true,