Summary Files Commits Branches @commit @diff @stats
path: root / badwolf.c
diff options
context:
space:
mode:
Commit7425c1579beea18aaf5150b0e80f532f35e597d5 (patch)
Author
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2020-07-04 07:15:29 +0200
Committer
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2020-07-08 07:20:54 +0200
Filesb64ab1aaa672ab0f501e22b4406f5290c9181cff /badwolf.c
goodwolf-7425c1579beea18aaf5150b0e80f532f35e597d5.tar
goodwolf-7425c1579beea18aaf5150b0e80f532f35e597d5.tar.gz
goodwolf-7425c1579beea18aaf5150b0e80f532f35e597d5.zip
Parent1d4e9c3d4a22be09c0dbc1bc01e618ce5a394ef3 (diff)
Switch automatically to a tab when user-requested
This changes behavior but doesn't breaks meaning nor documentation and significantly improves usability. So meant to be applied directly into 1.0.x release branch. Closes: https://gitlab.com/lanodan/badWolf/-/issues/8
1 files changed, 12 insertions, 6 deletions
-rw-r--r--badwolf.c18
diff --git a/badwolf.c b/badwolf.c
index d7d1001..184c4a3 100644
--- a/badwolf.c
+++ b/badwolf.c
@@ -286,7 +286,7 @@ WebViewCb_create(WebKitWebView *related_web_view,
struct Window *window = (struct Window *)user_data;
struct Client *browser = new_browser(window, NULL, related_web_view);
- if(badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser) < 0)
+ if(badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser, FALSE) < 0)
return NULL;
else
return browser->webView;
@@ -824,7 +824,8 @@ new_browser(struct Window *window, const gchar *target_url, WebKitWebView *relat
return browser;
}
-/* badwolf_new_tab: Inserts struct Client *browser in GtkNotebook *notebook
+/* badwolf_new_tab: Inserts struct Client *browser in GtkNotebook *notebook
+ * and optionally switches selected tab to it.
*
* returns:
* 0 : Ran successfully
@@ -832,7 +833,7 @@ new_browser(struct Window *window, const gchar *target_url, WebKitWebView *relat
* -2 : browser is NULL
*/
int
-badwolf_new_tab(GtkNotebook *notebook, struct Client *browser)
+badwolf_new_tab(GtkNotebook *notebook, struct Client *browser, bool auto_switch)
{
gint current_page = gtk_notebook_get_current_page(notebook);
gchar *title = _("New tab");
@@ -849,6 +850,11 @@ badwolf_new_tab(GtkNotebook *notebook, struct Client *browser)
gtk_widget_queue_draw(GTK_WIDGET(notebook));
+ if(auto_switch)
+ {
+ gtk_notebook_set_current_page(notebook, gtk_notebook_page_num(notebook, browser->box));
+ }
+
return 0;
}
@@ -859,7 +865,7 @@ new_tabCb_clicked(GtkButton *new_tab, gpointer user_data)
struct Window *window = (struct Window *)user_data;
struct Client *browser = new_browser(window, NULL, NULL);
- badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser);
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser, TRUE);
}
static void
@@ -967,10 +973,10 @@ main(int argc, char *argv[])
gtk_widget_show_all(window->main_window);
if(argc == 1)
- badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL));
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL), FALSE);
else
for(int i = 1; i < argc; ++i)
- badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL));
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL), FALSE);
gtk_notebook_set_current_page(GTK_NOTEBOOK(window->notebook), 1);