commit a37d1a1c5a31a55446ae3f647aa2dfd9d27babd4 from: Omar Polo date: Sat Aug 14 20:10:47 2021 UTC move load_url_in_tab, switch_to_tab, new_tab{,_id} to telescope.c commit - 002b074d60872b777f91911a890220a16a274a2b commit + a37d1a1c5a31a55446ae3f647aa2dfd9d27babd4 blob - 9aae5b14987ea75fa46c4e7429b368fad0180a0d blob + a3369803052b9b1054d382f1d6e4c8c5f05f72bc --- telescope.c +++ telescope.c @@ -41,6 +41,11 @@ static struct option longopts[] = { }; static const char *opts = "Cc:hnT:v"; + +/* + * Used to know when we're finished loading. + */ +static int operating; static struct imsgev *iev_fs, *iev_net; @@ -897,6 +902,21 @@ load_url(struct tab *tab, const char *url, const char erase_buffer(&tab->buffer); } +void +load_url_in_tab(struct tab *tab, const char *url, const char *base, int nohist) +{ + if (!operating) { + load_url(tab, url, base, nohist); + return; + } + + autosave_hook(); + + message("Loading %s...", url); + start_loading_anim(tab); + load_url(tab, url, base, nohist); +} + int load_previous_page(struct tab *tab) { @@ -921,6 +941,56 @@ load_next_page(struct tab *tab) return 1; } +void +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, NULL, 0); +} + +unsigned int +tab_new_id(void) +{ + static uint32_t tab_counter; + + return tab_counter++; +} + +struct tab * +new_tab(const char *url, const char *base, struct tab *after) +{ + struct tab *tab; + + autosave_hook(); + + if ((tab = calloc(1, sizeof(*tab))) == NULL) { + event_loopbreak(); + return NULL; + } + tab->fd = -1; + + TAILQ_INIT(&tab->hist.head); + + TAILQ_INIT(&tab->buffer.head); + TAILQ_INIT(&tab->buffer.page.head); + + tab->id = tab_new_id(); + if (!operating) + tab->flags |= TAB_LAZY; + switch_to_tab(tab); + + if (after != NULL) + TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs); + else + TAILQ_INSERT_TAIL(&tabshead, tab, tabs); + + load_url_in_tab(tab, url, base, 0); + return tab; +} + /* * Free every resource linked to the tab, including the tab itself. * Removes the tab from the tablist, but doesn't update the @@ -1287,6 +1357,7 @@ main(int argc, char * const *argv) new_tab(url, NULL, NULL); sandbox_ui_process(); + operating = 1; ui_main_loop(); ui_end(); } blob - 756a7092d2927d064b0bb4d658654e5f5159672b blob + 0d27078306404e67cb153ed72bd19478b4d061c0 --- telescope.h +++ telescope.h @@ -322,8 +322,12 @@ void sandbox_fs_process(void); /* telescope.c */ void gopher_send_search_req(struct tab *, const char *); void load_url(struct tab *, const char *, const char *, int); +void load_url_in_tab(struct tab *, const char *, const char *, int); int load_previous_page(struct tab*); int load_next_page(struct tab*); +void switch_to_tab(struct tab *); +unsigned int tab_new_id(void); +struct tab *new_tab(const char *, const char *base, struct tab *); void free_tab(struct tab *); void stop_tab(struct tab*); void add_to_bookmarks(const char*); blob - ebcc415e867d3b10c2b2694c98be3b531c923019 blob + 878802ee8a3c2c9cfb3f230b6213df55d25d10e3 --- ui.c +++ ui.c @@ -72,11 +72,6 @@ static void redraw_tab(struct tab*); 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; static int x_offset; @@ -101,8 +96,6 @@ static int in_side_window; static struct timeval loadingev_timer = { 0, 250000 }; -static uint32_t tab_counter; - static char keybuf[64]; /* XXX: don't forget to init these in main() */ @@ -951,73 +944,8 @@ stop_loading_anim(struct tab *tab) wrefresh(body); if (in_minibuffer) wrefresh(echoarea); -} - -void -load_url_in_tab(struct tab *tab, const char *url, const char *base, int nohist) -{ - if (!operating) { - load_url(tab, url, base, nohist); - return; - } - - autosave_hook(); - - message("Loading %s...", url); - start_loading_anim(tab); - load_url(tab, url, base, nohist); - - redraw_tab(tab); } -void -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, NULL, 0); -} - -unsigned int -tab_new_id(void) -{ - return tab_counter++; -} - -struct tab * -new_tab(const char *url, const char *base, struct tab *after) -{ - struct tab *tab; - - autosave_hook(); - - if ((tab = calloc(1, sizeof(*tab))) == NULL) { - event_loopbreak(); - return NULL; - } - tab->fd = -1; - - TAILQ_INIT(&tab->hist.head); - - TAILQ_INIT(&tab->buffer.head); - TAILQ_INIT(&tab->buffer.page.head); - - tab->id = tab_new_id(); - if (!operating) - tab->flags |= TAB_LAZY; - switch_to_tab(tab); - - if (after != NULL) - TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs); - else - TAILQ_INSERT_TAIL(&tabshead, tab, tabs); - - load_url_in_tab(tab, url, base, 0); - return tab; -} - int ui_print_colors(void) { @@ -1140,7 +1068,6 @@ ui_init() void ui_main_loop(void) { - operating = 1; switch_to_tab(current_tab); redraw_tab(current_tab); blob - 0d4ad22b7005186c29b924d57b2036c982d33765 blob + b479a930f7959a6047d0fa987c10bde159356ce7 --- ui.h +++ ui.h @@ -122,11 +122,7 @@ void restore_excursion(struct excursion *, struct bu void global_key_unbound(void); struct vline *adjust_line(struct vline *, struct buffer *); void start_loading_anim(struct tab *); -void load_url_in_tab(struct tab *, const char *, const char *, int); -void switch_to_tab(struct tab *); struct buffer *current_buffer(void); -struct tab *new_tab(const char *, const char *base, struct tab *); -unsigned int tab_new_id(void); int ui_print_colors(void); int ui_init(void);