nyx: Add Home Screen selection

You can now choose between Main menu and Launch/More Cfg as home screens.
This commit is contained in:
CTCaer 2020-04-30 14:49:28 +03:00
parent ab304c9178
commit 6d75f96ed5
4 changed files with 83 additions and 13 deletions

View file

@ -57,6 +57,7 @@ void set_default_configuration()
void set_nyx_default_configuration() void set_nyx_default_configuration()
{ {
n_cfg.themecolor = 167; n_cfg.themecolor = 167;
n_cfg.home_screen = 0;
n_cfg.verification = 1; n_cfg.verification = 1;
} }
@ -191,6 +192,9 @@ int create_nyx_config_entry()
f_puts("[config]\nthemecolor=", &fp); f_puts("[config]\nthemecolor=", &fp);
itoa(n_cfg.themecolor, lbuf, 10); itoa(n_cfg.themecolor, lbuf, 10);
f_puts(lbuf, &fp); f_puts(lbuf, &fp);
f_puts("\nhomescreen=", &fp);
itoa(n_cfg.home_screen, lbuf, 10);
f_puts(lbuf, &fp);
f_puts("\nverification=", &fp); f_puts("\nverification=", &fp);
itoa(n_cfg.verification, lbuf, 10); itoa(n_cfg.verification, lbuf, 10);
f_puts(lbuf, &fp); f_puts(lbuf, &fp);

View file

@ -45,6 +45,7 @@ typedef struct _hekate_config
typedef struct _nyx_config typedef struct _nyx_config
{ {
u32 themecolor; u32 themecolor;
u32 home_screen;
u32 verification; u32 verification;
} nyx_config; } nyx_config;

View file

@ -1257,6 +1257,8 @@ out_end:
} }
static lv_obj_t *launch_ctxt[16]; static lv_obj_t *launch_ctxt[16];
static lv_obj_t *launch_bg = NULL;
static bool launch_bg_done = false;
static lv_res_t _launch_more_cfg_action(lv_obj_t *btn) static lv_res_t _launch_more_cfg_action(lv_obj_t *btn)
{ {
@ -1292,22 +1294,50 @@ static lv_res_t _win_launch_close_action(lv_obj_t * btn)
lv_obj_del(win); lv_obj_del(win);
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
{
lv_obj_set_opa_scale_enable(launch_bg, true);
lv_obj_set_opa_scale(launch_bg, LV_OPA_TRANSP);
//if (launch_bg)
// lv_obj_del(launch_bg); //! TODO: Find why it hangs.
launch_bg_done = true;
}
return LV_RES_INV; return LV_RES_INV;
} }
lv_obj_t *create_window_launch(const char *win_title) static lv_obj_t *create_window_launch(const char *win_title)
{ {
static lv_style_t win_bg_style; static lv_style_t win_bg_style, win_header;
lv_style_copy(&win_bg_style, &lv_style_plain); lv_style_copy(&win_bg_style, &lv_style_plain);
win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color; win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color;
win_bg_style.body.grad_color = win_bg_style.body.main_color; win_bg_style.body.grad_color = win_bg_style.body.main_color;
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
{
lv_obj_t *img = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img, hekate_bg);
launch_bg = img;
}
lv_obj_t *win = lv_win_create(lv_scr_act(), NULL); lv_obj_t *win = lv_win_create(lv_scr_act(), NULL);
lv_win_set_title(win, win_title); lv_win_set_title(win, win_title);
lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style);
lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES);
if (n_cfg.home_screen && !launch_bg_done && hekate_bg)
{
lv_style_copy(&win_header, lv_theme_get_current()->win.header);
win_header.body.opa = LV_OPA_TRANSP;
win_bg_style.body.opa = LV_OPA_TRANSP;
lv_win_set_style(win, LV_WIN_STYLE_HEADER, &win_header);
}
lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style);
close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action); close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action);
return win; return win;
@ -1388,10 +1418,28 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
lv_obj_t *win; lv_obj_t *win;
bool more_cfg = false; bool more_cfg = false;
if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)),"#00EDBA Launch#")) bool combined_cfg = false;
if (btn)
{
if (strcmp(lv_label_get_text(lv_obj_get_child(btn, NULL)) + 8,"Launch#"))
more_cfg = true; more_cfg = true;
}
else
{
switch (n_cfg.home_screen)
{
case 1: // All configs.
combined_cfg = true;
break;
case 3: // More configs
more_cfg = true;
break;
}
}
if (!more_cfg) if (!btn)
win = create_window_launch(SYMBOL_GPS" hekate - Launch");
else if (!more_cfg)
win = create_window_launch(SYMBOL_GPS" Launch"); win = create_window_launch(SYMBOL_GPS" Launch");
else else
win = create_window_launch(SYMBOL_GPS" More Configurations"); win = create_window_launch(SYMBOL_GPS" More Configurations");
@ -1449,7 +1497,9 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
// Parse ini boot entries and set buttons/icons. // Parse ini boot entries and set buttons/icons.
char *tmp_path = malloc(1024); char *tmp_path = malloc(1024);
u32 curr_btn_idx = 0; // Active buttons.
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
if (sd_mount()) if (sd_mount())
{ {
// Choose what to parse. // Choose what to parse.
@ -1459,10 +1509,21 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
else else
ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true); ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true);
if (combined_cfg && !ini_parse_success)
{
ini_parsing:
// Reinit list.
ini_sections.prev = &ini_sections;
ini_sections.next = &ini_sections;
ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true);
more_cfg = true;
}
if (ini_parse_success) if (ini_parse_success)
{ {
// Iterate to all boot entries and load icons. // Iterate to all boot entries and load icons.
u32 i = 1, curr_btn_idx = 0; u32 i = 1;
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE)) if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE))
@ -1544,16 +1605,16 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
i++; i++;
curr_btn_idx += 2; curr_btn_idx += 2;
if (i > max_entries) if (curr_btn_idx >= (max_entries * 2))
break; break;
} }
if (i < 2)
no_boot_entries = true;
} }
else // Reiterate the loop with more cfgs if combined.
no_boot_entries = true; if (combined_cfg && (curr_btn_idx < 16) && !more_cfg)
goto ini_parsing;
} }
else
if (curr_btn_idx < 2)
no_boot_entries = true; no_boot_entries = true;
sd_unmount(false); sd_unmount(false);
@ -1984,6 +2045,8 @@ static void _nyx_main_menu(lv_theme_t * th)
lv_task_t *task_run_ums = lv_task_create(nyx_run_ums, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, (void *)&nyx_str->cfg); lv_task_t *task_run_ums = lv_task_create(nyx_run_ums, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, (void *)&nyx_str->cfg);
lv_task_once(task_run_ums); lv_task_once(task_run_ums);
} }
else if (n_cfg.home_screen)
_create_window_home_launch(NULL);
} }
void nyx_load_and_run() void nyx_load_and_run()

View file

@ -264,6 +264,8 @@ void load_saved_configuration()
{ {
if (!strcmp("themecolor", kv->key)) if (!strcmp("themecolor", kv->key))
n_cfg.themecolor = atoi(kv->val); n_cfg.themecolor = atoi(kv->val);
else if (!strcmp("homescreen", kv->key))
n_cfg.home_screen = atoi(kv->val);
else if (!strcmp("verification", kv->key)) else if (!strcmp("verification", kv->key))
n_cfg.verification = atoi(kv->val); n_cfg.verification = atoi(kv->val);
} }