commit: d33378425a568cfa421de689cc0ff571b30daf12
parent: f6471bb313fd4ec075d1d4360c33380c0501b741
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 9 Mar 2019 12:21:07 +0100
badwolf.c: simplify code with int badwolf_new_tab()
Diffstat:
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/badwolf.c b/badwolf.c
@@ -42,6 +42,7 @@ static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer u
static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data);
struct Client *new_browser(struct Window *window, gchar *target_url);
void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data);
+int badwolf_new_tab(GtkNotebook *notebook, GtkWidget *box);
int main(int argc, char *argv[]);
static gboolean WebViewCb_close(WebKitWebView *webView, GtkWidget *window)
@@ -148,14 +149,9 @@ static WebKitWebView *WebViewCb_create(WebKitWebView *webView, WebKitNavigationA
struct Window *window = (struct Window *)user_data;
struct Client *browser = new_browser(window, NULL);
- gtk_widget_show_all(browser->box);
-
- if(gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), browser->box, NULL) == -1) {
+ if(badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser->box) < 0) {
return NULL;
} else {
- gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(window->notebook), browser->box, TRUE);
-
- gtk_widget_draw(window->notebook, NULL);
return browser->webView;
}
}
@@ -313,16 +309,28 @@ struct Client *new_browser(struct Window *window, gchar *target_url)
return browser;
}
+int badwolf_new_tab(GtkNotebook *notebook, GtkWidget *box)
+{
+ gtk_widget_show_all(box);
+
+ if(gtk_notebook_append_page(notebook, box, NULL) == -1) {
+ return -1;
+ }
+
+ gtk_notebook_set_tab_reorderable(notebook, box, TRUE);
+
+ gtk_widget_draw(GTK_WIDGET(notebook), NULL);
+
+ return 0;
+}
+
void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data)
{
(void)new_tab;
struct Window *window = (struct Window *)user_data;
struct Client *browser = new_browser(window, NULL);
- gtk_widget_show_all(browser->box);
-
- gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), browser->box, NULL);
- gtk_widget_draw(window->notebook, NULL);
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser->box);
}
int main(int argc, char *argv[])
@@ -342,7 +350,8 @@ int main(int argc, char *argv[])
gtk_notebook_set_scrollable(GTK_NOTEBOOK(window->notebook), TRUE);
gtk_container_add(GTK_CONTAINER(window->main_window), window->notebook);
- gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url)->box, NULL);
+
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url)->box);
g_signal_connect(window->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window->new_tab, "clicked", G_CALLBACK(new_tabCb_clicked), window);