Use bbx prefix for shared code
This commit is contained in:
parent
6cea4e60d6
commit
1578617560
29 changed files with 224 additions and 354 deletions
|
|
@ -28,10 +28,10 @@ const char *ul_backends_backends[] = {
|
|||
ul_backends_backend_id_t ul_backends_find_backend_with_name(const char *name) {
|
||||
for (int i = 0; ul_backends_backends[i] != NULL; ++i) {
|
||||
if (strcmp(ul_backends_backends[i], name) == 0) {
|
||||
bb_log(BB_LOG_LEVEL_VERBOSE, "Found backend: %s\n", name);
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Found backend: %s\n", name);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Backend %s not found\n", name);
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Backend %s not found\n", name);
|
||||
return UL_BACKENDS_BACKEND_NONE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) {
|
|||
case 'C':
|
||||
opts->config_files = realloc(opts->config_files, (opts->num_config_files + 1) * sizeof(char *));
|
||||
if (!opts->config_files) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Could not allocate memory for config file paths");
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Could not allocate memory for config file paths");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
opts->config_files[opts->num_config_files] = optarg;
|
||||
|
|
@ -106,14 +106,14 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) {
|
|||
case 'g':
|
||||
if (sscanf(optarg, "%ix%i@%i,%i", &(opts->hor_res), &(opts->ver_res), &(opts->x_offset), &(opts->y_offset)) != 4) {
|
||||
if (sscanf(optarg, "%ix%i", &(opts->hor_res), &(opts->ver_res)) != 2) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Invalid geometry argument \"%s\"\n", optarg);
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Invalid geometry argument \"%s\"\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (sscanf(optarg, "%i", &(opts->dpi)) != 1) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Invalid dpi argument \"%s\"\n", optarg);
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Invalid dpi argument \"%s\"\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ static void find_files(const char *path, char ***found, int *num_found) {
|
|||
/* Open directory */
|
||||
DIR *d = opendir(path);
|
||||
if (!d) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not read contents of folder %s", path);
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not read contents of folder %s", path);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ static void find_files(const char *path, char ***found, int *num_found) {
|
|||
/* Grow output array */
|
||||
char **tmp = realloc(*found, (*num_found + 1) * sizeof(char *));
|
||||
if (!tmp) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Could not reallocate memory for configuration file paths");
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Could not reallocate memory for configuration file paths");
|
||||
break;
|
||||
}
|
||||
*found = tmp;
|
||||
|
|
@ -122,7 +122,7 @@ static void find_files(const char *path, char ***found, int *num_found) {
|
|||
/* Allocate memory for full path */
|
||||
char *found_path = malloc(path_length + name_length + 2); /* +1 for path separator and null terminator, respectively */
|
||||
if (!found_path) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Could not allocate memory for configuration file path");
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Could not allocate memory for configuration file path");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -189,14 +189,14 @@ static int parsing_handler(void* user_data, const char* section, const char* key
|
|||
}
|
||||
} else if (strcmp(section, "theme") == 0) {
|
||||
if (strcmp(key, "default") == 0) {
|
||||
bb_themes_theme_id_t id = bb_themes_find_theme_with_name(value);
|
||||
if (id != BB_THEMES_THEME_NONE) {
|
||||
bbx_themes_theme_id_t id = bbx_themes_find_theme_with_name(value);
|
||||
if (id != BBX_THEMES_THEME_NONE) {
|
||||
opts->theme.default_id = id;
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(key, "alternate") == 0) {
|
||||
bb_themes_theme_id_t id = bb_themes_find_theme_with_name(value);
|
||||
if (id != BB_THEMES_THEME_NONE) {
|
||||
bbx_themes_theme_id_t id = bbx_themes_find_theme_with_name(value);
|
||||
if (id != BBX_THEMES_THEME_NONE) {
|
||||
opts->theme.alternate_id = id;
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ static int parsing_handler(void* user_data, const char* section, const char* key
|
|||
}
|
||||
}
|
||||
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Ignoring invalid config value \"%s\" for key \"%s\" in section \"%s\"", value, key, section);
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Ignoring invalid config value \"%s\" for key \"%s\" in section \"%s\"", value, key, section);
|
||||
return 1; /* Return 1 (true) so that we can use the return value of ini_parse exclusively for file-level errors (e.g. file not found) */
|
||||
}
|
||||
|
||||
|
|
@ -263,8 +263,8 @@ void ul_config_init_opts(ul_config_opts *opts) {
|
|||
opts->keyboard.popovers = true;
|
||||
opts->textarea.obscured = true;
|
||||
opts->textarea.bullet = LV_SYMBOL_BULLET;
|
||||
opts->theme.default_id = BB_THEMES_THEME_BREEZY_DARK;
|
||||
opts->theme.alternate_id = BB_THEMES_THEME_BREEZY_LIGHT;
|
||||
opts->theme.default_id = BBX_THEMES_THEME_BREEZY_DARK;
|
||||
opts->theme.alternate_id = BBX_THEMES_THEME_BREEZY_LIGHT;
|
||||
opts->input.keyboard = true;
|
||||
opts->input.pointer = true;
|
||||
opts->input.touchscreen = true;
|
||||
|
|
@ -297,8 +297,8 @@ void ul_config_parse_files(const char **files, int num_files, ul_config_opts *op
|
|||
}
|
||||
|
||||
void ul_config_parse_file(const char *path, ul_config_opts *opts) {
|
||||
bb_log(BB_LOG_LEVEL_VERBOSE, "Parsing config file %s", path);
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Parsing config file %s", path);
|
||||
if (ini_parse(path, parsing_handler, opts) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Ignoring invalid config file %s", path);
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Ignoring invalid config file %s", path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
/* Default theme */
|
||||
bb_themes_theme_id_t default_id;
|
||||
bbx_themes_theme_id_t default_id;
|
||||
/* Alternate theme */
|
||||
bb_themes_theme_id_t alternate_id;
|
||||
bbx_themes_theme_id_t alternate_id;
|
||||
} ul_config_opts_theme;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -286,10 +286,10 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
|
|||
/*Optionally declare custom fonts here.
|
||||
*You can use these fonts as default font too and they will be available globally.
|
||||
*E.g. #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/
|
||||
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(bb_font_32)
|
||||
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(bbx_font_32)
|
||||
|
||||
/*Always set a default font*/
|
||||
#define LV_FONT_DEFAULT &bb_font_32
|
||||
#define LV_FONT_DEFAULT &bbx_font_32
|
||||
|
||||
/*Enable handling large font and/or fonts with a lot of characters.
|
||||
*The limit depends on the font size, font face and bpp.
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ static void set_theme(bool is_alternate);
|
|||
*
|
||||
* @param is_alternate true if the alternate theme should be selected, false if the default theme should be selected
|
||||
*/
|
||||
static const bb_theme * get_theme(bool is_alternate);
|
||||
static const bbx_theme * get_theme(bool is_alternate);
|
||||
|
||||
/**
|
||||
* Handle LV_EVENT_CLICKED events from the show/hide password toggle button.
|
||||
|
|
@ -220,11 +220,11 @@ static void toggle_theme(void) {
|
|||
}
|
||||
|
||||
static void set_theme(bool is_alternate) {
|
||||
bb_theme_apply(get_theme(is_alternate));
|
||||
bbx_theme_apply(get_theme(is_alternate));
|
||||
}
|
||||
|
||||
static const bb_theme * get_theme(bool is_alternate) {
|
||||
return bb_themes_themes[is_alternate ? conf_opts.theme.alternate_id : conf_opts.theme.default_id];
|
||||
static const bbx_theme * get_theme(bool is_alternate) {
|
||||
return bbx_themes_themes[is_alternate ? conf_opts.theme.alternate_id : conf_opts.theme.default_id];
|
||||
}
|
||||
|
||||
static void toggle_pw_btn_clicked_cb(lv_event_t *event) {
|
||||
|
|
@ -363,11 +363,11 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* Set up log level */
|
||||
if (cli_opts.verbose) {
|
||||
bb_log_set_level(BB_LOG_LEVEL_VERBOSE);
|
||||
bbx_log_set_level(BBX_LOG_LEVEL_VERBOSE);
|
||||
}
|
||||
|
||||
/* Announce ourselves */
|
||||
bb_log(BB_LOG_LEVEL_VERBOSE, "unl0kr %s", UL_VERSION);
|
||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "unl0kr %s", UL_VERSION);
|
||||
|
||||
/* Parse config files */
|
||||
ul_config_init_opts(&conf_opts);
|
||||
|
|
@ -385,7 +385,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* Initialise LVGL and set up logging callback */
|
||||
lv_init();
|
||||
lv_log_register_print_cb(bb_log_print_cb);
|
||||
lv_log_register_print_cb(bbx_log_print_cb);
|
||||
|
||||
/* Start the tick thread */
|
||||
pthread_t ticker;
|
||||
|
|
@ -410,7 +410,7 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
#endif /* LV_USE_LINUX_DRM */
|
||||
default:
|
||||
bb_log(BB_LOG_LEVEL_ERROR, "Unable to find suitable backend");
|
||||
bbx_log(BBX_LOG_LEVEL_ERROR, "Unable to find suitable backend");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -430,13 +430,13 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* Prepare for routing physical keyboard input into the textarea */
|
||||
lv_group_t *keyboard_input_group = lv_group_create();
|
||||
bb_indev_set_keyboard_input_group(keyboard_input_group);
|
||||
bbx_indev_set_keyboard_input_group(keyboard_input_group);
|
||||
|
||||
/* Start input device monitor and auto-connect available devices */
|
||||
bb_indev_start_monitor_and_autoconnect(conf_opts.input.keyboard, conf_opts.input.pointer, conf_opts.input.touchscreen);
|
||||
bbx_indev_start_monitor_and_autoconnect(conf_opts.input.keyboard, conf_opts.input.pointer, conf_opts.input.touchscreen);
|
||||
|
||||
/* Hide the on-screen keyboard by default if a physical keyboard is connected */
|
||||
if (conf_opts.keyboard.autohide && bb_indev_is_keyboard_connected()) {
|
||||
if (conf_opts.keyboard.autohide && bbx_indev_is_keyboard_connected()) {
|
||||
is_keyboard_hidden = true;
|
||||
}
|
||||
|
||||
|
|
@ -462,7 +462,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* Header flexbox */
|
||||
lv_obj_t *header = lv_obj_create(container);
|
||||
lv_obj_add_flag(header, BB_WIDGET_HEADER);
|
||||
lv_obj_add_flag(header, BBX_WIDGET_HEADER);
|
||||
lv_theme_apply(header); /* Force re-apply theme after setting flag so that the widget can be identified */
|
||||
lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(header, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
|
@ -561,7 +561,7 @@ int main(int argc, char *argv[]) {
|
|||
lv_obj_add_event_cb(keyboard, keyboard_ready_cb, LV_EVENT_READY, NULL);
|
||||
lv_obj_set_pos(keyboard, 0, is_keyboard_hidden ? keyboard_height : 0);
|
||||
lv_obj_set_size(keyboard, hor_res, keyboard_height);
|
||||
bb_theme_prepare_keyboard(keyboard);
|
||||
bbx_theme_prepare_keyboard(keyboard);
|
||||
|
||||
/* Apply textarea options */
|
||||
set_password_obscured(conf_opts.textarea.obscured);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ static bool reopen_current_terminal(void) {
|
|||
|
||||
current_fd = open("/dev/tty0", O_RDWR);
|
||||
if (current_fd < 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not open /dev/tty0");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not open /dev/tty0");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -84,29 +84,29 @@ void ul_terminal_prepare_current_terminal(bool enable_graphics_mode, bool disabl
|
|||
reopen_current_terminal();
|
||||
|
||||
if (current_fd < 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not prepare current terminal");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not prepare current terminal");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Disable terminal keyboard input (hides entered text) */
|
||||
if (disable_keyboard_input) {
|
||||
if (ioctl(current_fd, KDGKBMODE, &original_kb_mode) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not get terminal keyboard mode");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not get terminal keyboard mode");
|
||||
}
|
||||
|
||||
if (ioctl(current_fd, KDSKBMODE, K_OFF) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not set terminal keyboard mode to off");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not set terminal keyboard mode to off");
|
||||
}
|
||||
}
|
||||
|
||||
/* Switch terminal into graphics mode (hides command prompt) */
|
||||
if (enable_graphics_mode) {
|
||||
if (ioctl(current_fd, KDGETMODE, &original_mode) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not get terminal mode");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not get terminal mode");
|
||||
}
|
||||
|
||||
if (ioctl(current_fd, KDSETMODE, KD_GRAPHICS) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not set terminal mode to graphics");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not set terminal mode to graphics");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -114,18 +114,18 @@ void ul_terminal_prepare_current_terminal(bool enable_graphics_mode, bool disabl
|
|||
void ul_terminal_reset_current_terminal(void) {
|
||||
/* If we haven't previously opened the current terminal, exit */
|
||||
if (current_fd < 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not reset current terminal");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not reset current terminal");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reset terminal mode if needed */
|
||||
if (original_mode >= 0 && ioctl(current_fd, KDSETMODE, original_mode) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not reset terminal mode");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not reset terminal mode");
|
||||
}
|
||||
|
||||
/* Reset terminal keyboard mode if needed */
|
||||
if (original_kb_mode >= 0 && ioctl(current_fd, KDSKBMODE, original_kb_mode) != 0) {
|
||||
bb_log(BB_LOG_LEVEL_WARNING, "Could not reset terminal keyboard mode");
|
||||
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not reset terminal keyboard mode");
|
||||
}
|
||||
|
||||
close_current_terminal();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue