Summary Files Commits Branches @commit @diff @stats
path: root / badwolf.c
diff options
context:
space:
mode:
Commiteaf289e8ebb017f7de4081a1564737da044dd341 (patch)
Author
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2020-07-04 07:15:29 +0200
Committer
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2020-07-04 07:16:58 +0200
Files5f7c31453d253b152e8a10fcb12b0b1bd0fba6a8 /badwolf.c
goodwolf-eaf289e8ebb017f7de4081a1564737da044dd341.tar
goodwolf-eaf289e8ebb017f7de4081a1564737da044dd341.tar.gz
goodwolf-eaf289e8ebb017f7de4081a1564737da044dd341.zip
Parente94212d51be4e15e12a67e633baa32f0a0d6273b (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 6bb0470..d3dcde9 100644
--- a/badwolf.c
+++ b/badwolf.c
@@ -300,7 +300,7 @@ WebViewCb_create(WebKitWebView *related_web_view,
browser = new_browser(old_browser->window, NULL, old_browser);
- if(badwolf_new_tab(GTK_NOTEBOOK(old_browser->window->notebook), browser) < 0)
+ if(badwolf_new_tab(GTK_NOTEBOOK(old_browser->window->notebook), browser, FALSE) < 0)
return NULL;
else
return browser->webView;
@@ -839,7 +839,8 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
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
@@ -847,7 +848,7 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
* -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");
@@ -864,6 +865,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;
}
@@ -874,7 +880,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
@@ -982,10 +988,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);