input: use events instead of threads
This commit is contained in:
parent
a22b192e23
commit
8ddc3d448e
22 changed files with 1027 additions and 597 deletions
|
|
@ -112,6 +112,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))) {
|
||||
|
|
@ -151,6 +168,11 @@ void ul_config_init_opts(ul_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;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
/**
|
||||
* General options
|
||||
|
|
@ -98,6 +99,8 @@ typedef struct {
|
|||
ul_config_opts_theme theme;
|
||||
/* Options related to input devices */
|
||||
ul_config_opts_input input;
|
||||
/* Options to create a keymap for hardware keyboards */
|
||||
struct xkb_rule_names hw_keyboard;
|
||||
/* Options related to (normally unneeded) quirks */
|
||||
ul_config_opts_quirks quirks;
|
||||
} ul_config_opts;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -21,34 +21,33 @@
|
|||
|
||||
#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>
|
||||
#include <sys/time.h>
|
||||
|
||||
ul_cli_opts cli_opts;
|
||||
ul_config_opts conf_opts;
|
||||
|
||||
/**
|
||||
* Static variables
|
||||
*/
|
||||
|
||||
ul_cli_opts cli_opts;
|
||||
ul_config_opts conf_opts;
|
||||
static bool is_alternate_theme = false;
|
||||
static bool is_password_obscured = true;
|
||||
static bool is_keyboard_hidden = false;
|
||||
|
||||
bool is_alternate_theme = false;
|
||||
bool is_password_obscured = true;
|
||||
bool is_keyboard_hidden = false;
|
||||
static lv_obj_t *container;
|
||||
static lv_obj_t *keyboard;
|
||||
|
||||
lv_obj_t *container = NULL;
|
||||
lv_obj_t *keyboard = NULL;
|
||||
|
||||
int32_t content_height_with_kb;
|
||||
int32_t content_height_without_kb;
|
||||
int32_t content_pad_bottom_with_kb;
|
||||
int32_t content_pad_bottom_without_kb;
|
||||
static int32_t content_height_with_kb;
|
||||
static int32_t content_height_without_kb;
|
||||
static int32_t content_pad_bottom_with_kb;
|
||||
static int32_t content_pad_bottom_without_kb;
|
||||
|
||||
/**
|
||||
* Static prototypes
|
||||
|
|
@ -401,13 +400,6 @@ int main(int argc, char *argv[]) {
|
|||
/* Announce ourselves */
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "unl0kr %s", PROJECT_VERSION);
|
||||
|
||||
/* Check that we have access to the clock */
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Unable to read the clock");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Parse config files */
|
||||
ul_config_init_opts(&conf_opts);
|
||||
ul_config_parse_file("/usr/share/unl0kr/unl0kr.conf", &conf_opts);
|
||||
|
|
@ -444,12 +436,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()) {
|
||||
|
|
@ -601,7 +604,20 @@ int main(int argc, char *argv[]) {
|
|||
time_till_next = time_till_shutdown;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ endif
|
|||
|
||||
executable('unl0kr',
|
||||
include_directories: common_include_dirs,
|
||||
sources: unl0kr_sources + shared_sources + squeek2lvgl_sources + lvgl_sources + header_sources,
|
||||
sources: unl0kr_sources + shared_sources + shared_sources_ul_f0 + squeek2lvgl_sources + lvgl_sources,
|
||||
dependencies: unl0kr_dependencies,
|
||||
c_args: unl0kr_args,
|
||||
install: true,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ alternate=breezy-dark
|
|||
#pointer=false
|
||||
#touchscreen=false
|
||||
|
||||
[hardware keyboard]
|
||||
#rules=
|
||||
model=pc101
|
||||
layout=us
|
||||
#variant=
|
||||
#options=
|
||||
|
||||
#[quirks]
|
||||
#fbdev_force_refresh=true
|
||||
#terminal_prevent_graphics_mode=true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue