commit: 7425c1579beea18aaf5150b0e80f532f35e597d5
parent 1d4e9c3d4a22be09c0dbc1bc01e618ce5a394ef3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 4 Jul 2020 07:15:29 +0200
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
Diffstat:
4 files changed, 24 insertions(+), 18 deletions(-)
diff --git 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);
diff --git a/badwolf.h b/badwolf.h
@@ -38,6 +38,6 @@ GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser);
void webView_tab_label_change(struct Client *browser, const gchar *title);
struct Client *
new_browser(struct Window *window, const gchar *target_url, WebKitWebView *related_web_view);
-int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser);
+int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser, bool auto_switch);
gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child);
#endif /* BADWOLF_H_INCLUDED */
diff --git a/keybindings.c b/keybindings.c
@@ -14,7 +14,7 @@ about_dialogCb_activate_link(GtkAboutDialog *about_dialog, gchar *uri, gpointer
(void)about_dialog;
struct Window *window = (struct Window *)user_data;
- badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, uri, NULL));
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, uri, NULL), FALSE);
gtk_widget_destroy(GTK_WIDGET(about_dialog));
@@ -112,7 +112,7 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *
{
case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE;
case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE;
- case GDK_KEY_t: badwolf_new_tab(notebook, new_browser(window, NULL, NULL)); return TRUE;
+ case GDK_KEY_t: badwolf_new_tab(notebook, new_browser(window, NULL, NULL), TRUE); return TRUE;
}
}
}
diff --git a/po/messages.pot b/po/messages.pot
@@ -6,9 +6,9 @@
#, fuzzy
msgid ""
msgstr ""
-"Project-Id-Version: Badwolf 1.0.0+g828e2e3.develop\n"
+"Project-Id-Version: Badwolf 1.0.0+g1d4e9c3.0\n"
"Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n"
-"POT-Creation-Date: 2020-06-12 02:16+0200\n"
+"POT-Creation-Date: 2020-07-08 07:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -41,7 +41,7 @@ msgstr ""
msgid "Badwolf Downloads"
msgstr ""
-#: badwolf.c:898
+#: badwolf.c:904
#, c-format
msgid "Buildtime WebKit version: %d.%d.%d\n"
msgstr ""
@@ -100,11 +100,11 @@ msgid ""
"Runtime WebKit version: %d.%d.%d"
msgstr ""
-#: badwolf.c:838
+#: badwolf.c:839
msgid "New tab"
msgstr ""
-#: badwolf.c:947
+#: badwolf.c:953
msgid "Open new tab"
msgstr ""
@@ -112,12 +112,12 @@ msgstr ""
msgid "Out of Memory"
msgstr ""
-#: badwolf.c:896
+#: badwolf.c:902
#, c-format
msgid "Running Badwolf version: %s\n"
msgstr ""
-#: badwolf.c:903
+#: badwolf.c:909
#, c-format
msgid "Runtime WebKit version: %d.%d.%d\n"
msgstr ""
@@ -167,12 +167,12 @@ msgstr ""
msgid "the web process terminated for an unknown reason.\n"
msgstr ""
-#: badwolf.c:910
+#: badwolf.c:916
#, c-format
msgid "webkit-web-extension directory set to: %s\n"
msgstr ""
#. TRANSLATOR Ignore this entry. Done for forcing Unicode in xgettext.
-#: badwolf.c:981
+#: badwolf.c:987
msgid "ΓΈ"
msgstr ""