2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 #include "minibuffer.h"
32 static struct event autosaveev;
35 switch_to_tab(struct tab *tab)
38 tab->flags &= ~TAB_URGENT;
40 if (operating && tab->flags & TAB_LAZY)
41 load_url_in_tab(tab, tab->hist_cur->h, NULL, 0);
47 static uint32_t tab_counter;
53 new_tab(const char *url, const char *base, struct tab *after)
60 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
65 TAILQ_INIT(&tab->hist.head);
67 TAILQ_INIT(&tab->buffer.head);
68 TAILQ_INIT(&tab->buffer.page.head);
70 tab->id = tab_new_id();
72 tab->flags |= TAB_LAZY;
76 TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs);
78 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
80 load_url_in_tab(tab, url, base, 0);
85 * Free every resource linked to the tab, including the tab itself.
86 * Removes the tab from the tablist, but doesn't update the
90 free_tab(struct tab *tab)
96 if (evtimer_pending(&tab->loadingev, NULL))
97 evtimer_del(&tab->loadingev);
99 TAILQ_REMOVE(&tabshead, tab, tabs);
104 stop_tab(struct tab *tab)
106 ui_send_net(IMSG_STOP, tab->id, NULL, 0);
112 struct session_tab st;
118 ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
120 TAILQ_FOREACH(tab, &tabshead, tabs) {
121 memset(&st, 0, sizeof(st));
123 if (tab == current_tab)
124 st.flags = TAB_CURRENT;
126 strlcpy(st.uri, tab->hist_cur->h, sizeof(st.uri));
127 strlcpy(st.title, tab->buffer.page.title, sizeof(st.title));
128 ui_send_fs(IMSG_SESSION_TAB, 0, &st, sizeof(st));
131 ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
137 evtimer_set(&autosaveev, autosave_timer, NULL);
141 autosave_timer(int fd, short event, void *data)
147 * Function to be called in "interesting" places where we may want to
148 * schedule an autosave (like on new tab or before loading an url.)
158 if (!evtimer_pending(&autosaveev, NULL)) {
159 tv.tv_sec = autosave;
162 evtimer_add(&autosaveev, &tv);