commit 2ddbda6b86c0d3c915ddd3e4e220682cfedd923f from: Omar Polo date: Sat Jul 17 18:47:55 2021 UTC lazy loading tabs on startup don't load all the tabs when starting up, only the current one. Defer the loading of the others when switching to them. commit - 9886bf9732750c285184211b957c1d0fffe21b4f commit + 2ddbda6b86c0d3c915ddd3e4e220682cfedd923f blob - ccfcc3cde3a0892912f5ffade64ebb70a6c3fd4c blob + c056284f05d9f84a9ccb325ba4d6955bf8a7881e --- ChangeLog +++ ChangeLog @@ -1,5 +1,7 @@ 2021-07-17 Omar Polo + * telescope.c (load_url): lazy loading for telescope: don't load all the tabs when starting up, only the current one. Defer the loading of the others when switching to them. + * defaults.c (line_faces): don't underline links by default add set-title option blob - 1948ec501f1f9a143e3e54f00afa4d47b7c4f2fd blob + 753f150d7d9f52feac477a5a20f94d92099386aa --- cmd.c +++ cmd.c @@ -444,8 +444,7 @@ cmd_tab_next(struct buffer *buffer) if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL) t = TAILQ_FIRST(&tabshead); - t->flags &= ~TAB_URGENT; - current_tab = t; + switch_to_tab(t); } void @@ -455,8 +454,7 @@ cmd_tab_previous(struct buffer *buffer) if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL) t = TAILQ_LAST(&tabshead, tabshead); - t->flags &= ~TAB_URGENT; - current_tab = t; + switch_to_tab(t); } void blob - 45b3de8e43439b48ab6e38c7d4ae2962a91fdfce blob + bb431883fc8665862e2ce9396f98d4ec3c9d57e6 --- telescope.c +++ telescope.c @@ -612,19 +612,43 @@ do_load_url(struct tab *tab, const char *url) return 0; } +/* + * Load url in tab. If tab is marked as lazy, only prepare the url + * but don't load it. If tab is lazy and a url was already prepared, + * do load it! + */ void load_url(struct tab *tab, const char *url) { - if (tab->hist_cur != NULL) - hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries)); + int lazy; - if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) { - event_loopbreak(); - return; + lazy = tab->flags & TAB_LAZY; + + if (lazy && tab->hist_cur != NULL) { + lazy = 0; + tab->flags &= ~TAB_LAZY; } - hist_push(&tab->hist, tab->hist_cur); - if (do_load_url(tab, url)) + if (!lazy || tab->hist_cur == NULL) { + if (tab->hist_cur != NULL) + hist_clear_forward(&tab->hist, + TAILQ_NEXT(tab->hist_cur, entries)); + + if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) { + event_loopbreak(); + return; + } + + strlcpy(tab->buffer.page.title, url, + sizeof(tab->buffer.page.title)); + hist_push(&tab->hist, tab->hist_cur); + + if (lazy) + strlcpy(tab->hist_cur->h, url, + sizeof(tab->hist_cur->h)); + } + + if (!lazy && do_load_url(tab, url)) erase_buffer(&tab->buffer); } @@ -951,8 +975,7 @@ main(int argc, char * const *argv) new_tab(url); sandbox_ui_process(); - ui_refresh(); - event_dispatch(); + ui_main_loop(); ui_end(); } blob - db1e9f2418b4cad2132d76acede8ae8f7a818453 blob + 148469949ebb5531445895b7e55ea8c388e9a39f --- telescope.h +++ telescope.h @@ -181,6 +181,7 @@ struct buffer { #define TAB_CURRENT 0x1 /* only for save_session */ #define TAB_URGENT 0x2 +#define TAB_LAZY 0x4 /* to lazy load tabs */ #define NEW_TAB_URL "about:new" @@ -315,7 +316,7 @@ void sandbox_fs_process(void); void load_about_url(struct tab*, const char*); void load_gemini_url(struct tab*, const char*); void load_via_proxy(struct tab *, const char *, struct proxy *); -void load_url(struct tab*, const char*); +void load_url(struct tab *, const char *); int load_previous_page(struct tab*); int load_next_page(struct tab*); void stop_tab(struct tab*); blob - b8d6a18ad2d752e7578c0a29eacad9b7310ca443 blob + aad33da1c3ba106216a61b7bd158d76fe593263b --- ui.c +++ ui.c @@ -76,6 +76,11 @@ static void rec_compute_help(struct kmap*, char*, si static void recompute_help(void); static void update_loading_anim(int, short, void*); static void stop_loading_anim(struct tab*); + +/* + * Used to know when we're finished loading. + */ +static int operating; static int should_rearrange_windows; static int too_small; @@ -1103,12 +1108,15 @@ stop_loading_anim(struct tab *tab) void load_url_in_tab(struct tab *tab, const char *url) { + if (!operating) { + load_url(tab, url); + return; + } + message("Loading %s...", url); start_loading_anim(tab); load_url(tab, url); - tab->buffer.curs_x = 0; - tab->buffer.curs_y = 0; redraw_tab(tab); } @@ -1117,6 +1125,9 @@ switch_to_tab(struct tab *tab) { current_tab = tab; tab->flags &= ~TAB_URGENT; + + if (operating && tab->flags & TAB_LAZY) + load_url_in_tab(tab, tab->hist_cur->h); } unsigned int @@ -1141,6 +1152,8 @@ new_tab(const char *url) TAILQ_INIT(&tab->buffer.head); tab->id = tab_new_id(); + if (!operating) + tab->flags |= TAB_LAZY; switch_to_tab(tab); if (TAILQ_EMPTY(&tabshead)) @@ -1278,9 +1291,13 @@ ui_init() } void -ui_refresh(void) +ui_main_loop(void) { + operating = 1; + switch_to_tab(current_tab); redraw_tab(current_tab); + + event_dispatch(); } void blob - 4842da52ee6c87e17611c8976f9de9f6ed722b6f blob + bbfbc375cd03917338fadb34a1a8f18538daa70d --- ui.h +++ ui.h @@ -113,7 +113,7 @@ struct tab *new_tab(const char *); unsigned int tab_new_id(void); int ui_print_colors(void); int ui_init(void); -void ui_refresh(void); +void ui_main_loop(void); void ui_on_tab_loaded(struct tab *); void ui_on_tab_refresh(struct tab *); const char *ui_keyname(int);