input: use events instead of threads
This commit is contained in:
parent
a22b192e23
commit
8ddc3d448e
22 changed files with 1027 additions and 597 deletions
|
|
@ -105,7 +105,7 @@ LV_USE_LINUX_FBDEV 1
|
|||
LV_LINUX_FBDEV_BSD 0
|
||||
LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL
|
||||
|
||||
LV_USE_LIBINPUT 1
|
||||
LV_USE_LIBINPUT 0
|
||||
LV_LIBINPUT_BSD 0
|
||||
LV_LIBINPUT_XKB 0
|
||||
|
||||
|
|
|
|||
|
|
@ -1249,7 +1249,7 @@
|
|||
#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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#include "buffyboard.h"
|
||||
#include "command_line.h"
|
||||
#include "config.h"
|
||||
|
|
@ -28,7 +27,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Static variables
|
||||
*/
|
||||
|
|
@ -36,6 +34,7 @@
|
|||
bb_cli_opts cli_opts;
|
||||
bb_config_opts conf_opts;
|
||||
|
||||
static int fd_active;
|
||||
static lv_obj_t *keyboard = NULL;
|
||||
static sig_atomic_t redraw_requested = false;
|
||||
|
||||
|
|
@ -148,6 +147,35 @@ static void pop_checked_modifier_keys(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void on_new_terminal() {
|
||||
if (!redraw_requested && conf_opts.quirks.ignore_unused_terminals) {
|
||||
lseek(fd_active, 0, SEEK_SET);
|
||||
|
||||
char buffer[8];
|
||||
ssize_t size = read(fd_active, buffer, sizeof(buffer) - 1);
|
||||
if (size <= 0) {
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Can't read /sys/class/tty/tty0/active");
|
||||
return;
|
||||
}
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned int tty;
|
||||
if (sscanf(buffer, "tty%u", &tty) != 1) {
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Unexpected value of /sys/class/tty/tty0/active");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bb_terminal_is_busy(tty)) {
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Terminal %u isn't used, skip automatic update.", tty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
redraw_requested = false;
|
||||
pop_checked_modifier_keys();
|
||||
bb_terminal_shrink_current();
|
||||
lv_obj_invalidate(keyboard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main
|
||||
|
|
@ -226,9 +254,6 @@ int main(int argc, char *argv[]) {
|
|||
/* Prepare for terminal resizing and reset */
|
||||
bb_terminal_init(tty_height - 8, hor_res, ver_res);
|
||||
|
||||
/* Start input device monitor and auto-connect available devices */
|
||||
bbx_indev_start_monitor_and_autoconnect(false, conf_opts.input.pointer, conf_opts.input.touchscreen);
|
||||
|
||||
/* Initialise theme */
|
||||
bbx_theme_apply(bbx_themes_themes[conf_opts.theme.default_id]);
|
||||
lv_theme_apply(lv_screen_active());
|
||||
|
|
@ -251,8 +276,8 @@ int main(int argc, char *argv[]) {
|
|||
sq2lv_switch_layout(keyboard, SQ2LV_LAYOUT_TERMINAL_US);
|
||||
|
||||
/* Open the file to track virtual terminals */
|
||||
int fd_tty = open("/sys/class/tty/tty0/active", O_RDONLY|O_NOCTTY|O_CLOEXEC);
|
||||
if (fd_tty < 0) {
|
||||
fd_active = open("/sys/class/tty/tty0/active", O_RDONLY|O_NOCTTY|O_CLOEXEC);
|
||||
if (fd_active < 0) {
|
||||
perror("Can't open /sys/class/tty/tty0/active");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
@ -265,14 +290,22 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
struct epoll_event event;
|
||||
event.events = EPOLLIN|EPOLLET;
|
||||
event.data.fd = fd_tty;
|
||||
event.data.ptr = __extension__ (void*) on_new_terminal;
|
||||
|
||||
int r = epoll_ctl(fd_epoll, EPOLL_CTL_ADD, fd_tty, &event);
|
||||
int r = epoll_ctl(fd_epoll, EPOLL_CTL_ADD, fd_active, &event);
|
||||
if (r == -1) {
|
||||
perror("epoll_ctl() is failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Attach input devices and start monitoring for new ones */
|
||||
struct bbx_indev_opts input_config = {
|
||||
.pointer = conf_opts.input.pointer,
|
||||
.touchscreen = conf_opts.input.touchscreen
|
||||
};
|
||||
if (bbx_indev_init(fd_epoll, &input_config) == 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
/* Set signal handlers */
|
||||
struct sigaction action;
|
||||
action.sa_handler = signal_handler;
|
||||
|
|
@ -300,39 +333,20 @@ int main(int argc, char *argv[]) {
|
|||
int r = epoll_pwait(fd_epoll, &event, 1, time_till_next, &sigmask);
|
||||
if (r == 0)
|
||||
continue;
|
||||
if (r < 0) {
|
||||
if (errno != EINTR) {
|
||||
perror("epoll_wait() is failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!redraw_requested)
|
||||
continue;
|
||||
redraw_requested = false;
|
||||
} else if (conf_opts.quirks.ignore_unused_terminals) {
|
||||
lseek(fd_tty, 0, SEEK_SET);
|
||||
|
||||
char buffer[8];
|
||||
ssize_t size = read(fd_tty, buffer, sizeof(buffer) - 1);
|
||||
if (size <= 0) {
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Can't read /sys/class/tty/tty0/active");
|
||||
continue;
|
||||
}
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned int tty;
|
||||
if (sscanf(buffer, "tty%u", &tty) != 1) {
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Unexpected value of /sys/class/tty/tty0/active");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!bb_terminal_is_busy(tty)) {
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Terminal %u isn't used, skip automatic update.", tty);
|
||||
continue;
|
||||
}
|
||||
if (r > 0) {
|
||||
__extension__ void (*handler)() = event.data.ptr;
|
||||
handler();
|
||||
continue;
|
||||
}
|
||||
if (errno == EINTR) {
|
||||
if (redraw_requested)
|
||||
on_new_terminal();
|
||||
continue;
|
||||
}
|
||||
|
||||
bb_terminal_shrink_current();
|
||||
lv_obj_invalidate(keyboard);
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "epoll_pwait() is failed");
|
||||
bb_terminal_reset_all();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -15,10 +15,15 @@ buffyboard_dependencies = [
|
|||
meson.get_compiler('c').find_library('m', required: false)
|
||||
]
|
||||
|
||||
buffyboard_args = [
|
||||
'-DBBX_APP_BUFFYBOARD'
|
||||
]
|
||||
|
||||
executable('buffyboard',
|
||||
include_directories: common_include_dirs,
|
||||
sources: buffyboard_sources + shared_sources + squeek2lvgl_sources + lvgl_sources,
|
||||
dependencies: buffyboard_dependencies,
|
||||
c_args: buffyboard_args,
|
||||
install: true,
|
||||
install_tag: 'buffyboard'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "terminal.h"
|
||||
|
||||
#include "../shared/indev.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -40,16 +42,17 @@ void bb_terminal_shrink_current() {
|
|||
if (fd < 0)
|
||||
return;
|
||||
|
||||
/* KDFONTOP returns EINVAL if we are not in the text mode,
|
||||
so we can skip this check */
|
||||
/*
|
||||
int mode;
|
||||
if (ioctl(fd, KDGETMODE, &mode) != 0)
|
||||
goto end;
|
||||
|
||||
if (mode != KD_TEXT)
|
||||
if (mode == KD_TEXT) {
|
||||
bbx_indev_resume();
|
||||
} else {
|
||||
bbx_indev_suspend();
|
||||
goto end;
|
||||
*/
|
||||
}
|
||||
|
||||
struct console_font_op cfo = {
|
||||
.op = KD_FONT_OP_GET,
|
||||
.width = UINT_MAX,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
56
f0rmz/main.c
56
f0rmz/main.c
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
16
meson.build
16
meson.build
|
|
@ -13,7 +13,7 @@ add_project_arguments(
|
|||
depinih = dependency('inih')
|
||||
deplibinput = dependency('libinput')
|
||||
deplibudev = dependency('libudev')
|
||||
depxkbcommon = dependency('xkbcommon') # For unl0kr only
|
||||
depxkbcommon = dependency('xkbcommon') # For unl0kr and f0rmz only
|
||||
|
||||
if get_option('man')
|
||||
depscdoc = dependency('scdoc', native: true)
|
||||
|
|
@ -22,21 +22,23 @@ endif
|
|||
common_include_dirs = include_directories('.')
|
||||
|
||||
shared_sources = files(
|
||||
'shared/backends.c',
|
||||
'shared/cursor/cursor.c',
|
||||
'shared/cli_common.c',
|
||||
'shared/display.c',
|
||||
'shared/fonts/font_32.c',
|
||||
'shared/cli_common.c',
|
||||
'shared/config.c',
|
||||
'shared/indev.c',
|
||||
'shared/keyboard.c',
|
||||
'shared/log.c',
|
||||
'shared/terminal.c',
|
||||
'shared/theme.c',
|
||||
'shared/themes.c'
|
||||
)
|
||||
|
||||
header_sources = files('shared/header.c')
|
||||
shared_sources_ul_f0 = files(
|
||||
'shared/backends.c',
|
||||
'shared/display.c',
|
||||
'shared/header.c',
|
||||
'shared/keyboard.c',
|
||||
'shared/terminal.c'
|
||||
)
|
||||
|
||||
squeek2lvgl_sources = files(
|
||||
'squeek2lvgl/sq2lv.c'
|
||||
|
|
|
|||
|
|
@ -68,16 +68,17 @@ lv_display_t *bbx_display_create(bbx_backends_backend_id_t backend_id, bbx_displ
|
|||
return NULL;
|
||||
}
|
||||
|
||||
lv_display_set_physical_resolution(disp,
|
||||
lv_display_get_horizontal_resolution(disp),
|
||||
lv_display_get_vertical_resolution(disp));
|
||||
|
||||
/* Apply configuration overrides if provided */
|
||||
if (config) {
|
||||
/* Set display offset */
|
||||
lv_display_set_offset(disp, config->x_offset, config->y_offset);
|
||||
|
||||
/* Override resolution if specified */
|
||||
if (config->hor_res > 0 || config->ver_res > 0) {
|
||||
lv_display_set_physical_resolution(disp,
|
||||
lv_display_get_horizontal_resolution(disp),
|
||||
lv_display_get_vertical_resolution(disp));
|
||||
if (config->hor_res > 0 && config->ver_res > 0) {
|
||||
lv_display_set_resolution(disp, config->hor_res, config->ver_res);
|
||||
}
|
||||
|
||||
|
|
|
|||
1207
shared/indev.c
1207
shared/indev.c
File diff suppressed because it is too large
Load diff
|
|
@ -3,59 +3,50 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BBX_INDEV_H
|
||||
#define BBX_INDEV_H
|
||||
|
||||
#ifndef BBX_APP_BUFFYBOARD
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct bbx_indev_opts {
|
||||
#ifndef BBX_APP_BUFFYBOARD
|
||||
struct xkb_rule_names* keymap;
|
||||
uint8_t keyboard : 1;
|
||||
#endif
|
||||
uint8_t pointer : 1;
|
||||
uint8_t touchscreen : 1;
|
||||
};
|
||||
|
||||
#ifndef BBX_APP_BUFFYBOARD
|
||||
/* All keyboard devices are added to this input group */
|
||||
extern lv_group_t *keyboard_input_group;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the required capabilities for input devices.
|
||||
* Attach input devices from /dev/input/event* and set up monitoring for new devices.
|
||||
*
|
||||
* @param keyboard if true, allow connection of keyboard devices
|
||||
* @param pointer if true, allow connection of pointer devices
|
||||
* @param touchscreen if true, allow connection of touchscreen devices
|
||||
* @param fd_epoll epoll descriptor to add monitored events to
|
||||
* @param opts options for filtering input devices and setting a keyboard keymap
|
||||
* @return the number of file descriptors added to fd_epoll
|
||||
*/
|
||||
void bbx_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool touchscreen);
|
||||
uint8_t bbx_indev_init(int fd_epoll, const struct bbx_indev_opts* opts);
|
||||
|
||||
/**
|
||||
* Set the group for receiving input from keyboard devices.
|
||||
*
|
||||
* @param group group that should receive input
|
||||
* Stop input processing.
|
||||
*/
|
||||
void bbx_indev_set_keyboard_input_group(lv_group_t *group);
|
||||
void bbx_indev_suspend();
|
||||
|
||||
/**
|
||||
* Start the udev device monitor and auto-connect currently available devices.
|
||||
*
|
||||
* @param keyboard if true, allow connection of keyboard devices
|
||||
* @param pointer if true, allow connection of pointer devices
|
||||
* @param touchscreen if true, allow connection of touchscreen devices
|
||||
* Resume input processing.
|
||||
*/
|
||||
void bbx_indev_start_monitor_and_autoconnect(bool keyboard, bool pointer, bool touchscreen);
|
||||
|
||||
/**
|
||||
* Auto-connect currently available keyboard, pointer and touchscreen input devices.
|
||||
*/
|
||||
void bbx_indev_auto_connect();
|
||||
|
||||
/**
|
||||
* Start the udev device monitor.
|
||||
*/
|
||||
void bbx_indev_start_monitor();
|
||||
|
||||
/**
|
||||
* Stop the udev device monitor.
|
||||
*/
|
||||
void bbx_indev_stop_monitor();
|
||||
|
||||
/**
|
||||
* Query the udev device monitor and (dis)connect added or removed devices
|
||||
*/
|
||||
void bbx_indev_query_monitor();
|
||||
void bbx_indev_resume();
|
||||
|
||||
#ifndef BBX_APP_BUFFYBOARD
|
||||
/**
|
||||
* Check if any keyboard devices are connected.
|
||||
*
|
||||
|
|
@ -63,4 +54,10 @@ void bbx_indev_query_monitor();
|
|||
*/
|
||||
bool bbx_indev_is_keyboard_connected();
|
||||
|
||||
/**
|
||||
* Set a function that will be called on pressing KEY_POWER.
|
||||
*/
|
||||
void bbx_indev_set_key_power_cb(void (*callback)());
|
||||
#endif
|
||||
|
||||
#endif /* BBX_INDEV_H */
|
||||
|
|
|
|||
|
|
@ -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