commit 9073042649752b844bd9b22f67aa88db8317b44d from: Omar Polo date: Wed Jul 21 09:11:09 2021 UTC refactoring tab-close and tab-close-other: introduce free_tab commit - cee823637088fe32b599f64e68987a55a420f706 commit + 9073042649752b844bd9b22f67aa88db8317b44d blob - e764b8bc6ec95f6c30068a3abe73794e998e902f blob + e4369a82c474c49f7d22c3d603a3fc81f031e582 --- cmd.c +++ cmd.c @@ -417,23 +417,14 @@ cmd_tab_close(struct buffer *buffer) struct tab *tab, *t; tab = current_tab; - if (TAILQ_PREV(tab, tabshead, tabs) == NULL && - TAILQ_NEXT(tab, tabs) == NULL) { - message("Can't close the only tab."); - return; - } - - if (evtimer_pending(&tab->loadingev, NULL)) - evtimer_del(&tab->loadingev); - stop_tab(tab); - - if ((t = TAILQ_NEXT(tab, tabs)) == NULL) - t =TAILQ_PREV(tab, tabshead, tabs); - TAILQ_REMOVE(&tabshead, tab, tabs); - free(tab); + if ((t = TAILQ_NEXT(tab, tabs)) != NULL || + (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) { + switch_to_tab(t); + free_tab(tab); + } else + message("Can't close the only tab."); - switch_to_tab(t); } void @@ -445,9 +436,7 @@ cmd_tab_close_other(struct buffer *buffer) if (t == current_tab) continue; - stop_tab(t); - TAILQ_REMOVE(&tabshead, t, tabs); - free(t); + free_tab(t); } } blob - 929eb99ebf685048d9bacf7d7cf6cb9f618a5d7b blob + 9eab390085611afbe1d8be27a1f96798f25041c3 --- telescope.c +++ telescope.c @@ -739,7 +739,24 @@ load_next_page(struct tab *tab) return 1; } +/* + * Free every resource linked to the tab, including the tab itself. + * Removes the tab from the tablist, but doesn't update the + * current_tab though. + */ void +free_tab(struct tab *tab) +{ + stop_tab(tab); + + if (evtimer_pending(&tab->loadingev, NULL)) + evtimer_del(&tab->loadingev); + + TAILQ_REMOVE(&tabshead, tab, tabs); + free(tab); +} + +void stop_tab(struct tab *tab) { ui_send_net(IMSG_STOP, tab->id, NULL, 0); blob - 5ab3f09c94af932d9be2bb9188942c1d0d5923a7 blob + 38aa01a79427614007b2c917e1bb1c9e6497906b --- telescope.h +++ telescope.h @@ -322,6 +322,7 @@ void load_via_proxy(struct tab *, const char *, stru void load_url(struct tab *, const char *, const char *); int load_previous_page(struct tab*); int load_next_page(struct tab*); +void free_tab(struct tab *); void stop_tab(struct tab*); void add_to_bookmarks(const char*); void save_session(void);