commit 83dce83d3c37cc7b9ef292fb4cbba6031bbd9405 from: Omar Polo date: Sat Jul 17 12:59:16 2021 UTC retire current_tab() in favour of current_tab commit - cc298130d72e43af1ec12f939125dde55405c8bf commit + 83dce83d3c37cc7b9ef292fb4cbba6031bbd9405 blob - 70acbd22185d661a0566f611b2cb93f710248751 blob + 1948ec501f1f9a143e3e54f00afa4d47b7c4f2fd --- cmd.c +++ cmd.c @@ -237,7 +237,7 @@ cmd_push_button(struct buffer *buffer) vl = buffer->current_line; switch (vl->parent->type) { case LINE_LINK: - load_url_in_tab(current_tab(), vl->parent->alt); + load_url_in_tab(current_tab, vl->parent->alt); break; case LINE_PRE_START: l = TAILQ_NEXT(vl->parent, lines); @@ -343,23 +343,19 @@ cmd_next_heading(struct buffer *buffer) void cmd_previous_page(struct buffer *buffer) { - struct tab *tab = current_tab(); - - if (!load_previous_page(tab)) + if (!load_previous_page(current_tab)) message("No previous page"); else - start_loading_anim(tab); + start_loading_anim(current_tab); } void cmd_next_page(struct buffer *buffer) { - struct tab *tab = current_tab(); - - if (!load_next_page(tab)) + if (!load_next_page(current_tab)) message("No next page"); else - start_loading_anim(tab); + start_loading_anim(current_tab); } void @@ -395,7 +391,7 @@ cmd_tab_close(struct buffer *buffer) { struct tab *tab, *t; - tab = current_tab(); + tab = current_tab; if (TAILQ_PREV(tab, tabshead, tabs) == NULL && TAILQ_NEXT(tab, tabs) == NULL) { message("Can't close the only tab."); @@ -421,7 +417,7 @@ cmd_tab_close_other(struct buffer *buffer) struct tab *t, *i; TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) { - if (t->flags & TAB_CURRENT) + if (t == current_tab) continue; stop_tab(t); @@ -444,62 +440,54 @@ cmd_tab_new(struct buffer *buffer) void cmd_tab_next(struct buffer *buffer) { - struct tab *tab, *t; + struct tab *t; - tab = current_tab(); - tab->flags &= ~TAB_CURRENT; - - if ((t = TAILQ_NEXT(tab, tabs)) == NULL) + if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL) t = TAILQ_FIRST(&tabshead); - t->flags |= TAB_CURRENT; t->flags &= ~TAB_URGENT; + current_tab = t; } void cmd_tab_previous(struct buffer *buffer) { - struct tab *tab, *t; + struct tab *t; - tab = current_tab(); - tab->flags &= ~TAB_CURRENT; - - if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL) + if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL) t = TAILQ_LAST(&tabshead, tabshead); - t->flags |= TAB_CURRENT; t->flags &= ~TAB_URGENT; + current_tab = t; } void cmd_tab_move(struct buffer *buffer) { - struct tab *tab, *t; + struct tab *t; - tab = current_tab(); - t = TAILQ_NEXT(tab, tabs); - TAILQ_REMOVE(&tabshead, tab, tabs); + t = TAILQ_NEXT(current_tab, tabs); + TAILQ_REMOVE(&tabshead, current_tab, tabs); if (t == NULL) - TAILQ_INSERT_HEAD(&tabshead, tab, tabs); + TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs); else - TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs); + TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs); } void cmd_tab_move_to(struct buffer *buffer) { - struct tab *tab, *t; + struct tab *t; - tab = current_tab(); - t = TAILQ_PREV(tab, tabshead, tabs); - TAILQ_REMOVE(&tabshead, tab, tabs); + t = TAILQ_PREV(current_tab, tabshead, tabs); + TAILQ_REMOVE(&tabshead, current_tab, tabs); if (t == NULL) { if (TAILQ_EMPTY(&tabshead)) - TAILQ_INSERT_HEAD(&tabshead, tab, tabs); + TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs); else - TAILQ_INSERT_TAIL(&tabshead, tab, tabs); + TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs); } else - TAILQ_INSERT_BEFORE(t, tab, tabs); + TAILQ_INSERT_BEFORE(t, current_tab, tabs); } void @@ -527,44 +515,37 @@ cmd_load_url(struct buffer *buffer) void cmd_load_current_url(struct buffer *buffer) { - struct tab *tab = current_tab(); - GUARD_RECURSIVE_MINIBUFFER(); enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer, &lu_history, NULL, NULL); strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt)); - strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf)); + strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf)); ministate.buffer.cpoff = utf8_cplen(ministate.buf); } void cmd_reload_page(struct buffer *buffer) { - struct tab *tab; - - tab = current_tab(); - load_url_in_tab(tab, tab->hist_cur->h); + load_url_in_tab(current_tab, current_tab->hist_cur->h); } void cmd_bookmark_page(struct buffer *buffer) { - struct tab *tab = current_tab(); - GUARD_RECURSIVE_MINIBUFFER(); enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL, NULL, NULL); strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt)); - strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf)); + strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf)); ministate.buffer.cpoff = utf8_cplen(ministate.buf); } void cmd_list_bookmarks(struct buffer *buffer) { - load_url_in_tab(current_tab(), "about:bookmarks"); + load_url_in_tab(current_tab, "about:bookmarks"); } void blob - c9515efc092ba97dacf2be9558f0b2c30d6b5a84 blob + 070b0eb02e2d41e1e4177b0f99faff43cb889232 --- minibuffer.c +++ minibuffer.c @@ -206,10 +206,8 @@ ir_select(void) { char buf[1025] = {0}; struct phos_uri uri; - struct tab *tab; + struct tab *tab = current_tab; - tab = current_tab(); - exit_minibuffer(); minibuffer_hist_save_entry(); @@ -225,7 +223,7 @@ lu_select(void) { exit_minibuffer(); minibuffer_hist_save_entry(); - load_url_in_tab(current_tab(), ministate.buf); + load_url_in_tab(current_tab, ministate.buf); } void @@ -263,17 +261,15 @@ ls_select(void) } exit_minibuffer(); - load_url_in_tab(current_tab(), l->alt); + load_url_in_tab(current_tab, l->alt); } static inline void jump_to_line(struct line *l) { struct vline *vl; - struct tab *tab; + struct tab *tab = current_tab; - tab = current_tab(); - TAILQ_FOREACH(vl, &tab->buffer.head, vlines) { if (vl->parent == l) break; blob - e48bb64b22125b338476d7be7e34cddae2690c24 blob + b4b1612f8f89dd857875b9ce9f5c3cbff6e58329 --- telescope.h +++ telescope.h @@ -178,8 +178,7 @@ struct buffer { TAILQ_HEAD(vhead, vline) head; }; -#define TAB_CURRENT 0x1 -#define TAB_URGENT 0x2 +#define TAB_URGENT 0x1 #define NEW_TAB_URL "about:new" blob - 673c032bc3787b04c3d9f06b164008b1a1aa1f13 blob + c4ea0103e6abc4a94279880058fbe8be2bd691e7 --- ui.c +++ ui.c @@ -81,7 +81,8 @@ static int should_rearrange_windows; static int too_small; static int x_offset; -struct thiskey thiskey; +struct thiskey thiskey; +struct tab *current_tab; static struct event resizeev; static struct timeval resize_timer = { 0, 250000 }; @@ -179,20 +180,6 @@ nth_line(struct buffer *buffer, size_t n) if (i == n) return vl; i++; - } - - /* unreachable */ - abort(); -} - -struct tab * -current_tab(void) -{ - struct tab *t; - - TAILQ_FOREACH(t, &tabshead, tabs) { - if (t->flags & TAB_CURRENT) - return t; } /* unreachable */ @@ -204,7 +191,7 @@ current_buffer(void) { if (in_minibuffer) return &ministate.buffer; - return ¤t_tab()->buffer; + return ¤t_tab->buffer; } static int @@ -295,7 +282,7 @@ done: if (should_rearrange_windows) rearrange_windows(); - redraw_tab(current_tab()); + redraw_tab(current_tab); } static void @@ -331,7 +318,6 @@ handle_resize_nodelay(int s, short ev, void *d) static void rearrange_windows(void) { - struct tab *tab; int lines; should_rearrange_windows = 0; @@ -382,10 +368,8 @@ rearrange_windows(void) wresize(tabline, 1, COLS); - tab = current_tab(); - - wrap_page(&tab->buffer, body_cols); - redraw_tab(tab); + wrap_page(¤t_tab->buffer, body_cols); + redraw_tab(current_tab); } static int @@ -585,7 +569,7 @@ redraw_tabline(void) toskip = 0; TAILQ_FOREACH(tab, &tabshead, tabs) { toskip++; - if (tab->flags & TAB_CURRENT) + if (tab == current_tab) break; } @@ -617,7 +601,7 @@ redraw_tabline(void) if (x + sizeof(buf)+2 >= (size_t)COLS) truncated = 1; - current = tab->flags & TAB_CURRENT; + current = tab == current_tab; if (*(title = tab->buffer.page.title) == '\0') title = tab->hist_cur->h; @@ -858,7 +842,7 @@ redraw_minibuffer(void) static void do_redraw_echoarea(void) { - struct tab *tab; + struct vline *vl; if (ministate.curmesg != NULL) wprintw(echoarea, "%s", ministate.curmesg); @@ -866,11 +850,9 @@ do_redraw_echoarea(void) waddstr(echoarea, keybuf); else { /* If nothing else, show the URL at point */ - tab = current_tab(); - if (tab->buffer.current_line != NULL && - tab->buffer.current_line->parent->type == LINE_LINK) - waddstr(echoarea, - tab->buffer.current_line->parent->alt); + vl = current_tab->buffer.current_line; + if (vl != NULL && vl->parent->type == LINE_LINK) + waddstr(echoarea, vl->parent->alt); } } @@ -1083,7 +1065,7 @@ update_loading_anim(int fd, short ev, void *d) tab->loading_anim_step = (tab->loading_anim_step+1)%4; - if (tab->flags & TAB_CURRENT) { + if (tab == current_tab) { redraw_modeline(tab); wrefresh(modeline); wrefresh(body); @@ -1103,7 +1085,7 @@ stop_loading_anim(struct tab *tab) tab->loading_anim = 0; tab->loading_anim_step = 0; - if (!(tab->flags & TAB_CURRENT)) + if (tab != current_tab) return; redraw_modeline(tab); @@ -1129,13 +1111,7 @@ load_url_in_tab(struct tab *tab, const char *url) void switch_to_tab(struct tab *tab) { - struct tab *t; - - TAILQ_FOREACH(t, &tabshead, tabs) { - t->flags &= ~TAB_CURRENT; - } - - tab->flags |= TAB_CURRENT; + current_tab = tab; tab->flags &= ~TAB_URGENT; } @@ -1312,7 +1288,7 @@ void ui_on_tab_refresh(struct tab *tab) { wrap_page(&tab->buffer, body_cols); - if (tab->flags & TAB_CURRENT) + if (tab == current_tab) redraw_tab(tab); else tab->flags |= TAB_URGENT; @@ -1365,7 +1341,7 @@ ui_yornp(const char *prompt, void (*fn)(int, struct ta struct tab *data) { yornp(prompt, fn, data); - redraw_tab(current_tab()); + redraw_tab(current_tab); } void @@ -1373,7 +1349,7 @@ ui_read(const char *prompt, void (*fn)(const char*, st struct tab *data) { completing_read(prompt, fn, data); - redraw_tab(current_tab()); + redraw_tab(current_tab); } void blob - d5244262d5a1a313f8fa64fa09647437b3a67a89 blob + fd2b1d1e28eb18527ee22fd67f4e3e457267215d --- ui.h +++ ui.h @@ -97,6 +97,8 @@ extern struct histhead eecmd_history, lu_history, read_history; +extern struct tab *current_tab; + void save_excursion(struct excursion *, struct buffer *); void restore_excursion(struct excursion *, struct buffer *); void global_key_unbound(void); @@ -106,7 +108,6 @@ void message(const char *, ...) __attribute__((forma void start_loading_anim(struct tab *); void load_url_in_tab(struct tab *, const char *); void switch_to_tab(struct tab *); -struct tab *current_tab(void); struct buffer *current_buffer(void); struct tab *new_tab(const char *); unsigned int tab_new_id(void);